AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Weapon Pickup / Set AK47 & M4A1 to 50 bullets clip. (https://forums.alliedmods.net/showthread.php?t=27216)

hebusletroll 04-17-2006 15:15

Weapon Pickup / Set AK47 & M4A1 to 50 bullets clip.
 
Dear friends

Actually, i have any trouble to define 50 bullets per clip (when weapon picked up).

My problem is that when i set the ammo count, this is not for the current picked up weapon, but the previous used weapon.

My code :

Code:

public plugin_init()
{
                register_plugin("PowerWeapons", "1.0", "Hebusletroll")
                register_event("WeapPickup","weapon_pickup","be")
}

public weapon_pickup(id)
{
        new clip,ammo
        new weapon = get_user_weapon(id,clip,ammo)
        cs_set_weapon_ammo(get_weaponid(id,weapon),50)
}

public get_weaponid(pid,wid)
{
        new wpn[32],weapon_index = -1
        get_weaponname(wid,wpn,31)
        while ((weapon_index = find_ent_by_class(weapon_index, wpn)) != 0)
                {
                if (pid == entity_get_edict(weapon_index, EV_ENT_owner))
                        {
                        return weapon_index
                }
        }
        return -1
}

:mrgreen: :mrgreen:

My plugins (PowerWeapons), add (not replace !), many new weapons like :

Silver Kalachnikov,
Colt Carabine M4M203,
Magnum 44,
Molotov cocktail,
Canister,
Poisonned grenade,
Sawed off,
Rocket launcher,
Minigun.

All without DLL servers side supplement (like WTF, etc). and no client modification.

And more features. :D

Actually i'm blocked with this 50 bullets features.

hebusletroll 04-18-2006 11:45

Up,

I have tried another solution, but not working, always previous selected weapon will set ammo to 50 :(

hihi :D

p3tsin 04-18-2006 12:09

Code:
public weapon_pickup(id,weapon) {    cs_set_weapon_ammo(get_weaponid(id,weapon),50) }

(or use read_data(1) to get the weapon) :wink:

nordy 04-18-2006 12:47

good idea just finish this well :D

VEN 04-19-2006 15:04

Quote:

I have tried another solution, but not working, always previous selected weapon will set ammo to 50
Because when that event is called player still not have that weapon.

You should note that this method is exploitable.
It's possible to reload weapon and gain 20 extra ammo (50-30) then drop and collect weapon again and repeat given steeps.

Take a look on the code below, it does not have such exploit.
Code:
#include <amxmodx> #include <engine> #include <cstrike> // should be greater than corresponding standard #define CLIP_AMMO 50 public plugin_init() {     register_event("WeapPickup", "event_weapon_pickup", "be") } public event_weapon_pickup(id) {     // get id of collected weapon     new wid = read_data(1)     if (wid == CSW_AK47 || wid == CSW_M4A1) { // if ak47 or m4a1         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) }

But you also should note that this method will not redefine clip capacity.
It only will set 50 ammo for collected weapon's clip and nothing more.

To complete that you need to figure out when weapon is reloaded and perfor similar steeps.


All times are GMT -4. The time now is 05:02.

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