pXent_setcollisionflag

Posted By: Power_P

pXent_setcollisionflag - 11/12/21 04:23

Hello...

... if I use the following code, the event works correctly.


pXent_setcollisionflag (ent1, ent2, NX_NOTIFY_ON_START_TOUCH)
ent.event = EventImpact1;


But if I add another collision event, the bottom event is triggered in both cases.


pXent_setcollisionflag (ent1, ent2, NX_NOTIFY_ON_START_TOUCH)
ent.event = EventImpact1;

pXent_setcollisionflag (ent1, ent3, NX_NOTIFY_ON_START_TOUCH)
ent.event = EventImpact2;


What can I do so that only the corresponding event is triggered?

Thanks...
Posted By: rayp

Re: pXent_setcollisionflag - 11/12/21 13:07

Everything in the event-impact block will be handeled on event_impact no matter what entity triggered it. You have to take care for it by yourself.
Maybe something like this (sry if i missunderstood your question):
Code
void testevent(){
   // --- do every frame
   if (event_type == EVENT_FRAME){ 
      //nothing here right now, just wanted to show how to react on different types in one event
      //c_move/ent_animate what ever
   }
   // --- handle scan events (use SCAN_ENTS[!] to trigger via c_scan)
   //if (event_type == EVENT_SCAN){ 
      //if (you) if (you.ent_id == id_explosion) do_booooom_me_in_the_air_now();
   //}
   // --- finally handle the impact event
   if (event_type == EVENT_IMPACT){ // handle impacts with ALL ents
      if (you) {
         //if (you == ent2){
            //pXent_setcollisionflag (me, ent2, NX_NOTIFY_ON_START_TOUCH); // if me == ent1 dont know right now...
         //}
         //if (you == ent3){
            //pXent_setcollisionflag (me, ent3, NX_NOTIFY_ON_START_TOUCH);
         //}
         pXent_setcollisionflag (me, you, NX_NOTIFY_ON_START_TOUCH); // or maybe only this if ent1=me and you(impacting ent) unknown...
      }
   }
}
action Test_WED(){
   //ent1 = me; // ???
   my.emask |= ENABLE_FRAME|ENABLE_IMPACT; // |ENABLE_SCAN;
   my.event = testevent;
}
Hope this shows the logic behind. Normally you use one event only / ent.

Something like an "id"-skill can helpsto identify different ent-types in events, scans, traces or whatever. Example:
Code
#define ent_id   skill90   // i would not use skill1-10 because you often use them in WED to input unique values for some ents placed in the map.
#define id_dog      1000

action Dog_WED(){
   my.ent_id = id_dog;
   ...
}
...
if (you) if (you.ent_id == id_dog) do_bark();
...


Greets



edit:
tip besides...try to use as few as possible global entity pointers (+always check them before using, make sure not using them while a level loads and so on)!When your project grows, something like this may be hard to track down later (interaction between different entitys causing handle errors etc).

For myself i use a global var called level_loading. Events and other stuff do something like this:
Code
if (event_type == EVENT_FRAME && !level_loading && !freeze_mode){
   ...
}
This way iam sure no empty pointers causing problems when switching the level for example. A good example is a global player entity pointer. Maybe he dies and you simply want to respawn him. While respawning you must take care that no other entity is using the player-pointer cause it might be empty for a frame or more. Such errors might feel like a "random" first.

Another info: If you remove me entity (safe_remove, ptr_remove) in any of the event-type-blocks, make sure to jump out fex via return; cause next thing in the event block will try to use the removed me pointer which may lead to a crash pretty sure cause its empty now.


Btw...
Just wondering is event impact triggered from physic collisions? My guess right now is not, only from ent to ent. Not sure yet...have enough own problems to solve laugh
Posted By: rayp

Re: pXent_setcollisionflag - 11/13/21 17:52

Code
#define ent_id skill90
#define id_dog  1000
#define id_cat  1001
//#define id_snake 1002 // and so on...

void do_bark() { ...snd_play (snd_bark, 50, 0);... }
void do_miau() { ...snd_play (snd_miau, 50, 0);... }

action Dog_WED(){
   ent2 = me;                   // please try to avoid using such global entity pointers, if possible
   my.ent_id = id_dog;
   //my.emask |= ENABLE_FRICTION;
}
action Cat_WED(){
   ent3 = me;
   my.ent_id = id_cat;
   //my.emask |= ENABLE_FRICTION;
}

/*
   Or instead of using a action for every ent (animals in my example) you can combine it in one WED action.
   Skill will be masked in WED as "AnimalNr". 0/1 = dog   2 = cat
   Same you can do with do_bark and do_miau...fex: void do_animalsound (var sndnr){ if (sndnr==1){}}
*/

//skill1 AnimalNr 0
action Animal_WED(){
   if (my.skill1 <= 1){
      //ent2=me;
      my.ent_id = id_dog;
   }
   if (my.skill1 >= 2){
      //ent3=me;
      my.ent_id = id_cat;
   }
}

void testevent(){
   if (event_type == EVENT_FRICTION){ // ent1(me) hit another activated entity(you)? which one?
      if (you){                       // if (you == ent2)
         if (you.ent_id == id_dog){   // ent1 hit ent2?  (when not using global pointers this will also work for more than one(ent2) dog-ents btw)
            do_bark();
         }                            // if (you == ent3)
         if (you.ent_id == id_cat){   // ent1 hit ent3?
            do_miau();
         }
      }
   }
}

...
...
pXent_setcollisionflag (ent1, ent2, NX_NOTIFY_ON_START_TOUCH); // activate coll between ent1 and ent2 / dog    (ent1 or better "my" instead?)
pXent_setcollisionflag (ent1, ent3, NX_NOTIFY_ON_START_TOUCH); // activate coll between ent1 and ent3 / cat
...
...

//ent1.emask |= ENABLE_FRICTION; // ent1 or better "my" instead?
ent1.event = testevent;        // ent1 handles collision event: hit a dog(ent2)? then bark! hit a cat(ent3)? miau!
Something like this will do the trick. Activate coll between ents. In event type friction react on it and check what type of entity it was.
I never used this command before thats why i made an example about event impact. Anyway it does not change much how to handle this as u can see.

And like i already said please try to do this without global entity pointers like ent1, ent2 and ent3. My example event shows you wont need them most times.
Lets say you make a FPS. Ideally you have something like two global entity pointers. A player and a gun laugh. Of course you end up with more for sure, i just want to point out that you can do 90% without those unique ENTITY*'s



Good luck.
Greets
Posted By: Power_P

Re: pXent_setcollisionflag - 11/19/21 08:49

Da du deinem Profil nach aus Deutschland kommst, anworte ich auf deutsch. smile

Danke für die umfangreiche Antwort. Ich werde mich mit dem EVENT Thema nochmal intensiver beschäftigen.
Posted By: rayp

Re: pXent_setcollisionflag - 11/19/21 18:18

Gerne und viel Erfolg.
© 2024 lite-C Forums