Entity I/O

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Articha
Member
Posts: 32
Joined: Tue Sep 21, 2021 12:13 pm
Location: Russia

Entity I/O

Postby Articha » Wed May 04, 2022 6:10 pm

I want to understand Entity Input/Output system. Source wiki shows examples for Hammer, but I can't make it work in Soucre.Python. No information found on MetaSource/SourceMod forums (may be bad searching. I believe so). So what I want to do:
  1. Understand The FireUser1-4 inputs and OnUser1-4 outputs from here
  2. Make entity trigger_once work (call function on touch), but without hooking 'touch' and rejecting other entities 'touches'. I mean, if I hook 'touch', it'l be called for every entity touch, but I want only for trigger_once. May be it's possible to transfer into FireUser?
  3. trigger_playermovement, trigger_softbarrier
  4. To be truly, all brush entities. Is them Hammer-editor-only?
  5. How to hook item_dogtags pickup? I mean hook OnCacheInteraction/OnPlayerTouch
  6. Ik, there's very low chance to but may be u can make func_ladder work through Source.Python?
User avatar
Articha
Member
Posts: 32
Joined: Tue Sep 21, 2021 12:13 pm
Location: Russia

Previous forum

Postby Articha » Thu May 05, 2022 11:52 am

I found this, but that only slightly helped me to realize what I want. I still don't want to hook OnTrigger like in trigger_multiple, bcz there's many triggers with OnTrigger output. Can I somehow move that trigger into FireUser1-4 without Hammer? Like, add it on Dust2 customly?

edit:
I also did some test. Nothing worked. I see trigger model, but nothing else

Syntax: Select all

# Generating random name
name = f"Static_mine{randint(0,1000000)}"

mine_model = entity.create('prop_dynamic_override')
mine_model.model = Model('models/props_unique/jukebox01_body.mdl')
mine_model.set_key_value_string('target', name)
mine_model.spawn()

# Setting mine origin
spawn_location = self.owner.view_coordinates *0.99
spawn_location[2] += 50
mine_model.origin = spawn_location

# Creating trigger
trigger = entity.create('trigger_proximity')
trigger.set_key_value_string('measuretarget', '!self')
trigger.model = Model('models/props_unique/jukebox01_body.mdl')
trigger.set_key_value_string('radius', '200')
trigger.flags = 1 | 2
trigger.spawn()

trigger.call_input('Enable')

Two jukeboxes spawned, but listener OnEntityOutput doesn't show anything
Last edited by Articha on Thu May 05, 2022 1:11 pm, edited 1 time in total.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Previous forum

Postby L'In20Cible » Thu May 05, 2022 1:59 pm

Articha wrote:I still don't want to hook OnTrigger like in trigger_multiple, bcz there's many triggers with OnTrigger output. Can I somehow move that trigger into FireUser1-4 without Hammer?

I understand the reasoning, but I don't think these inputs/outputs are the solution here. Instead, you could simply inject your own touch callback into entities you want to listen to. Here is a quick example that illustrate the concept:

Syntax: Select all

from entities.entity import Entity
from memory import Callback, Convention, DataType, make_object

_touch_prototype = (
Convention.THISCALL,
(
DataType.POINTER, # this
DataType.POINTER # pOther
),
DataType.VOID
)

@Callback(*_touch_prototype)
def touch_callback(stack_data):
this = make_object(Entity, stack_data[0])
other = make_object(Entity, stack_data[1])

print(this.index, 'has been touched by', other.index)

# Forward the touch to the original function
original_touch(*stack_data)

trigger_multiple = Entity.create('trigger_multiple')
trigger_multiple.spawn()

# Store the original touch function
original_touch = trigger_multiple.get_property_pointer(
'm_pfnTouch'
).make_function(*_touch_prototype)

# Inject our own
trigger_multiple.set_property_pointer(
'm_pfnTouch',
touch_callback
)

# Simulate a touch
trigger_multiple.touch(trigger_multiple)


Articha wrote:I also did some test. Nothing worked. I see trigger model, but nothing else

My first guess would be because you don't set its origin as well as its bounding size via mins/maxs.
User avatar
Articha
Member
Posts: 32
Joined: Tue Sep 21, 2021 12:13 pm
Location: Russia

Re: Entity I/O

Postby Articha » Thu May 05, 2022 4:11 pm

Good answer. But I still don't know how to hook property-function, to view it's arguments. May be there's another way to view property function arguments to properly inject mine function?
I mean, here:

Syntax: Select all

_touch_prototype = (
Convention.THISCALL,
(
DataType.POINTER, # this
DataType.POINTER # pOther
),
DataType.VOID
)

you write two DataType.Pointer. How I know what arguments should be passed to function?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Entity I/O

Postby L'In20Cible » Thu May 05, 2022 5:22 pm

Articha wrote:you write two DataType.Pointer. How I know what arguments should be passed to function?

That specific function is defined as an ENTITYFUNCPTR:

Syntax: Select all

typedef void (CBaseEntity::*ENTITYFUNCPTR)(CBaseEntity *pOther );
So, it accepts 2 CBaseEntity pointers; this and pOther.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 39 guests