Solved Counter Attack Dummy Script

Question that is answered or resolved.

Aerisetta

Active member
Hi

Spent a few hours trying to do this but couldnt get it to work.

I would like to do this

1. Player spawns a dummy NPC
2. Dummy stays on screen for a few seconds
3. When dummy gets hit, it deals direct damage to the enemy who hit it (not AOE), and a numbered attack (i.e. ATTACK5) and knocks down the opponent
4. This is so that the enemy gets hit with ATTACK5, they will spawn an item.

I it happens, my game crashes, please help
Invalid entity parameter.
Script function 'damageentity' returned an exception, check the manual for details.
parameters: <VT_EMPTY> Unitialized, #202862632, 1, 1, 9,


Code:
name        Parry
type        npc
health        1000
nomove        1
candamage            enemy npc obstacle
lifespan    3
animationscript     data/scripts/prscript.c


anim    idle

    delay    1
    @cmd    spawner "trail" 0 0 0
    drawmethod alpha 1
    offset    800 620
    bbox 750 340 100 280
    delay    70
    frame    data/chars/lucifer/float.png
    delay    5
    @cmd    suicide
    frame    data/chars/lucifer/float.png

   
anim    pain
@script
    void self = getlocalvar("self");
    void Opp = getlocalvar("attacker");
   
    if(frame==1)
    {
    damageentity(Opp, self, 1, 1, openborconstant("ATK_NORMAL5"));
    }
    @end_script  
    delay    1
    offset    800 620
    bbox 750 340 100 280
    frame    data/chars/lucifer/float.png
    delay    100
    @cmd    suicide
    frame    data/chars/lucifer/float.png

anim    attack5
    delay    1
    offset    800 620
    bbox 750 340 100 280
    frame    data/chars/lucifer/float.png
    attack5 800 353 120 200 1 1 0 0 40 0
    delay    100
    @cmd    suicide
    frame    data/chars/lucifer/float.png
 
Solution
This script is the cause of the crash:
C:
anim    pain
@script
    void self = getlocalvar("self");
    void Opp = getlocalvar("attacker");
   
    if(frame==1)
    {
    damageentity(Opp, self, 1, 1, openborconstant("ATK_NORMAL5"));
    }
    @end_script

I believe it should be this:
C:
anim    pain
@script
    void self = getlocalvar("self");
    void Opp = getentityproperty(self,"opponent");
   
    if(frame==1)
    {
    damageentity(Opp, self, 1, 1, openborconstant("ATK_NORMAL5"));
    }
    @end_script
Isn't "lifespan 3" causing issues ?

How is this entity alive for more than 3 seconds?(or milliseconds?)


 nevermind.
I've had a Similar issue and I would check enemies pain animations .
 
Last edited:
This script is the cause of the crash:
C:
anim    pain
@script
    void self = getlocalvar("self");
    void Opp = getlocalvar("attacker");
   
    if(frame==1)
    {
    damageentity(Opp, self, 1, 1, openborconstant("ATK_NORMAL5"));
    }
    @end_script

I believe it should be this:
C:
anim    pain
@script
    void self = getlocalvar("self");
    void Opp = getentityproperty(self,"opponent");
   
    if(frame==1)
    {
    damageentity(Opp, self, 1, 1, openborconstant("ATK_NORMAL5"));
    }
    @end_script
 
Solution
This script is the cause of the crash:
C:
anim    pain
@script
    void self = getlocalvar("self");
    void Opp = getlocalvar("attacker");
 
    if(frame==1)
    {
    damageentity(Opp, self, 1, 1, openborconstant("ATK_NORMAL5"));
    }
    @end_script

I believe it should be this:
C:
anim    pain
@script
    void self = getlocalvar("self");
    void Opp = getentityproperty(self,"opponent");
 
    if(frame==1)
    {
    damageentity(Opp, self, 1, 1, openborconstant("ATK_NORMAL5"));
    }
    @end_script
Yay thanks a lot everyone!!!!! @Bloodbane 's code solved the crash problem!!!!

Below is a video showing it in action. The player slows down time and produces clones around himself. If the enemy hits the clone, they get attacked by ATK_NORMAL5 and fall. When enemy is hit by ATK_Normal5, they will drop a gun (the main way to get guns in this game, but the risk is player will get grabbed, 20 grabs = game over)

Something unexpected happened though...I thought it would just damageentity against the melee attackers and the bullets themselves, unfortunately the engine is so smart it counter attacked the shooter of the bullet as well lol (shown at the end of the video)

hmmmmm
I want to deal damage to the melee attacker themselves
I want to deal damage to the bullet, but NOT the shooter of the bullet.
Any tips? :)


This is the bullet, shot out using @cmd shooter by enemy entity
Code:
name    bullet1
health  1
type    none
speed    30
noquake 1
remove    1
nolife  1
candamage       player npc obstacle
lifespan  4
offscreenkill     200

anim    idle
    loop    1
    delay    3
    offset    39 55
    bbox    0 0 0 0
    hitfx    data/sounds/sl1.wav
    hitflash    Flash4
    attack3    22 23 35 45 0 0 0 0 0 25
    frame    data/chars/misc/bullets/bullet01.gif
    frame    data/chars/misc/bullets/bullet01.gif
    frame    data/chars/misc/bullets/bullet01.gif
    frame    data/chars/misc/bullets/bullet01.gif
 
Last edited:
Hmmm.... projectiles shot using projectile function usually define the shooter as their owner. This causes any entity who gets hit by the former to accept the owner as the one who hit him/her/it.

Alternate way is to use different kind of projectile fired using shooter2 function. This function doesn't register shooter as owner of the fired projectile therefore when opponent is acquired, it will get the projectile.

[couple hours later]

Alright, I've figured out another alternate solution which still allow enemies to shoot using shooter function.
Parry NPC should use not use script in its PAIN but use this damagescript instead:
DumHit.c
C:
void main()
{// Dummy's damagescript
    void self = getlocalvar("self"); //Get calling entity.
    void Opp = getlocalvar("attacker"); //Get attacker
    int L = getentityproperty(self,"lifespancountdown");

    if(Opp && L > 0){
      damageentity(Opp, self, 10, 0, openborconstant("ATK_NORMAL"));
    }
}

Save that in data/scripts folder.
Declare this script in Parry's header with this:
takedamagescript data/scripts/dumhit.c
 
Last edited:
Hmmm.... projectiles shot using projectile function usually define the shooter as their owner. This causes any entity who gets hit by the former to accept the owner as the one who hit him/her/it.

Alternate way is to use different kind of projectile fired using shooter2 function. This function doesn't register shooter as owner of the fired projectile therefore when opponent is acquired, it will get the projectile.

[couple hours later]

Alright, I've figured out another alternate solution which still allow enemies to shoot using shooter function.
Parry NPC should use not use script in its PAIN but use this damagescript instead:
DumHit.c
C:
void main()
{// Dummy's damagescript
    void self = getlocalvar("self"); //Get calling entity.
    void Opp = getlocalvar("attacker"); //Get attacker

    if(Opp){
      damageentity(Opp, self, 10, 0, openborconstant("ATK_NORMAL"));
    }
}

Save that in data/scripts folder.
Declare this script in Parry's header with this:

perfect that did it, thanks a lot!
 
Back
Top Bottom