Skip to content

Any Ideas on this transition?

I have a get location script that marks the position of PC (on rest atm).
  object oPC = oPlayer;
  object oArea = GetArea(oPC);
  string sArea = GetTag(oArea);
 string sId = GetTag(oPC);

 vector v = GetPosition(oPC);
 float x = v.x;
 float y = v.y;
 float z = v.z;
 float o = GetFacing(oPC);

 SetCampaignFloat("LDB","LOC_X_"+sId,x);
 SetCampaignFloat("LDB","LOC_Y_"+sId,y);
 SetCampaignFloat("LDB","LOC_Z_"+sId,z);
 SetCampaignFloat("LDB","LOC_O_"+sId,o);
 SetCampaignString("LDB","LOC_A_"+sId,GetTag(oArea));
 //SetCampaignInt("DB","HP_"+sId,GetMaxHitPoints(oPC)-GetCurrentHitPoints(oPC));
  //debug
SendMessageToPC(oPC,sArea);

It works on all except one area (my main town), and I can't figure out why. The Script fires and debug gives me the correct tag of the area (see debug). However, the port script below fails only on this one area. Ive checked tag duplication etc. The reason Id like this to work is because I want to put it on onclientleave.

port script
 float fX = GetCampaignFloat("LDB","LOC_X_"+sId);
 float fY = GetCampaignFloat("LDB","LOC_Y_"+sId);
 float fZ = GetCampaignFloat("LDB","LOC_Z_"+sId);
 float fOrientation = GetCampaignFloat("LDB","LOC_O_"+sId);
 string sArea = GetCampaignString("LDB","LOC_A_"+sId);
 object oArea = GetObjectByTag(sArea);
 vector vPosition = Vector(fX, fY, fZ);
 location lLocation = Location(oArea, vPosition, fOrientation);
    // Verify that the location is valid before attempting to teleport.
    // (The script will stop here if no location was previously stored.)
    if ( GetAreaFromLocation(lLocation ) == OBJECT_INVALID )
        {
        SendMessageToPC(oPC,"invalid location");
        return;
        }




    // Teleport the PC.
    eVFX = EffectVisualEffect(VFX_IMP_UNSUMMON);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oPC);
    DelayCommand(3.0, AssignCommand(oPC, ClearAndJumpToLocation(lLocation)));



This works in every other area Ive tried so far except the one area. I do not get the invalid location line in port script. Any Ideas what could cause this?

Comments

  • NeverwinterWightsNeverwinterWights Member Posts: 339
    edited March 2021
    What is the 2nd script firing from? If it works everywhere else except one area it might have something to do with how/where the script is firing from. Could be something as simple as an item placed on the ground for testing that doesn't have the updated tag of the blueprint item. <---I'm guilty of this one.

    Also just for information purposes you can store and retrieve persistent locations using 2 campaign variables rather than five. Something like so:

    Store:
    void main()
    {
        object oPC = GetLastUsedBy();//Or whatever
        SetCampaignLocation("LDB", "PERSISTENT_LOC", GetLocation(oPC));
        SetCampaignString("LDB", "PERSISTENT_AREA", GetTag(GetArea(oPC)));
    }
    

    Retrieve, create new location and check for validity or what not:
    void main()
    {
        object oPC = GetLastUsedBy();//Or whatever
        location lSaved = GetCampaignLocation("LDB", "PERSISTENT_LOC");
        string sSaved = GetCampaignString("LDB", "PERSISTENT_AREA");
    
        object oArea = GetObjectByTag(sSaved);
        if (GetIsObjectValid(oArea))
        {
            vector vPosition = GetPositionFromLocation(lSaved);
            float fFace = GetFacingFromLocation(lSaved);
            location lLoc = Location(oArea, vPosition, fFace);
        }
        else
        {
            //Send message, etc
        }
    }
    
  • vonstormvonstorm Member Posts: 66
    2nd script is firing from onenter of a polygon trigger in the start lobby.
    I used to use the GetLocation with intermittent results, and someone advised it was broken. If it's reliable that's good to know. Also I know that grabbing location on client exit used to be hit or miss because the PC object was sometimes no longer in an area when it ran, is this still true to anyones knowledge?

    Thanks again for any insights.
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    Hmm. I haven't heard about "GetLocation" specifically being broken. Something I'll have to look into more. I do know that in NWN:EE it has been fixed to where you can now reliably grab more information before the client object is removed. As per NWN Lexicon:
    The bugs related to this script firing are fixed; OnClientLeave event is now called before the creature is physically removed from the area, instead of after, to allow scripting to determine the creature’s position as it leaves. However, OnClientLeave event is still after the automatic server call to save the Character file. Therefore if you add items or save local variables during this event be sure to call ExportSingleCharacter explicitly before the event end.

    You are correct that GetLocation was one of those things you used to not be able to do OnClientLeave. It could be that it still has issues that I am unaware of though.

    As far as your script still not working for one area I'm still not sure. One of those things you'd have to be able to see all the scripts, the trigger, tags, etc.

    Could add a few more debug lines and see if it helps to track anything down. You did say you aren't seeing the "invalid location" message which would indicate that you still have a valid AREA at least but maybe the rest of the location is broken or missing. Not sure.
        SendMessageToPC(oPC, "Area: " + sArea);
        SendMessageToPC(oPC, "Area Object: " + ObjectToString(oArea));
        SendMessageToPC(oPC, "fX: " + FloatToString(fX, 0, 2));
        SendMessageToPC(oPC, "fY: " + FloatToString(fY, 0, 2));
        SendMessageToPC(oPC, "fZ: " + FloatToString(fZ, 0, 2));
        SendMessageToPC(oPC, "Orientation: " + FloatToString(fOrientation, 0, 2));
    
  • vonstormvonstorm Member Posts: 66
    So I kludged the issue by adding an if statement for the one offending area and using a getwaypoint to spawn the PC in the middle of town. ClientExit does work so that's an awesome improvement from last time I messed with this :) . I checked the float values and it seems that I'm getting them for the area in question. I think there just maybe something fundamentally wrong with the Area, and when I get time will re-design it and see how it goes. Appreciate the information and time.
  • vonstormvonstorm Member Posts: 66
    I think I figured it out... I found an NPC with the same tag as the area. I guess an object is an object is an object, and it doesn't differentiate between object types.
  • ZephiriusZephirius Member Posts: 419
    Glad to see everything is working out! ;)
    Alas, I would offer you scripting advice, but I fear you would end up helping me to help you. :#
    Still learning NW script...
  • vonstormvonstorm Member Posts: 66
    Aye, I'm always learning and shaking off the rust :)
  • ForSeriousForSerious Member Posts: 466
    Sorry guys, that was me who said Set/GetCampaignLocation was broken. Really it was a super outdated script I am using that was broken. Glad you got it working!
  • vonstormvonstorm Member Posts: 66
    Not a problem. I always had problems with location storing, I believe your post helped me get my head around it.
Sign In or Register to comment.