Hendrickson Posted November 15, 2011 Share Posted November 15, 2011 (edited) OK so I'm trying to code in a small edit that will check if a player is attacking. And if so, Make them loose if they go to their inventory. Often players play unfair and take morphine to boost health and win. Where the other player can't. I'm sure others will want this small mod. So far I've come up with: if($_SESSION['attacking']=0) { print "You lost the fight you were just in! Only losers try take morphine during a fight. Next time fight fair!<br />"; print "You lost to {$r['username']}"; $expgain=abs(($ir['level']-$r['level'])^3); $expgainp=$expgain/$ir['exp_needed']*100; print " and lost $expgainp% EXP!"; $db->query("UPDATE users SET exp=exp-$expgain, attacking=0 WHERE userid=$userid"); $db->query("UPDATE users SET exp=0 WHERE exp<0"); $db->query("UPDATE users SET hospital=5, hospreason='Tried to take morphine in a fight.'"); } But its not working....Where am I going wrong here? (As you can tell i'm learning php) I think the if($_SESSION['attacking']=0) is where I'm going wrong. Edited November 15, 2011 by Hendrickson Quote Link to comment Share on other sites More sharing options...
Uridium Posted November 15, 2011 Share Posted November 15, 2011 Easiest way would be to stop users from re-directing to any page thus putting them back in the fight.... Quote Link to comment Share on other sites More sharing options...
Hendrickson Posted November 16, 2011 Author Share Posted November 16, 2011 Ok how exactly does one go about that? Quote Link to comment Share on other sites More sharing options...
Uridium Posted November 16, 2011 Share Posted November 16, 2011 create 2 new entries in the users call it attsave and attrem ALTER TABLE users ADD attsave INT(11) NOT NULL default 0; ALTER TABLE users ADD attrem INT(11) NOT NULL default 0; Now in your attack.php add $db->query("UPDATE users SET attsave=0,attrem=0 WHERE userid=$userid"); to place where if a user cant fight for example they are in hosp or jail or low on energy or no weapon equipped or anywhere where the user needs to leave the page for example print "WTF you doing, bro?"; $db->query("UPDATE users SET attsave=0, attrem=0 WHERE userid=$userid"); // new entry print "<a href='index.php'> Leave here</a>"; $h->endpage(); exit; } now open header.php and get rid of the part that says you ran from the fight.. and add if($ir['attsave'] == 1 ) { die("<h1>Attack Count ERROR!</h1></h2>Your in a fight you cant just leave ?<br/><br/><b><a href='attack.php?ID={$ir['attrem']}'><br />Rejoin Fight!</a></b>"); } Quote Link to comment Share on other sites More sharing options...
Djkanna Posted November 16, 2011 Share Posted November 16, 2011 Somewhat believe this way would be simplier. <?php /* Check to see if there's a attacking session set: (I believe in one of the secondary attack files the session is then unset not sure though.) Check that the page they're accessing isn't one of the attack files. (again names not my strongest suit you may have to change them in the array.) If they're currently in an attack, and try to access a page that isn't within that array, give them the error message. */ if (isset ($_SESSION['attacking']) && !in_array ($_SERVER['PHP_SELF'], array ('/attack.php', '/attackwon.php', 'attacklost.php'))) { echo '<p>Sorry but this page cannot be accessed whilst in a battle.</p>'; $this->endpage(); exit; } The userdata function below fed jail checks in header, I believe would be an appropriate place to put it. *Read the comments within the file, as I really don't recall what MCCodes does in this situation. Quote Link to comment Share on other sites More sharing options...
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.