Jump to content

Home

OnEnter script question


R2-X2

Recommended Posts

Posted

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?

Posted

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 : )

Posted

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?

Posted

You may completely remove line you don't want. And yeah, if you don't want first one you'll need to replace && with "if(" later.

Posted

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.

Archived

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

×
×
  • Create New...