Jump to content

Home

OnEnter script question


R2-X2

Recommended Posts

And again a scripting question:

 

How two make scripts that check if an NPC already exists in a module, check a GlobalNumber (or two) and if the NPC doesn't exist and the GlobalN. is right, spawns an NPC? And, is there a way to do it with multiple NPCs in one script?

Link to comment
Share on other sites

Add this to your OnEnter script, it will check if NPC was already spawned in module and if globals were set:

      if(GetGlobalNumber("NAME_OF_YOUR_GLOBAL") == X // Global number equals X
       && GetGlobalNumber("NAME_OF_SECOND_GLOBAL") == X // cause you asked for two globals 
       && !GetIsObjectValid(GetObjectByTag("TAG_OF_YOUR_NPC"))) { // only if NPC doesn't exist in module

              CreateObject(OBJECT_TYPE_CREATURE, "YOUR_NPC", Location(Vector(0.0, 0.0, 0.0), 0.0f));    //remember to change tag of your NPC and coordinates
         }

 

 

 

Hope that helps : )

Link to comment
Share on other sites

Yep that helps. Thank you.

If I want to use just one of these conditions, I just would have to put an "//" (without the quotes, sure) in front of them, or, if I don't use the first one change the "&&" to an "if", right?

Link to comment
Share on other sites

I can compile it.

Did you add "void main() {" at the very beginning? Like this one:

void main(){
     if(GetGlobalNumber("NAME_OF_YOUR_GLOBAL") == X 
       && GetGlobalNumber("NAME_OF_SECOND_GLOBAL") == X 
       && !GetIsObjectValid(GetObjectByTag("TAG_OF_YOUR_NPC"))) { 

              CreateObject(OBJECT_TYPE_CREATURE, "YOUR_NPC", Location(Vector(0.0, 0.0, 0.0), 0.0f));  
         }
}

It's always needed to add void main() at beginning of all your scripts (except they're conditional scripts for conversation, but well), otherwise you won't compile anything.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...