Grenades noblock

Release your plugins here!
cssbestrpg
Senior Member
Posts: 192
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Grenades noblock

Postby cssbestrpg » Thu Jan 14, 2021 9:44 pm

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
Last edited by cssbestrpg on Fri Jan 15, 2021 2:26 pm, edited 3 times in total.
User avatar
satoon101
Project Leader
Posts: 2680
Joined: Sat Jul 07, 2012 1:59 am

Re: Grenades noblock

Postby satoon101 » Thu Jan 14, 2021 10:16 pm

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)
Image
cssbestrpg
Senior Member
Posts: 192
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: Grenades noblock

Postby cssbestrpg » Fri Jan 15, 2021 6:05 am

Thanks satoon101, i didn't know of those functions.
User avatar
Ayuto
Project Leader
Posts: 2164
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Grenades noblock

Postby Ayuto » Fri Jan 15, 2021 12:27 pm

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.

Return to “Plugin Releases”

Who is online

Users browsing this forum: Google [Bot] and 1 guest