Nicholas Posted January 2, 2010 Posted January 2, 2010 hi... im wondering could anyone fix it for me? im trying to make it so say that the players get the $chance 1 (shown below the coding) in my streets which makes you lose money. but then they could go into say $-56 im wondering... can anyone fix this part the script below so it doesnt make their money go into $-1 or lower? it just automaticly goes to $0 not $-1 or lower. hopefully you know what im talking about :) if ($chance == 1) { $amnt=rand(1,125); if($ir['money'] > $amnt) { print "As you search the streets you see <font color=blue>Nickizzle</font>; he asks you for $$amnt and you tell him to piss off. Then he proceeds to smack the hell out of you. He takes the $$amnt anyway. "; $db->query("UPDATE users SET money=money-$amnt where userid=$userid",$c); $ir['money']-=$amnt; } else { print "As you walk the streets you see <font color=blue>Nickizzle</font> he asks you for $$amnt and you tell him to go away! so <font color=blue>Nickizzle</font> smacks you over the head and looks in your wallet. Finding it almost empty and just walks off with your wallet. "; $db->query("UPDATE users SET money=money-$amnt where userid=$userid",$c); } } ive tried changing $db->query("UPDATE users SET money=money-$amnt where userid=$userid",$c); into $db->query("UPDATE users SET money=money-$amnt > 0 where userid=$userid",$c); but when the players got the money taking chance it put there money onto $1 no matter how much money they got in hand. but if i changed it to this $db->query("UPDATE users SET money=money-$amnt where userid=$userid",$c); into $db->query("UPDATE users SET money=money-$amnt where userid=$userid >0",$c); just got a sql error when you came upto that chance. Quote
Guest Null Posted January 2, 2010 Posted January 2, 2010 hmm... if($ir['money'] <=0){ $db->query("UPDATE users SET money=0 WHERE userid=$userid",$c); } .. im not exactly sure about that but its worth a try. tell me how that works out for you Quote
Guest Null Posted January 2, 2010 Posted January 2, 2010 hmm..sorry. Im not real good at negatives. Quote
wolfe Posted January 2, 2010 Posted January 2, 2010 If money on hand is not greater than or equal to the amount needed then take what is in the wallet. So you want to make it money = 0 instead of money = money = $amnt Quote
Nicholas Posted January 2, 2010 Author Posted January 2, 2010 could you by any chance put the correct coding into the part of the script i put up top please to stop it? Quote
Guest Null Posted January 2, 2010 Posted January 2, 2010 add this and it should work. hopefully lol... if(0 < $ir['money']){$db->query("UPDATE users SET money=0 where userid=$userid");} Quote
Dayo Posted January 2, 2010 Posted January 2, 2010 if ($chance == 1) { $amnt=rand(1,125); if($ir['money'] > $amnt) { print "As you search the streets you see <font color=blue>Nickizzle</font>; he asks you for $$amnt and you tell him to piss off. Then he proceeds to smack the hell out of you. He takes the $$amnt anyway. "; $db->query("UPDATE users SET money=money-$amnt where userid=$userid",$c); $ir['money']-=$amnt; } else { print "As you walk the streets you see <font color=blue>Nickizzle</font> he asks you for $$amnt and you tell him to go away! so <font color=blue>Nickizzle</font> smacks you over the head and looks in your wallet. Finding it almost empty and just walks off with your wallet. "; if ($ir['money'] < $amnt) { $db->query("UPDATE users SET money='0' where userid=$userid",$c); } else { $db->query("UPDATE users SET money=money-$amnt where userid=$userid",$c);} } } this will check if $amnt is grater then money if so it will make money 0 if not it will subtract $amnt please note this is not tested Quote
Nicholas Posted January 2, 2010 Author Posted January 2, 2010 i think that worked :) thanks Dayo. Quote
Danny696 Posted January 2, 2010 Posted January 2, 2010 Dayo, the 0 in the query, doesnt have to have ' & ' around it as its a number, not a string. Quote
wolfe Posted January 3, 2010 Posted January 3, 2010 if ($chance == 1) { $amnt=rand(1,125); if($ir['money'] > $amnt) { print "As you search the streets you see Nickizzle; he asks you for $amnt and you tell him to piss off. Then he proceeds to smack the hell out of you. He takes the $amnt anyway."; $db->query("UPDATE users SET money=money-$amnt where userid=$userid",$c); $ir['money']-=$amnt; } else { print "As you walk the streets you see Nickizzle he asks you for $amnt and you tell him to go away! so Nickizzle smacks you over the head and looks in your wallet. Finding it almost empty and just walks off with your wallet."; $db->query("UPDATE users SET money=0 where userid=$userid",$c); $ir['money']=0; } } This would also work i believe, and would eliminate a few extra lines. Quote
Danny696 Posted January 3, 2010 Posted January 3, 2010 Oh, and for the $db->query, theres no need for the $c, because its already done in the database ;) Quote
Zero-Affect Posted January 3, 2010 Posted January 3, 2010 if ( $chance == 1 ) { $amnt = mt_rand(1,125); if($ir['money'] > $amnt) { echo ' As you search the streets you see Nickizzle, he asks you for '.$amnt.' and you tell him to piss off. Then he proceeds to smack the hell out of you. He takes the '.$amnt.' anyway. '; $db->query("UPDATE `users` SET `money` = `money` - $amnt WHERE `userid` = $userid"); $ir['money']-=$amnt; } else { echo ' As you walk the streets you see Nickizzle he asks you for '.$amnt.' and you tell him to go away! so Nickizzle smacks you over the head and looks in your wallet. Finding it almost empty and just walks off with your wallet. '; $db->query("UPDATE `users` SET `money` = 0 WHERE `userid` = $userid"); $ir['money']=0; } } Quote
Guest Null Posted January 3, 2010 Posted January 3, 2010 Would abs(intval($ir['money'])) work for this, or is that just for $_GET and $_POST variables? like... if(!abs(intval($ir['money']))) { mysql_query("UPDATE `users` SET `money`=0 WHERE `userid`=$userid"); } Note: i use mysql_query because i perfer it, and because i do more than code for mccodes Quote
Magictallguy Posted January 13, 2010 Posted January 13, 2010 Using abs() and intval() on a number that's been extracted from the database is pointless. Unless you've edited the number in some way - i.e. user input - then there is no need for the extra code. if(!$ir['money']) { $db->query("UPDATE users SET money = 0 WHERE userid = ".$userid); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.