Page 1 of 1

[CSGO] Ammo problem

Posted: Tue Jun 06, 2017 1:07 pm
by existenz
Hey !

I have a problem with ammo in Csgo. If i give ammo and i reload, my clip is reloading well but i lost all given ammo ...
My AK47 has 30 clip and 0 ammo.

My code :

Syntax: Select all

weapon = player.active_weapon
weapon.ammo += 10


For example if i use 5 clip and i reaload it must remain 5 ammo but i have 0 ammo. I don't know why.

Sincerly Existenz.

Re: [CSGO] Ammo problem

Posted: Sat Jun 17, 2017 9:41 am
by existenz
Hey !
Sorry to rebump this subject but nobody have an idea how fix it ?
I have found nothing ... :(

Re: [CSGO] Ammo problem

Posted: Sat Jun 17, 2017 10:25 am
by Ayuto
Works fine for me. Could you please post tested code (copy and pastable) that reproduces this issue?

Edit:
Please also post the output of "sp info".

Re: [CSGO] Ammo problem

Posted: Sat Jun 17, 2017 10:41 am
by existenz
Thanks for your answer.

Syntax: Select all

from commands.say import SayCommand
from players.entity import Player
from weapons.entity import Weapon

@SayCommand('test')
def on_test(command, index, team_only=None):
player = Player(index)
weapon = Weapon.create('weapon_ak47')
weapon.teleport(player.origin)
weapon.spawn()

@SayCommand('add')
def on_test(command, index, team_only=None):
player = Player(index)
weapon = player.active_weapon
weapon.ammo += 50


Date : 2017-06-17 10:31:18.920739
OS : Linux-3.16.0-4-amd64-x86_64-with-debian-8.7
Game : csgo
SP version : 581
Server plugins:
00: Source.Python, (C) 2012-2016, Source.Python Team.
SP plugins:
00: admin, 0.1, https://venomz.fr/

Re: [CSGO] Ammo problem

Posted: Sat Jun 17, 2017 11:25 am
by Predz
Yeh I was having the same problem even when the Weapon.create classmethod to handle the item definition index was updated. So I had altered my weapon class in my pickupables plugin to work on <prop>.use rather than actually creating a weapon entity. You can see that here:
https://github.com/Predz/SP-Pickupables ... s/items.py

I am unsure what other data is missing when you create a weapon entity in the world but there must be something quite blatant as the item_definition_index fixes the sound issue. As Existenz said above the ammo and clip never works correctly on a spawned in weapon. However it works perfectly on a weapon spawned in by <player>.give_named_item

Re: [CSGO] Ammo problem

Posted: Sat Jun 17, 2017 4:31 pm
by satoon101
I found the fix, so I'm going to go through all the steps I used to help anyone that has similar issues in the future.

Because give_named_item works properly while create does not, I figured it had to be another property that isn't set during create. So, to determine that, I used the following to gather all of the properties for both create and give:

Syntax: Select all

from commands.say import SayCommand
from listeners.tick import Delay
from memory import make_object
from players.entity import Player
from weapons.entity import Weapon

comparison_dict = {}

@SayCommand('test1')
def on_test1(command, index, team_only=None):
weapon = make_object(
Weapon,
Player(index).give_named_item('weapon_ak47'),
)
store_values('give', weapon)

@SayCommand('test2')
def on_test2(command, index, team_only=None):
player = Player(index)
weapon = Weapon.create('weapon_ak47')
weapon.teleport(player.origin)
weapon.spawn()
Delay(0.1, store_values, ('create', weapon))

def store_values(key, weapon):
values = comparison_dict[key] = {}
for server_class in weapon.server_classes:
for prop, instance in server_class.properties.items():
try:
values[server_class.__name__ + '.' + prop] = getattr(
weapon,
'get_property_{prop_type}'.format(
prop_type=instance.prop_type,
)
)(prop)
except:
print(prop)

@SayCommand('compare')
def compare(command, index, team_only=None):
length = len(comparison_dict)
if length != 2:
raise ValueError(
'comparison_dict has {length} keys not 2!'.format(
length=length,
)
)
one, two = comparison_dict.keys()
other = comparison_dict[two]
for prop, value in sorted(comparison_dict[one].items()):
if value != other[prop]:
print(prop)
print('\t', value, other[prop])

Note that I used a Delay for the 'create' because some properties hadn't been set by that point. So, I first used the 'test1' command to give myself an AK using give_named_item. Then, after dropping that weapon, I used 'test2' to create the weapon and teleport it to my location. After it has compiled both sets of properties, I used the 'compare' command to print out all the differences in the server's console.

I copy/pasted the output into a txt file for easier reading. There were quite a few that I was sure were irrelevant, so I deleted them. In the end, I ended up with the following properties that I thought could be the one:
  • CBaseCombatWeapon.m_iState
  • CBaseEntity.m_iEFlags
  • CBaseEntity.m_spawnflags
  • CBaseEntity.touchStamp
  • CEconEntity.m_AttributeManager.m_Item.m_bInitialized
  • CEconEntity.m_AttributeManager.m_iReapplyProvisionParity

Using a Delay again, I set each of these values on the weapon in create:

Syntax: Select all

from commands.say import SayCommand
from listeners.tick import Delay
from players.entity import Player
from weapons.entity import Weapon

@SayCommand('test2')
def on_test2(command, index, team_only=None):
player = Player(index)
weapon = Weapon.create('weapon_ak47')
Delay(0.1, set_properties, (weapon, ))
weapon.teleport(player.origin)
weapon.spawn()

@SayCommand('add')
def on_test(command, index, team_only=None):
player = Player(index)
weapon = player.active_weapon
weapon.ammo += 50

def set_properties(weapon):
weapon.set_property_uchar('m_iState', 0)
weapon.set_property_int('m_iEFlags', 41992192)
weapon.set_property_int('m_spawnflags', 1073741824)
weapon.set_property_int('touchStamp', 0)
weapon.set_property_bool('m_AttributeManager.m_Item.m_bInitialized', True)
weapon.set_property_uchar('m_AttributeManager.m_iReapplyProvisionParity', 2)

I had to use a Delay because, without it, I actually never received the weapon. I'm not sure which of the properties caused this, but thankfully it wasn't the one we need for this fix.

Using this plugin, I was able to successfully receive the extra ammo and it stayed after reload. I then narrowed down the properties and determined that m_AttributeManager.m_Item.m_bInitialized was the one that we are looking for.

Also of note, if I use the Delay, the reserve ammo I have after picking up is 0. However, if I set the property prior to my client picking up the weapon, I have full reserve ammo (90).

Re: [CSGO] Ammo problem

Posted: Sun Jun 18, 2017 8:03 am
by existenz
Thanks for your answers :)

I works fine :D.
In set_properties how can i also set the player weapon skins ?

Re: [CSGO] Ammo problem

Posted: Sun Jun 18, 2017 10:15 am
by Predz
Existenz you are now asking for something that even Valve has banned xD Valve will ban any server changing weapon skins because they do not want people having access to skins they haven't purchased. Basically they are money grabbing assholes :P

TBH I am unsure whether they will have anything against my model changer package... :s

Re: [CSGO] Ammo problem

Posted: Sun Jun 18, 2017 10:55 am
by existenz
Hey Predz ! Should not work during your holidays :P

No i want just reapply player skin because the create don't apply the player skin like gived_item_name :)

You can create a new skin model. But don't use existing model your own texture and you can't also use valve texture to apply on your own model. I think it's that.

Look : http://blog.counter-strike.net/index.ph ... uidelines/

Re: [CSGO] Ammo problem

Posted: Tue Oct 31, 2017 11:27 am
by battleweaver
About skins:
Long story short: it is possible. The only thing you need is to set a valid number in skin property. (hint: m_nFallbackPaintKit and other props)
Now, why Valve bans this. It is not allowed to play with skins you do not own.
But such trick can be used, for example, to force player use default weapon skin (1) or ensure that player uses skin from her layout(0).

Punishment:
If you used server without token (anonymous server), a server IP address will be banned.
If you used server with token, an account will be banned.