Need some help with the following script. It’s part of a few other scripts that clean up my areas. I just want to make sure that it won’t clean out players inventory.
Is there any other check to be sure it leaves player’s alone?
Also, on the same subject, when a client leaves the server. I have my cleanup checking what area the player was in when they leave and running the clean up on that area.
Module’s OnClientLeave
void main()
{
object oPC = GetExitingObject();
if (GetArea(oPC) == GetObjectByTag("area001"))
{
ExecuteScript("d_exit001", OBJECT_SELF);
}
if (GetArea(oPC) == GetObjectByTag("area002"))
{
ExecuteScript("d_exit002", OBJECT_SELF);
}
if (GetObjectType(oObject) == OBJECT_TYPE_CREATURE && !GetIsPC(oObject))
^- If it’s a creature, and not a PC, clean it’s inventory out.
I’m not quite sure that the “GetFirstObjectInArea() -> then GetIsPC(), abort if it is”-thing is solid. Does GetFirstObjectInArea prioritize PCs? Will it always return a player character first if one is in the area?
For the second - why not just set up a single clean-area script? Does there really need to be a different one per area? You could just set up a single one, wherein the to-be-cleaned area is the caller, and go
ExecuteScript("area_clean", GetArea(oPC));
If different things need to happen depending on the area, use local ints stored on the area to set what will or won’t happen during this area’s cleanup, or check for the tag of the area within the area-cleaning script.
For the second one, if the clean-area scripts are all very different, and there are lots of areas, you need to store the name of the script to be used by area. Two ways of doing that - either store the script name as a local string on the area, or create a custom 2da file with columns for Area and Script (Get2daString will treat this as a look-up table).
The first method appears easier at first sight, but it does mean you have to edit every area one by one to create and maintain the script names. The second method is probably easier in the long run, especially if there are a lot of areas and frequent changes.
I’ll post again later when I get home. I may need a little more help. I’ll post more scripts that are part of my cleanup system that have been acting up lately.
Here is one of the scripts that runs when a player exits an area OnExit, also the module’s OnClientLeave when a player logs off.
Something odd that I’ve noticed, is that sometimes when a player logs off, the part of this script that checks if there are any other players still in the area doesn’t work. So, sometimes other players might be in the same area as the player who left and the cleanup scripts fire anyway!
Not sure what I’ve missed to make sure it only fires when there are no players left in the area before running.
The script in OnClientLeave is being run by the module rather than by the area, so the (OBJECT_SELF == GetArea(oPC)) condition will never be TRUE in that one. The module is not going to be equal to any area, ever.
Try adding a
object oArea = GetArea(oPC);
at the beginning, while oPC is still the exiting object, and replace OBJECT_SELF in the condition with oArea.
When inexplicable weird stuff like this happens, always try adding debug messages to check who your various objects are. It happens pretty easily, what with the various event-dependent GetThingamabob functions. Use the wrong function to determine who your player or your target is, right at the start of the script, and bam, nothing works despite the code making perfect sense. Bleh!
Seriously? Oop. It can’t be the OnClientLeave script that’s causing the areas to be cleaned despite PCs still being in them, then. If the GetIsPC() check at the beginning is FALSE, the script would abort before the cleaning even happens.
…
And, depending on what’s in the code for cleaning the areas, it wouldn’t be happening to the area either, targeting the module instead. I’ve pointed the finger at the wrong suspect. What else could it be?
I don’t know. I haven’t been looking at this thread very carefully. Instead of trying to run the same code onclientleave as on area exit I’d use a PHB on each area as the first PC enters. Then either track a count or check when the PHB fires that there is no PC in the area. If there is then Delay again, if not then clean.