Content Creation > Work In Progress

Having more than 32 weapons in Half-Life mod?


Hello All, I hope the old crew is doing good those days.

I know it's more than 20 year old engine, but still It never gets old if you know what I mean.
So I started again with one of my coding projects for Half-Life - it's arena mod with intended more than 32 weapons. The original idea was to have around 40 different weapons, unfortunately I guess I hit a roadblock...

I have the following issue:

Having more than 32 weapons in Half-Life mod.

For quite some time I was trying to incorporate more than 32 weapon in my Half-Life mod. I noticed there's a dependency between the number of "WEAPON_SUIT" and the number of allowed weapons on the mod.

For example by default the number of the suit is 31:


--- Code: ---#define WEAPON_SUIT 31 // ?????
--- End code ---


--- Code: ---#define WEAPON_SUIT 31
--- End code ---

Note that I already have the Max_WEAPONS redefined as 64 defined (I know that the hard limit for max weapons in the engine is actually 64:

--- Code: ---
--- End code ---
#define MAX_WEAPONS 64[/code]

The definition for all weapons is the following:

--- Code: ---#define WEAPON_ALLWEAPONS (~(1<<WEAPON_SUIT))
--- End code ---

So we're dependent on the number of the WEAPON_SUIT. If I try to add weapon with number above 32, I get the game to crash/freeze. I have double checked and it's not with the weapon code or with the definitions for that specific weapon (I obviously commented out another weapon and placed my code over that weapon's place and it all worked fine).
If I add weapon beyond 32, I don't get errors in the compiler and the "client" and "server" library compile well. So I started playing around with the definitions.

If I put WEAPON_SUIT to greater value than 31, (example 64, 128 or 256; I tested other values from 33 to 256 - the result is the same).
I can define more than 32 weapons for the mod, however there are other issues arising after that...

1. I get the following warnings when I compile:

--- Quote ---1>d:\sdk_\dlls\player.cpp(761): warning C4293: '<<' : shift count negative or too big, undefined behavior
1>d:\sdk_\dlls\items.cpp(188): warning C4293: '<<' : shift count negative or too big, undefined behavior
1>d:\sdk_\dlls\healthkit.cpp(199): warning C4293: '<<' : shift count negative or too big, undefined behavior
1>d:\sdk_\dlls\h_battery.cpp(121): warning C4293: '<<' : shift count negative or too big, undefined behavior
1>d:\sdk_\dlls\bot.cpp(882): warning C4293: '<<' : shift count negative or too big, undefined behavior
--- End quote ---

Those warnings are related to lines containing
--- Code: ---pev->weapons & (1<<WEAPON_SUIT)
--- End code ---
--- Code: ---pev->weapons &= ~WEAPON_ALLWEAPONS;
--- End code ---

So clearly changing the number of WEAPON_SUIT is the issue here.

2. When I start a game with the compiled libraries (with more than 32 weapons defined), I observe stage behaviors with the weapons above 32:

a) game crashing / freezing upon spawning / getting that weapon.
b) game working OK, however the gun has no animations, sprites and sounds.
c) game working, but with no sprites for the game in general.

So I guess the current definition does not support more than 32 (32-1).
I've searched everywhere for example on how to change the definitions properly to support more than 32 bytes (including based on warning C4293) and I'm unable to find a solution or workaround.

I know there are mods out there that have the functionality implemented - I've seen it in HL Weapon's Edition, XASH, Half-Life: Enhanced and few others; and I was wondering did anyone faced the same issue like me?
Have you been able to find a workaround for this one?

Any inside on this would be greatly appreciated.

You'll need to remove the dependency on pev->weapons altogether for actual weapons. The suit can be left there, you'll just have to modify the client to track which weapons were added and removed:

This relies on the weapon bits so it needs to depend solely on the weapon list that the engine passes to the client in HUD_WeaponsPostThink:

You can tell if the player has a weapon by checking if the m_iId variable in weapon_data_t for the weapon is non-zero. So you'd check it like this:

--- Code: ---if( from->weapondata[ WEAPON_MP5 ].m_iId != 0 )
    //Player has the MP5

--- End code ---

The simplest solution is to modify the code in that function so that the client side CBasePlayer instance also keeps the list of weapons just like the server does. So if from->weapondata says the player has the weapon and the player does not have the weapon in their inventory then add it, conversely if it says they do not and it's in the inventory remove it.

Then in CHudAmmo::Think you can just check which weapons the player has and make sure they've been added to the hud list.

You'll also need to force cl_lw on because otherwise the weapon data list won't be sent to clients.

It's not the cleanest solution, but since GoldSource lacks proper networking for stuff like this this is the best solution you can go for.


[0] Message Index

Go to full version