How do I use engine_trace.enumerate_entities_in_box

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

How do I use engine_trace.enumerate_entities_in_box

Postby Doldol » Thu Jul 19, 2018 2:25 am

How do I use engine_trace.enumerate_entities_in_box?
Predz
Senior Member
Posts: 158
Joined: Wed Aug 08, 2012 9:05 pm
Location: Bristol, United Kingdom

Re: How do I use engine_trace.enumerate_entities_in_box

Postby Predz » Thu Jul 19, 2018 12:58 pm

Finally back after some time at Uni, so will try to help :D

I got the enumerate functions working but failed further down the line. You cannot call the virtual functions for the EntityEnumerator class which makes this function a bit unusable at the moment, unless I am missing something in the src directory. I will take a look at recompiling with a fix later this weekend. Also took me a while to find where to get a HandleEntity instance xD

Syntax: Select all

from engines.trace import engine_trace, EntityEnumerator, MAX_TRACE_LENGTH, Ray
from commands.say import SayCommand
from players.entity import Player
from messages import SayText2
from entities import HandleEntity

@SayCommand('test')
def on_start(command, index, team):
player = Player(index)
start_vec = player.eye_location
end_vec = start_vec + player.view_vector * MAX_TRACE_LENGTH
ray = Ray(start_vec, end_vec)

SayText2(f"Finding entities along your view distance...").send()

enumerator = EntityEnumerator()
engine_trace.enumerate_entities(ray, True, enumerator)

## Fails here because cannot call <EntityEnumerator>.enum_entity(<HandleEntity>)
print(enumerator.enum_entity(player.networkable.entity_handle))
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: How do I use engine_trace.enumerate_entities_in_box

Postby Ayuto » Thu Jul 19, 2018 8:09 pm

You need to subclass EntityEnumerator. enum_entity is getting called for every found entity.
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: How do I use engine_trace.enumerate_entities_in_box

Postby Doldol » Thu Jul 19, 2018 9:48 pm

Thanks got it to work

Edit: have to return True in enum_entity

Syntax: Select all

from engines.trace import engine_trace
from engines.trace import EntityEnumerator
from commands.say import SayCommand
from players.entity import Player
from entities.entity import Entity
from memory import make_object
from entities import HandleEntity
from entities.helpers import index_from_basehandle

from entities.constants import WORLD_ENTITY_INDEX
from messages import SayText2


#print(dir(EntityEnumerator))


class MyEntEnum(EntityEnumerator):
def enum_entity(self, entity_handle):
handleentity = make_object(HandleEntity, entity_handle)
entity = Entity(index_from_basehandle(handleentity.basehandle))
SayText2("enum_entity - classname: {} origin: {}".format(entity.classname, entity.origin)).send()
return True

def get_entities_in_box(mins, maxs):
my_entity_enumerator = MyEntEnum()
engine_trace.enumerate_entities_in_box(mins, maxs, my_entity_enumerator)

@SayCommand('!trace')
def say_command_trace(command, index, teamonly):
world = Entity(WORLD_ENTITY_INDEX)
get_entities_in_box(world.world_mins, world.world_maxs)
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: How do I use engine_trace.enumerate_entities_in_box

Postby Doldol » Thu Jul 19, 2018 11:22 pm

Question, is engine_trace.enumerate_entities_in_box guaranteed to return only after the enumerator is finished?
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: How do I use engine_trace.enumerate_entities_in_box

Postby Ayuto » Sun Jul 22, 2018 6:08 pm

I'm pretty sure it's a sequential task. So, the answer to your question is yes.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 27 guests