Jump to content
MakeWebGames

Recommended Posts

Posted

Hey, I have tried a couple bits of code for this but can't seem to nail it. I even went for search on the forums and can't seem to find anything unless I am not using the right search words.

What I am trying to achieve is that I have an item and it increases energy and decreases health each time you use it. What happens is that when you hit 0 energy, you can keep using the item to your hearts content without fear of going to hospital. What I am after is the three/four lines of code that will send the user to hospital when the enrgy hits 0. I would have thought the code would look something like this and please correct where i am wrong

If ($ir['hp'] <= 0)

{

$hosptime=rand(5,20);

die("

You have over done it and need to spend some time in hospital");

$db->query("UPDATE users SET hp=1,hospital=$hosptime,hospreason='over cooking it' WHERE userid=$userid");

}

Posted

Re: V2 Code Help

lol i did it. What a lamo!!!

What I did was went to the street code looked at what that was for hospital and changed the reasons and gave it a test. So if anyone else has the same issue, have a look at your codes like this one:

if ($ir['hp'] <= 0) {

$hosptime=(int) rand(1,20);

$loseruser = $ir['userid'];

$reasonhosp = 'Over cooking it.';

$db->query("UPDATE users SET hospital=$hosptime WHERE userid=$loseruser",$c);

$db->query("UPDATE users SET hospreason='$reasonhosp' WHERE userid=$loseruser",$c);

event_add($ir['userid'],"Did you have a good time doing it!",$c);

die ("WOW, you know how to go too far!! Your off to the hospital for $hosptime ");

}

Posted

Re: V2 Code Help

Good deal.

You might want to note that in the first post, you had a database query after the die.

 

die("

You have over done it and need to spend some time in hospital");
$db->query("UPDATE users SET hp=1,hospital=$hosptime,hospreason='over cooking it' WHERE userid=$userid");

 

That query wouldn't ever run since it's right after the die. ;)

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