Skip to content

Trigger script to spawn a moving creature not working

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
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?



Comments

  • vonstormvonstorm Member Posts: 66
    Creating object isn't an int its an object -

    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));
    }


  • vonstormvonstorm Member Posts: 66
    Lilac souls script generator is a great tool for checking scripts in the beginning.
    https://neverwintervault.org/project/nwn1/other/tool/ls-tk-script-generator
  • FreshLemonBunFreshLemonBun Member Posts: 909
    It's not a type problem, the argument OBJECT_TYPE_CREATURE is an int constant so it's the same thing. You also don't need to assign the output of CreatObject because you're not using it again in the script.

    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.
  • vonstormvonstorm Member Posts: 66
    my bad.Still new/rusty.
  • ValeriyaValeriya Member Posts: 55
    edited January 2019
    Great! But the script only works on "standard creatures" not on my custom ones. Any way to make it work on on custom creatures?
    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!
  • vonstormvonstorm Member Posts: 66
    I just created the effect I think you are looking for using the following:
    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. :)

  • FreshLemonBunFreshLemonBun Member Posts: 909
    Valeriya said:

    Great! But the script only works on "standard creatures" not on my custom ones. Any way to make it work on on custom creatures?
    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!

    I have tested with custom creatures and it works fine for me at least. You must make sure that you are using the resource reference of the creature, not the tag, in the createobject function. If you use the tag and the resref is something else it wont work. If you're using "edit copy" it will usually change the resref to something unique, so check to see what it is in the "Advanced" tab of the creature window, it will be at the top and say Blueprint ResRef. To view the actual resref of a standard palette resource you can also use the menu in the top left of the toolset that says view, then "view preview window" and it will display a small window with the tag and resource reference. You need the resource reference to create the object.

    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.
    vonstorm said:

    my bad.Still new/rusty.

    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.
  • ValeriyaValeriya Member Posts: 55
    You're right, I used the tag not the resref *smacks forehead*, that was my mistake
    Much appreciated! Your help is beyond what I had hoped for.
Sign In or Register to comment.