Also i would use EVENT_FRAME instead of all those whiles. If you use a while for every ent this will slow down your code.
Code
#define health skill90
#define mytimer skill89

void healthtakerevent(){
   /*if (event_type == EVENT_IMPACT || event_type == EVENT_ENTITY){
      if (you){
         //dont do c_move etc here but u can store the handle and do it in event frame my.skill10 = handle(you)...ent = ptr_for_handle (my.skill10)
      } 
   }*/
   if (event_type == EVENT_FRAME){ // do every frame		
      if (player){
         if (!is (my, FLAG1)){
            if (vec_dist (player.x, my.x) <= my.skill1){ // && random (1) > 0.98){
                //c_trace (my.x, player.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|USE_POLYGON);
                //if (HIT_TARGET) if (you) if (you == player){
              	   player.health -= my.skill3;
            	   set (my, FLAG1);
                   //if (!snd_playing (my.skill4)) my.skill4 = ent_playsound (me, snd_healthtaker_hurtplayer, 100+random(100));
                //}
            }
         }
         else{
            my.mytimer += time_step;
            if (vec_dist (player.x, my.x) > my.skill1 || my.mytimer > my.skill2){
                my.mytimer = 0;
            	reset (my, FLAG1);
            }
         }
      }
      /*
      if (my.health <= 0){        // example how to remove "me" in event_frame
         my.event = NULL;
         //wait(1);
         safe_remove (me);
         //return; // only if this block is not at event's end,dont execute further lines
      }
      */
   }
}
// --- those lines below will mask the WED skills like define ----
//skill1 TakeRange 200
//skill2 DamageTime 100
//skill3 HealthTaken 10
//flag1 touched 0
action health_taker(){
	if (my.skill1 <= 0) my.skill1 = 200;  // react range
	if (my.skill2 <= 0) my.skill2 = 100;  // time to take health again even if player is still close
	if (my.skill3 <= 0) my.skill3 = 10;   // take this amount of player's health
        //my.health = 100;
	my.event = healthtakerevent;
	my.emask |= ENABLE_FRAME;//|ENABLE_ENTITY|ENABLE_IMPACT;
}
One of the secrets to fast code. 3run warned already, but u can use a var like player_died to simply avoid those error like
Code
if(event_type == EVENT_FRAME && !player_died) {use the pointer etc}

For myself i use a global var "level_loading" in every(!) event_frame event/while. Before doing stuff like switching the level i set this to 1. This will stop ALL running frame-events/break every while running, and prevent using lost pointers during the next frame(and i only use around two global ent pointers).

Better use
Code
safe_remove(ent)
instead of
Code
ptr_remove(ent)

If you want to make it a bit more realistic, do a c_trace when close. Now healthtaker will always reduce health when close, even with a wall in between.
edit: see above.

Wish i had used event_frame in the past. i was also stuck to this while-stuff. One day 3run(thanks again) told me to look into event_frame, i totally forgot about.
Still using whiles of course in my code, but i can count them with one hand laugh
Not saying whiles are bad in general, just saying use them carefully.

greets

Last edited by rayp; 06/26/21 20:42.

Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;