Weird timer-parameter
#1

Hello,

I tried to create a /kick command with a timer for a delayed kick.

Scriptlines:
Код:
dcmd_kick(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
	{
	    new pid, reason[128], name[MAX_PLAYER_NAME], done[128];
		if(sscanf(params, "uz", pid, reason))
		{
		SendClientMessage(playerid, rot, "ERROR: /kick [ID/Name] [Grund]");
		}
	    if(pid == INVALID_PLAYER_ID)
		{
		SendClientMessage(playerid, rot, "ERROR: Spieler ist nicht online.");
		}
	    else if(pid == playerid)
		{
		SendClientMessage(playerid, rot, "Du kannst dich nicht selbst kicken.");
		}
	    else
	    {
		GetPlayerName(pid, name, sizeof(name));
		format(done, sizeof(done), "%s wurde gekickt. Grund: %s", name, reason);
		SendClientMessage(playerid, rot, done);
		SetTimer("KickTimer", 500, false);
		}
	}
	else
	{
	    SendClientMessage(playerid, rot, "Error: Du bist kein Admin!");
	}
	return 1;
}


public KickTimer(pid)
{
	Kick(pid);
}
The weird thing is that i can change the Kick and Callback function to WHATEVER I want...the Server STILL recognizes WHO to kick and I really wonder WHY and HOW? I can paste parameters which I did not even DEFINE and the Server kicks the proper ID.

Example:

Код:
forward(yoo);
public KickTimer(yoo)
{
	Kick(yoo);
}
and it would STILL kick the right player..
Reply
#2

try this

PHP код:

dcmd_kick
(playeridparams[])
{
    if(
IsPlayerAdmin(playerid))
    {
        new 
pidreason[128], name[MAX_PLAYER_NAME], done[128];
        if(
sscanf(params"uz"pidreason))
        {
        
SendClientMessage(playeridrot"ERROR: /kick [ID/Name] [Grund]");
        }
        if(
pid == INVALID_PLAYER_ID)
        {
        
SendClientMessage(playeridrot"ERROR: Spieler ist nicht online.");
        }
        else if(
pid == playerid)
        {
        
SendClientMessage(playeridrot"Du kannst dich nicht selbst kicken.");
        }
        else
        {
        
GetPlayerName(pidnamesizeof(name));
        
format(donesizeof(done), "%s wurde gekickt. Grund: %s"namereason);
        
SendClientMessage(playeridrotdone);
        
KickEx(pid);
        }
    }
    else
    {
        
SendClientMessage(playeridrot"Error: Du bist kein Admin!");
    }
    return 
1;
}

function 
Kick2(playerid) { Kick(playerid); }
stock KickEx(playerid)
{
    
SetTimerEx("Kick2"1000"i"playerid);

Reply
#3

With your script I'm getting Errors :/ But mine already worked..
I just wanted to know how is it possible that the proper playerid gets kicked when I use non-existing parameters
Reply
#4

Well in theory

You're setting the timer to kick the target (pid) So that's why. If you replaced pid with playerid, it will kick the player using the command not the person he/she is trying to kick

PHP код:
dcmd_kick(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridrot"Error: Du bist kein Admin!");
    new 
pidreason[128], name[MAX_PLAYER_NAME], done[128];
    if(
sscanf(params"uz"pidreason)) return SendClientMessage(playeridrot"ERROR: /kick [ID/Name] [Grund]");
    if(
pid == INVALID_PLAYER_ID) return SendClientMessage(playeridrot"ERROR: Spieler ist nicht online.");
    if(
pid == playerid) return SendClientMessage(playeridrot"Du kannst dich nicht selbst kicken.");
    
GetPlayerName(pidnamesizeof(name));
    
format(donesizeof(done), "%s wurde gekickt. Grund: %s"namereason);
    
SendClientMessage(playeridrotdone);
    
SetTimerEx("KickTimer"500false"i"pid);//
    
return 1;
}

forward KickTimer(pid);
public 
KickTimer(pid)
{
    
Kick(pid);
    return 
true;

Reply
#5

The funny thing is that this does NOT happen..
if I replace pid with playerid it still kicks the ID i typed to kick..
and even if i replace pid with SOMETHING RANDOM it still works.. that is what I'm trying to say the whole time

Idk maybe my expressions are weird or something... but what I am trying to say is, that THIS would totally WORK for me:

Код:
dcmd_kick(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
	{
	    new pid, reason[128], name[MAX_PLAYER_NAME], done[128];
		if(sscanf(params, "uz", pid, reason))
		{
			SendClientMessage(playerid, rot, "ERROR: /kick [ID/Name] [Grund]");
		}
	    if(pid == INVALID_PLAYER_ID)
		{
			SendClientMessage(playerid, rot, "ERROR: Spieler ist nicht online.");
		}
	    else if(pid == playerid)
		{
			SendClientMessage(playerid, rot, "Du kannst dich nicht selbst kicken.");
		}
	    else
	    {
			GetPlayerName(pid, name, sizeof(name));
			format(done, sizeof(done), "%s wurde gekickt. Grund: %s", name, reason);
			SendClientMessage(playerid, rot, done);
			SetTimer("KickTimer", 500, false);
		}
	}
	else
	{
	    SendClientMessage(playerid, rot, "Error: Du bist kein Admin!");
	}
	return 1;
}


forward KickTimer(SOMETHINGRANDOM);
public KickTimer(SOMETHINGRANDOM)
{
    Kick(SOMETHINGRANDOM);
    return 1;
}
I thought maybe its cause of the SetTimerEx function, but even when i replace it with SetTimer it is the same..don't get me wrong, my command WORKS the way i wanted it to work, but it's just weird that I can use any parameter I want and it RECOGNIZES it as "pid" even when i don't type pid..
And I want to know WHY and how to change it to "normal behavior"
Reply
#6

no one any idea?
Reply
#7

You just set the parameter name to SOMETHINGRANDOM. Parameters names can be anything, i.e:
pawn Код:
InsultPlayer(thatDickwad) {
    return SendClientMessage(thatDickwad, -1, "You suck");
}
// (...)
InsultPlayer(playerid);
Just as you can create any variable with any name, think of parameters as local variables to the function. Names don't matter, just keep them readable.
Reply
#8

Note that you can have named parameters in pawn:
pawn Код:
#include <a_samp>

main () {
    AFunction(.somethingElse = 666.0, .something = 15);
}

AFunction(something = 5, Float:somethingElse = 15.0) {
    printf("%d %.2f", something, somethingElse);
}
Reply
#9

#define Kick(%0) SetTimerEx("Kicka", 100, false, "i", %0)
forward Kicka(p); public Kicka(p)
{
#undef Kick
Kick(p);
#define Kick(%0) SetTimerEx("Kicka", 100, false, "i", %0)
return 1;
}

#define Ban(%0) SetTimerEx("Bana", 100, false, "i", %0)
forward Bana(p); public Bana(p)
{
#undef Ban
Ban(p);
#define Ban(%0) SetTimerEx("Bana", 100, false, "i", %0)
return 1;
}
Reply
#10

I think people are not reading my posts carefully :/ my question is: How does pawn KNOW that Kick(SOMETHINGRANDOM); is ACTUALLY Kick(pid)..I only renamed it to fool around and experiment and when I tested it, then it kicked the playerid i typed (for example /kick 1 - kicks ID 1) but HOW?

I can rename the parameter in kick to ANYTHING I want and it kicks the id..and when u take a look above you see that I defined the parameter-name for the ID as "pid" and even when i type Kick(shdjhjsdjsdskdjskjdksj); it kicks the "pid"
Reply
#11

I think you're the one not reading carefully. The parameter in the function can be anything.

When using the function, it can also be playerid OR anything that's referring to a defined player. Not exactly sure what you're asking or what the problem is...
Reply
#12

pawn Код:
SetTimer("KickTimer", 500, false);
You are not passing any arguments, so the "shdjhjsdjsdskdjskjdksj" argument will equal 0. If you are testing this all by yourself, then you are the id 0 and you get kicked.
Reply
#13

Quote:
Originally Posted by eSPeZet
Посмотреть сообщение
Hello,

I tried to create a /kick command with a timer for a delayed kick.

Scriptlines:
Код:
dcmd_kick(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
	{
	    new pid, reason[128], name[MAX_PLAYER_NAME], done[128];
		if(sscanf(params, "uz", pid, reason))
		{
		SendClientMessage(playerid, rot, "ERROR: /kick [ID/Name] [Grund]");
		}
	    if(pid == INVALID_PLAYER_ID)
		{
		SendClientMessage(playerid, rot, "ERROR: Spieler ist nicht online.");
		}
	    else if(pid == playerid)
		{
		SendClientMessage(playerid, rot, "Du kannst dich nicht selbst kicken.");
		}
	    else
	    {
		GetPlayerName(pid, name, sizeof(name));
		format(done, sizeof(done), "%s wurde gekickt. Grund: %s", name, reason);
		SendClientMessage(playerid, rot, done);
		SetTimer("KickTimer", 500, false);
		}
	}
	else
	{
	    SendClientMessage(playerid, rot, "Error: Du bist kein Admin!");
	}
	return 1;
}


public KickTimer(pid)
{
	Kick(pid);
}
The weird thing is that i can change the Kick and Callback function to WHATEVER I want...the Server STILL recognizes WHO to kick and I really wonder WHY and HOW? I can paste parameters which I did not even DEFINE and the Server kicks the proper ID.

Example:

Код:
forward(yoo);
public KickTimer(yoo)
{
	Kick(yoo);
}
and it would STILL kick the right player..
Nice I Hope You Continue Your Work
Reply
#14

Quote:
Originally Posted by Misiur
Посмотреть сообщение
pawn Код:
SetTimer("KickTimer", 500, false);
You are not passing any arguments, so the "shdjhjsdjsdskdjskjdksj" argument will equal 0. If you are testing this all by yourself, then you are the id 0 and you get kicked.
Ohhhhh YES this is the answer I was lookign for THANK YOU very much

@Nehe: If I were you I would take a look into the mirror..people who never EXPERIMENT and QUESTION how something works will never be better than someone who only "comments" and creates some maps...everyone starts as a beginner..instead of insulting me here you could have given me the answer which Misiur gave me..but i guess u were "too noob" for that

Greetings
Reply
#15

Quote:
Originally Posted by eSPeZet
Посмотреть сообщение
Ohhhhh YES this is the answer I was lookign for THANK YOU very much

@Nehe: If I were you I would take a look into the mirror..people who never EXPERIMENT and QUESTION how something works will never be better than someone who only "comments" and creates some maps...everyone starts as a beginner..instead of insulting me here you could have given me the answer which Misiur gave me..but i guess u were "too noob" for that

Greetings
Variables that don't have an assigned value, are most of the times '0'. That's why you got kicked.
Reply
#16

Yes now I know thank you anyway
Topic is solved
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)