Jump to content
MakeWebGames

Stop morphine use in a fight. Please hlep with my code


Hendrickson

Recommended Posts

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 by Hendrickson
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...