05.11.2012, 08:20
How to make Anti-Spawn Kill
Introduction
I'm bored nothing to do at home right now,
I decide to make a tutorial how to make a Anti-Spawn Kill with Timer.
Let's get started!!
Explain
Ok first off all, Open your script .pwn.
press CTRL+F, type in the field "OnPlayerSpawn"
inside of it, Put
pawn Код:
SetTimerEx("AntiSKEnd", 10000, false, "i", playerid);
SetPlayerHealth(playerid, 999999.0);
SendClientMessage(playerid, -1, "Your spawn protection will expires in 10 seconds!");
Runs a timer, AntiSKEnd is the name of the function to call, 10,000 is the time how many mileseconds the timer will end, 10,000 is 10 seconds, false means the timer will not repeat when it's called, True means it will repeat after the timer is called - True = 1, False = 0, i is Special format indicating the types of values the timer will carry, We use i because it will carry playerid parameters, We could also use d because it works like integer, DON'T EVER USE STRING WHEN IT WILL CARRY A PLAYERID PARAMETERS., playerid is Indefinite number of arguments to pass
List for the format[], we used i in the format[], It is already explained above why we use i.
Код:
Format syntax Placeholder Meaning i Stands for an integer parameter. d Exactly the same as i. a Passes an array, the next parameter must be an integer ("i") with the array's size. [CURRENTLY UNUSABLE] s Stands for a string parameter. [CURRENTLY UNUSABLE] f Stands for a float parameter. b Stands for a boolean parameter.
playerid is the player who will spawn, 999999.0 means setting their health 999999.0, Remember, 999999.0 is float not an integer or string.
- Explanation for SendClientMessage
playerid is the player where the message will be sended, -1 is COLOR_WHITE, It's not invalid color, "Your spawn protection will expires in 10 seconds", is the message will be sended to playerid.
So it would look like this
When you add the SetTimerEx
pawn Код:
public OnPlayerSpawn(playerid)
{
SetPlayerHealth(playerid, 999999.0);
SetTimerEx("AntiSKEnd", 10000, false, "i", playerid);
//Your other codes
return 1;
}
Explanation is the comment with "//" and "/*"
pawn Код:
forward AntiSKEnd(playerid); //We'll use this to avoid future warnings
public AntiSKEnd(playerid) //When the Timer Ends, This callback is called
{
SetPlayerHealth(playerid, 100.0);
/* - Explanation for SetPlayerHealth
playerid is the target which will set the health, 100.0, set's player health back to normal, 100.0 is float not an integer or string
*/
SendClientMessage(playerid, -1, "Spawn Protection expired!");
/*
- Explanation for SendClientMessage
playerid is the player where the message will be sended, -1 is COLOR_WHITE, It's not invalid color, "Spawn Protection expired!"
*/
return 1; //return 1 to prevent calling the function below the public callback.
}
pawn Код:
public OnPlayerSpawn(playerid)
{
SetPlayerHealth(playerid, 999999.0);
SetTimerEx("AntiSKEnd", 10000, false, "i", playerid);
//Your other codes
return 1;
}
forward AntiSKEnd(playerid); //We'll use this to avoid future warnings
public AntiSKEnd(playerid) //When the Timer Ends, This callback is called
{
SetPlayerHealth(playerid, 100.0);
/* - Explanation for SetPlayerHealth
playerid is the target which will set the health, 100.0, set's player health back to normal, 100.0 is float not an integer or string
*/
SendClientMessage(playerid, -1, "Spawn Protection expired!");
/*
- Explanation for SendClientMessage
playerid is the player where the message will be sended, -1 is COLOR_WHITE, It's not invalid color, "Spawn Protection expired!"
*/
return 1; //return 1 to prevent calling the function below the public callback.
}