CMD:give(playerid, params[])
{
new targetid, type, amount, msg[256];
if(sscanf(params, "us[10]i", targetid, type, amount))
{
if(amount < 1 || amount > 9999999)
{
SendClientMessage(playerid, COLOR_RED, "You have typed an invalid amount.");
return 1;
}
if(targetid == playerid)
{
SendClientMessage(playerid, COLOR_RED, "You cannot give an item to yourself.");
return 1;
}
if(PlayerInfo[playerid][LoggedIn] == false)
{
SendClientMessage(playerid, COLOR_RED, "This player was not found.");
return 1;
}
printf("%s", targetid);
new Float:X, Float:Y, Float:Z;
GetPlayerPos(targetid, X, Y, Z);
if(!IsPlayerInRangeOfPoint(playerid, 5.5, X, Y, Z))
{
SendClientMessage(playerid, COLOR_RED, "You are too far away from this player.");
return 1;
}
if(!strcmp(params, "Pot", true))
{
if(amount > PlayerInfo[playerid][Marijuana])
{
SendClientMessage(playerid, COLOR_RED, "You don't have enough of this item on you.");
return 1;
}
PlayerInfo[playerid][Marijuana] -= amount;
PlayerInfo[targetid][Marijuana] += amount;
format(msg, sizeof(msg), "You gave %s grams of marijuana to %s.", amount, GetPlayerNameEx(targetid));
SendClientMessage(playerid, COLOR_GREEN, msg);
format(msg, sizeof(msg), "You received %s grams of marijuana from %s.", amount, GetPlayerNameEx(playerid));
SendClientMessage(targetid, COLOR_GREEN, msg);
format(msg, sizeof(msg), "* %s hands some marijuana to %s.",GetPlayerNameEx(playerid), GetPlayerNameEx(targetid));
ProxDetector(GetPlayerVirtualWorld(playerid) == 0 ? 20.0 : 7.0, playerid, msg, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "HINT: /give [playerid] [item] [amount]");
SendClientMessage(playerid, COLOR_GREY, "HINT: Items: pot");
}
return 1;
}
if(!IsPlayerInRangeOfPoint(playerid, 5.5, X, Y, Z))
{
SendClientMessage(playerid, COLOR_RED, "You are too far away from this player.");
return 1;
}
if(IsPlayerInRangeOfPoint(playerid, 5.5, X, Y, Z))
{
SendClientMessage(playerid, COLOR_RED, "You are too far away from this player.");
return 1;
}
if (sscanf...)
if (!sscanf...)
|
First of all you are doing all the stuff when sscanf stuff. It returns 0 if it succeeds so change
Код:
if (sscanf...) Код:
if (!sscanf...) so as sscanf fails the targetid is 0 or INVALID_PLAYER_ID I assume. Second you are using strcmp on params when you check the type, you must use it on the "type" string. Third you should also check if the target ID is invalid by checking if it's INVALID_PLAYER_ID. Also it's printing something else because targetid is an integer and you are trying to print it as a string, use %i or %d instead. Also you don't need 256 cells for messages because the max length of a client message is 144 as far as I know. You should even use less than 144. |
CMD:give(playerid, params[])
{
new targetid, type[10], amount, msg[144];
if(!sscanf(params, "us[10]i", targetid, type, amount))
{
SendClientMessage(playerid, COLOR_GREY, "HINT: /give [playerid] [item] [amount]");
SendClientMessage(playerid, COLOR_GREY, "HINT: Items: pot");
return 1;
}
if(amount < 1 || amount > 9999999) return SendClientMessage(playerid, COLOR_RED, "You have typed an invalid amount.");
if(targetid == playerid) return SendClientMessage(playerid, COLOR_RED, "You cannot give an item to yourself.");
if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "This player was not found.");
if(PlayerInfo[targetid][LoggedIn] == false) return SendClientMessage(playerid, COLOR_RED, "This player was not found.");
new Float:X, Float:Y, Float:Z;
GetPlayerPos(targetid, X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, 5.5, X, Y, Z))
{
if(!strcmp(type, "Pot", true))
{
if(amount > PlayerInfo[playerid][Marijuana])
{
SendClientMessage(playerid, COLOR_RED, "You don't have enough of this item on you.");
return 1;
}
PlayerInfo[playerid][Marijuana] -= amount;
PlayerInfo[targetid][Marijuana] += amount;
format(msg, sizeof(msg), "You gave %s grams of marijuana to %s.", amount, GetPlayerNameEx(targetid));
SendClientMessage(playerid, COLOR_GREEN, msg);
format(msg, sizeof(msg), "You received %s grams of marijuana from %s.", amount, GetPlayerNameEx(playerid));
SendClientMessage(targetid, COLOR_GREEN, msg);
format(msg, sizeof(msg), "* %s hands some marijuana to %s.",GetPlayerNameEx(playerid), GetPlayerNameEx(targetid));
ProxDetector(GetPlayerVirtualWorld(playerid) == 0 ? 20.0 : 7.0, playerid, msg, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
return 1;
}
} else SendClientMessage(playerid, COLOR_RED, "You are too far away from this player.");
return 1;
}
|
Thanks for pointing out a lot of my mistakes. However, I'm still having some issues. Now when I perform the command, it is saying I've inserted a invalid amount.
Sorry for this, but as you can probably tell, I've never used sscanf2 before. |
|
It is very convenient and easy to use, check out more about it here.
Did you enter a valid amount? Everything seems to be fine in "if(amount < 1 || amount > 9999999)". |