PDA

View Full Version : Setting a Timer for damages


aoky
13/06/2017, 06:25 PM
I want to add a timer to this code here, so he can't take damage for 3 seconds, after the timer is done he can take damage.
This is on the OnPlayerDamage function.

else if(Character[playerid][BrutalM] == 1)
{
//Timer here for 3 seconds
GetPlayerPos(playerid, DPos2[playerid][0], DPos2[playerid][1], DPos2[playerid][2]);
Delete3DTextLabel(label[playerid]);
label2[playerid] = Create3DTextLabel("(( THIS PLAYER IS NOW DEAD ))", COLOR_RED, DPos2[playerid][0], DPos2[playerid][1], DPos2[playerid][2], 10.0, 0);
Attach3DTextLabelToPlayer(label2[playerid], playerid, 0, 0, 0.7);
Character[playerid][Dead] = 1;
Character[playerid][BrutalM] = 0;
SCM(playerid, COLOR_YELLOW, ">> You are now dead. You can use /respawnme after 60 seconds to respawn.");
Character[playerid][CanSpawn] = 0;
KillTimer(DeathT);
RespawnT = 60;
RespawnEx = SetTimer("RespawnTimer", 999, true);
RTimer = SetTimerEx("RespawnTimer2", 60000, false, "i", playerid);
}

renatog
13/06/2017, 06:33 PM
Create a variable to check if player can be damaged. Example:

new bool:canBeDamaged[MAX_PLAYERS] = {true, true, true, ...};
(...)
public OnPlayerDamage(...)
{
if(!canBeDamaged[playerid]) //if can't be damage, return 0 and stop damage process
return 0;

(...)
else if(Character[playerid][BrutalM] == 1)
{
canBeDamaged[playerid] = false; //can't be damaged
//Timer here for 3 seconds
GetPlayerPos(playerid, DPos2[playerid][0], DPos2[playerid][1], DPos2[playerid][2]);
Delete3DTextLabel(label[playerid]);
label2[playerid] = Create3DTextLabel("(( THIS PLAYER IS NOW DEAD ))", COLOR_RED, DPos2[playerid][0], DPos2[playerid][1], DPos2[playerid][2], 10.0, 0);
Attach3DTextLabelToPlayer(label2[playerid], playerid, 0, 0, 0.7);
Character[playerid][Dead] = 1;
Character[playerid][BrutalM] = 0;
SCM(playerid, COLOR_YELLOW, ">> You are now dead. You can use /respawnme after 60 seconds to respawn.");
Character[playerid][CanSpawn] = 0;
KillTimer(DeathT);
RespawnT = 60;
RespawnEx = SetTimer("RespawnTimer", 999, true);
RTimer = SetTimerEx("RespawnTimer2", 60000, false, "i", playerid);
SetTimerEx("RemoveInvulnerability", 3000, false, "i", playerid); //3 seconds timer
}
}

(...)

forward...
public RemoveInvulnerability(playerid)
{
canBeDamaged[playerid] = true; //player can be damaged
}