[Tutorial] How to make Anti-Spawn Kill
#1

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!");
- Explanation for SetTimerEx:

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.
- Explanation for SetPlayerHealth

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;
}
Add this somewhere except inside the public callbacks, commands etc...

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.
}
So it must be look like this in all

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.
}
Hope you learn how to create Anti-Spawn Kill, I did all my best to explain it, Also you won't get the warning loose indentation because i properly write it with clean indentation.
Reply
#2

Nice tutorial kinda good for a newbie to start off with his TDM
Reply
#3

Thank you.

- Edit: Lol i saw your rep comment, My answer is no.
Reply
#4

Nice very good for newbie players
Reply
#5

Newbie players?
You mean Newbie Scripters?

Anyway Thanks
Reply
#6

Very nice, well explained!
Reply
#7

Nice Tut! Keep it up
Reply
#8

Thanks.
Reply
#9

So I open "new.pwn" ?
Reply
#10

Nice tutorial,it will help a lot to beginners, +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)