Admin command to giveweapon
#4

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.

PHP код:
COMMAND:agiveweapon(playeridparams[])
{
    if(!
logged[playerid])
        return 
SendClientMessage(playeridCOLOR_BRIGHTRED"You must be logged in!");
    
    if(
PlayerInfo[playerid][pAdmin] < 1)
        return 
SendClientMessage(playeridCOLOR_BRIGHTRED"You are not allowed to use that command!");
    
    new
        
targetid INVALID_PLAYER_ID,
        
weaponid,
        
ammo;
    
    if(
sscanf(params"uii"targetidweaponid ammo))
        return 
SendClientMessage(playeridCOLOR_LIGHTBLUE"USAGE: /agiveweapon [id] [arme] [munitions]");
        
    if(!
IsPlayerConnected(targetid))
    {            
        
format(stringsizeof(string), "ID:%d is not an active player."targetid);
        
SendClientMessage(playeridCOLOR_BRIGHTREDstring);
        return 
1;
    }

    new
        
targetName[MAX_PLAYER_NAME],
        
weaponName[32];
        
    
GetPlayerName(targetidtargetNamesizeof targetName);
    
GetWeaponName(weaponidweaponNamesizeof weaponName);
    
    
GivePlayerWeapon(targetidweaponidammo);
    
    
format(stringsizeof(string), "You have given %s a %d with %d ammo."targetNameweaponNameammo);
    
SendClientMessage(playeridCOLOR_ORANGEstring);
    return 
1;

Reply


Messages In This Thread
[FIXED] Admin command to giveweapon - by Adamsy - 13.08.2016, 13:16
Re: Admin command to giveweapon - by oMa37 - 13.08.2016, 13:49
Re: Admin command to giveweapon - by Adamsy - 13.08.2016, 14:12
Re: Admin command to giveweapon - by Vince - 13.08.2016, 14:21
Re: Admin command to giveweapon - by Adamsy - 13.08.2016, 23:23
Re: Admin command to giveweapon - by Dayrion - 14.08.2016, 00:00
Re: Admin command to giveweapon - by Adamsy - 14.08.2016, 01:48
Re: Admin command to giveweapon - by Shinja - 14.08.2016, 02:46
Re: Admin command to giveweapon - by Adamsy - 14.08.2016, 03:15
Re: Admin command to giveweapon - by Shinja - 14.08.2016, 11:37

Forum Jump:


Users browsing this thread: 1 Guest(s)