How to get weapon's max ammo?

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

How to get weapon's max ammo?

Postby Mahi » Wed Nov 04, 2015 3:25 pm

Say I want to give player ammo every time he jumps, if he doesn't have full ammo already:

Syntax: Select all

from entities.helpers import index_from_inthandle
from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from weapons.entity import WeaponEntity

@Event
def on_jump(event):
player = PlayerEntity(index_from_userid(event['userid']))
weapon = WeaponEntity(index_from_inthandle(player.active_weapon))
if weapon.ammo < weapon.max_ammo: # No such attr as max_ammo
weapon.ammo += 1

How would I get the weapon's maximum ammo? For example 90 for AK47 and 40 for M4A1-S in CS:GO
necavi
Developer
Posts: 129
Joined: Wed Jan 30, 2013 9:51 pm

Postby necavi » Wed Nov 04, 2015 3:41 pm

If I remember correctly you're going to have to find the GetMaxAmmo (or something very similar) signature for the weapon entity - it isn't as easy as a simple entity property, unfortunately.
necavi
Developer
Posts: 129
Joined: Wed Jan 30, 2013 9:51 pm

Postby necavi » Wed Nov 04, 2015 4:57 pm

Bloody hell that's useful!
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Nov 04, 2015 7:25 pm

There are 4 weapons that we do not have the proper data for in CS:GO. I know that info is somewhere on the forums, but I don't remember if it is in the private section or public. I will look for it and post again when I get the chance tonight.

The issue with those weapons is they share the same classname as other weapons, making it much more difficult to store the data.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Nov 06, 2015 3:13 am

Here is the information I found back in January, some of it might have changed since then:


The following entity class names are used for 2 different weapons each. The weapons are the ones you can choose between in the game's loadout screen:

  • weapon_hkp2000:

    • USP-S:
      • Clip: 12
      • AmmoProp: 12
      • MaxAmmo Cvar: ammo_357sig_small_max
    • P2000:
      • Clip: 13
      • AmmoProp: 10
      • MaxAmmo Cvar: ammo_357sig_max
  • weapon_m4a1:

    • M4A4:
      • Clip: 30
      • AmmoProp: 3
      • MaxAmmo Cvar: ammo_556mm_max
    • M4A1-S:
      • Clip: 20
      • AmmoProp: 4
      • MaxAmmo Cvar: ammo_556mm_small_max
  • weapon_p250:

    • P250:
      • Clip: 13
      • AmmoProp: 11
      • MaxAmmo Cvar: ammo_357sig_p250_max
    • CZ75-Auto:
      • Clip: 12
      • AmmoProp: 13
      • MaxAmmo Cvar: ammo_357sig_min_max
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 124 guests