Forum posts

Oops. You are right.
I'll bump it there a bit later today.
Thanks!
Hey folks!

Here's a quick and easy tutorial on how to implement a rushed gun reloading mechanism.
In a nutshell, when you reload, you lose your mag and any bullets left inside.
Nice feature if you want to make a realistic mode (have you ever removed bullets from large-size mags and put them back in another one after?? If so, you know it doesn't take 1 second to do).

I'm using the latest version of SamVanheer SDK (half-life updated)

First, open weapons_shared.cpp and go to Line 120.
You will see the following:
void CBasePlayerWeapon::ItemPostFrame()
{
    if ((m_fInReload) && (m_pPlayer->m_flNextAttack <= UTIL_WeaponTimeBase()))
    {
        // complete the reload.
        int j = V_min(iMaxClip() - m_iClip, m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]);

        // Add them to the clip
        m_iClip += j;
        m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= j;
To better understand how this code works.
  • int j = we are looking for how many bullets we need in our current clip to get a full clip (or the maximum ammo amounts available)
  • V_min(a,b) = "j" will be either the necessary amount to make a full clip OR the remaining ammo amount left. (You can't get a full Glock clip if you only have 3 bullets in your inventory)
  • Now that we know "j" we add the amount to the current clip ( m_iClip += j; )
  • Obviously, we subtract the amount from our ammo inventory ( `m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= j;` )
Now that you know how everything works let's build our new feature.

Before starting, let's see what we need:
  • If I have 12/17 bullets left in my Glock and I reload, I want to get 17 (max amount) if possible
  • If not possible, I want to get my only non-full mag. (If currently at 12/17 in my mag and I have 13 in my inventory, I'll get a mag with 13/17 and be at 0 in my inventory).
  • Any mag dropped is lost permanently. (If currently at 12/17 and I have 117 in my inventory, I'll be at 17/17 and 100, so I lost 12 bullets in my dropped mag).
To make it happen, we will need to use simple if and else statements.

Here's how it looks. (Replace the previous lines with these)
void CBasePlayerWeapon::ItemPostFrame()
{
    if ((m_fInReload) && (m_pPlayer->m_flNextAttack <= UTIL_WeaponTimeBase()))
    {
        // get j count
        int j = V_min(iMaxClip() - m_iClip, m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]);

        // Add a full clip and permanently remove the previous one if a full clip is available
        // m_iClip = MaxClip(); could work as well.
        if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= iMaxClip())
        {
            m_iClip += j;
            m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= iMaxClip();
        }
        // Add the only remaining clip (full or not) and permanently remove the previous one.
        else
        {
            m_iClip = m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType];
            m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] = 0;
        }
Now, the only thing to do is to ensure that none of your guns share the same type of ammo.
For Original Half-Life, you must create a specific 9mm ammo type for either the Glock (9mm_glock) or the mp5 (9mm_mp5).

With this feature, if you drop a mp5 mag, it shouldn't affect your 9mm mags.

To create Custom Ammo Types you can refer to *this tutorial*

I hope it helps!
This is what I was thinking of doing since things are hardcoded.
I'm currently using the SamVanheer SDK (half-life updated, not unified)
  • Build a map with changelevel triggers that go to the right game mode. I'm currently rebuilding c0a0, allowing Gordon to choose a train associated with the game mode the player wants to play (game rules (i.e. crowbar only, 9mm only, 1hp, etc.) with Original Half-Life maps (for most cases), loading c0a0_gamemode1, 2, 3, and so on).
  • Renaming maps and modifying their changelevel entities to trigger the right "game_mode" map.
Now I just need to find a way to associate gamerules to those maps or game modes
I was afraid of that... Thanks!
Now, I'll even go more in-depth, asking a more complex question.
How/Where do you change the behaviour of the "Play" and "PlayGameAlt"/ command?
I don't mean writing a console-oriented command (i.e. engine map c1a0) but changing the backend code.

You are going to be my saviour if you know that.

The command in question:

"PlayGame_Alt"
{
"ControlName" "Button"
"fieldName" "PlayGame_Alt"
"xpos" "40"
"ypos" "216"
"wide" "200"
"tall" "24"
"autoResize" "0"
"pinCorner" "0"
"visible" "0"
"enabled" "1"
"tabPosition" "4"
"labelText" "#GameUI_PlayGame_Alt"
"textAlignment" "center"
"dulltext" "0"
"command" "PlayGameAlt" <-- That
"default" "0"
}
Posted 5 months ago2023-12-01 17:58:42 UTC
in Multiple Game modes Post #348132
Alright, alright, alright!
Me again...

I'm looking for a way to build multiple game modes within the same mod. That's it for now!
I'm currently blocked and lost. Let's start with what I can see with other mods (from basic UI to code).

Half-Life Pre-25th vs. 25th
  • (25th) In the NewGameDialog.res file, there is a "PlayGameAlt" command that launches Uplink. With SDK, Uplink doesn't appear, so this command might be associated with something in the code??
  • (Pre-25th) In the same file, there is a "Play" command, but you can add engine commands. (i.e. "command" "engine map c1a0")
  • skills are not associated with any sort of command in this file (Easy, Medium, Hard). How does the game know?
  • I can modify the UI, but I CAN'T change how it operates. (Wouldn't be able to remove the Skills and just add a button with a command that redirects to a map and a skill. I absolutely need to select a skill to execute a "command".
Half-Life MMod
  • They modified GameMenu.res instead, adding a bunch of commands.
  • They allowed view for Custom Games and redirect the user to other mods (.dll) that operate differently. It doesn't seem efficient IMO, am I right?
SDK (coding)
  • gamerules files - seem only to be a if else command via InstallGameRules. Redirect to singleplayer_gamerules or multiplayer_gamerules.

My questions
  • What's the best practice to create multiple single-player gamerules that modify mainly weapons, models, player, etc? Should I create a mode1_gamerules file and mode1_weapon, mode1_player, etc. files that override some elements of the regular files? (For example, I know there's a player.cpp and CSplayer.cpp file in CS SDK)
  • Which file would I have to change/duplicate for each game mode (world?)
  • How do I connect those game mode to the UI? (obviously, I don't think it could work with a simple "engine" command in the .res, or even an associated .cfg file).
The main goal right now is to :
1. Create those modes and their triggers in the code.
2. Create an ALERT print in the console during Precache to test that these modes are correctly triggered when loaded.
3. Connect those modes with UI buttons (Ideally through a NewGameDialogue window, but I don't mind via the GameMenu

... If you made it that far, thank you!
I see I can modify (i.e.) the weapon behavior per "Game mode".
As an example, the crossbow arrow explode on hit MP vs. regular hit in SP

Code: https://github.com/SamVanheer/halflife-updated/blob/fae5e0180a3caaba53b0c2ae7ad2f1218367817e/dlls/crossbow.cpp#L96

For weapon behavior for specific modes, I was thinking about adding the same pattern for each weapons.
For pickup restriction (i.e. crowbar-only mode), I guess I can do the same thing, instead of creating new entities.

Tweaking those isn't that much of a problem.
But I'm a bit lost at adding gamerules associated to this.

Should I copy the code of singleplay_gamerules.cpp and create a new crowbar_gamerules, glock_gamerules, lowhealth_gamerules.cpp files and tweak it accordingly. (Then point in different files with/ IsCrowbarmode, IsGlockmode/, etc.)

If so, how do I add those mode to the UI afterward.
A bit like the new 25th anniversary. You have your skills (1,2,3) and you can select regular or uplink with those skills.
Hey folks,

I'm building a challenge mod as a part of Half-Life's 25th Anniversary.
I have previous experience with C# .Net (school experience, 15 years ago), but I am new to C++, so I might not have all the right reflexes.

In a nutshell. I'm building a mod with different scenarios:
  • Crowbar only (with a few map iterations to remove the impossibility of making it happen - i.e. removing the mines in c2a4c and c2a4e and removing the explosive crates in c2a4g).
  • 9mm only (with iterations at c1a1 to make the doors open without having to break the glass)
  • 1hp mode (with iteration to c1a0d to remove the HEV suit, easy since .rmf is included in SDK)
  • Adding Hardcore skill (4th skill - realistic damage to player/monsters + slow when injured).
  • Realistic mode (counter-strike mechanism for weapons (1 side, 1 main, 1 melee, 1 explosive, with G to drop/change) + hardcore skill)
  • Permadeath mode (no save allowed, exit when dead, default skills + hardcore)
So far, I've programmed the crowbar & 9mm mechanism, and it works (created a new FallThinkProp and FallInitProp entity and removed Materialize() from them to create real pickable and prop unpickable weapons and avoid sound (weapon drop) looping issues.)

But now, it works for the entire game, no matter the skill I select.

If I want to incorporate everything under the same mod, what would be the best practice? How would I achieve that? Should I just create different .dlls and point the right ones depending on the mod selected with the in-game menu?

Open for collaboration as well :)