skizzy Posted April 7, 2011 Posted April 7, 2011 ?php include "globals.php"; if($r['itmname'] == 'Weed') { mysql_query("UPDATE users SET brave=brave+10 WHERE userid=$userid",$c); } print "You roll a fat blunt full of {$r['itmname']} and start to hit it. You feel a bit more focused."; $h->endpage(); ?> It wont update the brave in the db that is what my problem is Quote
Redeye Posted April 7, 2011 Posted April 7, 2011 I assume that is <?php at the start rather then ?php Quote
skizzy Posted April 7, 2011 Author Posted April 7, 2011 to answer reeye yeah that is just missed it when i copyed and pasted it and danny there is no error it works fine just wont update the db to make it lets say 15/5 instead of 5/5 Quote
Danny696 Posted April 7, 2011 Posted April 7, 2011 Thats because your updating the brave by 10 only. Quote
Redeye Posted April 7, 2011 Posted April 7, 2011 I see your issue. The second number of the brave indicated the MAX value that the brave can be. You cannot add 10 since the max is only 5 brave (which is why it is 5/5) Quote
skizzy Posted April 7, 2011 Author Posted April 7, 2011 ok so how would i make it do that to make it so it would go 15/5 instead of 5/5 im trying to implement drugs into my game sorta like tcs drug system Quote
Danny696 Posted April 7, 2011 Posted April 7, 2011 Opps, i read your problem wrong. I actually cant see a problem with that script. also, Redeye, your wrong. Just becuase you have a max value (i a diff column) then you shouldnt have a problem. Unless your checking that your not over the max in your script somewhere. Quote
skizzy Posted April 7, 2011 Author Posted April 7, 2011 does mccodes v2 check that somewhere by default because i didnt add anything that checks to see if your over the max im just so confused Quote
Djkanna Posted April 8, 2011 Posted April 8, 2011 I may be wrong, but what you've provided isn't the full script and just an excerpt, if it is the full script, where exactly is $r['itmname'] defined? Quote
skizzy Posted April 8, 2011 Author Posted April 8, 2011 (edited) yeah its no big ill fix that and define it there but as danny had said there is a check to change the vaules back as it is in the cron_fivemins.php $query2="UPDATE users SET brave=maxbrave WHERE brave>maxbrave"; ok so to fix what Dj had said i edit the itemuse.php so i could use it even if a effect wasn't on because the effects don't up date a brave either if i do it that way the stat just wont update in the db know matter what it try Edited April 8, 2011 by skizzy because problem not solved as i thought it was Quote
skizzy Posted April 8, 2011 Author Posted April 8, 2011 if($r['itmname'] == 'Weed') { mysql_query("UPDATE users SET brave=brave+10 WHERE userid=$userid",$c); } print "You roll a fat blunt full of {$r['itmname']} and start to hit it. You feel a bit more focused."; i add this into the itemuse.php as {$r['itmname']} would be defined there and it still dont update the brave Quote
Diesl Posted April 8, 2011 Posted April 8, 2011 Can you post the entire code, as it looks like your if statement is not meeting the conditions, thus not getting to the query. Quote
skizzy Posted April 8, 2011 Author Posted April 8, 2011 <?php include "globals.php"; $_GET['ID'] = abs((int) $_GET['ID']); //Food if(!$_GET['ID']) { print "Invalid use of file"; } else { $i=$db->query("SELECT iv.*,i.*,it.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i.itmid LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid WHERE iv.inv_id={$_GET['ID']} AND iv.inv_userid=$userid"); if(mysql_num_rows($i) == 0) { print "Invalid item ID"; } else { $r=$db->fetch_row($i); if($r['effect1_on']) { $einfo=unserialize($r['effect1']); if($einfo['inc_type']=="percent") { if(in_array($einfo['stat'],array('energy','will','brave','hp'))) { $inc=round($ir['max'.$einfo['stat']]/100*$einfo['inc_amount']); } else { $inc=round($ir[$einfo['stat']]/100*$einfo['inc_amount']); } } else { $inc=$einfo['inc_amount']; } if($einfo['dir']=="pos") { if(in_array($einfo['stat'],array('energy','will','brave','hp'))) { $ir[$einfo['stat']]=min($ir[$einfo['stat']]+$inc, $ir['max'.$einfo['stat']]); } else { $ir[$einfo['stat']]+=$inc; } } else { $ir[$einfo['stat']]=max($ir[$einfo['stat']]-$inc, 0); } $upd=$ir[$einfo['stat']]; if(in_array($einfo['stat'], array('strength', 'agility', 'guard', 'labour', 'IQ'))) { $db->query("UPDATE `userstats` SET {$einfo['stat']} = '{$upd}' WHERE userid={$userid}"); } else { $db->query("UPDATE `users` SET {$einfo['stat']} = '{$upd}' WHERE userid={$userid}"); } } if($r['effect2_on']) { $einfo=unserialize($r['effect2']); if($einfo['inc_type']=="percent") { if(in_array($einfo['stat'],array('energy','will','brave','hp'))) { $inc=round($ir['max'.$einfo['stat']]/100*$einfo['inc_amount']); } else { $inc=round($ir[$einfo['stat']]/100*$einfo['inc_amount']); } } else { $inc=$einfo['inc_amount']; } if($einfo['dir']=="pos") { if(in_array($einfo['stat'],array('energy','will','brave','hp'))) { $ir[$einfo['stat']]=min($ir[$einfo['stat']]+$inc, $ir['max'.$einfo['stat']]); } else { $ir[$einfo['stat']]+=$inc; } } else { $ir[$einfo['stat']]=max($ir[$einfo['stat']]-$inc, 0); } $upd=$ir[$einfo['stat']]; if(in_array($einfo['stat'], array('strength', 'agility', 'guard', 'labour', 'IQ'))) { $db->query("UPDATE `userstats` SET {$einfo['stat']} = '{$upd}' WHERE userid={$userid}"); } else { $db->query("UPDATE `users` SET {$einfo['stat']} = '{$upd}' WHERE userid={$userid}"); } } if($r['effect3_on']) { $einfo=unserialize($r['effect3']); if($einfo['inc_type']=="percent") { if(in_array($einfo['stat'],array('energy','will','brave','hp'))) { $inc=round($ir['max'.$einfo['stat']]/100*$einfo['inc_amount']); } else { $inc=round($ir[$einfo['stat']]/100*$einfo['inc_amount']); } } else { $inc=$einfo['inc_amount']; } if($einfo['dir']=="pos") { if(in_array($einfo['stat'],array('energy','will','brave','hp'))) { $ir[$einfo['stat']]=min($ir[$einfo['stat']]+$inc, $ir['max'.$einfo['stat']]); } else { $ir[$einfo['stat']]+=$inc; } } else { $ir[$einfo['stat']]=max($ir[$einfo['stat']]-$inc, 0); } $upd=$ir[$einfo['stat']]; if(in_array($einfo['stat'], array('strength', 'agility', 'guard', 'labour', 'IQ'))) { $db->query("UPDATE `userstats` SET {$einfo['stat']} = '{$upd}' WHERE userid={$userid}"); } else { $db->query("UPDATE `users` SET {$einfo['stat']} = '{$upd}' WHERE userid={$userid}"); } } print "{$r['itmname']} used successfully!"; item_remove($userid, $r['inv_itemid'], 1); } } if($r['itmname'] == 'Weed') { mysql_query("UPDATE users SET brave=brave+10 WHERE userid=$userid",$c); } print "You roll a fat blunt full of {$r['itmname']} and start to hit it. You feel a bit more focused."; $h->endpage(); ?> here is my entire itemuse.php Quote
rulerofzu Posted April 8, 2011 Posted April 8, 2011 Place your code above the last } so like this and give it a try.... item_remove($userid, $r['inv_itemid'], 1); } if($r['itmname'] == 'Weed') { mysql_query("UPDATE users SET brave=brave+10 WHERE userid=$userid",$c); print "You roll a fat blunt full of {$r['itmname']} and start to hit it. You feel a bit more focused."; } } $h->endpage(); Quote
skizzy Posted April 8, 2011 Author Posted April 8, 2011 it is send to call to the db as it updated my braave but did not make it go above the maxbrave i had 5/9 it updated to 9/9 but i should of had 14/9 Quote
Redeye Posted April 13, 2011 Posted April 13, 2011 it is send to call to the db as it updated my braave but did not make it go above the maxbrave i had 5/9 it updated to 9/9 but i should of had 14/9 Like I said, the brave is being set automatically to the maxbrave $query2="UPDATE users SET brave=maxbrave This changes the brave to the same as the max brave WHERE brave>maxbrave but only when the brave exceeds the max brave like what you said"; Like in that code, you can see that the brave is being set to the maxbrave by the code I bolded (the red tells you what it is doing) Quote
lucky3809 Posted April 13, 2011 Posted April 13, 2011 (edited) dont know if this will work but try... mysql_query('UPDATE `users` SET `brave`=brave + 10 WHERE `brave` > 0'); Edited April 13, 2011 by lucky3809 Quote
Redeye Posted April 13, 2011 Posted April 13, 2011 That would make the WHERE statement useless. You could shorten it to mysql_query(UPDATE users SET brave = brave + 10); I don't know if that is correct syntax since I have only worked with C# in the last 3/4 years (and not much of that lol) Quote
lucky3809 Posted April 13, 2011 Posted April 13, 2011 (edited) mine works i have tested it... Edited April 14, 2011 by lucky3809 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.