13.08.2016, 14:21
It's weird, but for some apparent reason "beginner" scripters always tend to start with the most outdated and/or complicated of scripts. I really don't know why that is.
The biggest underlying problem is that you are using a mixture of "id" and "giveplayerid". Where the latter one comes from, I don't know because you don't declare it. Use either of those but not a mixture of both.
Furthermore, you can only get the name of the target player after you have verified that this player is, in fact, connected. You'll also want to give the weapon to the target player instead of the player that executes the command.
Here is the command in a modern command processor, ZCMD. I'm not going to provide the solution in old-fashioned strcmp because a) I find that to be counterproductive and b) the code will likely be copy-pasted and you will still not understand what is going on.
The biggest underlying problem is that you are using a mixture of "id" and "giveplayerid". Where the latter one comes from, I don't know because you don't declare it. Use either of those but not a mixture of both.
Furthermore, you can only get the name of the target player after you have verified that this player is, in fact, connected. You'll also want to give the weapon to the target player instead of the player that executes the command.
Here is the command in a modern command processor, ZCMD. I'm not going to provide the solution in old-fashioned strcmp because a) I find that to be counterproductive and b) the code will likely be copy-pasted and you will still not understand what is going on.
PHP код:
COMMAND:agiveweapon(playerid, params[])
{
if(!logged[playerid])
return SendClientMessage(playerid, COLOR_BRIGHTRED, "You must be logged in!");
if(PlayerInfo[playerid][pAdmin] < 1)
return SendClientMessage(playerid, COLOR_BRIGHTRED, "You are not allowed to use that command!");
new
targetid = INVALID_PLAYER_ID,
weaponid,
ammo;
if(sscanf(params, "uii", targetid, weaponid ammo))
return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /agiveweapon [id] [arme] [munitions]");
if(!IsPlayerConnected(targetid))
{
format(string, sizeof(string), "ID:%d is not an active player.", targetid);
SendClientMessage(playerid, COLOR_BRIGHTRED, string);
return 1;
}
new
targetName[MAX_PLAYER_NAME],
weaponName[32];
GetPlayerName(targetid, targetName, sizeof targetName);
GetWeaponName(weaponid, weaponName, sizeof weaponName);
GivePlayerWeapon(targetid, weaponid, ammo);
format(string, sizeof(string), "You have given %s a %d with %d ammo.", targetName, weaponName, ammo);
SendClientMessage(playerid, COLOR_ORANGE, string);
return 1;
}