kick command
#1

Once again, i scripted a /kick command to kick a player but i don't know how to show the "targetid" who kicked him/her and what the reason is.

To those who are interested on helping me, please edit/add a line that shows the KICKED player who kicked him/her and what the reason is.

OR make this command more unique and understandable for a newbie like me.

PHP код:
CMD:kick(playeridparams[])
{
    if(
pInfo[playerid][pAdmin] < 1)
        return 
SendClientMessage(playeridGREY"You are not authorized to use that command.");
        
    new
        
targetid,
        
Reason[128],
        
str[128]
    ;
    
    if(
sscanf(params"us[128]"targetidReason))
        return 
SendClientMessage(playeridGREY"USAGE: /kick [Playerid] [Reason]");
        
    if(!
IsPlayerConnected(targetid))
        return 
SendClientMessage(playeridGREY"Player is not connected.");
        
    new
        
pname[MAX_PLAYER_NAME],
        
tname[MAX_PLAYER_NAME]
    ;
    
    
GetPlayerName(playeridpnamesizeof(pname));
    
GetPlayerName(playeridtnamesizeof(tname));
    
    
format(strsizeof(str), "You have been kicked by %s."tnameReason);
    
SendClientMessage(targetidREDstr);
    
format(strsizeof(str), "You have kicked %s."pnameReason);
    
SendClientMessage(playeridREDstr);
    
Kick(targetid);
    return 
1;

Reply
#2

put in ur command after new targetid etc new targetid = strval(cmdstr1);

should look like this
PHP код:
    new 
        
targetid
        
Reason[128], 
        
str[128],
        
cmdstr1[5
    ; 
targetid strval(cmdstr1); 
Reply
#3

Add this code in your script:
Код:
forward _KickPlayer(playerid);
public _KickPlayer(playerid) { Kick(playerid); }
 
KickPlayer(playerid)
{
    SetTimerEx("_KickPlayer", 1000, 0, "d", playerid);
}
and replace Kick(targetid);
to KickPlayer(targetid);
Reply
#4

You are retrieving the same player's name twice. tname stands for 'targetname' and pname stands for 'playername', that I assume at least. So the following is correcter:
PHP код:
    GetPlayerName(playeridpnamesizeof(pname)); 
    
GetPlayerName(targetidtnamesizeof(tname)); 
You are formatting the names in the string, but not the reason and thus the reason will not be included into the formatted string. The following is correcter:
PHP код:
    format(strsizeof(str), "You have been kicked by %s, reason: %s."tnameReason); 
    
SendClientMessage(targetidREDstr); 
    
format(strsizeof(str), "You have kicked %s, reason: %s."pnameReason); 
    
SendClientMessage(playeridREDstr); 
I've helped you once by recreating your /makeadmin command, but don't expect people in this section to do that with every problem you have.

EDIT: Use X337's code too. You have to delay the kick to give the messages the time to display. You could have figured that out by reading the wiki page: https://sampwiki.blast.hk/wiki/Kick
Reply
#5

@AndySedeyn, I would suggest avoid using X337's code, etc for delaying the kick.

Simply add Timer and kick that X337's code or whatever. That's what I do. Simple and Easy to use.

First use this in the kick cmd.
PHP код:
SetTimerEx("Kicking"1000false"i"targetid); 
Put this below the kick cmd.
PHP код:
forward Kicking(targetid);
public 
Kicking(targetid)
{
    
Kick(targetid);
    return 
1;

Now roam like a gangsta!
Reply
#6

Quote:
Originally Posted by Akbaig
Посмотреть сообщение
@AndySedeyn, I would suggest avoid using X337's code, etc for delaying the kick.

Simply add Timer and kick that X337's code or whatever. That's what I do. Simple and Easy to use.

First use this in the kick cmd.
PHP код:
SetTimerEx("Kicking"1000false"i"targetid); 
Put this below the kick cmd.
PHP код:
forward Kicking(targetid);
public 
Kicking(targetid)
{
    
Kick(targetid);
    return 
1;

Now roam like a gangsta!
Could you state why you would recommend avoiding it? As it is exactly the same thing as yours. I would even recommend doing it like X337 if you are using the SetTimerEx function to kick a player multiple times in your gamemode. It is also a lot easier to maintain.

An example:
Let's say I've got 10 instances of creating a timer to kick a player. So, I have this line 10 times in my gamemode on different locations:
PHP код:
SetTimerEx("Kicking"1000"i"targetid); 
The one second delay is a bit long and I would like to change that. In order to change it everywhere, I would have to use the built-in search function of my IDE, search for that exact line and then replace all of them.

Another approach (that of X337) would be to put the SetTimerEx call in a separate function and when I want to change the delay, I just go to the function, change it and done.

It's trivial and you can choose yourself really.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)