Page 1 of 1

Grenades noblock

Posted: Thu Jan 14, 2021 9:44 pm
by cssbestrpg
Hi, this plugin removes grenade collision, so you can't get stucked if throw inside of player

Syntax: Select all

from listeners import OnNetworkedEntityCreated
from weapons.manager import weapon_manager
from entities.constants import CollisionGroup

@OnNetworkedEntityCreated
def on_entity_created(entity):
if entity.classname in weapon_manager.projectiles:
entity.collision_group = CollisionGroup.DEBRIS_TRIGGER


Edit:
- Shorten code, huge thanks to saaton101
- Made code faster huge thanks to Ayuto

Re: Grenades noblock

Posted: Thu Jan 14, 2021 10:16 pm
by satoon101
The entity argument given to OnEntityCreated hooks is a BaseEntity object, which already has access to the set_property_uchar method. Also, we store the game's projectiles in the weapon_manager, so you could use that instead of writing each of the weapons down in the plugin. So, with those changes, you could shorten the plugin to:

Syntax: Select all

from listeners import OnEntityCreated
from weapons.manager import weapon_manager

@OnEntityCreated
def on_entity_created(entity):
if entity.classname in weapon_manager.projectiles:
entity.set_property_uchar('m_CollisionGroup', 2)

Re: Grenades noblock

Posted: Fri Jan 15, 2021 6:05 am
by cssbestrpg
Thanks satoon101, i didn't know of those functions.

Re: Grenades noblock

Posted: Fri Jan 15, 2021 12:27 pm
by Ayuto
Beside shortening the code, you can also speed it up and make it more readable.

Syntax: Select all

from listeners import OnNetworkedEntityCreated
from weapons.manager import weapon_manager
from entities.constants import CollisionGroup

@OnNetworkedEntityCreated
def on_entity_created(entity):
if entity.classname in weapon_manager.projectiles:
entity.collision_group = CollisionGroup.DEBRIS_TRIGGER

m_CollisionGroup has been exported on the C++ side, which makes the access to the property much faster and more cross-game compatible in case the property is called differently in other games. It also forces the programmer to use the correct constants (CollisionGroup), which makes the code more readable. Moreover, we only need to apply the new collision group to certain projectiles. Those are always networked entities. So, we use the OnNetworkedEntityCreated listener and don't need to to the classname check for every entitiy.