Projectile that acts like a Molotov cocktail

kimono

Well-known member
Hello everyone,
I'd like Han to throw a fireball that transforms into a cloud of flames (a bit like the holy water weapon in Castlevania).

Here's how the throw is coded:
Code:
anim freespecial2 #Energy Ball shot
    fastattack 1
    jugglecost 5
    forcedirection -1
    delay    10
    offset    28 92
    bbox 14 8 30 84
    range 171 400
    sound    data/chars/han/voice/hanshot.wav
    hitfx data/sounds/aof2-199.wav
    jumpframe    0 4 0 0   
    frame    data/chars/han/shoot1.png
    frame    data/chars/han/shoot2.png
    frame    data/chars/han/shoot3.png
    frame    data/chars/han/shoot4.png
    delay    6
    attack1 22 14 30 19 2 0 0 0 5 12
    frame    data/chars/han/shoot5.png
    @cmd    shooter2 "hanshot" 77 68 2 1
    frame    data/chars/han/shoot5.png
    frame    data/chars/han/shoot5.png
    attack1 0
    frame    data/chars/han/shoot2.png
    frame    data/chars/han/shoot1.png
    frame    data/chars/han/jump.png   
    delay    20
    frame    data/chars/han/idle.png
    frame    data/chars/han/idle.png

And here is the projectile in question:
Code:
name    hanshot
health    1
type    npc
hostile player obstacle
candamage player obstacle
nomove 1 1
remove 0
noquake 1
falldie 1
jumpheight 2
jumpspeed  3
animationscript        data/scripts/escript.c

##ANIMATIONS#############################################################################

anim idle
    delay    1
    offset    11 9
    bbox 0 0 16 16
    attack1 0 0 16 16 2 1 0 0 0 0
    frame    data/chars/weapons/hanshot1.png
    frame    data/chars/weapons/hanshot1.png   

anim    attack1
    range 0 480
    fastattack 1
    delay    15
    offset    1 31
    attack1 1 24 15 7 2 1 0 0 0 0
    frame    data/chars/weapons/hanshot2.png
    attack1 0
    frame    data/chars/weapons/hanshot3.png
    attack1 0 8 47 23 2 1 0 0 0 0
    frame    data/chars/weapons/hanshot4.png
    attack1 0
    frame    data/chars/weapons/hanshot5.png
    attack1 0 8 64 23 2 1 0 0 0 0
    frame    data/chars/weapons/hanshot6.png
    attack1 0
    frame    data/chars/weapons/hanshot7.png
    attack1 0 8 64 23 2 1 0 0 0 0
    frame    data/chars/weapons/hanshot8.png
    attack1 0
    frame    data/chars/weapons/hanshot9.png
    attack1 32 8 30 23 2 1 0 0 0 0
    frame    data/chars/weapons/hanshot10.png
    attack1 0
    frame    data/chars/weapons/hanshot11.png
    attack1 46 24 15 7 2 1 0 0 0 0
    frame    data/chars/weapons/hanshot12.png
    attack1 0
    @cmd    suicide
    frame    data/chars/misc/empty.gif

Here's how the projectile behaves in video:
How could this projectile react immediately upon hitting the ground?
Thank you as always for your valuable advice :)
 
Solution
Instead of the shooter2() function, you should use toss(), as it will spawn the projectile as a bomb

C-like:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");


   if (Direction == 0){ //Is entity facing left?                
      dx = -dx; //Reverse X direction to match facing
   }
   projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
}
Instead of the shooter2() function, you should use toss(), as it will spawn the projectile as a bomb

C-like:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");


   if (Direction == 0){ //Is entity facing left?                
      dx = -dx; //Reverse X direction to match facing
   }
   projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
}
 
Solution
The perfect solution for this specific case was the tosser function, which allowed me to manage the projectile's speed as follows:
Code:
@cmd    tosser "hanshot" 77 68 0 1 -1 0
Thanks again O' for this great lead ;)
 
which allowed me to manage the projectile's speed as follows:
ah, I use toss2() for that
C-like:
void toss2(void Shot, float dx, float dy, float dz, float Vx, float Vy, float Vz)
{ // Shooting projectile
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");
   void vShot;

      if (Direction == 0){ //Is entity facing left?                 
      dx = -dx; //Reverse X direction to match facing
   }

    vShot = projectile(Shot, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
    if (vShot){// safe check
    changeentityproperty(vShot, "velocity", Vx, Vz, Vy);
   if(Vy < 0){changeentityproperty(vShot, "base", 0);} //APPLY DEFAULT BASE VALUE FOR DOWNWARD SHOTS
   return vShot;
 }
}

Its almost the same thing of your tosser() function, but mine has a safe check and can be used on air too

C-like:
void tosser(void Bomb, float dx, float dy, float dz, float Vx, float Vy, float Vz)
{ // Tossing bomb with desired speed
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");
   void Shot;

   if (Direction == 0){ //Is entity facing left?                 
      dx = -dx; //Reverse X direction to match facing
   }

   Shot = projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
   tossentity(Shot, Vy, Vx, Vz);
   changeentityproperty(Shot, "speed", Vx);
}
 
Back
Top Bottom