[CSGO] Setting ammo doesn't work

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

[CSGO] Setting ammo doesn't work

Postby VinciT » Tue Apr 12, 2016 8:08 pm

I can't get set_ammo to work in CSGO. Setting the weapon clip works fine, but setting the weapon ammo only changes the ammo count on the UI.
As soon as you either reload or drop and pick up the weapon again, the ammo will revert to the previous value.

Syntax: Select all

#set_ammo_test.py
from events import Event
from mathlib import NULL_VECTOR

from entities.entity import Entity

from players.entity import Player
from players.helpers import index_from_userid

from weapons.entity import Weapon
from listeners.tick import Delay

@Event('player_spawn')
def player_setup(game_event):
player = Player(index_from_userid(game_event.get_int('userid')))

for index in player.weapon_indexes():
weapon = Entity(index)
player.drop_weapon(weapon.pointer, NULL_VECTOR, NULL_VECTOR)
weapon.remove()

player.give_named_item('weapon_deagle', 0, None, True)
Delay(0, ammo_setup, player)

def ammo_setup(player):
player.set_secondary_clip(1)
player.set_secondary_ammo(1)

Am I messing something up, or is setting ammo broken in CSGO?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Apr 12, 2016 8:34 pm

There is an issue for that already:
https://github.com/Source-Python-Dev-Team/Source.Python/issues/50

We have not yet gotten around to fully fixing that on CS:GO, yet. The issue is that they moved ownership of the extra ammo to the weapon itself instead of the player. So, it has to be handled differently than it used to. Not sure why they did this, as it really doesn't make sense to me, but whatever Valve...
Image
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Postby VinciT » Tue Apr 12, 2016 9:30 pm

My bad, forgot to check github. Thanks for the workaround, satoon.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 43 guests