Help with getting the player id
#8

Since apparently everyone simply assumes that everybody here uses the third party library sscanf, here is a version that would run even without sscanf, although I'd not recommend it.

pawn Код:
if (!strcmp("/killp", cmdtext, true, 5))
{
    new tmp[10], idx;
    strtok(cmdtext, idx); tmp=strtok(cmdtext, idx);
    if(!strlen(tmp)) { return SendClientMessage(playerid, 0xFFFFFF, "USAGE: \"/killp [PlayerID\""); }
    new userid = strval(tmp);
    if(userid < 0 || userid > MAX_PLAYERS) { return SendClientMessage(playerid, 0xFFFFFF, "USAGE: \"/killp [PlayerId]\""); }
    SetPlayerHealth(userid, 0);
}
Now I admit I didnt test this code and it relies on the fact that you do NOT have the following line somewhere on the top of OnPlayerCommandText:

pawn Код:
cmd = strtok(cmdtext, idx); // where as cmd could be any string name really and so could be idx!
If you do, simply remove the first strtok. I am also unaware wether simply executing an strtok without fetching the result is possible. Anyway, I hope it helps and I am sure it gives you a general idea. If you have any further questions feel free to ask, I'll gladly explain the code.
Reply


Messages In This Thread
Help with getting the player id - by HighHP - 16.02.2015, 05:24
Re: Help with getting the player id - by The__ - 16.02.2015, 06:12
Re: Help with getting the player id - by JeaSon - 16.02.2015, 06:22
Re: Help with getting the player id - by Nabster - 16.02.2015, 07:13
Re: Help with getting the player id - by AndySedeyn - 16.02.2015, 07:24
Re: Help with getting the player id - by HighHP - 16.02.2015, 08:53
Re: Help with getting the player id - by GGW - 16.02.2015, 14:20
Re: Help with getting the player id - by Extremo - 16.02.2015, 15:08

Forum Jump:


Users browsing this thread: 1 Guest(s)