This seems like a very basic task, but it isn’t working for me yet. I want my script to spawn an item on top of a placeable. Should be easy, right? Set up the location of the item to be spawned and call CreateObject(), right? For example:
const string sPropRR = "my_item_rr";
// This location is right over the placeable
vector vItem = Vector(49.85f, 109.2f, 14.50f);
float fBearing = 181.4f;
object oPlaceable = GetObjectByTag("MyPlaceable");
object oArea = GetArea(oPlaceable);
location lItem = Location(oArea, vItem, fBearing);
CreateObject(OBJECT_TYPE_ITEM, sPropRR, lItem);
The problem I am having is that the spawned item appears inside of the placeable, at a lower z value that specified. The vector used above is where the item would be if it were on top of the placeable and was obtained by putting the item there using the Toolset. FWIW, the item is a helmet and the placeable is one of the CEP altars (zep_altar001).
I have the feeling the item is being created in the right spot but is instantly sinking to the floor. How do I get the item to stay at the desired spawn location?
Can’t promise it will work (it’s supposed to in NWN2, but doesn’t always work there either), but try pressing the s button when you choose the item or placeable to be placed on top of another placeable.
fkirenicus, I am not sure I understand you. I am asking how to get an item that was spawned via a script to stay where it was created over a placeable. I know how to do that in the Toolset. I need to be able to do it from a script.
Good idea. Maybe I will try and move it to a location that is 0.01 higher along the z-axis than the nominal location.
The question becomes: What scripting function moves an item object? To be honest, I usually do this sort of thing by creating a copy of the object at the new location and then destroying the old one. Is there a way to actually move en existing object that doesn’t have an action queue? It doesn’t seem like JumpToLocation() would work…
I don’t think there is a function to move. To get items at specific locations I usually spawn an invisible placeable with inventory at the location, put the item in it and the destroy the placeable. But I usually use that to drop items to the ground and not to put them on placeables, so I don’t know if it will work for your case.
fkirenicus: No worries. I wasn’t clear enough when I described my issue.
meaglyn: I tried spawning a placeable at the right spot, creating my item in it, and then destroying the placeable. But, a “remains” was left at the spot where the placeable was. The good news is that it was at the right spot, on top of the other placeable. The bad news is that the PCs will see a remains instead of the item I want them to see.
Is there a way to destroy a placeable that has an inventory in such a way that the inventory is left, but not a remains? Would there be a way for me to find the remains bag and destroy it? Or would that just create another bag?
Maybe I need to spawn a creature at the location, give the creature the item, then have the creature drop the item, and then destroy the creature? Is that too crazy or is that what I have to do here? And, I still don’t know that 1) I can spawn a creature and he would be at the right spot and 2) whether the item he drops will stay on top of the placeable and not end up inside of it.
I did some testing. It only seems to be possible to spawn an item on top of static geometry.
Furniture built in to a tileset works fine. So does a static placeable, such as a table.
However, items spawned on a dynamic placeable appear on the floor.
There seems to be no control over the exact height at which the item spawns - it appears to be a function of the placeable geometry. If the z value specified is greater than the height of the placeable, the item always spawns at exactly the same height.
If you look carefully, in the cases I tried, the item is floating just above the placeable. A sword on a table doesn’t look too bad, because the player will normally be looking down at the table, but the gap is more noticeable on taller placeables.
Some custom placeables seem to have more than one top. For example, Lisa’s marble table behaves normally if the z specified is above the table, but z just below the table top spawns the item on a plane about half way up the table. That might cast some light on the CEP altar issue mentioned in the OP.
is it possible to lodge a static table inside of the altar (where it can’t be seen because it’s inside the altar). Position the top of the table just barely under the top of the altar, so that the helm will rest on the table but appear to be resting on the altar
@kevL_s An even better solution is to place a static invisible object at exactly the desired height, then spawn the item in game at the location of that object. It seems that any item can be created at any height with that method - thanks for the inspiration!
Incidentally, the floating appearance of the item seems to be a property of the item model geometry. So, for example, when you spawn an item on the ground, it is actually floating, but so close to the ground that you’d never notice.
I will have to take a crack at spawning my item on top of a static placeable which is inside the usable placeable that the item won’t otherwise stay on top of. Thanks for that suggestion.
FP, the thing I am ultimately spawning isn’t a placeable, it’s an item. If I spawn it at a waypoint that isn’t on the ground, then it falls to the ground. (I think. I have gone through many iterations at this point.)
BTW, part of why I am looking to do this is the goal is for the item to be created at a spot where the PCs can see it but they cannot pick it up. Instead, to get it, they interact with the placeable that it’s on and then a script takes care of giving it to them and removing the one they can see.
Thank you! That method of spawning a static placeable (either invisible or hidden inside my usable placeable) and then spawning the item on top of that did the trick. That difference between a static and usable placeable was key.
alas, creating an item atop a static invisible object doesn’t seem to work. i thought this could be a great way to create a magic sword floating in midair, but the sword always ends up on the ground. this also fails w/any object that doesn’t have polygons, such as shafts of light, magic sparks, etc.
even more curious, debug output tells me nwn thinks the sword actually is in midair, at z=4.0 – and insists on it even 1 second after the item is spawned – although it’s clearly lying on the ground.
spawning over a non-invisible static object works fine [you must, however, spawn over the object, not at its location, else the item still appears on the ground]. oh frabjous day, you can spawn a sword on a birdbath…
i was able to get an interesting effect by spawning over a flame ‘hanging’ in midair. i think this worked because the flame placeable has scorch marks, which serve as the ‘solid’ polygons the item rests on.