SMF Shop
SMFShop => Items => Topic started by: inkstains on March 24, 2007, 02:52:10 pm
-
Basically a user picks what they think they will roll with a six sided dice (giving them a 1 in 6 chance so i'd keep the price low but your choice) and if they are correct they receive a random amount of credits (which you can set when you do item setup) below is the code just save it as Prediction.php
New dice roll animations
Example:
(http://www.nurcharecords.com/forum/Sources/shop/item_images/Roll1.gif)
Link:
http://www.nurcharecords.com/scrawl/Dice_Roll_Animations_01.zip
<?php
class item_Prediction extends itemTemplate {
function getItemDetails() {
$this->authorName = 'Inkstains';
$this->authorWeb = '';
$this->authorEmail = 'inkstains@nurcharecords.com';
$this->name = "Prediction";
$this->desc = "Predict what you will roll with the dice";
$this->price = 10;
$this->require_input = true;
$this->can_use_item = true;
$this->addInput_editable = true;
}
function getAddInput()
{
global $item_info, $db_prefix;
return '<br><b>You must assign a value</b><br>
Minimum amount of credits to give: <input type="text" name="info1" value="' . $item_info[1] . '" /><br />
Maximum amount of credits to give: <input type="text" name="info2" value="' . $item_info[2] . '" /><br />';
}
function getUseInput() {
return 'Select which number you think you will roll: <select name="dieside_" size="1" id="number">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>';
}
function onUse() {
global $db_prefix, $ID_MEMBER, $item_info, $boardurl;
$failedTextArray = array(
"You rolled a %s <br/><br/>The force is weak in this one",
"You rolled a %s <br/><br/>I don't think you'll be opening a psychic hotline any time soon :p");
srand(time());
$value = rand(1, 6);
if($value == $_REQUEST["dieside_"]){
$value1 = rand($item_info[1], $item_info[2]);
db_query("UPDATE {$db_prefix}members SET money = money + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Roll".$value.".gif' align='texttop'/><br><br>Congratulations your prediction was right you rolled a ".$value." and got ".formatMoney($value1)."";
}else
return sprintf($failedTextArray[array_rand($failedTextArray)], $value);
}
}
?>
enjoy
updated Oct 08 2007
thanks to feeble for the condensed code.
-
NEAT!! I tested this out on my forum, and no errors what-so-ever, it seemed to work perfectly!
-
This is great I added it and tested, no problems..
I set the buy price for 200, but if you win you win anywhere from 300-1000, this should get people posting more on my forum.....They seeem to like the idea of gettin free money....
-
glad to hear it O0
-
hi inkstains
I just installed this to play with it, and it works but where do the dice animations show up - the ones in the zip that are numbered 1-6. I didnt see any when I used my item. Am I supposed to put them elsewhere?
I put them in the item images folder
-
yeh that's where they go but the animations only display if you win
-
lol I see hehehe
-
Sadly I've found a bug...I suspect it's to do with php 5.2.1...
8: Undefined variable: rollIs
File: /home/****/smf_clean_install/Sources/shop/items/Prediction.php
Line: 106
This is one example but each instance of rollIs generates the same problem (Undefined variable: rollIs)...i.e. whenever the user guesses correctly the dice roll number.
I hope you can help.
Thanks.
-
Very useful inkstains!
-
very good item, thanks.
-
The item works, but no animations show up when your roll?
-
Actually when you get it right it shows the animation, but otherwise no.
-
Hmm.. I've done everything it says to, and I haven't edited anything and it says this when I try to add the item: ERROR: Could not create instance of 'Predictions' item!
help?
-
Hmm.. I've done everything it says to, and I haven't edited anything and it says this when I try to add the item: ERROR: Could not create instance of 'Predictions' item!
help?
i'd say it's because the item file isn't named properly. it should be
Prediction.php
so check the file name and let me know.
-
Cool item! :D
However, I had a similar problem to David:
"http://www.********/forum/index.php?action=shop;do=inv3;id=454
8: Undefined variable: rollIs
File: /************/htdocs/forum/Sources/shop/items/prediction.php
Line: 61"
Nothing appeared to go wrong but it logged an error :S
It happened after guessing correctly :P (In this case a "1")
Just wondering if you have any ideas on what caused it and how to fix it? :)
Thanks for the great item! =D
-
@ lelekins
Just to see if I might be right...would you please be so kind as to supply us with your php version details? If it turns out to be php 5.x then we may have confirmed my earlier guess.
-
Aw sorry - mine is 4.4.7
=P
-
We will have to wait for inkstains to give some guidance though it does look to be some sort of server configuration issue as I've had it work properly on other servers.
-
use this code instead fellas
<?php
class item_Prediction extends itemTemplate {
function getItemDetails() {
$this->authorName = 'Inkstains';
$this->authorWeb = '';
$this->authorEmail = 'inkstains@nurcharecords.com';
$this->name = "Prediction";
$this->desc = "Predict what you will roll with the dice";
$this->price = 10;
$this->require_input = true;
$this->can_use_item = true;
$this->addInput_editable = true;
}
function getAddInput()
{
global $item_info, $db_prefix;
return '<br><b>You must assign a value to each</b><br>
Minimum amount of credits to give: <input type="text" name="info1" value="' . $item_info[1] . '" /><br />
Maximum amount of credits to give: <input type="text" name="info2" value="' . $item_info[2] . '" /><br />';
}
function getUseInput() {
return 'Select which number you think you will roll: <select name="dieside_" size="1" id="number">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>';
}
function onUse() {
global $db_prefix, $ID_MEMBER, $item_info, $boardurl, $txt, $scripturl;
$value = mt_rand(1, 6);
if ($value == 1) {
if ($_REQUEST["dieside_"] == $value)
{ $value1 = mt_rand($item_info[1], $item_info[2]);
$result = db_query("UPDATE {$db_prefix}members SET money = money + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Roll1.gif' align='texttop'/><br><br>Congratulations your prediction was right you rolled a 1 and got ".formatMoney($value1)."";
}
else
{return "You rolled a $value <br><br>The force is weak in this one";}
}
elseif ($value == 2) {
if ($_REQUEST["dieside_"] == $value)
{ $value1 = mt_rand($item_info[1], $item_info[2]);
$result = db_query("UPDATE {$db_prefix}members SET money = money + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Roll2.gif' align='texttop'/><br><br>Congratulations your prediction was right you rolled a 2 and got ".formatMoney($value1)."";
}
else
{return "You rolled a $value <br><br>I don't think you'll be opening a psychic hotline any time soon :p";}
}
elseif ($value == 3) {
if ($_REQUEST["dieside_"] == $value)
{ $value1 = mt_rand($item_info[1], $item_info[2]);
$result = db_query("UPDATE {$db_prefix}members SET money = money + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Roll3.gif' align='texttop'/><br><br>Congratulations your prediction was right you rolled a 3 and got ".formatMoney($value1)."";
}
else
{return "You rolled a $value <br><br>I predicted you would fail you must meditate and focus your mind";}
}
elseif ($value == 4) {
if ($_REQUEST["dieside_"] == $value)
{ $value1 = mt_rand($item_info[1], $item_info[2]);
$result = db_query("UPDATE {$db_prefix}members SET money = money + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Roll4.gif' align='texttop'/><br><br>Congratulations your prediction was right you rolled a 4 and got ".formatMoney($value1)."";
}
else
{return "You rolled a $value <br><br>Duh!";}
}
elseif ($value == 5) {
if ($_REQUEST["dieside_"] == $value)
{ $value1 = mt_rand($item_info[1], $item_info[2]);
$result = db_query("UPDATE {$db_prefix}members SET money = money + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Roll5.gif' align='texttop'/><br><br>Congratulations your prediction was right you rolled a 5 and got ".formatMoney($value1)."";
}
else
{return "You rolled a $value <br><br>I don't think you'll be opening a psychic hotline any time soon :p";}
}
elseif ($value == 6) {
if ($_REQUEST["dieside_"] == $value)
{ $value1 = mt_rand($item_info[1], $item_info[2]);
$result = db_query("UPDATE {$db_prefix}members SET money = money + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Roll6.gif' align='texttop'/><br><br>Congratulations your prediction was right you rolled a 6 and got ".formatMoney($value1)."";
}
else
{return "You rolled a $value <br><br>Try calling 1900-YOUR-NO-PSYCHIC for the answer :p";}
}
}
}
?>
also code updated in first post
-
Thanks! Tested and no errors found.
-
O0
-
nice work again with this item inkstain
small suggestion for your prediction item
function onUse() {
global $db_prefix, $ID_MEMBER, $item_info, $boardurl;
$failedTextArray = array(
"You rolled a %s <br/><br/>The force is weak in this one",
"You rolled a %s <br/><br/>I don't think you'll be opening a psychic hotline any time soon :p");
srand(time());
$value = rand(1, 6);
if($value == $_REQUEST["dieside_"]){
$value1 = rand($item_info[1], $item_info[2]);
db_query("UPDATE {$db_prefix}members SET money = money + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Roll".$value.".gif' align='texttop'/><br><br>Congratulations your prediction was right you rolled a ".$value." and got ".formatMoney($value1)."";
}else
return sprintf($failedTextArray[array_rand($failedTextArray)], $value);
}
-
it's pretty old but cheers feeble O0
edit: when ya gonna finish that topic rating mod
me wants ;D
-
Aw fantastic! :D It's working fine now :)
Thank you!
-
updated roll/item images in the first post as well as updated code.