Skip to content

Jumping to location

4BOLTMAIN4BOLTMAIN Member Posts: 90
edited February 2020 in Builders - Scripting
I have a script that creates a corpse when a player dies and all the players gold is then placed on the corpse. This script is working as intended. I am trying to create a DM tool that allows me to jump to the first corpse found but it is not working. The code is pretty simple but maybe there is something I am missing.

This is the check to make the "Port to nearest corpse" conversation show but it doesn't show the conversation even though there is an object with the tag "deadbody" in an area.
#include "nw_i0_tool"

int StartingConditional()
{
object oPC = GetPCSpeaker();
if (!GetIsObjectValid(GetNearestObjectByTag("deadbody", oPC))) return FALSE;
return TRUE;
}

This is the code to port me to the location of the corpse when I choose the option from the conversation but it doesnt port me anywhere. Obviously if the above code is not picking up the corpse then this port code will never work either.
void main()
{
object oPC = GetPCSpeaker();
object oCorpse = GetNearestObjectByTag("deadbody", oPC);
location lLocation = GetLocation(oCorpse);
ExecuteScript("randomportfx", oPC);
AssignCommand( oPC, ClearAllActions( TRUE));
DelayCommand(1.00, AssignCommand(oPC, JumpToLocation(lLocation)));
}

Comments

  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    edited February 2020
    I just discovered that this only works if I am in the same area as the corpse, how would I make this work for different areas?
  • ProlericProleric Member Posts: 1,316
    GetNearestObjectByTag returns OBJECT_INVALID if there are no such objects in the current area.

    Even if there are objects in other areas, the game has no notion of how "near" one area is to another.

    Your problem is really semantic - what do you mean exactly by "first corpse found"?

    If any corpse will do, GetObjectByTag will work across areas. This is likely to be the oldest one.
  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    Thanks for your help.

    This is not what my toolset says so I was assuming GetNearestObjectByTag() worked across all areas.
    // Retrieves the nearest object in the area with the same tag 
    // as the object calling the function. Of course, if this is an area, 
    // or module, it will return an invalid object. It will also never return itself.
     
    void main()
    {
        string sTag = GetTag(OBJECT_SELF);
        object oNearestObject = GetNearestObjectByTag(sTag);
    }
    


    I used GetObjectByTag and now it works as intended. The first or second corpse doesn't matter because when I loot the gold the object is destroyed. Here is the working code.

    On conversation check to show "Port to Corpse" option.
    #include "nw_i0_tool"
    
    int StartingConditional()
    {
    object oPC = GetPCSpeaker();
    if (!GetIsObjectValid(GetObjectByTag("deadbody"))) return FALSE;
    return TRUE;
    }
    


    Then the actual port.
    void main()
    {
    object oPC = GetPCSpeaker();
    ExecuteScript("randomportfx", oPC);
    AssignCommand( oPC, ClearAllActions( TRUE));
    DelayCommand(1.00, AssignCommand(oPC, JumpToLocation(GetLocation(GetObjectByTag("deadbody")))));
    }
    
Sign In or Register to comment.