thedestroyer Posted January 16, 2010 Posted January 16, 2010 Hi basically with the attack system i use it takes 50% of your energy when attacking a player but i want it so that for donators it takes a value of 6 energy instead of a percentage. I need it added somewhere in here whne the player picks their next weapon to attack with if anyone could help that would be great thanks. if($_GET['wepid']) { if($_SESSION['attacking']==0 && $ir['attacking'] == 0) { if ($youdata['energy'] >= $youdata['maxenergy']/2) { $youdata['energy']-= floor($youdata['maxenergy']/2); $me=floor($youdata['maxenergy']/2); $db->query("UPDATE users SET energy=energy- {$me} WHERE userid=$userid"); $_SESSION['attacklog']=""; $_SESSION['attackdmg']=0; } else { print "You can only attack someone when you have 50% energy"; $h->endpage(); exit; Quote
AlabamaHit Posted January 17, 2010 Posted January 17, 2010 So you want 50% for non-donators and a "value" of 6 for donators? if($_GET['wepid']) { if($_SESSION['attacking']==0 && $ir['attacking'] == 0) { $energy_cost = $ir['donatordays'] == 0 ? $youdata['maxenergy'] / 2 : '6'; if ($youdata['energy'] >= $energy_cost) { $energy_cost = floor($energy_cost); $db->query("UPDATE users SET energy=energy - {$energy_cost} WHERE userid=$userid"); $_SESSION['attacklog']=""; $_SESSION['attackdmg']=0; } else { print "You can only attack someone when you have 50% energy"; $h->endpage(); exit; This is not a complete work over jsut a quick thing that should it work. Quote
thedestroyer Posted January 17, 2010 Author Posted January 17, 2010 So you want 50% for non-donators and a "value" of 6 for donators? if($_GET['wepid']) { if($_SESSION['attacking']==0 && $ir['attacking'] == 0) { $energy_cost = $ir['donatordays'] == 0 ? $youdata['maxenergy'] / 2 : '6'; if ($youdata['energy'] >= $energy_cost) { $energy_cost = floor($energy_cost); $db->query("UPDATE users SET energy=energy - {$energy_cost} WHERE userid=$userid"); $_SESSION['attacklog']=""; $_SESSION['attackdmg']=0; } else { print "You can only attack someone when you have 50% energy"; $h->endpage(); exit; This is not a complete work over jsut a quick thing that should it work. You sure this will work? Sorry for saying this but it doesnt look like it makes sense ?( Quote
rulerofzu Posted January 17, 2010 Posted January 17, 2010 It does make sense. $energy_cost = $ir['donatordays'] == 0 ? $youdata['maxenergy'] / 2 : '6'; Is asking.... does the player have donator days if 0 days divide the energy by 2 (50%) else set the value as 6 which is what you asked for isnt it? Quote
thedestroyer Posted January 17, 2010 Author Posted January 17, 2010 It does make sense. $energy_cost = $ir['donatordays'] == 0 ? $youdata['maxenergy'] / 2 : '6'; Is asking.... does the player have donator days if 0 days divide the energy by 2 (50%) else set the value as 6 which is what you asked for isnt it? Ok its just i have never seen a formula like that thats why i wasnt sure thanks. Quote
AlabamaHit Posted January 18, 2010 Posted January 18, 2010 lol, just cause it don't make sense don't mean it won't work. lol But really I have not tested that., You should try it on a test site first. but I think it should work. Quote
Zero-Affect Posted January 18, 2010 Posted January 18, 2010 Yeah the ternary operator is confusing as people seem to misunderstand it, it is very straight forward but many people on here probably didn't even know the name till just now (they won't abit that) but it's true most of them learn stuff from others IE ternary operator from lostone's codes. but yeah Alabama looks good mate. Quote
rulerofzu Posted January 18, 2010 Posted January 18, 2010 Its called what???? I thought it was the PHP question mark function 8| Quote
AlabamaHit Posted January 18, 2010 Posted January 18, 2010 It's what Crimegame.com said. (Zero right?) http://en.wikipedia.org/wiki/Ternary_operation Their is a link to it. Quote
Zero-Affect Posted January 18, 2010 Posted January 18, 2010 or if people actually went to php.net they could of read what i did like 9 month ago language.operators.comparison Quote
iSOS Posted January 18, 2010 Posted January 18, 2010 Just so people know, there is no benefit nor disadvantage to using the ternary operator, simply preference, readability vs less lines lol Quote
Zero-Affect Posted January 19, 2010 Posted January 19, 2010 Oh yeah basically it's a short version of IF-ELSE 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.