Jump to content

Photo

Enemy Death Script


  • Please log in to reply
7 replies to this topic

#1 klop422

klop422

    Guess I'm full of monsters and treasure

  • Members
  • Real Name:Not George
  • Location:Planet Earth

Posted 25 May 2018 - 09:16 AM

I know I've been asking a lot, but I think this may be the last one.

 

I have a Wizzrobe enemy that I need to trigger three things when it dies. First, I need it to activate secrets (which works without scripts, but I'm mentioning just so you know); second, I need it to split into another enemy (because apparently Wizzrobes don't have that ability); thirdly, I need it to play a string when it dies.

Ideally, it should be general enough to allow no enemy to be spawned and/or no string to play, because I may need it again for something else.



#2 Gégé

Gégé

    Senior

  • Members
  • Real Name:Gérard
  • Location:France

Posted 26 May 2018 - 06:34 AM

Untested
 

const int PERMANENT = 1; // 0 = temporary secrets
const int SCRD_1 = 0; //Screend->D1
const int SCRD_2 = 1; //Screend->D2
const int SCRD_3 = 2; //Screend->D3
const int WIZZROBE_ID = 0;
const int WIZZSPLIT_ID = 0;

void FunctionWizzrobe(){
    if(Screen->D[SCRD_1] < 3){
        for(int i=1; i<=Screen->NumNPCs(); i++){
            npc wiz = Screen->LoadNPC(i);
            if(Screen->D[SCRD_1] == 0){
                if(WizzSPresent(i)){
                    if(wiz->HP <= 0){
                        Screen->D[SCRD_2] = wiz->X;
                        Screen->D[SCRD_3] = wiz->Y;
                        Screen->D[SCRD_1] = 1;
                    }
                }
            }
            else if(Screen->D[SCRD_1] == 1){
                CreateNPCAt(WIZZSPLIT_ID, Screen->D[SCRD_2], Screen->D[SCRD_3]);
                CreateNPCAt(WIZZSPLIT_ID, Screen->D[SCRD_2], Screen->D[SCRD_3]);
                Screen->D[SCRD_1] = 2;
            }
            else if(Screen->D[SCRD_1] == 2){
                if(Link->HP <= 0)Screen->D[SCRD_1] = 0;
                if(!WizzSpitedPresent(i)){
                    Screen->TriggerSecrets();
                    if(PERMANENT > 0)Screen->State[ST_SECRET] = true;
                    Game->PlaySound(SFX_SECRET);
                    Screen->D[SCRD_1] = 3;
                }
            }
        }
    }
}

bool WizzSpitedPresent(int i){
    npc wizsplited = Screen->LoadNPC(i);
    if(wizsplited->isValid())return true;
    return false;
}

bool WizzSPresent(int i){
    npc wiz = Screen->LoadNPC(i);
    if(wiz->ID == WIZZROBE_ID)return true;
    return false;
}

Put FunctionWizzrobe(); into global script


Edited by Gégé, 26 May 2018 - 06:34 AM.


#3 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 27 May 2018 - 09:45 AM

ffc script klop_request //Not sure what else to call it this time.
{
     void run(int target_enemy_id, int split, int num_splits, int msg)
     //There had better only be one enemy of this type on the screen!
     {
          int teloc[3]; //target enemy location
          npc n; teloc[1] = -1; teloc[2] = -1;
          while(1)
          {
               teloc[0] = 0; //wipe every frame
               for ( int q = Screen->NumNPCs(); q > 0; --q )
               {
                    n = Screen->LoadNPC(q);
                    if ( n->ID == target_enemy_id )
                    {
                         teloc[0] = q; teloc[1] = n->X; teloc[2] = n->Y;
                    }
               }
               if ( !teloc[0] ) //no target npc, but we preserve its last coordinates.
               {
                    break;
               }
               Waitframe();
          } //infinite loop ends here.
          if ( split )
          {
               if ( teloc[1] > -1 ) //only if there was a valid target with good coordinates.
               {
                    if ( teloc[2] > -1 )
                    {
                         for ( ; num_splits > 0; --num_splits )
                         {
                              n = Screen->CreateNPC(split);
                              n->X = teloc[1];
                              n->Y = teloc[2];
                         }
                    }
               }
          }
          if ( msg ) 
          {
               Screen->Message(msg);
          }
          this->Data = 0; Quit();
     }
} //runs out of scope


#4 klop422

klop422

    Guess I'm full of monsters and treasure

  • Members
  • Real Name:Not George
  • Location:Planet Earth

Posted 27 May 2018 - 05:49 PM

Getting a syntax error with 'line 1706' i.e.

for ( int q = Screen->NumNPCs(); q > 0; --q; )

where it's saying there's an "unexpected semicolon, expected rparen, on token ;"

I'm not quite knowledgeable enough in Zscript's syntax to be able to fix it myself...



#5 Orithan

Orithan

    Studying Scientist - Commission from Silvixen

  • Members
  • Location:Australia

Posted 27 May 2018 - 08:46 PM

Remove the semicolon after the "--q". The compiler is complaining about there being an unexpected semicolon, which is there.



#6 klop422

klop422

    Guess I'm full of monsters and treasure

  • Members
  • Real Name:Not George
  • Location:Planet Earth

Posted 29 May 2018 - 07:04 AM

Getting the same syntax error with it pointing at the last (useful) line (this->Data etc.)



#7 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 29 May 2018 - 12:26 PM

Getting the same syntax error with it pointing at the last (useful) line (this->Data etc.)

It's on the wrong line. That line needs to be above the right curly brace that closes run().

I fixed it, above.

#8 klop422

klop422

    Guess I'm full of monsters and treasure

  • Members
  • Real Name:Not George
  • Location:Planet Earth

Posted 01 June 2018 - 07:13 AM

Finally got round to actually testing it - string appears to play on entry to the screen before enemies spawn.

Fixed that by adding Waitframes(5) between lines 7 and 8.

Other issue is that killing the first enemy activates screen secrets (I have enemies->secret active on this screen), when I want the secrets to activate after the second enemy dies. Is there a solution to this?

 

EDIT: On another test, it seems to only activate after the latter enemy dies. I'll check again, but this is probably fine.


Edited by klop422, 06 June 2018 - 08:22 PM.



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users