SMF Shop
SMFShop => Items => Topic started by: inkstains on March 23, 2007, 12:33:20 am
-
code updated 28-09-07
This is based on a idea by GhostWriter http://www.daniel15.com/forum/index.php/topic,703.0.html
I'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.zip
It 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?
-
also can anyone recommend some good php tutorial sites?
-
http://www.w3schools.com/php/default.asp
-
That works great...I installed it and everythingf is fine wit it. I do like the idea about the flipping of the card..
NOW, I need to really learn PHP...
-
http://www.w3schools.com/php/default.asp
Thanks Basil Beard
That works great...I installed it and everythingf is fine wit it. I do like the idea about the flipping of the card..
NOW, I need to really learn PHP...
Yeh i would have liked to have done it that way as well but a bit beyond me for the moment, maybe someone else will offer it up.
-
First off, i like how you incorporated how the admin can modify how much karma, credit and so on will be effected. As for me i hate it when it affects the karma, because thats not what karma is all about. So i like that feature. My only question is what in the world is the probability set at?
I assume and figured out... getting the joker is bad! because out of 5 tries i got the joker 4 times and then i get the king and get a measly 10 credits? ha ha.
-
First off, i like how you incorporated how the admin can modify how much karma, credit and so on will be effected. As for me i hate it when it affects the karma, because thats not what karma is all about. So i like that feature. My only question is what in the world is the probability set at?
I assume and figured out... getting the joker is bad! because out of 5 tries i got the joker 4 times and then i get the king and get a measly 10 credits? ha ha.
you mean whats the probability of getting a king over a queen and a jack over a joker etc? it's based on a generated random number which is assigned to an outcome none of the numbers have a higher probability of being chosen than others it's just random. but that'd be good to add, though i'm not sure how it would be done but i'll look into it.
anyone wanna add a suggestion on how to do that?
-
well, whats the point of the game? to get anything but the joker?
maybe im misunderstanding the intent of the game.
-
i guess it's basically a game of chance. the cards are basically irrelevant but were included in GhostWriters idea and so were included in the item (though you could use it without them or with something different) it'd be good to do an interactive animated version as i was saying earlier in this thread but is a bit beyond my abilities at the moment (but i've come up with some ideas on how to do it) someone else may offer something like that up. I just sorta did this as practice i'm still learning php so seemed like something interesting to learn from coding.
-
oh yeah. its pretty neat. dont get me wrong there. I think its cool. Im guessing though since i only allowed credits affected, that only the ace or the king will do anything, and the joker. the queen and jack wouldnt do anything as i didnt put anything in for karma or post count.
keep it up. good job.
-
yeh i never really thought of that i just tested that and i get an error if anything but a card that corresponds to credits comes up. i guess the easiest thing to do is state all sections must be assigned a value or else remove what you don't want to use from the code. i will try and add some error handling for this soon though.
oh yeah. its pretty neat. dont get me wrong there. I think its cool. Im guessing though since i only allowed credits affected, that only the ace or the king will do anything, and the joker. the queen and jack wouldnt do anything as i didnt put anything in for karma or post count.
keep it up. good job.
and yeh whatever cards don't correspond to the settings you've made they will not do anything
but by only using the credits you are pretty much better off just using the random credits item as that does exactly what you want.
-
code removed check first post
-
I tested this on my forum, and so far everything seems to be working perfectly!! Awesome little item, I'm sure my members will love it!!
-
Ive tried this and shows an error every time the item is used?!
Undefined variable: cardIs
File: \Sources\shop\items\Cards.php
Line: 102
-
Ive tried this and shows an error every time the item is used?!
Undefined variable: cardIs
File: \Sources\shop\items\Cards.php
Line: 102
I'll have a look at that when i get home Max couldn't say why it's doing that at the moment
what version of shop and smf are you running? just in case
though i think i might have just missed an declaration though i've had no problems and nobody else has as far as i know
-
what version of shop and smf are you running? just in case
SMF 1.1.2... Latest version of SMF Shop. 3.0 (Build 12)
Also 'decreased your time online' dosent work either with the joker!
-
that should work umm which code did you use? make sure to use the latest code in the latest post http://www.daniel15.com/forum/index.php/topic,709.msg3843.html#msg3843
-
Database Error
Please try again. If you come back to this error screen, report the error to an administrator.
I bought a CARD on my inventory to try my luck .. but that message showed.
-
This installed fine but when I went to use my item, I got this
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ID_MEMBER = 1' at line 1
File: /home/content/t/h/e/thegame212/html/board/Sources/shop/items/Cards.php
Line: 109
Here is the code on that line
$result = db_query("UPDATE {$db_prefix}members SET totalTimeLoggedIn = totalTimeLoggedIn - {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
EDIT: Sorry, I figured it out. :)
-
Database Error
Please try again. If you come back to this error screen, report the error to an administrator.
I bought a CARD on my inventory to try my luck .. but that message showed.
i believe thats an issue with your database not the card item can you confirm?
This installed fine but when I went to use my item, I got this
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ID_MEMBER = 1' at line 1
File: /home/content/t/h/e/thegame212/html/board/Sources/shop/items/Cards.php
Line: 109
Here is the code on that line
$result = db_query("UPDATE {$db_prefix}members SET totalTimeLoggedIn = totalTimeLoggedIn - {$value1} WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
EDIT: Sorry, I figured it out. :)
what was the answer?
-
It was an interferring mod. I didn't need that mod anyways as it was just a test so I uninstalled it.
-
For future reference what was the mod?
-
Oops, thought I posted that..It was the
Users Online Today Mod 1.4.0
-
I have that mod installed too but mine is giving me no problems with this item :)
-
Yeah, not sure, I just did a fresh install of everything and all is well now.
-
I used this item today and got an error in the log:
8: Undefined variable: cardIs
File: /home/*****/public_html/forum/Sources/shop/items/Cards.php
Line: 102
I got a joker if that helps, seemed to work properly, but just noticed the error
-
Nice item...
-
Whats wrong with the code since we cant use it?
-
When you use the item it says "This item requires further input. Please complete the fields below, and then press "Use Item" and there is another use button, and you have to press that for it to work.
-
When you install the item in the shop admin you should fill in some data fields...the error you are discussing is there because you installed the item with those fields empty. You might be able to edit the item and add the missing data via the shop admin...I haven't tried it with this particular item...or you might have to delete it then add it again this time filling in the data fields.