AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Changing clip and backpack ammo in Half-Life (https://forums.alliedmods.net/showthread.php?t=94138)

Silencer123 06-06-2009 21:41

Changing clip and backpack ammo in Half-Life
 
Yes... how would one go on about that?

For Team Fortress, Day of Defeat, Natural Selection, of course for Counter-Strike, and even for the uncommon mod The Specialists there are appropriate modules which provide the functions. But Half-Life, which is the incarnation of standard and default seems to have no support for this at all.

If I am just blind please direct me to the right direction.

Untill then...
Code:
    static wpnid;     static clip;     static ammo;     wpnid = get_user_weapon(id, clip, ammo);         static weapname[33];     get_weaponname(wpnid , weapname , 32);     static wpn;     wpn = -1;         while((wpn = engfunc(EngFunc_FindEntityByString, wpn, "classname", weapname)) != 0) {         if(id == pev(wpn, pev_owner)) {             // Insert magic here             break;         }     }

Exolent[jNr] 06-06-2009 22:07

Re: Changing clip and backpack ammo in Half-Life
 
I saw a thread about this before that had the offsets for half-life.
Search the Scripting Help section for it.

Silencer123 06-07-2009 09:59

Re: Changing clip and backpack ammo in Half-Life
 
This is all I found:
PHP Code:

#include <hamsandwich>
// [...]
ExecuteHam(Ham_GiveAmmoplayerIdammoToAddtype[], bAmmoMax);
// [...] 

Where type would be the ammo type. Unfortunately
"type" is not simply ammo_xyz, but some internal names.
E.g. for radioactive ammo (ammo_gaussclip) you'd write "uranium",
and for crossbow ammo (ammo_crossbow) you'd write "bolts".
The others are "357", "9mm", "buckshot", "rocket" and "ARgrenades".
Took me some time to figure them all out, especially "uranium".

This works, but it changes backpack ammo only. ("uranium" and "ARgrenades" excepted)
My great plan is to directly change clip ammo.
Other Hamsandwich functions only allow to read ammo.
I might use Ham_Player_UpdateClientData, but I don't
know the offsets.

It would be great if you could search for that thread you have in mind.
You'd probably recognize it faster than me?

Thanks in advance.

ConnorMcLeod 06-07-2009 10:28

Re: Changing clip and backpack ammo in Half-Life
 
See this for bpammo offsets : http://forums.alliedmods.net/showthread.php?t=93103

For weapons m_iClip offset you will have to find them by yourself.
For ammo names, you can hook GiveAmmo forward, and for weaponbox ammo names (can be slightly differents like some caps at some places) you have to retrieve weaponbox offset, then convert from iString to szStrind with gbl_SzStringFromIndex or some name like that)

To retrieve weapon by player id, see my snippet (search for id offsets first) :
http://forums.alliedmods.net/showthread.php?t=85962

Arkshine 06-07-2009 10:57

Re: Changing clip and backpack ammo in Half-Life
 
// Weapon

35 - m_flNextPrimaryAttack
36 - m_flNextSecondaryAttack
37 - m_flTimeWeaponIdle
38 - m_iPrimaryAmmoType
39 - m_iSecondaryAmmoType
40 - m_iClip
41 - m_iClientClip


// player

306 - m_pActiveItem
307 - m_pClientActiveItem
308 - m_pLastItem
310 -> 321 : m_rgAmmo
342 -> 353 : m_rgAmmoLast

Silencer123 06-07-2009 13:34

Re: Changing clip and backpack ammo in Half-Life
 
Thanks for the offsets, but I can't get it to work...
Code:
#include <amxmodx> #include <hamsandwich> new const VERSION[] = "1.0"; public plugin_init() {     register_plugin("HL Unlimited Ammo", VERSION, "Silencer");     register_concmd("say ammo", "hlum_ammo"); } public hlum_ammo(id) {     client_print(id, print_chat, "Ammoes!1");     for(new i = 310; i <= 321; i++) {         ExecuteHam(Ham_Player_UpdateClientData, id, i, 250);     }     for(new i = 342; i <= 353; i++) {         ExecuteHam(Ham_Player_UpdateClientData, id, i, 250);     } }

Not even a merciless crash, as if nothing happened.

Arkshine 06-07-2009 13:46

Re: Changing clip and backpack ammo in Half-Life
 
Ham_Player_UpdateClientData has not the purpose to give clip or bpammo.

Use : set_pdata_int( WeaponIndex, m_iClip, Ammo, 4 );

- WeaponIndex = Weapon entity index
- m_iClip = Weapon offset, 40
- Ammo = New ammo value
- 4 = Extra offset for linux. Since it's a linux offset, it's 4.

Silencer123 06-09-2009 12:44

Re: Changing clip and backpack ammo in Half-Life
 
That works fine, especially doing fastfire with m_flNextPrimaryAttack on the rocket launcher is awesome. Thanks!

Now... how would I go about nicely hooking this up to player fire? Like: Player fires, and I block ammo deduction and hook up a different value for m_flNextPrimaryAttack. Would that be possible with forwarding UpdateClientData?

--kml-- 06-09-2009 21:55

Re: Changing clip and backpack ammo in Half-Life
 
PHP Code:

if(pev(idpev_button) & ATTACK

token from here
http://forums.alliedmods.net/showthread.php?t=93644


EDIT:

ooops i forgot put crabs xD

:crab::crab::crab:



ConnorMcLeod 06-10-2009 00:38

Re: Changing clip and backpack ammo in Half-Life
 
Look at my 2 plugins :

http://forums.alliedmods.net/showthread.php?p=728613
http://forums.alliedmods.net/showthread.php?t=81183

I also suggest you to have a look at HLSDK from where i copied almost all code of those plugins and where you gonna find code for each HL weapon.
Also, not that what i did is hook correct places, but doesn't mean you can't achieve it more efficiently, or less cpu using.


All times are GMT -4. The time now is 15:09.

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