[HELP]: Commands
#1

Hello !

Well, here is my command:

pawn Код:
CMD:slap(playerid, params[])
{
    new targetid; new string[150]; new Float: x, Float: y, Float: z;
    if(sscanf(params, "u", targetid))return SendClientMessage(playerid, GREY, "[USAGE]: /slap {FF0000}[PlayerID]");
    if(targetid == INVALID_PLAYER_ID)return SendClientMessage(playerid, RED, "[SERVER]: {FFFFFF}This player is {FF0000}NOT {FFFFFF}valid !");
    format(string, sizeof(string), "{FFFFFF}[SERVER]: {800080}%s(ID:%d) {FFFFFF}has been slapped by {800080}%s(ID:%d) {FFFFFF}!", GetName(targetid), targetid, GetName(playerid), playerid);
    SendClientMessageToAll(PURPLE, string);
    GetPlayerPos(targetid, x, y, z);
    SetPlayerPos(targetid, x, y, z +10);
    return 1;
}
So the problem is, whatever id i type, the message is still send that the player has been slapped. It should send that the player is invalid...
Reply
#2

Try this.
pawn Код:
CMD:slap(playerid, params[])
{
    new targetid; new string[150]; new Float: x, Float: y, Float: z;
    if(sscanf(params, "u", targetid))return SendClientMessage(playerid, GREY, "[USAGE]: /slap {FF0000}[PlayerID]");
    if(!IsPlayerConnected(targetid))return SendClientMessage(playerid, RED, "[SERVER]: {FFFFFF}This player is {FF0000}NOT {FFFFFF}valid !");
    format(string, sizeof(string), "{FFFFFF}[SERVER]: {800080}%s(ID:%d) {FFFFFF}has been slapped by {800080}%s(ID:%d) {FFFFFF}!", GetName(targetid), targetid, GetName(playerid), playerid);
    SendClientMessageToAll(PURPLE, string);
    GetPlayerPos(targetid, x, y, z);
    SetPlayerPos(targetid, x, y, z +10);
    return 1;
}
Reply
#3

It's really weird since it returns a value.

Try it like that:
pawn Код:
CMD:slap(playerid, params[])
{
    new targetid;
    if(sscanf(params, "r", targetid)) SendClientMessage(playerid, GREY, "[USAGE]: /slap {FF0000}[PlayerID]");
    else if(targetid == INVALID_PLAYER_ID) SendClientMessage(playerid, RED, "[SERVER]: {FFFFFF}This player is {FF0000}NOT {FFFFFF}valid !");
    else
    {
        new string[144], Float: x, Float: y, Float: z;
        format(string, sizeof(string), "{FFFFFF}[SERVER]: {800080}%s(ID:%d) {FFFFFF}has been slapped by {800080}%s(ID:%d) {FFFFFF}!", GetName(targetid), targetid, GetName(playerid), playerid);
        SendClientMessageToAll(PURPLE, string);
        GetPlayerPos(targetid, x, y, z);
        SetPlayerPos(targetid, x, y, z +10);
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It's really weird since it returns a value.

Try it like that:
pawn Код:
CMD:slap(playerid, params[])
{
    new targetid;
    if(sscanf(params, "r", targetid)) SendClientMessage(playerid, GREY, "[USAGE]: /slap {FF0000}[PlayerID]");
    else if(targetid == INVALID_PLAYER_ID) SendClientMessage(playerid, RED, "[SERVER]: {FFFFFF}This player is {FF0000}NOT {FFFFFF}valid !");
    else
    {
        new string[144], Float: x, Float: y, Float: z;
        format(string, sizeof(string), "{FFFFFF}[SERVER]: {800080}%s(ID:%d) {FFFFFF}has been slapped by {800080}%s(ID:%d) {FFFFFF}!", GetName(targetid), targetid, GetName(playerid), playerid);
        SendClientMessageToAll(PURPLE, string);
        GetPlayerPos(targetid, x, y, z);
        SetPlayerPos(targetid, x, y, z +10);
    }
    return 1;
}
Well, that's works. Thanks
Reply
#5

So, the problem was "u" in sscanf part ?
Reply
#6

R checks for username and ID for players only, u checks for both, bots and players. I think it's the issue.
Reply
#7

Quote:
Originally Posted by Areax
Посмотреть сообщение
So, the problem was "u" in sscanf part ?
I'm not sure.

I just changed it to "r" because you'll never slap a NPC! But I don't think that would be the problem as long as the message appeared but the name of the player you chose was NULL.

It should've worked in the first place but for some reason return failed so if/else if/else was the only way I could think of.
Reply
#8

Try This
Код:
CMD:slap(playerid,params[])
{
    new string[128];
    new ID;
    if(sscanf(params,"ui",ID))
	{
	    SendClientMessage(playerid,COLOR_ERROR,"USAGE: /slap (Player Name/ID)");
	    return 1;
	}
	if(!IsPlayerConnected(ID))
	{
	    format(string,sizeof(string),"The player ID (%d) is not connected to the server. You cannot give them Regular Player status.",ID);
	    SendClientMessage(playerid,COLOR_ERROR,string);
	    return 1;
	}
	if(IsKidnapped[playerid] == 1)
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You are kidnapped. You cannot use this command.");
	    return 1;
	}
	if(IsKidnapped[ID] == 1)
	{
	    SendClientMessage(playerid,COLOR_ERROR,"This player is kidnapped. You cannot use this command.");
	    return 1;
	}
	if(!IsPlayerConnected(ID))
	{
		format(string,sizeof(string),"The Player ID (%d) is not connected to the server. You cannot cure them.",ID);
		SendClientMessage(playerid,COLOR_ERROR,string);
		return 1;
	}
	new Float:x,Float:y,Float:z;
	GetPlayerPos(ID,x,y,z);

	SetPlayerPos(ID,x,y,z+30);
	SendClientMessage(ID,COLOR_DEADCONNECT,"[[_Slaped_]]");
	format(string,sizeof(string),"[ADMIN ACTION]You have been slaped by %s(%d)",PlayerName(playerid),playerid);
	SendClientMessage(ID,COLOR_ADMIN,string);

	format(string,sizeof(string),"[ADMIN ACTION]You have Slaped %s(%d).",PlayerName(ID),ID);
	SendClientMessage(playerid,COLOR_ADMIN,string);

	format(string,sizeof(string),"3[ADMIN ACTION] %s(%d) has been slaped by %s(%d).",PlayerName(ID),ID,PlayerName(playerid),playerid);
	IRC_GroupSay(gGroupID,IRC_CHANNEL,string);
	return 1;
}
+REP IF HELPED
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)