Jump to content

Photo

keeping an npc alive?


  • Please log in to reply
13 replies to this topic

#1 Jambu

Jambu

    Junior

  • Members
  • Pronouns:He / Him, They / Them

Posted 02 May 2024 - 11:21 AM

npc script AquamentusGleeok{
    void run(int HeadHP, int LooseHeadID){
        npc head[3];
        int i;
        while(i<3){
            if(this->HP==0){
                this->HP = HeadHP;
                head[i] = Screen->CreateNPC(LooseHeadID);
                head[i]->X = this->X;
                head[i]->Y = this->Y;
                i++;
                continue;
            }
            Waitframe();
        }
        while(this->HP>0){
            Waitframe();
        }
        //Kill Heads.
        for (int i; i < 3;i++){
            head[i]->HP = -1000;
            this->HP = 0;
        }
    }
}

I'm trying to make a  Aquamentus that spawns additional heads detaching the defeated heads. I got the looseheads working but the Body isn't working it just dies when HP reaches 0 and I have no idea how to keep it alive.


Edited by Jambu, 02 May 2024 - 11:25 AM.


#2 Taco Chopper

Taco Chopper

    protector of the darn forum

  • Administrators
  • Pronouns:He / Him
  • Location:South Australia

Posted 02 May 2024 - 11:34 AM

Set up an int so it's something like int BodyHP = HeadHP+1000, and have the HP check statement take place when BodyHP is equal to or less than 1000 - something like BodyHP =< 1000 (I think that's the right way to write it?)
  • Jambu likes this

#3 Jambu

Jambu

    Junior

  • Members
  • Pronouns:He / Him, They / Them

Posted 02 May 2024 - 12:37 PM

npc script AquamentusGleeok{
    void run(int HeadHP, int LooseHeadID){
        npc head[3];
        int heads = 1;
        int BodyHP = this->HP; //Ugly Hack
        this->HP = 1000;
        while(true){
            BodyHP -= (1000 - this->HP);
            this->HP = 1000;
            if(BodyHP == 0){ //chopped off?
                BodyHP = HeadHP; //reset hp...
                head[heads-1] = Screen->CreateNPC(LooseHeadID);
                head[heads-1]->X = this->X;
                head[heads-1]->Y = this->Y;
                heads++;
            }
            if(heads==4) //fourth head is active
                break;
            else
                Waitframe();
        }
     
        BodyHP = HeadHP;
        this->HP = 1000;
        while(BodyHP>0){ //big guy still alive?
            BodyHP -= (1000 - this->HP);
            this->HP = 1000;
            Waitframe();
        }
        //kill heads
        for (int i; i<3;i++){
            head[i]->HP = -1000; //silently kill the heads.
        }
        //kill big guy
        this->HP = 0; //DIE YOU MONSTER!
    }
} 

Still not working... Hmm any thoughts what I might of missed.


Edited by Jambu, 02 May 2024 - 01:22 PM.


#4 Emily

Emily

    Scripter / Dev

  • ZC Developers
  • Pronouns:She / Her

Posted 02 May 2024 - 02:41 PM

You should just use `Immortal`. Just set `this->Immortal = true;`, and it won't be able to die. When you want it to finally die, just set `this->Immortal = false;` to let it die normally again.



#5 Jambu

Jambu

    Junior

  • Members
  • Pronouns:He / Him, They / Them

Posted 02 May 2024 - 05:03 PM

Nevermind


Edited by Jambu, 02 May 2024 - 05:34 PM.


#6 Emily

Emily

    Scripter / Dev

  • ZC Developers
  • Pronouns:She / Her

Posted 02 May 2024 - 05:33 PM

That code looks right, so not sure what would be wrong. Is the script running properly?



#7 Jambu

Jambu

    Junior

  • Members
  • Pronouns:He / Him, They / Them

Posted 02 May 2024 - 05:41 PM

That code looks right, so not sure what would be wrong. Is the script running properly?

The primary problem is that the heads are not spawning

Here's Both Scripts

npc script Aquamentus{ //broken piece of crap
    void run(int HeadHP, int LooseHeadID){
        npc head[3];
        int heads = 1;
        this->Immortal = true;
        while(true){
            if(this->HP <= 0){ //chopped off?
                this->HP = HeadHP; //reset hp...
                head[heads-1] = Screen->CreateNPC(LooseHeadID);
                head[heads-1]->X = this->X;
                head[heads-1]->Y = this->Y;
                heads++;
            }
            if(heads==4) //fourth head is active
                break;
            else
                Waitframe();
        }
        this->HP = HeadHP;
        while(this->HP>0){ //big guy still alive?
            Waitframe();
        }
        //kill heads
        for (int i; i<3;i++){
            head[i]->HP = -1000; //silently kill the heads.
        }
        //kill big guy
        this->Immortal = false;
        this->HP = 0; //DIE YOU MONSTER!
    }
}

ffc script AquamentusLooseHead{
    void run(int enemyID){
        int clk = 0;
        int clk2 = 0;
        npc ghost = Ghost_InitAutoGhost(this,enemyID);
        Ghost_Dir = Rand(8);
        Ghost_SetFlag(GHF_FLYING_ENEMY | GHF_IGNORE_ALL_TERRAIN | GHF_NO_FALL);
        while(ghost->isValid()){
            Ghost_HP = 1000;
            clk = Ghost_VariableWalk8(clk,ghost->Step,ghost->Rate,ghost->Homing,ghost->Hunger,ghost->Haltrate);
            if(++clk2 > 72 && Rand(ghost->Attributes[0])==0){
                Attack(ghost);
                clk2=0;
            }
            Ghost_Waitframe(this,ghost,true,true);
        }
    }
    void Attack(npc ghost){
		eweapon fireballA = FireAimedEWeapon(ghost->Weapon, ghost->X, ghost->Y, 0, 175, ghost->WeaponDamage, SP_FIREBALL, SFX_FIREBALL, 0);
		eweapon fireballB = FireAimedEWeapon(ghost->Weapon, ghost->X, ghost->Y, 0, 175, ghost->WeaponDamage, SP_FIREBALL, SFX_FIREBALL, 0);
		eweapon fireballC = FireAimedEWeapon(ghost->Weapon, ghost->X, ghost->Y, 0, 175, ghost->WeaponDamage, SP_FIREBALL, SFX_FIREBALL, 0);
		SetEWeaponMovement(fireballA, EWM_DRIFT_WAIT, DIR_UP,1);
		SetEWeaponMovement(fireballB, EWM_DRIFT_WAIT, DIR_DOWN,1);
    }
}

I'ved test the heads independently and those work fine I just cannot get them to spawn, and the COnsole isn't printing any errors either, :(


Edited by Jambu, 02 May 2024 - 05:44 PM.


#8 Jambu

Jambu

    Junior

  • Members
  • Pronouns:He / Him, They / Them

Posted 02 May 2024 - 08:03 PM

Found the problem. This immortal is preventing the enemy from taking damage cause this statement never happens unless I comment out the unless... (not sure why) So umm Life is all about how we handle Plan B Plan C right... But I'm not sure what Plan C is right now.

unless(this->HP > 0){ //chopped off?
    this->HP = HeadHP; //reset hp...
    head[heads-1] = CreateNPCAt(LooseHeadID,this->X,this->Y);
    heads++;
}


#9 Deedee

Deedee

    Bug Frog Dragon Girl

  • Moderators
  • Real Name:Deedee
  • Pronouns:She / Her, They / Them
  • Location:Canada

Posted 03 May 2024 - 02:44 AM

Could you try putting Traces in the script and having the console open? I'd put a trace near the beginning just to make sure that the script is running at all, and then a trace inside the if statement when the enemy is supposed to summon the heads to check if that if statement is running.

What happens if you spawn, say, an octorock instead of the heads? Does it work right then? If so, are the head's type/family set to Other type? Nothing in that script looks wrong from a sleep-deprived glance, so I wonder if the problem is something where placing the heads as a screen enemy works while spawning them doesn't.

Sorry if this is standard debugging stuff, just want to get a handle on what's happening.


  • Jambu likes this

#10 Jambu

Jambu

    Junior

  • Members
  • Pronouns:He / Him, They / Them

Posted 03 May 2024 - 08:38 AM

Could you try putting Traces in the script and having the console open? I'd put a trace near the beginning just to make sure that the script is running at all, and then a trace inside the if statement when the enemy is supposed to summon the heads to check if that if statement is running.

What happens if you spawn, say, an octorock instead of the heads? Does it work right then? If so, are the head's type/family set to Other type? Nothing in that script looks wrong from a sleep-deprived glance, so I wonder if the problem is something where placing the heads as a screen enemy works while spawning them doesn't.

Sorry if this is standard debugging stuff, just want to get a handle on what's happening.

From commenting out sections of code I was able to diagnose the problematic code, as I said the unless statement isn't running.

npc script Aquamentus{ //broken piece of crap
    void run(int HeadHP, int LooseHeadID){
        npc head[3];
        int heads = 1;
        this->Immortal = true;
        while(true){
            //unless(this->HP > 0){ //chopped off?
            this->HP = HeadHP; //reset hp...
            head[heads-1] = CreateNPCAt(LooseHeadID,this->X,this->Y);
            heads++;
            //}
            if(heads==4) //fourth head is active
                break;
            else
                Waitframe();
        }
        this->HP = HeadHP;
        while(this->HP>0){ //big guy still alive?
            Waitframe();
        }
        //kill heads
        for (int i; i<3;i++){
            head[i]->HP = -1000; //silently kill the heads.
        }
        //kill big guy
        this->Immortal = false;
        this->HP = 0; //DIE YOU MONSTER!
    }
}


#11 Deedee

Deedee

    Bug Frog Dragon Girl

  • Moderators
  • Real Name:Deedee
  • Pronouns:She / Her, They / Them
  • Location:Canada

Posted 03 May 2024 - 09:02 AM

Oh! What's the HP set to? Could you try tracing the HP every frame? 



#12 Jambu

Jambu

    Junior

  • Members
  • Pronouns:He / Him, They / Them

Posted 03 May 2024 - 09:22 AM

How do I get it to trace everyframe? It only runs the trace value once.

 

@DeeDee this what I get from this

while(true){
    Trace(this->HP);
    Waitframe();
}

NPC(3, Aquamentus): 12.0000








Edited by Jambu, 03 May 2024 - 10:17 AM.


#13 Deedee

Deedee

    Bug Frog Dragon Girl

  • Moderators
  • Real Name:Deedee
  • Pronouns:She / Her, They / Them
  • Location:Canada

Posted 03 May 2024 - 10:50 AM

Okay, it seems like Aquamentus, Gohma, Ganon, Digdoggers, and Dodongos don't run their script for more than a single frame, that's a bug. Good catch!


  • Alucard648 and Jambu like this

#14 Jambu

Jambu

    Junior

  • Members
  • Pronouns:He / Him, They / Them

Posted 03 May 2024 - 11:13 AM

Added a issue to the github.




4 user(s) are reading this topic

0 members, 4 guests, 0 anonymous users