I made a system last night, spent hours on it in fact, and I thought I had come up with something good. When I tested it today nothing worked (of course). NWN2 is so weird sometimes.
I wanted to do an illusion of you as a player moving crates. I have a conversation with a placeable (the crate) where I try to move it. To achieve this illusion I first run ga_destroy at the end node of the conversation and then right after my own script that looks like this:
void Spawn(string sCratesWP)
object oCrates = SpawnPlaceableAtWP("wh_cratesm", sCratesWP);
void main(string sCratesWP)
The placeable is destroyed but the same placeable isn’t spawned again at a different waypoint. At first I thought it had to do with the destroying and spawning being so close to each other, that’s why I made a delay in my script. Maybe that delay isn’t enough? I tried with 4.0 and 5.0 but still nothing happens. Maybe it’s because it’s at the end of a conversation…In that case all my hours making this will have been for nothing…ugh, I’m asking here if anyone maybe understands, knows, what’s going on, and why it doesn’t work. Thanks. (It’s really frustrating to always be stopped dead in developing a module, when the toolset won’t do what I want it to do, and there’s always a million tests to be made before anything works…Ok, sorry, but I’ve had quite a bad day at work today, and when coming home and wanting to test something that should work then…it sucks the energy out of you).
After thinking a bit further when taking a break from this, I thought “Ok, maybe you can’t destroy the same object and spawn it right after” so I made a copy of the blueprint of the placeable and gave it a new tag, resource name and template resref, but the problem still persists. Really weird. Now, I have really no clue what’s going on. There must be something wrong with my script…
Well, what do you know…Since I didn’t trust myself anymore, I did a new script with the Lilac Soul Script Generator and even without a delay that seemed to solve it for some reason. Here’s the new script:
void main(string sWP)
oTarget = GetWaypointByTag(sWP);
lTarget = GetLocation(oTarget);
oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "wh_cratesm", lTarget);
And this is quite odd, since I’ve used the first kind of script many times before, and it has always worked but not now for some strange reason.
I think it was “cant run script because OBJECT_SELF got destroyed” – that is, not using a delay is what allows the spawn to work.
anyway, i was curious so this seems to work also (combines destroy and create in one script)
Destroys OBJECT_SELF and creates a placeable at a waypoint.
const float fDELAY = 0.25f;
void CreateObjectVoid(string sResref, object oWaypoint, string sTag2);
// sResref - resref of placeable to create
// sWaypoint - tag of waypoint to create 'sResref' at
// sTag2 - tag of created object (use the blueprint's tag if blank)
// fDelay - delay between destruction and creation
void main(string sResref, string sWaypoint, string sTag2, float fDelay)
object oWaypoint = GetNearestObjectByTag(sWaypoint);
DelayCommand(fDELAY + fDelay,
CreateObjectVoid(sResref, oWaypoint, sTag2)));
void CreateObjectVoid(string sResref, object oWaypoint, string sTag2)
note CreateObject() is assigned to the module
Precisely. After further testing I noticed that was the problem all along. As much as I’d like to use your script it will be easier for me to do it as I’ve done it, since the work is already done. If I were to put your script in my “system” it would require more work than what I need to do now. I got it working with a delay when using CreateIPSpeaker instead on the placeable’s OnUsed, instead of gp_talk_object. And I now use one of the companions as the conversation owner, and thus the destroying and spawning problems went away, even with a delay.
Yes, beware of trying to execute stuff from something you are destroying. If you destroy the object doing the functions prior the function running, nothing will happen.
Here is a great tip for you … Use the SetScale on the object you want to destroy with 0.001 in every parameter, and delay it’s destruction until all function calls from it are done.
It gives an excellent illusion of immediate destruction, but allows you to still work with it until you are done. I use that trick in many situations to great effect.
Hehe. That sounds like a neat trick, actually. I’ll keep that in mind.