Need help this this /hptest
#1

I'm working on a command for admins called /hptest. Once typed it will send a client message saying "Current HP: 100" then minus hp by 2, then wait 1 second, then "New Hp: 98"

Although it doesn't do that, it does this

Current HP: 100
(Waits one second)
New Hp: 100

But then I check my hp and it says I have 98, and my health bar had gone down but it thought my hp was 100.


Код:
  			if(IsPlayerConnected(pid))
			{
				new Float:Health;
                new Float:Health2;
				GetPlayerHealth(pid,Health);
				format(message,128,"Current HP: %f",Health);
				SendClientMessage(playerid,COLOR_YELLOW,message);
                SetPlayerHealth(pid,Health-2);
				wait(1000);
				GetPlayerHealth(pid,Health2);
				format(message2,128,"New HP: %f",Health2);
				SendClientMessage(playerid,COLOR_YELLOW,message2);
				return 1;
			}
Any ideas of why it's not working?
Reply
#2

Try to use SetTimer.

Or try to use SetPlayerHealth after wait(1000);.
Reply
#3

Quote:
Originally Posted by Luby
Try to use SetTimer.

Or try to use SetPlayerHealth after wait(1000);.
Tried putting the SetHealth after the wait but had no luck, still the same problem. And a settimer is the last thing I'll do.

But thanks anyway
Reply
#4

Comon does anybody have any suggestions, or does anybody know how I could do it with a timer?
Reply
#5

Quote:
Originally Posted by Celson
Comon does anybody have any suggestions, or does anybody know how I could do it with a timer?
You can use wait func.

try to make it like this :

Код:
  			
if(IsPlayerConnected(pid))
{
	new Float:Health;
	new Float:Health2;
	GetPlayerHealth(pid,Health);
	format(message,128,"Current HP: %f",Health);
	SendClientMessage(playerid,COLOR_YELLOW,message);
	SetPlayerHealth(pid,Health-2);
	if(wait(1000)){
		GetPlayerHealth(pid,Health2);
		format(message2,128,"New HP: %f",Health2);
		SendClientMessage(playerid,COLOR_YELLOW,message2);
	}
	return 1;
}
Reply
#6

Just a little note, if i am right, this will freeze your script for a whole second which can obvisiously fuck up alot. I would really suggest you to use SetTimer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)