Raised This Month: $12 Target: $400
 3% 

Changing clip and backpack ammo in Half-Life


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Silencer123
Veteran Member
Join Date: Jul 2006
Location: Germany (GMT+1)
Old 06-06-2009 , 21:41   Changing clip and backpack ammo in Half-Life
Reply With Quote #1

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;         }     }
__________________
EAT YOUR VEGGIES
Silencer123 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-06-2009 , 22:07   Re: Changing clip and backpack ammo in Half-Life
Reply With Quote #2

I saw a thread about this before that had the offsets for half-life.
Search the Scripting Help section for it.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Silencer123
Veteran Member
Join Date: Jul 2006
Location: Germany (GMT+1)
Old 06-07-2009 , 09:59   Re: Changing clip and backpack ammo in Half-Life
Reply With Quote #3

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.
__________________
EAT YOUR VEGGIES

Last edited by Silencer123; 06-07-2009 at 10:04.
Silencer123 is offline
Old 06-07-2009, 10:13
xPaw
This message has been deleted by xPaw. Reason: nvm
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-07-2009 , 10:28   Re: Changing clip and backpack ammo in Half-Life
Reply With Quote #4

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
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-07-2009 , 10:57   Re: Changing clip and backpack ammo in Half-Life
Reply With Quote #5

// 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
__________________

Last edited by Arkshine; 06-07-2009 at 11:20.
Arkshine is offline
Silencer123
Veteran Member
Join Date: Jul 2006
Location: Germany (GMT+1)
Old 06-07-2009 , 13:34   Re: Changing clip and backpack ammo in Half-Life
Reply With Quote #6

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.
__________________
EAT YOUR VEGGIES
Silencer123 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-07-2009 , 13:46   Re: Changing clip and backpack ammo in Half-Life
Reply With Quote #7

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.
__________________
Arkshine is offline
Silencer123
Veteran Member
Join Date: Jul 2006
Location: Germany (GMT+1)
Old 06-09-2009 , 12:44   Re: Changing clip and backpack ammo in Half-Life
Reply With Quote #8

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?
__________________
EAT YOUR VEGGIES
Silencer123 is offline
--kml--
Senior Member
Join Date: Jan 2009
Old 06-09-2009 , 21:55   Re: Changing clip and backpack ammo in Half-Life
Reply With Quote #9

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




__________________
wooT now is asking season
will ask you plenty of things for learning

Last edited by --kml--; 06-09-2009 at 21:57.
--kml-- is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-10-2009 , 00:38   Re: Changing clip and backpack ammo in Half-Life
Reply With Quote #10

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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply


Thread Tools
Display Modes

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 04:42.


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