N-DReW25 1,336 Posted March 19, 2018 Ok, so I am trying to edit a script from the base game that makes NPC's hostile. Essentially, I've added a third NPC to a module and I want to make it so after a dialogue he will go hostile along with the other NPC's. The problem is I am running into some sort of compiling issue, presumably caused by me because I don't know how to script properly. Here is my script. // Prototypes void sub1(); void sub1() { int int1 = 0; string string1 = "REThug5"; object object1 = GetObjectByTag(string1, int1); while ((object1 != OBJECT_INVALID)) { ChangeToStandardFaction(object1, 1); SetLockOrientationInDialog(object1, 3); (int1++); object1 = GetObjectByTag(string1, int1); } } void main() { sub1(); int int1 = 0; string string1 = "REThug4"; object object1 = GetObjectByTag(string1, int1); while ((object1 != OBJECT_INVALID)) { ChangeToStandardFaction(object1, 1); SetLockOrientationInDialog(object1, 1); (int1++); object1 = GetObjectByTag(string1, int1); } } If anyone would be so kind as to explain/show me how to add a third NPC to the script that would be much appreciated. Quote Share this post Link to post Share on other sites
Kexikus 995 Posted March 19, 2018 The elegant way to do this entire thing would be to to give the sub1() function an argument with the tag of the NPC and then just call it twice in main, once with the REThug5 argument and once with the name of your third NPC. The simple way would be to make a copy of everything in void main() except for the sub1(); and change the variable names from int1, string1, etc to int2, string2 etc, and to change the value of string2 to the tag of your third NPC. Quote Share this post Link to post Share on other sites
N-DReW25 1,336 Posted March 23, 2018 The elegant way to do this entire thing would be to to give the sub1() function an argument with the tag of the NPC and then just call it twice in main, once with the REThug5 argument and once with the name of your third NPC. The simple way would be to make a copy of everything in void main() except for the sub1(); and change the variable names from int1, string1, etc to int2, string2 etc, and to change the value of string2 to the tag of your third NPC. As I do not know much about scripting I am certain what I've done is probably wrong and will need correcting. How does this look? // Prototypes void sub1(); void sub1() { int int1 = 0; string string1 = "REThug5"; object object1 = GetObjectByTag(string1, int1); while ((object1 != OBJECT_INVALID)) { ChangeToStandardFaction(object1, 1); SetLockOrientationInDialog(object1, 3); (int1++); object1 = GetObjectByTag(string1, int1); } } void sub2() { int int2 = 0; string string2 = "REThug1"; object object1 = GetObjectByTag(string1, int1); while ((object1 != OBJECT_INVALID)) { ChangeToStandardFaction(object1, 1); SetLockOrientationInDialog(object1, 3); (int1++); object1 = GetObjectByTag(string1, int1); } } void main() { sub1(); int int1 = 0; string string1 = "REThug4"; object object1 = GetObjectByTag(string1, int1); while ((object1 != OBJECT_INVALID)) { ChangeToStandardFaction(object1, 1); SetLockOrientationInDialog(object1, 1); (int1++); object1 = GetObjectByTag(string1, int1); } } Quote Share this post Link to post Share on other sites
Hassat Hunter 571 Posted March 23, 2018 Well, sub2 is never triggered, and I think sub1 should already have different int strings and object names. Also you still check for string1, int1 in sub2 Quote Share this post Link to post Share on other sites
Kexikus 995 Posted March 23, 2018 That's somehow neither of my suggestions but also a possibility. As Hassat Hunter said, your sub2 function is never triggered. To help you understand that, here's what a KotOR script does: It has either a void main() function or a int startingConditional() function if it's a conditional script. void or int are the return type of the function. void main() is used in "normal" scripts and returns nothing as it just does some stuff. int startingConditional() returns an integer (0 or 1, i.e. true or false) that is used for conditions in dialogs. Since yours is a normal script, the main function will be called. The first thing it does in your case is to call another function called sub1() (which turns REThug5 hostile). Then it proceeds to turn REThug4 hostile itself. The problem here is that sub2() is never called, so it will never be executed and does nothing. And then there's the other problem in your sub2() function. You declare variables int2 and string2, but then later in the function you check for int1 and string1, but these variables don't exist inside sub2() as you never declared them. So you need to either rename your int1 and string1 to int2 and string2 or vice versa. Since those variables are only used inside a function, it doesn't matter that their name is the same as the variables in sub1(). They're only declared locally, inside the function. Quote Share this post Link to post Share on other sites
N-DReW25 1,336 Posted March 24, 2018 That's somehow neither of my suggestions but also a possibility. As Hassat Hunter said, your sub2 function is never triggered. To help you understand that, here's what a KotOR script does: It has either a void main() function or a int startingConditional() function if it's a conditional script. void or int are the return type of the function. void main() is used in "normal" scripts and returns nothing as it just does some stuff. int startingConditional() returns an integer (0 or 1, i.e. true or false) that is used for conditions in dialogs. Since yours is a normal script, the main function will be called. The first thing it does in your case is to call another function called sub1() (which turns REThug5 hostile). Then it proceeds to turn REThug4 hostile itself. The problem here is that sub2() is never called, so it will never be executed and does nothing. And then there's the other problem in your sub2() function. You declare variables int2 and string2, but then later in the function you check for int1 and string1, but these variables don't exist inside sub2() as you never declared them. So you need to either rename your int1 and string1 to int2 and string2 or vice versa. Since those variables are only used inside a function, it doesn't matter that their name is the same as the variables in sub1(). They're only declared locally, inside the function. That just goes to show how horrible I am with this sort of stuff. Quote Share this post Link to post Share on other sites
Guest Qui-Gon Glenn Posted March 29, 2018 Yes, but you are trying... That gives us something to work with. The others have mentioned your syntactical errors, so I will not address them. What I will say is you may want to consider being more verbose in the naming of your variables. Here's an example: You are looking for "object1". You want that to be found by string, specifically "REThug1". I won't question your use of string substitution for a tag you know in this instance, but it is curious. What I do suggest is making your variable names more "readable". It will make your code easier to follow, for yourself and us. I would name variables like this - object oThugToChange = GetObjectByTag(sThugTag, iCounter);When you leave variables with generic names, it is harder for anybody to follow the logic. Also, a convention of the game devs and most modders is to add the variable type to the name of their variable, as a lower case letter prefix. In my example above, you can see that in use. Quote Share this post Link to post Share on other sites