Trigger script to spawn a moving creature not working
Valeriya
Member Posts: 57
Hey guys, I want that when a player steps on a trigger, he sees a creature that moves from point A to point B then disappears. I am unable to get the creature to appear...this is the script on the "OnEnter" handle of a generic trigger

What am I missing?
void main()
{
int nObjectType = OBJECT_TYPE_CREATURE;
string sLatern = "hz_latern";
location StartTarget = GetLocation(GetWaypointByTag("Latern_Enter"));
CreateObject(nObjectType, sLatern, StartTarget);
}
This is the script on the on spawn handle of the creature itself
void main()
{
object oWP = GetObjectByTag("Latern_Exit");
location lDestination = GetLocation(oWP);
ActionMoveToLocation(lDestination,FALSE);
}

What am I missing?
0
Comments
try something like this:
void main()
{
object oTarget;
object oSpawn;
// Get the creature who triggered this event.
object oPC = GetEnteringObject();
// Only fire for (real) PCs.
if ( !GetIsPC(oPC) || GetIsDMPossessed(oPC) )
return;
// Spawn "lantern".
oTarget = GetWaypointByTag("startpoint");
oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "lantern", GetLocation(oTarget));
}
https://neverwintervault.org/project/nwn1/other/tool/ls-tk-script-generator
What's probably going on if it isn't being created is that the identifiers "Latern_Enter" or "hz_latern" aren't correct. Keep in mind the waypoint tag must be unique, and keep in mind that the resource reference is needed for CreateObject, not the tag.
I double checked the tags. Whenever it's a standard creature it works, whenever it's a custom one it doesn't.
Edit: I forgot about Lilac souls script generator, it will come in handy!
Created an invisible Humanoid100% resref "lantern", tag "Lanterntag" and equipped a torch.
placed a spawnpoint tagged "appear" and another tagged "disappear"
Created a generic area trigger with the following onenter:
------------------------------------------------------------------------
void main() { object oTarget; object oSpawn; // Get the creature who triggered this event. object oPC = GetEnteringObject(); // Only fire for (real) PCs. if ( !GetIsPC(oPC) || GetIsDMPossessed(oPC) ) return; // Spawn "lantern". oTarget = GetWaypointByTag("appear"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "lantern", GetLocation(oTarget)); // Have "lantern" perform a sequence of actions. AssignCommand(oSpawn, ActionMoveToObject(GetNearestObjectByTag("disappear"))); }-------------------------------------------------------------------------Then another generic areatrigger on the disappear waypoint with the following script:
-------------------------------------------------------------------------
void main() { // Get the creature who triggered this event. object oLantern = GetEnteringObject(); // Only fire for the Lanten if ( GetTag(oLantern)!="Lanterntag") return; // Destroy an object (not fully effective until this script ends). DestroyObject(oLantern); }-------------------------------------------------------------------------I had a torch appear, walk to the waypoint then disappear.
There are probably more elegant ways of doing this, but I like Lego bricks.
With the following code I can spawn a custom goblin with the resource reference (not the tag) "test_goblin" at the waypoint with the tag "spawn_point" using the onenter event of a trigger. It doesn't need to be complicated but it needs to be 100% accurate using the right string identifiers. Tag and resref are treated as completely different things. Here is the simplest code you could do.
void main() { location lTarget = GetLocation(GetWaypointByTag("spawn_point")); CreateObject(OBJECT_TYPE_CREATURE, "test_goblin", lTarget); }If that simple example doesn't work, with a waypoint that has the tag "spawn_point" and a custom creature with the resref "test_goblin" on an onenter event of a trigger, either the tag of the waypoint or resref of the goblin was incorrect. Otherwise if it was correct and still didn't work you should file a bug. That's fine we're all learning something new all of the time. It's good you're experimenting and trying things out and not getting intimidated by how complex some of the tech/script stuff can be.
Much appreciated! Your help is beyond what I had hoped for.