Kick is dominant
#1

Hello guys
I am new here and quite a beginner in pawn.
I am trying to create a kick command and BEFORE the player gets kicked I want him to see a message.
The problem is that the message which SHOULD be shown, doesn't show up, BUT gets kicked.
And YES I did pay attention to put the line which shows the person the message ABOVE the kick-function.

Here is my code:
Код:
dcmd_kick(playerid, params[])
{
	new pid, reason[128], name[MAX_PLAYER_NAME], done[128];
	if(sscanf(params, "uz", pid, reason)) return SendClientMessage(playerid, rot, "ERROR: /kick [ID/Name] [Grund]");
	GetPlayerName(pid, name, sizeof(name));
	format(done, sizeof(done), "%s wurde gekickt. Grund: %s", name, reason);
	SendClientMessage(pid, rot, done);
	Kick(pid);
	return 1;
}
And yes I am aware, that i can kick myself. This is wanted because I have no test-subject.
Reply
#2

i know its stupid but i solved it with setting a timer to kick so kick happens after this code block ends.

Код:
new kickedid;

dcmd_kick(playerid, params[])
{
	new pid, reason[128], name[MAX_PLAYER_NAME], done[128];
	if(sscanf(params, "uz", pid, reason)) return SendClientMessage(playerid, rot, "ERROR: /kick [ID/Name] [Grund]");
	GetPlayerName(pid, name, sizeof(name));
	format(done, sizeof(done), "%s wurde gekickt. Grund: %s", name, reason);
	SendClientMessage(playerid, rot, done);
	kickedid=pid;
        SetTimer("timedkick",100,false);
	return 1;
}

public timedkick()
{
        Kick(kickedid);
        return 1;
}
im a beginner in coding too and this looks kind of messy i know. But gets the job done
Reply
#3

Thank you very much for your answer
Yes now it is working, but I get the following warning:

warning 235: public function lacks forward declaration (symbol "timedkick")

line of the warning: public timedkick()

And I also wonder, what the issue is (in general) - why do i get kicked BEFORE I get to see the message?
Reply
#4

oh sorry my bad

Код:
new kickedid;

dcmd_kick(playerid, params[])
{
	new pid, reason[128], name[MAX_PLAYER_NAME], done[128];
	if(sscanf(params, "uz", pid, reason)) return SendClientMessage(playerid, rot, "ERROR: /kick [ID/Name] [Grund]");
	GetPlayerName(pid, name, sizeof(name));
	format(done, sizeof(done), "%s wurde gekickt. Grund: %s", name, reason);
	SendClientMessage(playerid, rot, done);
	kickedid=pid;
        SetTimer("timedkick",100,false);
	return 1;
}

public timedkick(playerid) //we are kicking a player here. if doesnt work please try adding in kickedid
{
        Kick(kickedid);
        return 1;
}
Reply
#5

Your new code didn't change anything (same warning and STILL working)
Thank you very much for your help anyway I also wanna know from others, if there are BETTER solutions to solve this issue here and i wish an explanation WHY it just won't work my way
Reply
#6

Quote:
Originally Posted by eSPeZet
Посмотреть сообщение
Your new code didn't change anything (same warning and STILL working)
Thank you very much for your help anyway I also wanna know from others, if there are BETTER solutions to solve this issue here and i wish an explanation WHY it just won't work my way
U need to forward it
Код:
forward timedkick(playerid);
Reply
#7

Quote:
Originally Posted by Crystallize
Посмотреть сообщение
U need to forward it
Код:
forward timedkick(playerid);
how stupid i am.... really lol. he has your answer
Reply
#8

Kickedid variable isn't necessary and also you created a global variable instead of a player variable. You can simply do that below and also just noticed that you are using a global timer, why are you seriously using a global timer?

PHP код:
dcmd_kick(playeridparams[])
{
    new 
pidreason[128], name[MAX_PLAYER_NAME], done[128];
    if(
sscanf(params"uz"pidreason)) return SendClientMessage(playeridrot"ERROR: /kick [ID/Name] [Grund]");
    
GetPlayerName(pidnamesizeof(name));
    
format(donesizeof(done), "%s wurde gekickt. Grund: %s"namereason);
    
SendClientMessage(playeridrotdone);
    
SetTimerEx("KickTimer"500false"i"pid);
    return 
1;
}

forward KickTimer(playerid);
public 
KickTimer(playerid)
{
     
Kick(playerid);

So all you need to do is to add this under the kick cmd.
PHP код:
SetTimerEx("KickTimer"500false"i"pid); 
And add this anywhere.
PHP код:
forward KickTimer(playerid);
public 
KickTimer(playerid)
{
     
Kick(playerid);

No need to make a variable and even if you made a variable, atleast make a per player variable not global variable and you shouldn't really make a global timer, like seriously.
Reply
#9

Hm seems like I have to learn about timers. I didn't expect that I HAVE to use one here.

So opened questions: Why does MY WAY of the first post not work and are there other solutions for my problem too?

Thanks to everyone who helped me already
Reply
#10

Kick and ban have been given a higher network priority. Presumably to be able to more effectively deal with idiots that try to crash servers by spoofing or flooding data. I don't know exactly how this works internally but I believe normal functions have a bit of a delay before they're sent to the client. Kick and ban don't have that delay and therefore they're received first.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)