Dcmd (/command id)
#1

Heey all,

I have sscanf and have made commands with dcmd.
But when i want to rob someone with (/rob id) it detects my id so it says :you cannot rob yourself
How can i fix it?

Thanks Admigo
Reply
#2

Do you have the latest version of sscanf?
Reply
#3

if(sscanf(cmdtext,"u", id)) return SendClientMessage(playerid, -1, "USAGE: /rob [id]");
Use "u", and yeh you probably forgot to add the "return" SCM.
Reply
#4

Код:
new ID;
if(sscanf(params,"u",ID)) return SendClientMessage(playerid,0xA70000FF,"Syntax: /Rob ID.");
if(playerid == ID) return SendClientMessage(playerid,0xA70000FF,"You cannot rob yourself.");
Reply
#5

show the code...
Reply
#6

Here is my code:
Код:
dcmd_rob(playerid,params[])
{
	new string[128];
	new ID;
	if(sscanf(params, "u", ID))
	{
	    SendClientMessage(playerid,COLOR_RED,"USAGE: /rob (Player Name/ID)");
	    return 1;
	}
    if(IsSpawned[playerid] != 1)
	{
	    SendClientMessage(playerid,COLOR_RED,"You must be alive and spawned in order to be able to use this command.");
	    return 1;
	}

	if(InAdminMode[ID] == 1)
	{
	    SendClientMessage(playerid,COLOR_RED,"You cannot use this command on this player because they are in Administrator mode.");
	    return 1;
	}
	if(IsKidnapped[playerid] == 1)
	{
	    SendClientMessage(playerid,COLOR_RED,"You are kidnapped. You cannot use this command.");
	    return 1;
	}
	if(gTeam[playerid] != TEAM_CONARTIST&&gTeam[playerid] != TEAM_PICKPOCKET)
	{
	    SendClientMessage(playerid,COLOR_RED,"Only Con Artist And Pickpocket Can Rob Players.");
	    return 1;
	}
	if(!IsPlayerConnected(ID))
	{
	    format(string,sizeof(string),"The player ID (%d) is not connected to the server. You cannot rob them",ID);
	    SendClientMessage(playerid,COLOR_RED,string);
	    return 1;
	}
	if(GetDistanceBetweenPlayers(playerid,ID) > 4)
	{
	    format(string,sizeof(string),"%s(%d) is too far away. You cannot reach him to rob him.",PlayerName(ID),ID);
	    SendClientMessage(playerid,COLOR_RED,string);
	    return 1;
	}
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
	{
	    SendClientMessage(playerid,COLOR_RED,"You cannot rob someone while in a vehicle. Exit the vehicle first.");
	    return 1;
	}
	if(GetPlayerState(ID) == PLAYER_STATE_DRIVER || GetPlayerState(ID) == PLAYER_STATE_PASSENGER)
	{
	    SendClientMessage(playerid,COLOR_RED,"You cannot rob someone while they are in a vehicle. Get them to exit the vehicle first.");
	    return 1;
	}
	if(playerid == ID)
	{
	    SendClientMessage(playerid,COLOR_RED,"You cannot rob yourself!");
	    return 1;
	}
	if(IsSpawned[ID] != 1)
	{
	    format(string,sizeof(string),"%s(%d) is not spawned. You cannot rob dead people ..",PlayerName(ID),ID);
	    SendClientMessage(playerid,COLOR_RED,string);
	    return 1;
	}

	if(AttemptedToRobRecently[playerid] >= 1)
	{
		SendClientMessage(playerid,COLOR_RED,"You are too tired from your last rob attempt. Please wait before robbing again.");
		return 1;
	}
	if(HasRobbedRecently[playerid] >= 1)
	{
	    SendClientMessage(playerid,COLOR_RED,"You are too tired from the last person you robbed. Please wait before robbing again.");
	    return 1;
	}
	if(GetPlayerMoney(ID) <= 0)
	{
	    SendClientMessage(playerid,COLOR_RED,"That player has no money in their pockets. What would be the point in robbing them?");
	    return 1;
	}
	new crand = random(100);
	if(crand <= 30 && gTeam[playerid] == TEAM_CONARTIST)
	{
	    format(string,sizeof(string),"You failed to rob %s(%d). ",PlayerName(ID),ID);
		AttemptedToRobRecently[playerid] =35;
		return 1;
	}
	if(crand <= 65 && gTeam[playerid] == TEAM_PICKPOCKET)
	{
	    format(string,sizeof(string),"You have robbed $%d from %s(%d). Careful they dont come after you!",PlayerName(ID),ID);
		AttemptedToRobRecently[playerid] =35;
		return 1;
	}
	if(GetDistanceBetweenPlayers(playerid,ID) <= 4 && crand > 70&& gTeam[playerid] == TEAM_CONARTIST)
	{
	    new current_zone = player_zone[playerid];
	    new RobMoney = floatround( floatmul( GetPlayerMoney(ID), 0.25 ), floatround_ceil );
		GivePlayerMoney(playerid, RobMoney);
		GivePlayerMoney(ID, -RobMoney);
	    SendClientMessage(playerid,COLOR_DEADCONNECT,"[[_Player Robbed_]]");
	    format(string,sizeof(string),"You have robbed $%d from %s(%d). Careful they dont come after you!",RobMoney,PlayerName(ID),ID);
		SendClientMessage(playerid,COLOR_LIGHTBLUE,string);

		SetPlayerWantedLevel(playerid,2);
		HasRobbedRecently[playerid] =60;
		IncreasePlayerScore(playerid,3);

	    format(string,sizeof(string),"There is $%d robbed from you by %s(%d).",RobMoney,PlayerName(playerid),playerid);
		SendClientMessage(ID,COLOR_RED,string);


		format(string,sizeof(string),"[POLICE RADIO] Robbery: %s(%d) has robbed $%d from %s(%d). Location: %s.",PlayerName(playerid),playerid,RobMoney,PlayerName(ID),ID,zones[current_zone][zone_name]);
		SendClientMessageToAllCops(string);
		return 1;
	}
	if(GetDistanceBetweenPlayers(playerid,ID) <= 4 && crand > 35&& gTeam[playerid] == TEAM_PICKPOCKET)
	{
	    new current_zone = player_zone[playerid];
	    new RobMoney = floatround( floatmul( GetPlayerMoney(ID), 0.38 ), floatround_ceil );
		GivePlayerMoney(playerid, RobMoney);
		GivePlayerMoney(ID, -RobMoney);
	    SendClientMessage(playerid,COLOR_DEADCONNECT,"[[_Player Robbed_]]");
	    format(string,sizeof(string),"You have robbed $%d from %s(%d). Careful they dont come after you!",RobMoney,PlayerName(ID),ID);
		SendClientMessage(playerid,COLOR_RED,string);

		SetPlayerWantedLevel(playerid,2);
		HasRobbedRecently[playerid] =60;
		IncreasePlayerScore(playerid,3);

	    format(string,sizeof(string),"You have had $%d robbed from you by %s(%d).",RobMoney,PlayerName(playerid),playerid);
		SendClientMessage(ID,COLOR_RED,string);


		format(string,sizeof(string),"[POLICE RADIO] Robbery: %s(%d) has robbed $%d from %s(%d). Location: %s.",PlayerName(playerid),playerid,RobMoney,PlayerName(ID),ID,zones[current_zone][zone_name]);
		SendClientMessageToAllCops(string);
		return 1;
	}
	return 1;
}
Pls help
Reply
#7

Change this

pawn Код:
if(sscanf(params, "u", ID))
{
     SendClientMessage(playerid,COLOR_RED,"USAGE: /rob (Player Name/ID)");
     return 1;
}
into

pawn Код:
if(sscanf(params, "u", ID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /rob (Player Name/ID)");
Reply
#8

But why he detects me id everytime?
Reply
#9

Quote:
Originally Posted by Bogdan1992
Посмотреть сообщение
Change this

pawn Код:
if(sscanf(params, "u", ID))
{
     SendClientMessage(playerid,COLOR_RED,"USAGE: /rob (Player Name/ID)");
     return 1;
}
into

pawn Код:
if(sscanf(params, "u", ID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /rob (Player Name/ID)");
That code does the same as above.

Quote:

But why he detects me id everytime?

Update your sscanf plugin then it should be fixed
Reply
#10

Quote:

But why he detects me id everytime?

try another name or id
not a part of your name
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)