R2-X2 Posted June 23, 2009 Share Posted June 23, 2009 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 More sharing options...
zbyl2 Posted June 23, 2009 Share Posted June 23, 2009 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 More sharing options...
R2-X2 Posted June 23, 2009 Author Share Posted June 23, 2009 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 More sharing options...
zbyl2 Posted June 23, 2009 Share Posted June 23, 2009 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. Link to comment Share on other sites More sharing options...
R2-X2 Posted June 23, 2009 Author Share Posted June 23, 2009 Ok, everything cleared, thanks! Link to comment Share on other sites More sharing options...
R2-X2 Posted June 25, 2009 Author Share Posted June 25, 2009 Your script doesn't work. I always get a syntax error at "if" Link to comment Share on other sites More sharing options...
zbyl2 Posted June 25, 2009 Share Posted June 25, 2009 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 More sharing options...
R2-X2 Posted June 27, 2009 Author Share Posted June 27, 2009 ouch. I always forget it. Everything should be cleared now. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.