When a player is low health, sending a client message.
#1

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.
Reply
#2

Set a timer ongamemodeinit and on the public function check if the player has 20 hp and if so do whatever you want there.
Reply
#3

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();
Reply
#4

Adding a timer is completly unnecessary!
Why wouldnt you do a check at his health at OnPlayerTakeDamage instead?
Reply
#5

Thats what i was thinking of but i thought it would spam Low Health at every hp lower than 20. could you explain?
Reply
#6

PHP код:
SetTimer("CheckLowHP"900000true);
 
forward CheckLowHP(playerid);
public 
CheckLowHP(playerid)
{
   if(
GetPlayerHealth(playeridvariable) < 20) return SendClientMessage(playeridCOLOR_RED"Text");
   return 
1;

Reply
#7

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;
Reply
#8

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"5000true"i"playerid);
    return 
1;
}

forward checkHP(); 
public 
checkHP(playerid

   new 
float:curHP;
   
GetPlayerHealth(playeridcurHP);
   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 
Reply
#9

And another timer...
Reply
#10

Use Sellize's code, that'll work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)