[CSGO]Spawned weapons behave like deagles

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]Spawned weapons behave like deagles

Postby VinciT » Fri Aug 21, 2015 2:50 am

Syntax: Select all

weapon = WeaponEntity(create_entity(weapon_name))
weapon.teleport(location, None, None)

spawn_entity(weapon.index)

No matter what weapon I spawn with the code above, the weapon will sound like a deagle and have no recoil at all.
I found a thread on SourceMod forums describing the same issue. The very same thread had the fix as well.

In order to make the spawned weapon behave like the weapon it is supposed to be, you need to set the m_iItemDefinition property.
I tried doing that, and I got this error:

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\commands\manager.py', line 151, in
__call__
    return_value = callback(*args)
  File '..\addons\source-python\packages\source-python\commands\auth.py', line 63, in __ca
ll__
    return self.callback(*args)
  File '..\addons\source-python\plugins\power_weapon\power_weapon.py', line 68, in create_
power_weapon
    weapon.set_property_int('m_iItemDefinitionIndex', 3)
  File '..\addons\source-python\packages\source-python\entities\entity.py', line 412, in s
et_property_int
    self._set_property(name, 'int', value)
  File '..\addons\source-python\packages\source-python\entities\entity.py', line 480, in _
set_property
    name, self.classname))

ValueError: Property 'm_iItemDefinitionIndex' not found for entity type 'weapon_ak47'

Any ideas on how to fix this?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Aug 21, 2015 2:59 am

Have you tried using give_named_item instead of creating the weapon and teleporting it?

Syntax: Select all

<PlayerEntity>.give_named_item(<weapon_name>, 0, None, True)


To find all properties (networked and non-networked) for any entity, use:

Syntax: Select all

for name in <Entity>.properties:
print(name)
Image
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Postby VinciT » Fri Aug 21, 2015 3:22 am

I'm trying to spawn weapons around the map at specific locations, which is why I'm not using give_named_item().
I checked the properties with the code you posted, couldn't find anything close to m_iItemDefinitionIndex.

Is there a reason SourceMod and Source.Python don't have the same properties?

Edit: In any case, here's the link to the SourceMod thread.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Aug 21, 2015 10:44 am

They do have the same properties. It is impossible for them to not have the same properties. I will do some testing when I get home from work tonight to see what I can find out.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Aug 22, 2015 2:51 am

The property is listed:

Code: Select all

m_AttributeManager.m_Item.m_iItemDefinitionIndex


You have to use the full name of the property to get/set the value. Also, you can dump all ServerClasses and DataMaps for a given game by using the "sp dump" command:

Code: Select all

// Output will be saved as ../logs/source-python/datamap_listing.txt
sp dump datamaps datamap_listing

// Output will be saved as ../logs/source-python/server_class_listing.txt
sp dump server_classes server_class_listing


Then, to get all ServerClasses and DataMaps that an entity uses, use:

Syntax: Select all

# This loops through all DataMaps and ServerClasses (most names are actually both and not either/or)
for server_class in <Entity>.server_classes:
print(server_class.__name__)
Image
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Postby VinciT » Sat Aug 22, 2015 4:33 am

Thank you so much satoon!

Weapons sound and shoot as they should now. There's only one issue, the alt fire(+attack2) is kinda messed up.
You can't change to burst mode on the famas and the glock, and the scope on snipers(AWP, scout) stay on the screen even after firing.

Is there a way to use give_named_item() on a random player, drop/remove the weapon from the player and teleport it to a specific location without the player noticing?

Edit: I think I've found a way to achieve this. Instead of spawning the weapon, I'll just use a prop_dynamic, hook the CBaseEntity::StartTouch, use give_named_item() when the player touches the prop_dynamic and remove the prop.
Maybe I'm overthinking this, but it should work. Again, thanks for all your help, satoon!
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Sun Aug 23, 2015 6:40 am

Are you sure you have set the correct property values for those weapons? Otherwise I would at first suggest you to do some more searching if there need to be set more properties, I'm sure there are.
If not, you could even try to use PreEvent hook for item_pickup, remove the weapon entity and then use give_named_item(). If that is noticeable for the player, you should try hooking CCSPlayer::BumpWeapon.
I would rather do one of those options if they work for you, because then players could still pickup weapons with their +use key.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 45 guests