16.07.2017, 18:49
It will not work as intended, there will be cases when more than one player has the 3DTextLabel; therefore, you must save all of the players' 3DTextLabel IDs in an array.
PHP Code:
new Text3D:antispawnkill[MAX_PLAYERS] = {Text3D:-1, ...}; // fill array with -1
public OnPlayerSpawn(playerid)
{
SetPlayerHealth(playerid, 99999.0);
SetPlayerVirtualWorld(playerid, 0);
SendClientMessage(playerid, 0xFF0000AA, "You can't be killed for 5 second(s) (spawn protection)");
SetPlayerWantedLevel(playerid, 0);
if(antispawnkill[playerid] != Text3D:-1) Delete3DTextLabel(antispawnkill[playerid]); // destroy old text label if player dies for whatever reason with spawn protection enabled (e.g. admin kill)
antispawnkill[playerid] = Create3DTextLabel("Anti-Spawnkill Protected", 0xFF0000FF , 30.0, 40.0, 50.0, 40.0, 0);
Attach3DTextLabelToPlayer(antispawnkill[playerid], playerid, 0.0, 0.0, 0.7);
SetTimerEx("AntiSpawnkill",PROTECTIONTIME*1500,0,"i",playerid);
return 1;
}
forward AntiSpawnkill(playerid);
public AntiSpawnkill(playerid)
{
Delete3DTextLabel(antispawnkill[playerid]);
antispawnkill[playerid] = Text3D:-1; // reset array index used to destroy old text label
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, 0x00ff00ff, "Anti Spawn kill protection over.");
return 1;
}