Help with getting the player id
#1

I'm making a /killp command, and instead of
Код:
SetPlayerHealth(playerid, 0.0);
so to make it so it kills the playerid i say, what would i replace playerid with?
Reply
#2

pawn Код:
COMMAND:killp(playerid, params[])
{
    new userid;
    if(sscanf(params, "u",userid)) return SendClientMessage(playerid, "/killp [PlayerID/Username]");
    SetPlayerHealth(userid, 0.0;
    return 1;
}
Reply
#3

@The___
pawn Код:
SetPlayerHealth(userid, 0.0;
wrong you are missing bracket
change it to
pawn Код:
SetPlayerHealth(userid, 0.0);
Reply
#4

Код:
CMD:killp(playerid,params[])
{        
        new id,string[128],pName[MAX_PLAYER_NAME];
        if(sscanf(params,"us",id))
	return SendClientMessage(playerid,BLUE,"USAGE: /killp [id]");
	if(!IsPlayerConnected(id))
	return SendClientMessage(playerid,BLUE,"That player is not connected!");
	GetPlayerName(id,pName,sizeof(pName));
	format(string,sizeof(string),"You have forcedfully killed %s.",pName);
	SendClientMessage(playerid,COLOR_MEDIUMORCHID,string);
	SetPlayerHealth(id,0.0);
	return 1;
}
Reply
#5

Quote:
Originally Posted by Nabster
Посмотреть сообщение
Код:
CMD:killp(playerid,params[])
{        
        new id,string[128],pName[MAX_PLAYER_NAME];
        if(sscanf(params,"us",id))
	return SendClientMessage(playerid,BLUE,"USAGE: /killp [id]");
	if(!IsPlayerConnected(id))
	return SendClientMessage(playerid,BLUE,"That player is not connected!");
	GetPlayerName(id,pName,sizeof(pName));
	format(string,sizeof(string),"You have forcedfully killed %s.",pName);
	SendClientMessage(playerid,COLOR_MEDIUMORCHID,string);
	SetPlayerHealth(id,0.0);
	return 1;
}
Why do you have an 's' parameter in your sscanf function? You are not using it.

pawn Код:
if(sscanf(params,"u",id))
    return SendClientMessage(playerid,BLUE,"USAGE: /killp [id]");
Reply
#6

Can anyone help with it in Strcmp?
Reply
#7

here you go

pawn Код:
if (!strcmp("/killp", cmdtext, true, 5))
    {
    if (!IsPlayerAdmin(playerid)) return 1;
    new id, pname[24], string[240];
    if (sscanf(cmdtext[5],"u", id)) return SendClientMessage(playerid, -1, "Usage: /killp [playerid]");
    if(id == INVALID_PLAYER_ID)return SendClientMessage(playerid, COLOR_RED, "Invalid Player");
    SetPlayerHealth(id,0.0);
    GetPlayerName(id, pname, 24);
    format(string, 245, "You Have Killed %s .", pname1);
    SendClientMessage(playerid, 0xFF0000AA, string);
    return 1;
    }
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)