6th Venom@Posted: Sun Oct 08, 2006 10:18 pm :
Ok, i did try to attach a light on an entity (a lamp) directly into the entitydef, but didn't achieve it. :cry:
I tested:
-to make a light entity and "def_attach" it to my lamp model...
-to define a mtr_light_shader with all the params (radius, color, etc.)...
-to make a light, with my lamp for model...

...but none of this allow me to create a moveable lamp that start on (the 2 first don't work at all), breakable with debris (the 3rd don't) that turn off when dead, without any scripts.

I planned to use it a lot in a map, and i don't want to make a big script for checking each lamp to know if i got to remove or not the appropriate light.

Anyone did something similar? How?

If i really got to use script, how can i make only one generic loop that check any death/break (let's say lamp1_1), then remove "/n"_light (lamp1_1_light) at the same time.
Like this, i will bind lamp1_1_light to lamp1_1, lamp1_2_light to lamp1_2, etc. in the editor, and let this little loop erase appropriate light if i break a lamp.

Any idea?

Thanks all.

EDIT: the 2 firsts don't work cause i use ASEs for models and collisions, don't allow to attach to any joints (cause don't got any bones).
EDIT2: I tested with a Md5mesh+AF (for moveable) but i still can't "def_attach" a light to it...



6th Venom@Posted: Mon Oct 09, 2006 7:00 pm :
I did a small script to create & bind a light (my light entity) to lamp models, here it is:
Code:
void create_lamplight (entity ent_lamp){
     vector light_origin;
     string light_name;
     entity light_ent;

     light_name=ent_lamp.getName()+"_light";
     light_origin=ent_lamp.getVectorKey("origin");

     sys.setSpawnArg("origin", light_origin);
     sys.setSpawnArg("name", light_name);

     light_ent=sys.spawn("env_lamp1_light");

     light_ent.bindPosition(ent_lamp);
}


void setup_objects()
{
     create_lamplight($env_lamp1_on_breakable_1);
}

// function that executes when script is loaded

void main ()
{
   setup_objects();
}


Now i got a couple of new questions:
A) If i call the "create_lamplight" script directly into the entities editor (mapeditor) by each lamps entities, will it work like i placed it in the "setup_objects" script? (like i did here for $env_lamp1_on_breakable_1)

B) What Script events should i use to check entities death? (i can't just run a loop with all my $env_lamps check "health" stat [getFloatKey("health")] at each frame :shock: , plus i don't know how many will be in my map)

Please, noobcoder (me) really need help on this! :wink:



rich_is_bored@Posted: Mon Oct 09, 2006 7:35 pm :
The only way to call functions from within the level editor is to assign a "call" key/value pair to an entity and point it to the function you wish to run. However, I can't remember if that sort of thing works with parameters.

But the more important issue is that entities who are setup to call functions in that manner, won't call anything until they are triggered.

As for your second question, key/value pairs are not always updated. Most of them, including the "health" key/value pair, are only used as spawn arguments.

In other words, you could monitor the "health" key/value pair but it wouldn't reflect any changes to an entities actual health value. All the key/value pair does is tell the game how much health the entity should start with.

You do realize however that light entities can be "broken" and they can have models assigned to them? That's probably the approach you should be going for.



6th Venom@Posted: Mon Oct 09, 2006 8:38 pm :
First of all, thank you rich to answer! damn, i hoped an answer so long... :wink:

Secondly, all you say look like to be justified and true.
But i got one problem with the "broken" light method, i can't spawn debris with that (or actually i did not succed doing it)...

So i made an upgrade of my little script with my little knowledge (learn as i need):
Code:
void create_lamplight (entity ent_lamp){
     vector light_origin;
     string light_name;
     entity light_ent;

     light_name=ent_lamp.getName()+"_light";
     light_origin=ent_lamp.getVectorKey("origin");

     sys.setSpawnArg("origin", light_origin);
     sys.setSpawnArg("name", light_name);

     light_ent=sys.spawn("env_lamp1_light");

     light_ent.bindPosition(ent_lamp);
}

void remove_lamplight (entity ent_lamp){
     float  ent_health;
     string ent_name;
     entity ent_light;

     ent_name=ent_lamp.getName()+"_light";
     ent_light=sys.getEntity(ent_name);
     ent_light.remove();
}

void check_lamplight (entity ent_lamp){
     float  ent_health;
     string ent_name;
     entity ent_light;

   while (1) {
         ent_health=ent_lamp.getFloatKey("health");
    if ( ent_health < 1 ) {
         remove_lamplight(ent_lamp);
                   sys.killthread("check_lamplight");
    }
         sys.waitFrame();
  }
}

void setup_objects()
{
     create_lamplight($env_lamp1_on_breakable_1);
     check_lamplight($env_lamp1_on_breakable_1);
}

// function that executes when script is loaded

void main ()
{
   setup_objects();
}

This one work good, but it look like the slowdown the whole framerate, maybe cause of the loop... plus there is another problem that came with it:
The engine don't kill the model right when it is broken, so my light is only removed 2-3 seconds after i break the lamp... strange thing.

Any other options? A script optimisation? (i repeat i'm a noob...)

EDIT: It seems that your right about the health check too, that's do nothing, that's why my light only disapear when the model is totally removed from the world...



6th Venom@Posted: Tue Oct 10, 2006 5:11 pm :
I didn't suceed with scripts, but obtain good results with many many tricks method... thanks anyway rich for help.