When a player is low health, sending a client message. -
Matical - 05.01.2016
Hello, I have just got back to scripting and i know how to go about this but i do not want to risk messing anything up,
i want to add when a player is at 20 hp it will send a message saying Low Health but i fear if i script it the way im thinking it will be longer and i think it will spam at each hp under 20 low health. Please help.
Re: When a player is low health, sending a client message. -
Karan007 - 05.01.2016
Set a timer ongamemodeinit and on the public function check if the player has 20 hp and if so do whatever you want there.
Re: When a player is low health, sending a client message. -
Matical - 05.01.2016
So like, I made a Timer, and a forward, and i just need help with the public function.
CheckLowHP = SetTimer("CheckLowHP", 900000, 1);
forward CheckLowHP();
Re: When a player is low health, sending a client message. -
justinnater - 05.01.2016
Adding a timer is completly unnecessary!
Why wouldnt you do a check at his health at OnPlayerTakeDamage instead?
Re: When a player is low health, sending a client message. -
Matical - 05.01.2016
Thats what i was thinking of but i thought it would spam Low Health at every hp lower than 20. could you explain?
Re: When a player is low health, sending a client message. -
saffierr - 05.01.2016
PHP код:
SetTimer("CheckLowHP", 900000, true);
forward CheckLowHP(playerid);
public CheckLowHP(playerid)
{
if(GetPlayerHealth(playerid, variable) < 20) return SendClientMessage(playerid, COLOR_RED, "Text");
return 1;
}
Re: When a player is low health, sending a client message. -
justinnater - 05.01.2016
Do something like this.
new lowhealth [MAX_PLAYERS]
public OnPlayerSpawn
lowhealth[playerid]=0;
public OnPlayerTakeDamage
Check if health is below 20
If so
Check if lowhealth[playerid]==0
If so
Send a text message and lowhealth[playerid]=1;
Re: When a player is low health, sending a client message. -
Sellize - 05.01.2016
Saffiers code is close, but that doesn't make correct use of the GetPlayerHealth function and it would spam the player, even if it worked.
This is to give you a rough idea how you could do it, however I recommend handling the timers better (assigning them variables)
PHP код:
new gotHPMessage[MAX_PLAYERS];
public OnPlayerConnect(playerid){
gotHPMessage[playerid] = 0;
SetTimerEx("checkHP", 5000, true, "i", playerid);
return 1;
}
forward checkHP();
public checkHP(playerid)
{
new float:curHP;
GetPlayerHealth(playerid, curHP);
if(curHP < 20 && gotHPMessage[playerid] == 0){
SendClientMessage(playerid, -1, "Looks like your health is under 20 now.");
gotHPMessage[playerid] = 1;
}
return 1;
}
// If you want to, you can reset gotHPMessage variable when the player dies or whatever
Re: When a player is low health, sending a client message. -
justinnater - 05.01.2016
And another timer...
Re: When a player is low health, sending a client message. -
saffierr - 05.01.2016
Use Sellize's code, that'll work.