givegun cmd
#1

How do I make a givegun cmd so like
If you have a gun and you want to give it to a friend you use

givegun name id

then they get the gun and you loose it?
Reply
#2

Check this http://forum.sa-mp.com/showthread.ph...ght=sendweapon
Reply
#3

I needed it in zcmd though
Reply
#4

pawn Код:
}
CMD:agivegun(playerid, params[])
{
    if(!AdminCheck(playerid, ADMINLEVEL_LEAD))
        return 1;

    new iPlayerID,
        iWeapon,
        iAmmo;

    if(sscanf(params, "uii", iPlayerID, iWeapon, iAmmo))
    {
        SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /agivegun <PlayerID/PartOfName> <WeaponID> <Ammo>");
        SendClientMessage(playerid, COLOR_WHITE, "3(Club) | 4(knife) | 5(bat) | 6(Shovel) | 7(Cue) | 8(Katana) | 10-13(Dildo) | 14(Flowers)");
        SendClientMessage(playerid, COLOR_WHITE, "16(Grenades) | 18(Molotovs) | 22(Pistol) | 23(SPistol) 24(Eagle) | 25(Shotgun) | 27(SPAS12)");
        SendClientMessage(playerid, COLOR_WHITE, "29(MP5) | 30(AK47) | 31(M4) | 33(Rifle) | 34(Sniper) | 35(Bazooka) | 37(Flamethrower)");
        SendClientMessage(playerid, COLOR_WHITE, "41(Spray) | 42(Fire Extinguisher) | 43(Camera) | 46(Parachute)");

        return 1;
    }

    if(iWeapon < 2 || iWeapon > 46)
    {
        return SendErrorMessage(playerid, "WeaponID cannot be less than 2 or above 46");
    }

    if(iAmmo < 1 || iAmmo > 1500)
    {
        return SendErrorMessage(playerid, "Ammo cannot be above 1500");
    }

    ///////////////Execution//////////////////////
    SafeGivePlayerWeapon(iPlayerID, iWeapon, iAmmo);

    //////////////Messages////////////////////////
    new szMessage[67+MAX_PLAYER_NAME+2+4+MAX_PLAYER_NAME+2+2+4],
        iYear,
        iMonth,
        iDate;
    //////////////////////Player/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    format(szMessage, 46+MAX_PLAYER_NAME+2+4,"[ADMIN] %s just gave you a weapon [%d] with %d ammo", GetPlayerNameEx(playerid), iWeapon, iAmmo);
    SendClientMessage(iPlayerID, COLOR_YELLOW, szMessage);
    ///////////////////////Admin/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    format(szMessage, 46+MAX_PLAYER_NAME+2+4,"[ADMIN] You just gave %s a weapon [%d] with %d ammo", GetPlayerNameEx(iPlayerID), iWeapon, iAmmo);
    SendClientMessage(playerid, COLOR_YELLOW, szMessage);
    ////////////////////////////////////////////////////////////Logging//////////////////////////////////////////////////////////////////////////
    getdate(iYear, iMonth, iDate);
    format(szMessage, 67+MAX_PLAYER_NAME+2+4+MAX_PLAYER_NAME+2+2+4,"[/agivegun] %s was just given a [%d] with %d ammo by administrator %s [%d/%d/%d]", GetPlayerNameEx(iPlayerID), iWeapon, iAmmo, GetPlayerNameEx(playerid), iDate, iMonth, iYear);

    return 1;
}
Reply
#5

I don't want it for admins

I want it so like
A player has a weapon another player has the player does like /givegun then the other player gets the weapon and the player who used /givegun doesn't have the gun anymore
Reply
#6

Here it is
pawn Код:
/*======================================================================================================*
* This /sendweapon Filterscript is made by Jeffry!                                                                  *
*                                                                                                       *
*                                                                                                       *
* Made in April 2010.                                                                                   *
*                                                                                                       *
* Your Rights:                                                                                          *
*                                                                                                       *
* -You are allowed to modify this Filterscript, aslong as you DO NOT remove credits or re-upload it.    *
*                                                                                                       *
* -You are NOT allowed to re-upload this Filterscript.                                                  *
* -You are NOT allowed to claim this as your own.                                                       *
* -You are NOT allowed to remove any credits.                                                           *
*                                                                                                       *
* Thank you.                                                                                            *
* Have fun. I would be happy if you give me /credits.  :D                                               *
*                                                                                                       *
*=======================================================================================================*/


//========================================================================================================================
//-------------------------Definitions that you may change----------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
#define WEAPON_TAX_BILL 10000  //Thats the amount you have to pay, when you send a weapon.
#define MAX_REFUSE_TIME 30    // Thats the time in seconds, which allows the receiver to do /weaponsback.
#define WAIT_TIME 30          // Thats the time in seconds the sender needs to wait to send another weapon.
new ForbiddenWeapons[]= { 44, 45, 38 }; // Here you add the weapon IDs that you do not want to be sent.
//------------------------------------------------------------------------------------------------------------------------
//-------------------------End of the Definitions-------------------------------------------------------------------------
//========================================================================================================================
#include <a_samp>
#include <zcmd>

// The colors.
#define red 0xFF0000AA
#define green 0x33FF33AA
#define dgreen 0x009000FF

new savedweapon[MAX_PLAYERS][13];
new savedammo[MAX_PLAYERS][13];
new Receiver[MAX_PLAYERS];
new Sender[MAX_PLAYERS];
new ReceivedWeapon[MAX_PLAYERS][2];
new Sended[MAX_PLAYERS];

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" [FS] /sendweapon FilterScript by Jeffry");
    print("--------------------------------------\n");
    return 1;
}

public OnPlayerConnect(playerid)
{
    Receiver[playerid]=0;
    Sender[playerid]=-1;
    ReceivedWeapon[playerid][0]=0;
    ReceivedWeapon[playerid][1]=0;
    Sended[playerid]=0;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(Receiver[playerid]!=0) KillTimer(Receiver[playerid]);
    for(new i=0; i<MAX_PLAYERS; i++) if(Sender[i]==playerid) Sender[i]=-1;
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    return 0;
}

CMD:sendweapon(playerid,params[])
{
    if(GetPlayerMoney(playerid) < WEAPON_TAX_BILL)
    {
        new msg[128];
        format(msg, 128, "ERROR: You need $%d to send a weapon!", WEAPON_TAX_BILL);
        return SendClientMessage(playerid, red, msg);
    }
    if(Sended[playerid] != 0)
    {
        new msg[128];
        format(msg, 128, "ERROR: You can only send a weapon every %d seconds!", WAIT_TIME);
        return SendClientMessage(playerid, red, msg);
    }
    new string[156], tmp[256], tmp2[256], weaponname[50], Index; tmp = strtok(params,Index); tmp2 = strtok(params,Index);
    if(!strlen(tmp) || !strlen(tmp2)) return SendClientMessage(playerid,red,"USAGE: /sendweapon [PlayerID] [Ammo]");
    new player1, ammo, weapon, weapon1, slot; player1=strval(tmp); ammo=strval(tmp2);
    if(!IsPlayerConnected(player1)) return SendClientMessage(playerid,red,"ERROR: This player is not connected!");
    if(playerid==player1) return SendClientMessage(playerid,red,"ERROR: You can't give yourself a weapon!");
    if(ammo<1) return SendClientMessage(playerid,red,"ERROR: Invalid ammo amount!");
    weapon=GetPlayerWeapon(playerid); weapon1=GetPlayerWeapon(player1);
    if(weapon==0) return SendClientMessage(playerid,red,"ERROR: You don't have a weapon!");
    for(new i=0; i<sizeof(ForbiddenWeapons); i++) if(weapon==ForbiddenWeapons[i]) return SendClientMessage(playerid,red,"ERROR: You are not allowed to send this weapon!");
    SaveWeapons(playerid); SaveWeapons(player1);
    slot=GetWeaponSlot(weapon);
    if(savedammo[playerid][slot]<ammo) return SendClientMessage(playerid,red,"ERROR: You don't have this amount of ammo!");
    savedammo[playerid][slot]-=ammo;
    ResetPlayerWeapons(playerid); ResetPlayerWeapons(player1);
    GetWeaponName(weapon, weaponname, 50);
    format(string, 156, "[Weapon] %s (ID:%d) has sent you a %s (ID:%d) with %d ammo. Type /weaponsback if you don't want it.", pName(playerid), playerid, weaponname, weapon, ammo);
    SendClientMessage(player1, green, string);
    format(string, 156, "[Weapon] You have sent %s (ID:%d) a %s (ID:%d) with %d ammo.", pName(player1), player1, weaponname, weapon, ammo);
    SendClientMessage(playerid, green, string);
    GivePlayerMoney(playerid, -WEAPON_TAX_BILL);
    GiveWeapons(playerid); GiveWeapons(player1);
    GivePlayerWeapon(player1, weapon, ammo);
    GivePlayerWeapon(player1, weapon1, 0);
    GivePlayerWeapon(playerid, weapon, 0);
    Sender[player1]=playerid; ReceivedWeapon[player1][0]=weapon; ReceivedWeapon[player1][1]=ammo;
    if(Receiver[playerid]!=0) KillTimer(Receiver[playerid]);
    Receiver[player1]=SetTimerEx("OldWeaponsBack", MAX_REFUSE_TIME*1000, 0, "d", player1);
    new time=WAIT_TIME;
    if(time!=0) Sended[playerid]=SetTimerEx("CanSendAgain", time*1000, 0, "d", playerid);
    return 1;
}

CMD:weaponsback(playerid,params[])
{
    #pragma unused params
    if(Receiver[playerid]!=0)
    {
        new weapon;
        weapon=GetPlayerWeapon(playerid);
        ResetPlayerWeapons(playerid);
        GiveWeapons(playerid);
        GivePlayerWeapon(playerid, weapon, 0);
        if(Sender[playerid]!=-1)
        {
            new weap, wname[50], string[128]; weap=GetPlayerWeapon(Sender[playerid]);
            GetWeaponName(ReceivedWeapon[playerid][0], wname, 50);
            ResetPlayerWeapons(Sender[playerid]);
            GiveWeapons(Sender[playerid]);
            GivePlayerWeapon(Sender[playerid], ReceivedWeapon[playerid][0], ReceivedWeapon[playerid][1]);
            GivePlayerWeapon(Sender[playerid], weap, 0);
            format(string, 128, "[Weapon] %s (ID:%d) has refused your weapon and you got it back (%s (ID:%d) with %d ammo) .", pName(playerid), playerid, wname, ReceivedWeapon[playerid][0], ReceivedWeapon[playerid][1]);
            SendClientMessage(Sender[playerid], dgreen, string);
        }
        Receiver[playerid]=0; KillTimer(Receiver[playerid]);
        SendClientMessage(playerid, dgreen, "[Weapon] You have you old weapons back!");
    }
    else
    {
        new string[128];
        format(string, 128, "ERROR: You don't have received any weapons in the last %d seconds!", MAX_REFUSE_TIME);
        SendClientMessage(playerid,red,string);
    }
    return 1;
}

forward SaveWeapons(playerid);
public SaveWeapons(playerid)
{
    for(new i=0; i<13; i++)
    {
        savedweapon[playerid][i]=0; savedammo[playerid][i]=0;
    }
    for(new i=0; i<13; i++) GetPlayerWeaponData(playerid, i, savedweapon[playerid][i], savedammo[playerid][i]);
    return 1;
}

forward GiveWeapons(playerid);
public GiveWeapons(playerid)
{
    for(new i=0; i<13; i++) GivePlayerWeapon(playerid, savedweapon[playerid][i], savedammo[playerid][i]);
    return 1;
}

forward OldWeaponsBack(playerid);
public OldWeaponsBack(playerid)
{
    Receiver[playerid]=0;
    return 1;
}

forward CanSendAgain(playerid);
public CanSendAgain(playerid)
{
    Sended[playerid]=0;
    return 1;
}

stock pName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}

stock GetWeaponSlot(weapon)
{
    switch(weapon)
    {
        case 0,1: return 0;
        case 2..9: return 1;
        case 22..24: return 2;
        case 25..27: return 3;
        case 28,29,32: return 4;
        case 30,31: return 5;
        case 33,34: return 6;
        case 35..38: return 7;
        case 16..18,39: return 8;
        case 41..43: return 9;
        case 10..15: return 10;
        case 44..46: return 11;
        case 40: return 12;
        default: return -1;
    }
    return -1;
}

//strtok
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Reply
#7

Just remove

pawn Код:
if(!AdminCheck(playerid, ADMINLEVEL_LEAD))
        return 1;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)