samp-streamer-plugin icon indicating copy to clipboard operation
samp-streamer-plugin copied to clipboard

OnPlayerLeaveDynArea not called when player leave the server

Open Jedrzej94 opened this issue 4 years ago • 4 comments

Console log:

OnPlayerEnterDynArea(Riddick)
Entered NPC ID: 998 statis area
NPC ID: 998 was disabled. Enabling it...
FCNPC_StartUpdateTimer(998)
[chat] [Riddick]: Gonna leave the server
*** Audio Plugin: Riddick (ID: 0) has disconnected
[part] Riddick has left the server (0:1)
[TLoU] Disconnected: 127.0.0.1|64888
[TLoU] Connection status: unhandledConnections: 0, players: 0

edit:// Also this doesn't print in OnPlayerDisconnect:

if(IsPlayerInAnyDynamicArea(playerid))
    {
        printf("I was in some dynamic area");
    }

So server removes me from the area overall seems like, but would be good to get OnPlayerLeaveDynArea call

Jedrzej94 avatar Sep 02 '21 13:09 Jedrzej94

As far as I know, neither is SA-MP calling similar callbacks when a player disconnects. It is a good practice to always reset everything in OnPlayerDisconnect.

Also, doing this change in the Streamer Plugin, to start calling every item-leaving callback, may lead to loss of performance for existing scripts and maybe even weirder things.

As of IsPlayerInAnyDynamicArea returning false in OnPlayerDisconnect, this is probably because Streamer's Plugin internal OnPlayerDisconnect may be called first by sampGDK (can't remember for sure), so it already has reset everything related to the player before your OnPlayerDisconnect is called. The common practice for this probably is to always reset everything, without having to use the condition beforehand. If heavier code is needed, instead of IsPlayerInAnyDynamicArea, some additional custom variable could be set to true/false when the player enters/leaves the area, then checking and resetting it in OnPlayerDisconnect as needed.

IstuntmanI avatar Sep 03 '21 03:09 IstuntmanI

I have 600 NPCs that have statis areas. When player enter statis area - enable NPC timer. When player leave statis area - disable NPC.

It works without me leaving the server. When I leave the server - simply it doesn't work and NPCs are always active in the statis area I was in.

Any potential workaround? I tried a few options but failed.

Jedrzej94 avatar Sep 03 '21 06:09 Jedrzej94

Try getting position OnPlayerDisconnect then checking if coordinates are in the area. (IsPointInDynamicArea)

xunder-matth avatar Sep 08 '21 17:09 xunder-matth

I've used iterator instead. Whenever player enters an area, I add that area to the iterator. When player leaves, I iterate through the list, do what I want and do the Clear at the end.

Jedrzej94 avatar Oct 10 '21 18:10 Jedrzej94