jarec Posted August 25, 2007 Share Posted August 25, 2007 I searched around these forums a bit and I've tried a few things in other threads that covered this kind of thing but nothing has worked so far. I want to spawn a custom NPC who you can pick up on Taris (he replaces Juhani's slot in the party table) into the hideout with the other NPCs there once you find and recruit him. There's some problem with the spawn script though and I just can't seem to figure out what I've missed: This is the enter script for the hideout: void main() { object oEnter = GetEnteringObject(); object oNPCtest = GetObjectByTag("p_NPC"); if (GetIsPC(oEnter)) { if (IsAvailableCreature(NPC_JUHANI)) { if (GetIsObjectValid(oNPCtest) == FALSE) { object oPC=GetFirstPC(); string cmMessage = "This part of the script is working"; SpawnAvailableNPC(NPC_JUHANI, Location(Vector(83.03,137.09,0.00), 0.0)); SendMessageToPC(oPC, cmMessage); } } } ExecuteScript("k_ptar_02af_en2", OBJECT_SELF); } p_NPC is the name of the creature file I used to add him into the party when you first recruit him, but I don't actually know one way or the other if this is what he'd be called if he was spawned in there like I'm trying to do. I know the conditional part of the script is working because I have two savegames before and after you get him - the one before you get him won't print the message when you enter the hideout, but the one after you get him will. So I'm guessing (cautiously) that I've messed up the spawning command somehow. I'm still new to scripting (I've only been trying it for a few days) and I've kind of run out of ideas. I don't even know for sure if it's some other thing completely that determines how/where/when party members get spawned into the hideout. If anyone can tell me what I've done wrong or suggest something, I'd really appreciate it. Link to comment Share on other sites More sharing options...
Darkkender Posted August 25, 2007 Share Posted August 25, 2007 Well from just a glance the first problem I see is that you are asking the script to do the following to get your NPC by it's tag and not by template. So when you later are calling your conditional later of checking if NPC_JUHANI it technically returns a FALSE however your if statement doesn't have a specific condition to check for. if (IsAvailableCreature(NPC_JUHANI)) needs to look more like this if (IsAvailableCreature(NPC_JUHANI) == TRUE) Otherwise your if statement gets ignored, actually I'm surprised the script compiles. Link to comment Share on other sites More sharing options...
jarec Posted August 25, 2007 Author Share Posted August 25, 2007 Well the thing is that the SendMessageToPC command works properly in spite of it all - when the NPC has been recruited, I see the message in my feedback log after entering the hideout and I don't see it if I enter and the NPC hasn't been recruited yet. If it was returning FALSE for the IsAvailableCreature check, wouldn't it just drop straight down to the ExecuteScript function and have me not seeing any message at all? Or do I just understand the way it works totally wrong (more than likely I do )? I did modify that part like you suggested though and it hasn't made any difference. Link to comment Share on other sites More sharing options...
stoffe Posted August 25, 2007 Share Posted August 25, 2007 I want to spawn a custom NPC who you can pick up on Taris (he replaces Juhani's slot in the party table) into the hideout with the other NPCs there once you find and recruit him. There's some problem with the spawn script though and I just can't seem to figure out what I've missed: (snip) p_NPC is the name of the creature file I used to add him into the party when you first recruit him, but I don't actually know one way or the other if this is what he'd be called if he was spawned in there like I'm trying to do. I can't see anything wrong with your script, assuming that the Tag set in p_NPC.utc also is p_NPC (which it probably is if you get past the condition check). Check that the coordinates you've specified are valid. Does it work to spawn the NPC in manually via the party selection screen? It's a long shot, but you could try to delay spawning the character somewhat and see if that makes any difference, in case there is some script running that clears out the hideout when you enter it, which might remove your character as well just after it's been spawned. Like: void ST_Spawn(int iSlot, location lLoc) { SpawnAvailableNPC(iSlot, lLoc); } void main() { object oEnter = GetEnteringObject(); object oNPCtest = GetObjectByTag("p_NPC"); if (GetIsPC(oEnter) && IsAvailableCreature(NPC_JUHANI) && !GetIsObjectValid(oNPCtest) ) { object oPC=GetFirstPC(); string cmMessage = "This part of the script is working"; DelayCommand(1.0, ST_Spawn(NPC_JUHANI, Location(Vector(83.03,137.09,0.00), 0.0))); SendMessageToPC(oPC, cmMessage); } ExecuteScript("k_ptar_02af_en2", OBJECT_SELF); } if (IsAvailableCreature(NPC_JUHANI)) needs to look more like this if (IsAvailableCreature(NPC_JUHANI) == TRUE) Otherwise your if statement gets ignored, actually I'm surprised the script compiles. This is not true, the first variant is a perfectly legal way of checking if the return value is not FALSE. Link to comment Share on other sites More sharing options...
jarec Posted August 25, 2007 Author Share Posted August 25, 2007 Ahhh, brilliant. That delay guess was right on the money it seems like - he spawns in perfectly now. There must be some other script running in there that gets rid of NPCs on its own, as entering, leaving and re-entering has him disappearing from his spawn position and no new one being spawned in its place (so I'd guess the check for the NPC comes back true before this other house-cleaning script activates, somehow? I don't know ...). I wound up removing the check for the NPC completely since this other script seems to wipe the hideout clean every time you enter - it was only there to make sure I didn't spawn in multiple copies of the NPC. Thank you very much for the help. Link to comment Share on other sites More sharing options...
Darkkender Posted August 28, 2007 Share Posted August 28, 2007 This is not true, the first variant is a perfectly legal way of checking if the return value is not FALSE. I've run into compiler errors in the past when using this method on some scripts. Not too mention the fact that it is a bad programming practice. Technically your telling the if Statement to execute the function and if it returns any value TRUE or FALSE to proceed as there is no else statement or condition for the function to fail. So yes the script compiles but really it's a fluff "IF" statement that is doing nothing at all if your not asking it to test for a result. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.