code updated 28-09-07
This is based on a idea by GhostWriter
http://www.daniel15.com/forum/index.php/topic,703.0.htmlI've tested as best i can but if you have any problems let me know also if any of the code can be done in a better way (especially the image stuff) please tell me as i'm still learning php also i think i would need some error catching on the remove credits code in case the user has no credits but i'm not sure how i would do that any recommendations would be appreciated.
save this file as Cards.php and upload to you shops item directory
<?php
if (!defined('SMF'))
die('Hacking attempt...');
class item_Cards extends itemTemplate
{
function getItemDetails()
{
$this->authorName = 'Inkstains';
$this->authorWeb = '';
$this->authorEmail = 'inkstains@nurcharecords.com';
$this->name = 'Cards';
$this->desc = 'Try your luck and win. Karma, Credits and more up for grabs, but dont cry if you get burnt.';
$this->price = 100;
$this->require_input = false;
$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 card</b><br>
Ace/Joker Maximum amount to increase/decrease post count by: <input type="text" name="info1" value="' . $item_info[1] . '" /><br />
King/Joker Maximum amount to increase/decrease credits by: <input type="text" name="info2" value="' . $item_info[2] . '" /><br />
Queen/Joker Maximum amount to increase/decrease karma by: <input type="text" name="info3" value="' . $item_info[3] . '" /><br />
Jack/Joker Maximum amount to increase/decrease time online by: <input type="text" name="info4" value="' . $item_info[4] . '" /><br />';
}
function onUse()
{
global $db_prefix, $ID_MEMBER, $item_info, $settings, $context, $boardurl, $txt, $scripturl;
$value = mt_rand(1, 8);
if ($value == 1) {
if ($item_info[1] == 0)
{return "All cards must be assigned a value please edit item settings";
die();}
else{ $value1 = mt_rand(0, $item_info[1]);
$result = db_query("UPDATE {$db_prefix}members SET posts = posts + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Cards_ace_d.gif' align='texttop'/><br><br>You got an Ace and increased your post count by ". ($value1) ."";
}}
elseif ($value == 2) {
if ($item_info[2] == 0)
{return "All cards must be assigned a value please edit item settings";
die();}
else{ $value1 = mt_rand(0, $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/Cards_king_d.gif' align='texttop'/><br><br>You got a King and gained ". formatMoney($value1) ."";
}}
elseif ($value == 3) {
if ($item_info[3] == 0)
{return "All cards must be assigned a value please edit item settings";
die();}
else{ $value1 = mt_rand(0, $item_info[3]);
$result = db_query("UPDATE {$db_prefix}members SET karmaGood = karmaGood + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Cards_queen_d.gif' align='texttop'/><br><br>You got a Queen and increased you karma by ". ($value1) ."";
}}
elseif ($value == 4) {
if ($item_info[4] == 0)
{return "All cards must be assigned a value please edit item settings";
die();}
else{ $value1 = mt_rand(0, $item_info[4]);
$result = db_query("UPDATE {$db_prefix}members SET totalTimeLoggedIn = totalTimeLoggedIn + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Cards_jack_d.gif' align='texttop'/><br><br>You got a Jack and increased your time online by ". ($value1) ."";
}}
elseif ($value == 5) {
if ($item_info[1] == 0)
{return "All cards must be assigned a value please edit item settings";
die();}
else{ $value1 = mt_rand(0, $item_info[1]);
$result = db_query("UPDATE {$db_prefix}members SET posts = posts - {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Cards_joker_d.gif' align='texttop'/><br><br>You got a Joker!! and decreased your post count by ". ($value1) ."";
}}
elseif ($value == 6) {
if ($item_info[2] == 0)
{return "All cards must be assigned a value please edit item settings";
die();}
else{ $value1 = mt_rand(0, $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/Cards_joker_d.gif' align='texttop'/><br><br>You got a Joker!! and lost ". formatMoney($value1) ."";
}}
elseif ($value == 7) {
if ($item_info[3] == 0)
{return "All cards must be assigned a value please edit item settings";
die();}
else{ $value1 = mt_rand(0, $item_info[3]);
$result = db_query("UPDATE {$db_prefix}members SET karmaBad = karmaBad + {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Cards_joker_d.gif' align='texttop'/><br><br>You got a Joker!! and decreased your karma by ". ($value1) ."";
}}
elseif ($value == 8) {
if ($item_info[4] == 0)
{return "All cards must be assigned a value please edit item settings";
die();}
else{ $value1 = mt_rand(0, $item_info[4]);
$result = db_query("UPDATE {$db_prefix}members SET totalTimeLoggedIn = totalTimeLoggedIn - {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
return "<img src='".$boardurl."/Sources/shop/item_images/Cards_joker_d.gif' align='texttop'/><br><br>You got a Joker!! and decreased your time online by ". ($value1) ."";
}}
}
}
?>
I've included the images for this item as a zip just extract and upload them to your shops item_images folder all images have transparent backgrounds so they should be cool on any theme
http://www.nurcharecords.com/scrawl/Cards_images.zipIt would be cool to be able to do an interface for this where it shows the back of the card on getUseInput and when the user clicks on it it flips to reveal what they got. i don't know if that would be possible and is probably a little to advanced for me but does anyone know if it's possible?