Making a trap explod when the players or enemies are close to it.

KanbeiKS7

New member
Need some pointers any ideas my dudes? I made a trap but I want it to explode when the player, enemy or NPCs get near it. any ideas on what to do?

Code:
code here
name  Landmine
type  trap
health     1
speedf    0
nolife  1
noatflash 1
nodieblink  3
gfxshadow    1
offscreenkill 1000000
candamage   enemy player npc obstacle
animationscript    data/scripts/escript.c
load explosion

anim    death
    delay    5
    offset    29 80
    frame    Data/chars/misc/Landmine/0-1.png
    frame    Data/chars/misc/Landmine/0-0.png
    frame    Data/chars/misc/Landmine/0-1.png
    frame    Data/chars/misc/Landmine/0-0.png
    frame    Data/chars/misc/Landmine/0-1.png
    @cmd    projectile 1 "explosion" 20 1 30 0 0 0
    frame    Data/chars/misc/Landmine/0-0.png

anim    idle
    bbox    0 0 55 57
    loop    1
    delay    16
    offset    28 80
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 78
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 76
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 74
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 72
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 70
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 68
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 70
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 72
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 74
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 76
    frame    Data/chars/misc/Landmine/0-0.png
    offset    28 78
    frame    Data/chars/misc/Landmine/0-0.png
 
You can make the landmine hostile to players, enemies, obstacles and NPCs then give the mine ATTACK animation in which the mine will explode when those entities are close or within range.

If that isn't good enough, I could share script to do the detecting stuff :cool:.
 
You can make the landmine hostile to players, enemies, obstacles and NPCs then give the mine ATTACK animation in which the mine will explode when those entities are close or within range.

If that isn't good enough, I could share script to do the detecting stuff :cool:.
Thank you as always bloodbane, I'll run some tests to see if that works for now
 
You can make the landmine hostile to players, enemies, obstacles and NPCs then give the mine ATTACK animation in which the mine will explode when those entities are close or within range.

If that isn't good enough, I could share script to do the detecting stuff :cool:.
I added an attack animation and seems to not ever do it, I am doing something wrong?
 
Have you declared hostile player enemy npc obstacle at landmine's header text?

If that doesn't work, you could use scripted method instead which doesn't need ATTACK animation. Well, you still need animation for the triggered state though, which is FOLLOW1 in my example below.
Here's my landmine text:
Code:
name        mine
gfxshadow    1
type        trap
hostile        player enemy
animationscript    data/scripts/harden.c
load        XplosX


anim    idle
@script
  if(frame>=1){
    attack4(-30, 30, -10, 10, 10, "ANI_FOLLOW1");
  }
@end_script
    loop    1
    delay    7
    offset    11 14
    frame    data/chars/misc/mine.png
    frame    data/chars/misc/mine.png
    frame    data/chars/misc/mine.png
    frame    data/chars/misc/mine.png
    frame    data/chars/misc/mine.png #
    frame    data/chars/misc/mine.png

anim    follow1
    delay    7
    offset    11 14
    drawmethod    tintmode 3
    drawmethod    tintcolor 255_64_64
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 200_10_10
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 255_64_64
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 200_10_10
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 255_64_64
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 200_10_10
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 255_64_64
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 200_10_10
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 255_64_64
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 200_10_10
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 255_64_64
    frame    data/chars/misc/mine.png
    drawmethod    tintmode 3
    drawmethod    tintcolor 200_10_10
    frame    data/chars/misc/mine.png
    @cmd    spawn01 "XplosX" 0 0 0
    frame    data/chars/misc/empty.gif
    @cmd    suicide
    frame    data/chars/misc/empty.gif

This is attack4 function:
C:
void attack4(int RxMin, int RxMax, int RyMin, int RyMax, int Rz, void Ani)
{// Attack interruption with 3D range check
    void self = getlocalvar("self");
    void target = findtarget(self); //Get nearest player
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    float y = getentityproperty(self, "a");
    int dir = getentityproperty(self, "direction");

    if(target!=NULL()){
      float Tx = getentityproperty(target, "x");
      float Tz = getentityproperty(target, "z");
      float Ty = getentityproperty(target, "a");
      float Disx = Tx - x;
      float Disz = Tz - z;
      float Disy = Ty - y;

      if(Disz < 0){
        Disz = -Disz;
      }

      if(Disx >= RxMin && Disx <= RxMax && Disy >= RyMin && Disy <= RyMax && Disz <= Rz && dir == 1) // Target within range on right facing?
      {
        performattack(self, openborconstant(Ani)); //Change the animation
      } else if(Disx >= -RxMax && Disx <= -RxMin && Disy >= RyMin && Disy <= RyMax && Disz <= Rz && dir == 0) // Target within range on left facing?
      {
        performattack(self, openborconstant(Ani)); //Change the animation
      }
    }
}

XPlosX is just an explosion entity.
 
Back
Top Bottom