Set/Get PC location to an item in their inventory
Quilistan
Member Posts: 186
I have an item that through a conversation a PC can use to Set Location
Then through a second choice in the conversation Jump to that location.
currently it stores the location on the PC. I need to know how to set it on the object itself, I am hoping that will make it stick over server resets? I am having trouble figuring this out, please help.
Then through a second choice in the conversation Jump to that location.
currently it stores the location on the PC. I need to know how to set it on the object itself, I am hoping that will make it stick over server resets? I am having trouble figuring this out, please help.
0
Comments
object oItem = GetItemPossessedBy(oPC, "Tag of item here"); SetLocalLocation(oItem, "blah blah", lLocation);
And as long as the character is saved at some point after this then the location will stick to the item.
resting after setting the location saves it persistent. Which is perfect for what I need.
thank you
...until you add/remove some areas to your module. Then the area IDs will be shifted, and your location will be broken. And it will be broken in such a way that it would refer to a different area.
It'd be much safer to store the location as separate variables, such as {string sAreaTag, vector vPosition}, then find the area object with GetObjectByTag(). If you have multiple areas with the same tag, then use area resref instead/aswell.
//////////////////////////////////////////////////////////////////////////////// void SavePersistentLocation(object oPC) { object oDBItem = GetItemPossessedBy(oPC, "PLAYER_HANDBOOK"); if (!GetIsObjectValid(oDBItem)) { CreateItemOnObject("playerhandbook", oPC); } SetLocalLocation(oDBItem, "PERSISTENT_LOC", GetLocation(oPC)); SetLocalString(oDBItem, "PERSISTENT_AREA", GetTag(GetArea(oPC))); } //////////////////////////////////////////////////////////////////////////////// void ReturnToPersistentLocation(object oPC) { object oDBItem = GetItemPossessedBy(oPC, "PLAYER_HANDBOOK"); if (GetIsObjectValid(oDBItem)) { string sArea = GetLocalString(oDBItem, "PERSISTENT_AREA"); location lStoredLoc = GetLocalLocation(oDBItem, "PERSISTENT_LOC"); if (sArea != "") { object oArea = GetAreaFromLocation(lStoredLoc); if (oArea != OBJECT_INVALID) AssignCommand(oPC, ActionJumpToLocation(lStoredLoc)); else SendMessageToPC(oPC, "The area you are trying to teleport to is not valid."); } else { SendMessageToPC(oPC, "You do not have a saved location."); } } else { SendMessageToPC(oPC, "You do not have a valid database item."); } } ////////////////////////////////////////////////////////////////////////////////
Also since we now have the GetSurfaceMaterial function to check the surface at a location which returns 0 if the location is invalid or has no surface, I'm playing around with the idea of changing how to check for valid locations with persistent locations.
Also the code above isn't really using the saved area tag. You could use that tag to find the right area and do the jump still. What's there won't handle the case Sherincall mentioned of changed area IDs. It only handles removed areas.
When you want to "save" the location: Check if your tracker object already exists -> if so, delete it. Create a new tracker object at the current location.
When you want to jump to the "saved" location: Check if your tracker object exists -> if so, jump to it. If not (e.g. because the area has been removed), display a corresponding message.
This way the system handles the Area and Location for you.