Jump to content
MakeWebGames

Recommended Posts

Posted

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.

Posted

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

Posted

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

Posted

add this and it should work. hopefully lol...

 

if(0 < $ir['money']){$db->query("UPDATE users SET money=0 where userid=$userid");}
Posted

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

Posted
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.
Posted
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; 
}
}
Posted

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

  • 2 weeks later...
Posted

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);
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...