PDA

View Full Version : Anti-SpawnKill Tag issue


Sting.
16/07/2017, 02:11 PM
Hey guys, I'm having a problem, with the Anti-Spawnkill tag, the problem is that it works fine but the problem or issue is that when the player Spawn's, the Tag is displayed and the player's health is blinking, but even after the Timer runs out for the Anti-Spawnkill, 5 seconds, the ridiculous Tag is not destroyed. Below I'll post the code:

new Text3D:antispawnkill;

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);
SetTimerEx("AntiSpawnkill",PROTECTIONTIME*1500,0,"d",playerid);
antispawnkill = Create3DTextLabel("Anti-Spawnkill Protected", 0xFF0000FF , 30.0, 40.0, 50.0, 40.0, 0); //SPAWNKILLTAG
Attach3DTextLabelToPlayer(antispawnkill, playerid, 0.0, 0.0, 0.7);

public AntiSpawnkill(playerid)
{
DeletePlayer3DTextLabel(playerid, PlayerText3D:antispawnkill); //SpawnKill TAG
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, 0x00ff00ff, "Anti Spawn kill protection over.");
return 1;
}

So what's the problem, can anyone help out in this mess?

GuilhermeNunes
16/07/2017, 02:39 PM
In your time put False
This bug is of the time and usually happens when ta in True has to be false.

Sting.
16/07/2017, 03:55 PM
You mean like this?

SetTimerEx("AntiSpawnkill",PROTECTIONTIME*1500, false,"d",playerid);

Vince
16/07/2017, 04:00 PM
You need an array to store the labelids otherwise you won't be able to destroy them.

GuilhermeNunes
16/07/2017, 04:03 PM
Yes, I did a spawn kill and it's giving you the same error yours, I put it false and it worked

Sting.
16/07/2017, 04:43 PM
You need an array to store the labelids otherwise you won't be able to destroy them.


Hey Vince, long time no see. Anyway man, can you elaborate? Label ID's?

Paulice
16/07/2017, 04:47 PM
Hey Vince, long time no see. Anyway man, can you elaborate? Label ID's?

You must store the IDs of every player's 3DTextLabel (this is returned by Create3DTextLabel), you're currently storing only one ID and destroying that ID regardless. Also, destroy the old 3DTextLabel when the player spawns to avoid any overlapping.

new Text3D:antispawnkill;
should be
new Text3D:antispawnkill[MAX_PLAYERS];
and I guess you know what to do next

Jefff
16/07/2017, 06:08 PM
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);
antispawnkill = Create3DTextLabel("Anti-Spawnkill Protected", 0xFF0000FF , 30.0, 40.0, 50.0, 40.0, 0); //SPAWNKILLTAG
Attach3DTextLabelToPlayer(antispawnkill, playerid, 0.0, 0.0, 0.7);
SetTimerEx("AntiSpawnkill",PROTECTIONTIME*1500,0,"ii",playerid,_:antispawnkill);


public AntiSpawnkill(playerid, labelid)
{
Delete3DTextLabel(Text3D:labelid); //SpawnKill TAG
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, 0x00ff00ff, "Anti Spawn kill protection over.");
return 1;
}

Sting.
16/07/2017, 06:19 PM
public AntiSpawnkill(playerid, labelid)

I get an error.

error 025: function heading differs from prototype

kubak01
16/07/2017, 06:25 PM
forward AntiSpawnkill(playerid, labelid);

Sting.
16/07/2017, 06:32 PM
Compiled it and got no errors, will check it though tomorrow with a friend to see whether it works.

Paulice
16/07/2017, 06:49 PM
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.

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;
}

Sting.
17/07/2017, 07:21 PM
Paulice's code, I still get this 2 errors,

error 017: undefined symbol "MAX_PLAYERS"
error 025: function heading differs from prototype

Paulice
17/07/2017, 07:40 PM
Download the server package and replace your includes with the ones found in said package.

jlalt
17/07/2017, 07:52 PM
@Sting. just use jefff code its the best method around here.

Paulice
17/07/2017, 08:16 PM
@Sting. just use jefff code its the best method around here.

No exactly, if a player is killed by an admin or respawned by the same then the previous label will overlap with the new label that will be created when the player spawns (or until the previous label gets deleted by the timer). This isn't crucial if the labels look the same, but if you decide to add the time left on the label then you got a problem.

Unlike timer IDs, unused/discarded 3DTextLabel IDs are used again (here's a minor modification to my previous code - improvement):
new Text3D:antispawnkill[MAX_PLAYERS] = {Text3D:-1, ...},
ptmAntiSpawnKill[MAX_PLAYERS];

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);
Delete3DTextLabel(antispawnkill[playerid]);
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);
KillTimer(ptmAntiSpawnKill[playerid]);
ptmAntiSpawnKill[playerid] = SetTimerEx("AntiSpawnkill",PROTECTIONTIME*1500,0,"i",playerid);
return 1;
}

forward AntiSpawnkill(playerid);
public AntiSpawnkill(playerid)
{
Delete3DTextLabel(antispawnkill[playerid]);
antispawnkill[playerid] = Text3D:-1;
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, 0x00ff00ff, "Anti Spawn kill protection over.");
return 1;
}
You can also do/use the previous if you do not want any overlapping in general.

Arbico
17/07/2017, 09:56 PM
Try this code, And let me know if it works or not
Rep if it works please

new Text3D:antispawnkill[MAX_PLAYERS];

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);
SetTimerEx("AntiSpawnkill",PROTECTIONTIME*1500,0,"d",playerid);
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);
}

public AntiSpawnkill(playerid)
{
Delete3DTextLabel(antispawnkill[playerid]); //SpawnKill TAG
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, 0x00ff00ff, "Anti Spawn kill protection over.");
return 1;
}

Paulice
17/07/2017, 10:34 PM
Try this code, And let me know if it works or not
Rep if it works please

new Text3D:antispawnkill[MAX_PLAYERS];

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);
SetTimerEx("AntiSpawnkill",PROTECTIONTIME*1500,0,"d",playerid);
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);
}

public AntiSpawnkill(playerid)
{
Delete3DTextLabel(antispawnkill[playerid]); //SpawnKill TAG
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, 0x00ff00ff, "Anti Spawn kill protection over.");
return 1;
}


The same issue mention above persists expect in addition to it, your code will not delete old overlapped labels.