kick command -
iCurse - 08.04.2016
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(playerid, params[])
{
if(pInfo[playerid][pAdmin] < 1)
return SendClientMessage(playerid, GREY, "You are not authorized to use that command.");
new
targetid,
Reason[128],
str[128]
;
if(sscanf(params, "us[128]", targetid, Reason))
return SendClientMessage(playerid, GREY, "USAGE: /kick [Playerid] [Reason]");
if(!IsPlayerConnected(targetid))
return SendClientMessage(playerid, GREY, "Player is not connected.");
new
pname[MAX_PLAYER_NAME],
tname[MAX_PLAYER_NAME]
;
GetPlayerName(playerid, pname, sizeof(pname));
GetPlayerName(playerid, tname, sizeof(tname));
format(str, sizeof(str), "You have been kicked by %s.", tname, Reason);
SendClientMessage(targetid, RED, str);
format(str, sizeof(str), "You have kicked %s.", pname, Reason);
SendClientMessage(playerid, RED, str);
Kick(targetid);
return 1;
}
Re: kick command -
sheNdjze - 08.04.2016
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);
Re: kick command -
X337 - 08.04.2016
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);
Re: kick command -
AndySedeyn - 08.04.2016
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(playerid, pname, sizeof(pname));
GetPlayerName(targetid, tname, sizeof(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(str, sizeof(str), "You have been kicked by %s, reason: %s.", tname, Reason);
SendClientMessage(targetid, RED, str);
format(str, sizeof(str), "You have kicked %s, reason: %s.", pname, Reason);
SendClientMessage(playerid, RED, str);
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
Re: kick command -
Akbaig - 08.04.2016
@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", 1000, false, "i", targetid);
Put this below the kick cmd.
PHP код:
forward Kicking(targetid);
public Kicking(targetid)
{
Kick(targetid);
return 1;
}
Now roam like a gangsta!
Re: kick command -
AndySedeyn - 08.04.2016
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", 1000, false, "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.