PDA

View Full Version : OnEnter script question


R2-X2
06-23-2009, 09:21 AM
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?

zbyl2
06-23-2009, 01:38 PM
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 : )

R2-X2
06-23-2009, 02:28 PM
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?

zbyl2
06-23-2009, 02:40 PM
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.

R2-X2
06-23-2009, 03:11 PM
Ok, everything cleared, thanks!

R2-X2
06-25-2009, 09:24 AM
Your script doesn't work. I always get a syntax error at "if"

zbyl2
06-25-2009, 10:35 AM
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.

R2-X2
06-27-2009, 06:19 AM
ouch. I always forget it.
Everything should be cleared now.