Getting a player -
arjanforgames - 13.07.2013
Hello,
How can I "get" a player again?
For example if I want to use /kick [player]
How do I get the playername stored so I can use:
or something like that.
Re: Getting a player -
Threshold - 13.07.2013
sscanf is the most up to date, and efficient way for the terms you're attempting to use it in. SSCANF has a 'u' parameter that will get a player's name or ID from the parameters you enter.
Example:
pawn Код:
CMD:kick(playerid, params[])
{
new playertobekicked, reason[50];
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "Nigga, you ain't an admin..."); //Obviously there are alternatives to this, but this will check if a player is logged into RCON
if(sscanf(params, "uS(No Reason)[50]", playertobekicked, reason)) return SendClientMessage(playerid, 0xFFFF00FF, "Usage: /kick [player id/name] [reason]");
new string[145];
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
GetPlayerName(playertobekicked, pName, MAX_PLAYER_NAME);
format(string, sizeof(string), "Player %s(%d) has been kicked by %s(%d) | Reason: %s", pName, playertobekicked, aName, playerid, reason);
SendClientMessageToAll(0xFF0000FF, string);
SetTimerEx("KickPlayer", 500, "i", playertobekicked);
return 1;
}
forward KickPlayer(playerid);
public KickPlayer(playerid)
{
Kick(playerid);
return 1;
}
Just a quick example, there are many sscanf tutorials, just search for them.
Re: Getting a player -
Scenario - 13.07.2013
You don't need a player's name for any of the native SA:MP functions... You simply use their player ID!
However, for reference, you can use
GetPlayerName to get their name.
Re: Getting a player -
JimmyCh - 13.07.2013
From BenzoAMG's code, one mistake at the top:
pawn Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "Nigga, you ain't an admin...");
Instead of:
pawn Код:
if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "Nigga, you ain't an admin...");
Re: Getting a player -
CreativityLacker - 13.07.2013
pawn Код:
new target;
if(!sscanf(params, "u", target))
{
//kick code
}
Re: Getting a player -
Konstantinos - 13.07.2013
Quote:
Originally Posted by RealCop228
You don't need a player's name for any of the native SA:MP functions... You simply use their player ID!
However, for reference, you can use GetPlayerName to get their name.
|
I believe he meant in order to use it for a message to the rest players.
In case I understood wrong and he meant; for example, he wants to use "/kick arjanforgames" then SSCANF is what he needs.
@arjanforgames - You can use either the playerid or Name/Part of name instead.
Re: Getting a player -
Threshold - 13.07.2013
@RealCop If I read it correctly, I think he's referring to being able to use a player's name as parameters rather than their ID when executing a command.
@JimmyCh
Thank you, I'll fix that up now. I'm on my phone, so I'm bound to make a mistake at some point.