Success! Entity Selection

Posted By: oldschoolj

Success! Entity Selection - 08/01/07 21:26

Hi folks,

Thanks to a tip from Ottawa, I gave up on the ent_remove bit. I finally have a working entity selection code, and wow, I was really just missing something small. No need to add or remove the selection cursor, only change it to match the next entities position.

Now you can select any entity within the mouse range, deselect by right clicking, or tab through entities (this is buggy, and needs fixing, because it tends to only want to pick certain entities)

But it works pretty good, if you downloaded my rar file from the Entity: Removal post, then you can just swap enemie.c code, with this.

Whew!

Code:
//#Includes
#include <acknex.h>
#include <default.c>

//Entity defines
ENTITY* marker_tga;

function marker_orientation () // the positioning of the marker
{
while (my)
{
set (my, PASSABLE);
my.scale_x = .4;
my.scale_y = .4;
my.scale_z = .4;
my.tilt = 90;
wait (1);
}
}

function enemy_selection() // the event that controls marker placement
{
if ((event_type == EVENT_CLICK) && (marker_tga == NULL))
{
marker_tga = ent_create ("marker.tga", vector (my.x, my.y, my.z -30), marker_orientation);
}

if ((event_type == EVENT_SCAN) && (key_tab == 1) && (marker_tga == NULL))
{
marker_tga = ent_create ("marker.tga", vector (my.x, my.y, my.z -30), marker_orientation);
}

if ((event_type == EVENT_CLICK) && (marker_tga != NULL))
{
reset (marker_tga, INVISIBLE);
vec_set (marker_tga.x, my.x);
vec_set (marker_tga.y, my.y);
vec_set (marker_tga.z, my.z -30);
}

if ((event_type == EVENT_SCAN) && (key_tab == 1) && (marker_tga != NULL))
{
reset (marker_tga, INVISIBLE);
vec_set (marker_tga.x, my.x);
vec_set (marker_tga.y, my.y);
vec_set (marker_tga.z, my.z -30);
}
if (mouse_right == 1)
{
set (marker_tga, INVISIBLE);
}
}

action test_enemy ()
{
my.emask = ENABLE_SCAN | ENABLE_CLICK | ENABLE_RIGHTCLICK | USE_AABB;
my.event = enemy_selection;
}


Posted By: Excessus

Re: Success! Entity Selection - 08/01/07 21:40

Congrats on getting it to work. Here are some ideas for improvement:

-Unless you think some other part of your code will change the markers properties, the marker_orientation() function doesn't need a loop. (remove the while and wait)

-vec_set (marker_tga.x, my.x); vec_set (marker_tga.y, my.y); vec_set (marker_tga.z, my.z -30); This is strange. vec_set() will set all 3 elements of the vector. No need for 3 instructions. There are two ways to code it:
vec_set(marker_tga.x, my.x); marker_tga.z -= 30;
or
marker_tga.x = my.x; marker_tga.y = my.y; marker_tga.z = my.z - 30;

If you leave the code like that (using vec_set with the y and z element) you might be overwriting other members of the entity struct.
Posted By: oldschoolj

Re: Success! Entity Selection - 08/01/07 21:46

thanks for the info, but I tried just doing it without vec-set:

marker_tga.x = my.x /// causes crashes
vec_set (marker_tga.x, my.x) // that only puts it at the enemies "x"

it seems to work fine, but I think your right about that loop, and I'll change it. Please give me an example of how that loop would be important though, in the senario you mentioned.

Oh here is the rar file for the demo, just replace this code in the enemy.c
download demo
Posted By: Ottawa

Re: Success! Entity Selection - 08/01/07 23:32

Hi again !

I was looking at your flags

my.emask = ENABLE_SCAN | ENABLE_CLICK | ENABLE_RIGHTCLICK | USE_AABB;

I had a query about the "=" so I tried it and it worked.



I've posted with the help of D3D a table of flags and I was just wondering if this line should be added?

Ottawa
© 2023 lite-C Forums