Raised This Month: $ Target: $400
 0% 

[AMXX 1.8.1] Changing the amount of ammunition for the weapons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Daku
Senior Member
Join Date: Nov 2009
Location: Poland / Polska
Old 11-13-2009 , 18:17   Re: [AMXX 1.8.1] Changing the amount of ammunition for the weapons
Reply With Quote #1

Code:
#include <amxmodx>
#include <engine>
#include <cstrike>

// should be greater than corresponding standard
#define CLIP_AMMO 60

public plugin_init() {
    register_event("WeapPickup", "event_weapon_pickup", "be")
    register_event("CurWeapon","CurWeapon","be", "1=1") 
    register_event("DeathMsg", "DeathMsg", "a")
}

public event_weapon_pickup(id) {
    // get id of collected weapon
    new wid = read_data(1)

    if (wid == CSW_MP5NAVY) {
        new param[1]
        param[0] = wid

        // wait a bit since weapon entity not created yet
        set_task(0.1, "task_set_ammo", id, param, 1)
    }
}

public task_set_ammo(param[1], id) {
    new wid = param[0], wname[20]

    // weapon name is the same as weapon entity classname
    get_weaponname(wid, wname, 19)

    // find weapon entity index by it's classname and owner
    new went = find_ent_by_owner(-1, wname, id)
    if (!went) // if weapon entity isn't found
        return

    // get amount of ammo in clip of collected weapon
    new clip = cs_get_weapon_ammo(went)
    if (clip >= CLIP_AMMO) // if ammo addition isn't required
        return

    // get amount of player's pack ammo for collected weapon
    new pack = cs_get_user_bpammo(id, wid)
    if (!pack) // if player have no ammo for that weapon
        return

    // total available amount of ammo for collected weapon
    new total = clip + pack

    // here will be stored result ammo amount for clip and pack
    new clip2, pack2

    // if total ammo greater than or equal to defined clip ammo
    if (total >= CLIP_AMMO) {
        clip2 = CLIP_AMMO
        pack2 = total - CLIP_AMMO
    }
    else {
        clip2 = total
        pack2 = 0
    }

    // set new clip and pack ammo amount for collected weapon
    cs_set_weapon_ammo(went, clip2)
    cs_set_user_bpammo(id, wid, pack2)


    }
new old_ammo[33] 

public CurWeapon(id) 
{ 
    new wid = read_data(2)    // Id broni 
    new ammo = read_data(3)    // liczba naboi w magazynku 
    if(wid== CSW_MP5NAVY) 
    { 
       if(old_ammo[id]<ammo)  // reload 
       { 
           new param[1] 
           param[0] = wid 
           set_task(0.1, "task_set_ammo", id, param, 1) 
           ammo=CLIP_AMMO 
       } 
       old_ammo[id]=ammo 
    } 
} 

public DeathMsg() 
{  
    new vid = read_data(2)    // ofiara 
    old_ammo[vid]=0 
}
public client_connect(id) 
{ 
    old_ammo[id]=0 
}
It works but it wrong if drop weapon and put ammo reset to 60 and from BPammo -ammo added to clip
Daku is offline
Send a message via Skype™ to Daku
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-13-2009 , 18:32   Re: [AMXX 1.8.1] Changing the amount of ammunition for the weapons
Reply With Quote #2

Use my plugin and register only mp5.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode