A Custom and Modified Kick(playerid); -
JaKe Elite - 05.04.2013
A Custom and Modified
Kick(playerid);
Introduction
Since 0.3x, You won't receive any messages anymore before you get kick.
It is because of SA-MP's new security system.
This can be fixed by setting a timer. No not the timer without the parameter settings.
I'm talking about timer with parameter settings by i mean that, i mean SetTimerEx.
Let's get started.
Kick(playerid) Time!!!
pawn Code:
new kick2[MAX_PLAYERS];
forward PlayerKick(playerid);
public PlayerKick(playerid)
{
Kick(playerid);
return KillTimer(kick2[playerid]);
}
stock KickEx(playerid, time = 500)
{
if(time == 0) return print("Error, Time is 0, Cannot run timer with that milesecond!");
else if(time != 0)
{
kick2[playerid] = SetTimerEx("PlayerKick", time, false, "d", playerid);
}
return 1;
}
Let's explained them one by one.
pawn Code:
new kick2[MAX_PLAYERS];
//Creates a variable
-
pawn Code:
forward PlayerKick(playerid);
Forwards the callback PlayerKick in order to avoid warnings when we create public PlayerKick(playerid)
-
pawn Code:
public PlayerKick(playerid) //gets called after the SetTimerEx's milesecond parameters execute!
{
Kick(playerid);
//kicks the player
return KillTimer(kick2[playerid]); //kills the timer that we run in the stock function KickEx
}
-
pawn Code:
stock KickEx(playerid, time = 500) //creates a new stock function.
-
pawn Code:
if(time == 0) return print("Error, Time is 0, Cannot run timer with that milesecond!");
//if the scripter accidentally typed 0 in the time parameter. The system will block it and send a error print!
-
pawn Code:
else if(time != 0) //if the time parameter is not 0
-
pawn Code:
kick2[playerid] = SetTimerEx("PlayerKick", time, false, "d", playerid);
//creates a timer, we will gonna kill it later
Re: A Custom and Modified Kick(playerid); - Patrick - 05.04.2013
Explanation Inside
pawn Code:
stock KickEx(playerid, time = 500)
// can be also done this way :), you're doing it in a hard way huh :)
SetTimerEx("PlayerKick", 500, false, "d", playerid); //put the time inside the timer
@Topic Nice job though. + useful thread,
Re: A Custom and Modified Kick(playerid); -
FUNExtreme - 05.04.2013
Quote:
Originally Posted by pds2012
Explanation Inside
pawn Code:
stock KickEx(playerid, time = 500) // can be also done this way :), you're doing it in a hard way huh :) SetTimerEx("PlayerKick", 500, false, "d", playerid); //put the time inside the timer
|
You can't be serious? The time variable in his code allows players to choose the delay. It's set to 500 as a default value making it an optional parameter
Re: A Custom and Modified Kick(playerid); -
Djole1337 - 05.04.2013
Why stock ?
pawn Code:
#define KickEx(%1) \
SetTimerEx("PlayerKick", 350, false, "i", (%1))
Re: A Custom and Modified Kick(playerid); -
RajatPawar - 05.04.2013
Why not? Good one, I'll link it up for all those guys who need this.
Re: A Custom and Modified Kick(playerid); -
JaKe Elite - 06.04.2013
^^
Nice job Y_Less.
anyway. Thanks Rajat and others who posted in this topic.
Re: A Custom and Modified Kick(playerid); -
Cell_ - 06.04.2013
Quote:
Originally Posted by Romel
pawn Code:
public PlayerKick(playerid) //gets called after the SetTimerEx's milesecond parameters execute! { Kick(playerid); //kicks the player return KillTimer(kick2[playerid]); //kills the timer that we run in the stock function KickEx }
|
I don't see a need why you need to kill the (non-repeating) timer.
Re: A Custom and Modified Kick(playerid); -
MP2 - 06.04.2013
IIRC you don't need a delay of more than 1 MS (does 0 work)?
Re: A Custom and Modified Kick(playerid); -
Djole1337 - 06.04.2013
Quote:
Originally Posted by Y_Less
Because there is a default parameter and doing those, while not impossible, is hard in macros. You would need something like this:
pawn Code:
#define KickEx(%1) SetTimerEx("PlayerKick",_:KickEx_DEFAULT_TIME:500,false,"i",(%1)) #define KickEx_DEFAULT_TIME:500,false,"i",(%0,%1)) (%1),false,"i",(%0))
Of course the better question is - why a macro? That creates multiple copies of the string, and multiple copies of the code. Though the first problem can be solved easily:
pawn Code:
stock const sc_szPlayerKick[] = "PlayerKick"; #define KickEx(%1) SetTimerEx(sc_szPlayerKick,_:KickEx_DEFAULT_TIME:500,false,"i",(%1)) #define KickEx_DEFAULT_TIME:500,false,"i",(%0,%1)) (%1),false,"i",(%0))
That is a MUCH better solution for strings in macros in terms of memory.
|
Yeah you're right, but I've got the same question as Cell_.