givegun cmd
#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


Messages In This Thread
givegun cmd - by sanrock - 17.06.2012, 09:37
Re: givegun cmd - by Ironboy - 17.06.2012, 09:40
Re: givegun cmd - by sanrock - 17.06.2012, 09:42
Re: givegun cmd - by N0FeaR - 17.06.2012, 09:50
Re: givegun cmd - by sanrock - 17.06.2012, 09:57
Re: givegun cmd - by Ironboy - 17.06.2012, 14:13
Re: givegun cmd - by N0FeaR - 17.06.2012, 14:26

Forum Jump:


Users browsing this thread: 1 Guest(s)