Thread: [Request] GetAmmoIndex by string (from HLSDK)

Results 1 to 3 of 3
  1. #1
    Giegue
    Join Date
    Oct 2013
    Location
    Argentina
    Posts
    91

    [Request] GetAmmoIndex by string (from HLSDK)

    HLSDK has a function on player.cpp, namely CBasePlayer::TabulateAmmo() with an interesing way to retrieve the value of a player's ammo index.

    By string.

    Code:
    /*
    ===========
    TabulateAmmo
    This function is used to find and store 
    all the ammo we have into the ammo vars.
    ============
    */
    void CBasePlayer::TabulateAmmo()
    {
        ammo_9mm = AmmoInventory( GetAmmoIndex( "9mm" ) );
        ammo_357 = AmmoInventory( GetAmmoIndex( "357" ) );
        ammo_argrens = AmmoInventory( GetAmmoIndex( "ARgrenades" ) );
        ammo_bolts = AmmoInventory( GetAmmoIndex( "bolts" ) );
        ammo_buckshot = AmmoInventory( GetAmmoIndex( "buckshot" ) );
        ammo_rockets = AmmoInventory( GetAmmoIndex( "rockets" ) );
        ammo_uranium = AmmoInventory( GetAmmoIndex( "uranium" ) );
        ammo_hornets = AmmoInventory( GetAmmoIndex( "Hornets" ) );
    }
    Notice how GetAmmoIndex( string ) is used to retrieve the ammo of an specific type? Currently the AngelScript API has a method to retrieve ammo, namely: pPlayer.m_rgAmmo( index ) but it comes with a fatal flaw: Your index search is limited to NUMBERS ONLY.

    If I want to know how many "buckshots" (Shotgun ammo) a player has, I use the number 4. But this only works if the map does NOT have any custom weapons registered. You register ANY custom weapon, and the ammo indexes scrambles all around, the number 4 may point to a completely different ammo type, and not giving me the desired results.

    You may surely suggest to me to retrieve the PrimaryAmmoIndex of a weapon and pass that value into the m_rgAmmo function but sorry, that won't do. As that will only work if the player were to have that current weapon on hand. What if the player can no longer select that weapon? Or if the player just does not have that weapon at all? How am I supposed to know something that is completely hidden?

    All ammo types have a name asociated to it, yet you can't do anything with it? Why should weapon scripters define a name for their ammo type if it's not going to have any use whatsoever? (Aside from multiple weapons sharing the same ammo type, that is...)

    Okay, leaving that blabbering aside. I would love it if you could find an ammo type searching by string, it would help me retrieve different ammo types without having to rely on magic numbers, or trying to work with obscure numbers that not even I know which value they'll take if any custom weapon is registered.

    Unless there IS actually a function on the API, or some wacky method to retrieve ammo by string. I can't find a way to deal with this problem.
    What's a signature?

  2. #2
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    Location
    U.S. West
    Posts
    1,541

    Re: [Request] GetAmmoIndex by string (from HLSDK)

    Code:
    pPlayer.m_rgAmmo(g_PlayerFuncs.GetAmmoIndex("buckshot"))
    Love,
    w00tguy

  3. #3
    Giegue
    Join Date
    Oct 2013
    Location
    Argentina
    Posts
    91

    Re: [Request] GetAmmoIndex by string (from HLSDK)

    P-P-PlayerFuncs? It was THERE the whole time? Darn I feel blind. Once again, many thanks!
    What's a signature?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •