ChAiNz.2da Posted March 20, 2005 Share Posted March 20, 2005 OK... I've said it before, and I'll say it again... Me & scripting... we just "ain't" gonna be friends.. : I've read the tutorials over injecting execute scripts (beancounter), as well as various spawning items (RedHawke, tk102, Darth333) and followed the steps to a tee. When I look at my scripts, they look fine (remember, this is me we're talking about..hehe).. they even compiled on the first try (that's a first)... problem is... no workey.... The item doesn't spawn, and even after trying to spawn a placeable container rather than the item itself... still nothing... Can someone please help this poor poor script-tard®?? I'm trying to spawn a datapad in the Underground Base. I figured using the on enter method would be the best method after trying to script it in a dialogue just didn't "fit" as to the purpose of why you find said datapad... Here's my scripts for the curious (comment tags giving credit left out for brevity, will be included in source files): On Enter "inject" script (k_232_enter.ncs) void main() { object oEntering = GetEnteringObject(); object bbpad = GetObjectByTag("ba122_blueprint"); if (GetIsPC(oEntering)) { if (GetIsObjectValid(bbpad) == FALSE) { ExecuteScript("spawn_BAplace", OBJECT_SELF); } } ExecuteScript("k_232_enter2", OBJECT_SELF); } Spawn script (spawn_BAplace.ncs) void main() { float x=0.39f; float y=35.95f; float z=-0.03f; float r=0.0f; vector MyVec=Vector(x,y,z); location MyLoc=Location(MyVec,0.0); CreateObject(OBJECT_TYPE_ITEM, "ba122_blueprint", MyLoc); } I'm using the latest nwnnsscomp, I have the nwscript.nss in my TSL override (extracted with KT)...and when I look over the compiling DOS box, everything checks out as far as execution and paths... I'm using a save game just before entering the Base (area), though I wonder if I need to try an even earlier save. Would the game (TSL) pre-load area enter scripts that early in the area?? God forbid I have to start the planet over just to test this thing Are there necessary "includes" scripts that need to be in the same folder when I'm compiling? If so, which ones... perhaps I have the wrong one(s) in there. Or, should there even be an include in the folder...? I've been trying this thing for 3 days now I tried... really I did... ChAiNz.2da <--- clueless p.s. if this is something as simple as capitalization, lie to me and make something up... otherwise I'm going to feel like the biggest dork in the world... hehehe p.s.s. but hey, if it works, I can handle being a dork... Link to comment Share on other sites More sharing options...
Shadow Blaze Posted March 20, 2005 Share Posted March 20, 2005 YIKES!!! Scripts!! I wish I could help you for once ChAiNz but well considering the problems I continue to have with lightsaber models I won't be getting to scripting any time soon. I hope eventually you get it. I am going to go and hide from anything to do with scripts for a while. Link to comment Share on other sites More sharing options...
ChAiNz.2da Posted March 20, 2005 Author Share Posted March 20, 2005 Originally posted by Shadow Blaze I am going to go and hide from anything to do with scripts for a while. Clue me in if you find a good spot hehehe It's no secret I absolutely cannot get scripts to play fair. It's holding a grudge since the KotOR days I imagine.... And of course TSL has to go and skimp on code so I'd be forced to deal with scripting (again, I think it's a plot summed up by tk102 & Darth333) Link to comment Share on other sites More sharing options...
Xcom Posted March 20, 2005 Share Posted March 20, 2005 Not sure if you can spawn OBJECT_TYPE_ITEM using CreateObject. I think you need placeable for this (OBJECT_TYPE_PLACEABLE) and obviously UTP, but since you said placeable doesn't work either... hmm. Anyway, try using only one script. You don't really need two scripts here. Also place a few debug lines like this in between those IFs: SendMessageToPC(GetFirstPC(), "Check.. 1"); to see if script is running at all. Link to comment Share on other sites More sharing options...
ChAiNz.2da Posted March 20, 2005 Author Share Posted March 20, 2005 Originally posted by Xcom Not sure if you can spawn OBJECT_TYPE_ITEM using CreateObject. I think you need placeable for this (OBJECT_TYPE_PLACEABLE) and obviously UTP, but since you said placeable doesn't work either... hmm. hmm... well there is a placeable (utp) datapad "plc_datapad", I could perhaps use that along with OBJECT_TYPE_PLACEABLE, but I need to make sure the PC is able to get a physical datapad in his/her inventory. It's going to be a required "component" later on.... Would placing the datapad (uti) in the datapad placeable's inventory work... or is that yet another script-calling function? My last attempt at spawning a placeable was a container (which didn't even spawn)... Thanks for the quick response Xcom I've been hurting my simple mind trying to deal with this hehehe... Link to comment Share on other sites More sharing options...
tk102 Posted March 20, 2005 Share Posted March 20, 2005 Xcom wisely advised: Anyway, try using only one script. You don't really need two scripts here. Also place a few debug lines like this in between those IFs This advice is critical for everybody learning to script. When a script doesn't seem to be working, this debugging in this manner is the only way to track down the problem. If it was me, I'd simplify the entering script to: void main() { if (!(GetIsObjectValid( GetObjectByTag("ba122_blueprint")))) { ExecuteScript("spawn_BAplace", OBJECT_SELF); } ExecuteScript("k_232_enter2", OBJECT_SELF); } Link to comment Share on other sites More sharing options...
stoffe Posted March 20, 2005 Share Posted March 20, 2005 Originally posted by ChAiNz.2da hmm... well there is a placeable (utp) datapad "plc_datapad", I could perhaps use that along with OBJECT_TYPE_PLACEABLE, but I need to make sure the PC is able to get a physical datapad in his/her inventory. It's going to be a required "component" later on.... Would placing the datapad (uti) in the datapad placeable's inventory work... or is that yet another script-calling function? My last attempt at spawning a placeable was a container (which didn't even spawn)... Thanks for the quick response Xcom I've been hurting my simple mind trying to deal with this hehehe... If I understand what you are trying to do correctly, I believe this should work: // ST: k_232_enter.nss (k_232_enter.ncs in TEL232_s.rim) void main() { object oEnter = GetEnteringObject(); if (oEnter == GetFirstPC()) { // ST: Remove the shuttle if it has left for the Polar Regions. if (GetGlobalBoolean("232_SHUTTLE_GONE")) PlayRoomAnimation("232Tel14", ANIMATION_ROOM_SCRIPTLOOP02); else PlayRoomAnimation("232Tel14", ANIMATION_ROOM_SCRIPTLOOP01); // ST: Change look of reactor if it's been activated if (GetGlobalNumber("232TEL_Reactor") == 0) PlayRoomAnimation("232tel01", ANIMATION_ROOM_SCRIPTLOOP01); else if (GetGlobalNumber("232TEL_Reactor") == 1) PlayRoomAnimation("232tel01", ANIMATION_ROOM_SCRIPTLOOP02); // ST: Set Player as party leader when first entering. if (!GetGlobalBoolean("232_FIRST_ENTER")) { SetGlobalBoolean("232_FIRST_ENTER", TRUE); SetPartyLeader(NPC_PLAYER); // ST: Added spawn of datapad location lLoc = Location(Vector(0.39, 35.95, 0.03), 0.0); object oPPad = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_datapad", lLoc); if (GetIsObjectValid(oPPad)) { CreateItemOnObject("ba122_blueprint", oPPad, 1, TRUE); } } } } If it still doesn't work, verify that the coordinates you specify are valid. Note that placeables don't snap to the floor automatically so you could spawn them below the floor or inside a wall if you are not careful. (EDIT: This assumed that "plc_datapad" is a container placeable.) Link to comment Share on other sites More sharing options...
Lorden Darkblade Posted March 20, 2005 Share Posted March 20, 2005 How do I put those debug lines? Cuz I'm trying to make Force Enlightenment to activate 5 force powers instead of 3 and the compiling goes well and I put all the necessary files in the same folder to compile. But in game nothing happens. The Power doesnt change, it's still the same only activating 3 force powers. Link to comment Share on other sites More sharing options...
ChAiNz.2da Posted March 20, 2005 Author Share Posted March 20, 2005 eeny meeny miney moe... Thanks everyone! So many choices I can miserably fail at... woohoo! Not by any fault of you guys, I'm sure I'll find some way to goof this up in the process all by myself hehehe I'll give each and every one of those a try, and add the dubugging lines this time. I'll also doublecheck the coordinates... but when I used the wherami, I was pretty much in an open area... so no walls. My luck it's in the floor somewhere (where'd I put the shovel?) Link to comment Share on other sites More sharing options...
Xcom Posted March 20, 2005 Share Posted March 20, 2005 Chainz, you might run into some problems with plc_datapad.utp. If I am not mistaken, it's not (configured to be) a container. Actually, I'm not sure if it's datapad at all, but ehh.....Good luck. Originally posted by Uchiha Itachi How do I put those debug lines? Well, you put them inside your script code to trace the "flow" of your script. Tracing a problem in the script can be ten times harder than fixing it. To demonstrate, using Chainz's script above, the possible "debug code" can look like this (in yellow): void main() { object oEntering = GetEnteringObject(); object bbpad = GetObjectByTag("some_placeable_TAG"); if (GetIsPC(oEntering)) { [color=yellow]SendMessageToPC(oEntering, "Player has entered..");[/color] if (!GetIsObjectValid(bbpad)) { [color=yellow]SendMessageToPC(oEntering, "Attempting to spawn...");[/color] object oTest = CreateObject(OBJECT_TYPE_PLACEABLE, "some_placeable", Location(Vector(0.39,35.95,-0.03),0.0)); [color=yellow] if (GetIsObjectValid(oTest)) { SendMessageToPC(oEntering, "Placeable is successfully spawned."); } [/color] } [color=yellow]else { SendMessageToPC(oEntering, "Placeable already exists"); }[/color] } ExecuteScript("k_232_enter2", OBJECT_SELF); } This is perhaps too much for a small script like this but you should get the idea. BTW, these message will be shown in Journal->Message Log->Feedback Link to comment Share on other sites More sharing options...
ChAiNz.2da Posted March 20, 2005 Author Share Posted March 20, 2005 Originally posted by Xcom Chainz, you might run into some problems with plc_datapad.utp. If I am not mistaken, it's not (configured to be) a container. Actually, I'm not sure if it's datapad at all, but ehh.....Good luck. Thanks for the wishes of luck... I'm quite sure I'll need it hehehe... Yeah, the datapad placeable, after reading it's tag, is a cutscene placeable. KT wouldn't even let me do anything with it other than save it to my drive. After looking at the script examples, I think I can slowly weasel out a working one it's just going to take a little time...(and alcohol)... I'm almost willing to bet it's the coordinates. I keep changing the z value (up & down) considering it's always giving me a 6.87553 entry (based on PC height??)... but I'll be doing the debugging as well just to see what's going on in the background (if anything)... I appreciate all the help everyone! I'm sure you'll here from me again Link to comment Share on other sites More sharing options...
Keiko Posted March 20, 2005 Share Posted March 20, 2005 Sorry to "Hi-Jack" your thread Chainz, but it seems no one likes me here, or i am just plain stupid, (I have made countless threads, and posts) But here I go anyway , "How in the heck to I spwan an NPC"? Thanks, Chainz! Link to comment Share on other sites More sharing options...
Darth333 Posted March 20, 2005 Share Posted March 20, 2005 Originally posted by ChAiNz.2da I'm almost willing to bet it's the coordinates. I keep changing the z value (up & down) considering it's always giving me a 6.87553 entry (based on PC height??)... but I'll be doing the debugging as well just to see what's going on in the background (if anything)... B] If the placeable does not appear, then there is something wrong probably with he placeable itself as everything seems fine. Send me the files if you want, I,ll look at them DarthSmallz: read the tutorials. If you are doing a receruit mod, check the recruit tutorial: everything is threre. Link to comment Share on other sites More sharing options...
Darkkender Posted March 20, 2005 Share Posted March 20, 2005 Ok Chainz I'll throw my 2 cents in here as well. First Tk's script will handle your on enter script. Next for creating the datapad on the floor you will want to use the placeable datapad via your original create object script however as covered make it the OBJECT_TYPE_PLACEABLE. Lastly you will need one more script that creates object in inventory there you will use the OBJECT_TYPE_ITEM. this will fire when you pick up the datapad. it then will destroy the placeable. Link to comment Share on other sites More sharing options...
Darth333 Posted March 20, 2005 Share Posted March 20, 2005 Originally posted by Darkkender Ok Chainz I'll throw my 2 cents in here as well. First Tk's script will handle your on enter script. Next for creating the datapad on the floor you will want to use the placeable datapad via your original create object script however as covered make it the OBJECT_TYPE_PLACEABLE. Lastly you will need one more script that creates object in inventory there you will use the OBJECT_TYPE_ITEM. this will fire when you pick up the datapad. it then will destroy the placeable. That won't work. If the item is not a placeable, you can't use OBJECT_TYPE_PLACEABLE. ...and he says that wehn he uses a placeable it doen't spawn either. Link to comment Share on other sites More sharing options...
Darkkender Posted March 20, 2005 Share Posted March 20, 2005 Originally posted by Darth333 That won't work. If the item is not a placeable, you can't use OBJECT_TYPE_PLACEABLE. ...and he says that wehn he uses a placeable it doen't spawn either. I'm sorry I was unclear I was tryin to expand upon what was already being said. What I was refering to first creating the placeable datapad using the the "plc_datapad.utp" file as a base for "ba122_bleprint". [size=1]void main() { float x=0.39f; float y=35.95f; float z=-0.03f; float r=0.0f; vector MyVec=Vector(x,y,z); location MyLoc=Location(MyVec,0.0); CreateObject(OBJECT_TYPE_PLACEABLE, "ba122_blueprint", MyLoc); }[/size] If he then uses TK's onenter script entry [size=1]void main() { if (!(GetIsObjectValid( GetObjectByTag("ba122_blueprint")))) { ExecuteScript("spawn_BAplace", OBJECT_SELF); } ExecuteScript("k_232_enter2", OBJECT_SELF); }[/size] Then when he clicks on the datapad on the floor if he sets the "OnDisturbed" or "OnUserActivated" function for the placeable(I can't recall what the name of the function I mean is offhand.) it fires the final script. This final script would do 2 things first it will use the "CreateObjectInInventory" script command which will use the "OBJECT_TYPE_ITEM" and the name of the item uti file to put the datapad in the inventory. After it has created the uti in inventory it will use a "DestroyObject" command with the "GetObject" calling the placeable and destroying it. I apologize I'm at work so I can't write a sample of what I mean. Nor can I refer back to the userdefined events field within the placeable to give the correct one. However All of this is assuming he can get the initial "OnEnter" script to work. Chainz you may want to start simple and remove the "if" statement in the "OnEnter" script for testing purposes. Then move into trying it with the "if" statement. I know this can be tedious but it can also be the most accurate way of error checking is to test from a point that you know works. [size=1]void main() { ExecuteScript("spawn_BAplace", OBJECT_SELF); ExecuteScript("k_232_enter2", OBJECT_SELF); }[/size] Also make sure the game is firing the "OnEnter" script for the first time. This is another way of testing untill you break it. Link to comment Share on other sites More sharing options...
Xcom Posted March 20, 2005 Share Posted March 20, 2005 Originally posted by Darkkender I apologize I'm at work so I can't write a sample of what I mean. Nor can I refer back to the userdefined events field within the placeable to give the correct one. I can though. In fact, this method is more "realistic" in a way. I mean if you use inventory and click on datapad it will open its inventory with .. the same datapad.. which is somewhat weird. Anways, you can use plc_datapad.utp for this, only it needs some GFFEdit tweaking. HasInventory = 0 PartyInteract = 1 Useable = 1 TrapDetectable = 1 and finally, onUsed = datapad_use_script datapad_use_script may look as follows: void main() { object oPC = GetFirstPC(); //give PC the datapad item object oDP = CreateItemOnObject("ba122_blueprint",oPC,1,TRUE); // showing Datapad popup if (GetIsObjectValid(oDP)) DisplayDatapad(oDP); //destroying placeable DelayCommand(0.5,DestroyObject(OBJECT_SELF)); } This of course will require different conditional check in the OnEnter script, so this doesn't happen every time when you enter the area. Maybe using GetItemPossessedBy to check if player carries the datapad. Link to comment Share on other sites More sharing options...
stoffe Posted March 20, 2005 Share Posted March 20, 2005 Originally posted by Xcom (snip) Anways, you can use plc_datapad.utp for this, only it needs some GFFEdit tweaking. HasInventory = 0 PartyInteract = 1 Useable = 1 TrapDetectable = 1 and finally, onUsed = datapad_use_script (snip) This of course will require different conditional check in the OnEnter script, so this doesn't happen every time when you enter the area. Maybe using GetItemPossessedBy to check if player carries the datapad. Or you could do like I did in my example and place the code spawning the datapad inside the script condition that only triggers the first time the player enters the area. Less extra checks to keep track of that way, and one less infinite source of datapads to break down at a workbench (if anyone would be crazy enough to do that). It's worth remembering that the OnEnter script triggers every time any creature enters the area (through an area transition, through being spawned or when loaded from a savegame), not just the player or party members. In either case I'd recommend making a copy of the placeable template and give it a unique tag and resref and use that instead, rather than modify the base "plc_datapad" template in the game. Messing with base templates is generally a bad idea that invites trouble. Link to comment Share on other sites More sharing options...
ChAiNz.2da Posted March 20, 2005 Author Share Posted March 20, 2005 Thanks for the input everyone! I FINALLY got it working! And of course, I'm a retard I had a number of things wrong, which is why it wasn't working... here's a re-cap: NEVER doubt Darth333's wherami coordinates. I used the 6.87 x coord.. after discovering that it was the proper value for the whole area. When I went outside and tried it... of course there was a diff. value My .utp (again Darth333 was right) didn't have the "usable" box checked. While I was in the .utp, I went ahead and checked "has inventory" and added my datapad in there changed the scripts so it would only spawn the unique placeable (which now has the inventory already in it)... went ahead and used the OBJECT_TYPE_PLACEABLE values since it was what I had originally intended Drank an "Abita Turbodog", kissed my fat-ass cat and did the Dance of Joy... hehehe Here's the final scripts that worked: On Enter // Script template provided by beancounter // checks for and spawns BA-122 blueprints void main() { object oEntering = GetEnteringObject(); object oCase = GetObjectByTag("ba_case"); if (GetIsPC(oEntering)) { if (GetIsObjectValid(oCase) == FALSE) { ExecuteScript("spawn_BAplace", OBJECT_SELF); } } ExecuteScript("k_232_enter2", OBJECT_SELF); } Spawn // Spawns BA-122 Saber Blueprints // thanks to tk102, RedHawke, Darth333, Xcom, stoffe -mkb-, Darkkender void main() { float x=-4.24f; float y=24.24f; float z=6.87f; float r=0.0f; vector MyVec=Vector(x,y,z); location MyLoc=Location(MyVec,0.0); CreateObject(OBJECT_TYPE_PLACEABLE, "ba_case", MyLoc); } Now onto yet another script function. I'm sure I'll be back for that one too Thank You Everyone! Link to comment Share on other sites More sharing options...
Xcom Posted March 20, 2005 Share Posted March 20, 2005 Chainz, glad you got it working. But since now you can devote some attention to perfectionism, using Stoffe's decompiled script is much better idea. You can simply replace original OnEnter script without having to "inject" ExecuteScript commands. Your mod's compatibilty rating will increase dramatically. Originally posted by stoffe -mkb- that only triggers the first time the player enters the area. Yes, but if you have been in Telos, went to Nar-Shadaa, installed the mod, went back to Telos, you won't get the pad. I was thinking more about making it happen once but not necessarily when you first enter the area. Of course, it depends on the mod's specifics. Originally posted by stoffe -mkb- In either case I'd recommend making a copy of the placeable template and give it a unique tag and resref and use that instead, rather than modify the base "plc_datapad" template in the game. Messing with base templates is generally a bad idea that invites trouble. You're absolutely right. I didn't mention it thinking it's obvious for most people. Link to comment Share on other sites More sharing options...
stoffe Posted March 20, 2005 Share Posted March 20, 2005 Originally posted by Xcom Chainz, glad you got it working. But since now you can devote some attention to perfectionism... (snip) If we're entering the realm of perfectionism I might as well mention a couple of things. Unless your datapad placeable sticks around even after the player has picked up the datapad inside, it will spawn a new datapad if the player re-enters the area or loads a savegame, if you only check if the placeable exists before spawning a new one. Also, in the realm of extreme nitpicking, note that the code... void main() { float x=-4.24f; float y=24.24f; float z=6.87f; float r=0.0f; vector MyVec=Vector(x,y,z); location MyLoc=Location(MyVec,0.0); CreateObject(OBJECT_TYPE_PLACEABLE, "ba_case", MyLoc); } ... produces a compiled script that is twice as big as the code... void main() { location MyLoc = Location(Vector(-4.24f,24.24f,6.87f), 0.0); CreateObject(OBJECT_TYPE_PLACEABLE, "ba_case", MyLoc); } ...does, even though they do exactly the same thing. For efficiency it's usually a good idea to only declare new local variables when the data they hold is supposed to be used in more than one place, or to break up code that would be heavily nestled otherwise. Not that it really matters in such a short script that's only supposed to run once, though. Originally posted by Xcom Yes, but if you have been in Telos, went to Nar-Shadaa, installed the mod, went back to Telos, you won't get the pad. I was thinking more about making it happen once but not necessarily when you first enter the area. Of course, it depends on the mod's specifics. You've got a point, but unless the mod allows you to revisit Telos you can only go there once. After you take the shuttle in the base there's normally no coming back. Link to comment Share on other sites More sharing options...
Xcom Posted March 20, 2005 Share Posted March 20, 2005 ^^^^ Perhaps we need to classify perfectionism in levels. Perfectionism Type I (xcom) .. .. Perfectionism Type V (stoffe) BTW.. datapad plc gets destroyed if you use OnUsed script. Link to comment Share on other sites More sharing options...
ChAiNz.2da Posted March 20, 2005 Author Share Posted March 20, 2005 The only reason I used the script I'm currently using... hehehe is that once you leave Telos' surface.. you can't return can you?? Isn't it a one shot deal once you take the shuttle to get back to the Citadel Station? Link to comment Share on other sites More sharing options...
stoffe Posted March 20, 2005 Share Posted March 20, 2005 Originally posted by ChAiNz.2da The only reason I used the script I'm currently using... hehehe is that once you leave Telos' surface.. you can't return can you?? Isn't it a one shot deal once you take the shuttle to get back to the Citadel Station? In the standard game you can't return to Telos once you've taken the shuttle. But while you are in the base you can go back outside and then go inside again. And you can save/reload while in the base. Both instances will make the OnEnter event script fire again. And spawn a new datapad if the previous one has already been picked up. Link to comment Share on other sites More sharing options...
ChAiNz.2da Posted March 20, 2005 Author Share Posted March 20, 2005 Originally posted by stoffe -mkb- Unless your datapad placeable sticks around even after the player has picked up the datapad inside, it will spawn a new datapad if the player re-enters the area or loads a savegame, if you only check if the placeable exists before spawning a new one. OK, I just noticed this after re-reading all the kewl little snippets everyone has posted My placeable does in fact stay after the datapad is retrieved. It's a metal case (groundbag appearance) .utp that has the datapad in it's inventory. Should I still look into getting rid of it, such as a "Destroy Object" inserted? Or an "inventory check" so that it won't respawn if the PC already has one in their possession? and of course, how to do that... hehehe Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.