Jump to content

onClientPlayerQuit - Client-side event


Morelli

Recommended Posts

This event seems to have no effect. I've tested it with numerous codes which rely on the trigger event to be 'onClientPlayerQuit'

Some test codes:

-- Client-side 
  
function onQuitGame2( reason ) 
    outputDebugString ( getPlayerName( source ).." has left the server TEST TEST ("..reason..")" ) 
end 
addEventHandler( "onClientPlayerQuit", getRootElement(), onQuitGame2 ) 

-- Client-side 
  
function QUIT(  ) 
    outputDebugString ( "Test" ) 
end 
addEventHandler( "onClientPlayerQuit", getRootElement(), QUIT) 

Link to comment

Erm, this code works fine for me :? .

Even though I haven't tested it with the "reason" parameter the following lines of script code trigger just fine.

  
-- destroy objects 
function clean() 
  if (source == player) then 
    objTextManager = nil 
    objProgressBar = nil 
    objSplash = nil 
    objClientVehicles:clean() 
  else 
    if (objTimerUtils:getLoaded()) then 
      -- player left 
      objKillMessages:Process(source, nil, 1003) 
    end 
  end 
end 
  
addEventHandler("onClientPlayerQuit", root, clean) 
  

Link to comment
Erm, this code works fine for me :? .

Are you positive that it works? I've tested this event for at least 10 different tasks to perform, and none of them have had any effect. Granted, they haven't crashed the MTA server.exe, but consequently, they have had absolutely no effect whatsoever. Just by glancing at your script (not fully knowing what all those tasks represent), I can see that it appears you want to set a Player's GUI (objProgressBar, objSplash, etc) to disappear. This is automatically handled by the server by default, when a player leaves the server. So it may infact not be your code that is causing it to work, but the native MTA coding.

Link to comment

Actually what it does is manually nullify gui created static images because somehow these aren't destroyed and removed properly from memory when leaving the server. When the source is not the local player it triggers an "exit" icon for the player that left on the local players' kill messages display. That's how I know it works because the "exit" icon is nicely triggered when a remote player leaves.

Link to comment

Morelli: stupid question but are you testing this with other players ? If you're doing this on your own you may not get the event.

Actually what it does is manually nullify gui created static images because somehow these aren't destroyed and removed properly from memory when leaving the server.

I don't think this is 100% right. If I run my game mode (including timers) and just "stop it" (removing all client tidy up code), my timers and MY gui elements disappear. I'm assuming there is some auto-garbage collection going on. It will leave some things as you set them - if you hide/show standard HUD components these will stay in the same state (also skins, gravity etc.)

Link to comment
Morelli: stupid question but are you testing this with other players ? If you're doing this on your own you may not get the event.

Testing on my own server.

This is the Client equivalent of the OnPlayerQuit, so it should be triggered even if there is only one player. Because it writes to the Debug, I should be able to verify if it works or not, just by checking if anything has been written in the MTA server.exe. I haven't seen anything been written in any of my tests, so I am to assume that there is a problem with either my code or the event.

Link to comment
Morelli: stupid question but are you testing this with other players ? If you're doing this on your own you may not get the event.
Actually what it does is manually nullify gui created static images because somehow these aren't destroyed and removed properly from memory when leaving the server.

I don't think this is 100% right. If I run my game mode (including timers) and just "stop it" (removing all client tidy up code), my timers and MY gui elements disappear. I'm assuming there is some auto-garbage collection going on. It will leave some things as you set them - if you hide/show standard HUD components these will stay in the same state (also skins, gravity etc.)

It is not the problem of gui elements not disappearing but rather the fact that it seems like some artifacts remain in memory when I leave the server running my game mode. And by artifact I mean object references in memory of static images. I've noticed rapidly decreasing performance after multiple times of leaving/joining the server when I don't nullify them (we are talking 300+ static image elements that are created every time you join...I am trying to push the limits here lol). Everything is back to normal again when I close MTA entirely and restart it.

Link to comment

Testing on my own server.

Yeah but on your own ? I mean, are you the only player ?

This is the Client equivalent of the OnPlayerQuit, so it should be triggered even if there is only one player. Because it writes to the Debug, I should be able to verify if it works or not, just by checking if anything has been written in the MTA server.exe. I haven't seen anything been written in any of my tests, so I am to assume that there is a problem with either my code or the event.

I'm aware of what it's meant to do, I'm just wondering if it'll work or not. If you're the only player and you're testing this, I can see why this wouldn't fire. If the server generates events for the clients (i.e. tells them players have left), if you're on your own it's easy to see why this might not occur - you quit, the server finds out and tries to inform others of your leaving - you may not get the event because you're not connected. I'm guestimating this - I don't know the internal mechanics of MTA to know what's guarenteed to happen but I can see in this case, how it might not.

If you are testing this with other players then OK, ignore the above - but I've not had a problem with this event before now ?

Link to comment
It is not the problem of gui elements not disappearing but rather the fact that it seems like some artifacts remain in memory when I leave the server running my game mode. And by artifact I mean object references in memory of static images. I've noticed rapidly decreasing performance after multiple times of leaving/joining the server when I don't nullify them (we are talking 300+ static image elements that are created every time you join...I am trying to push the limits here lol). Everything is back to normal again when I close MTA entirely and restart it.

Maybe, as you say, it's just the sheer number of image elements you've got. When coding I reconnect/restart numerous times but haven't really run into anything like this. I do try to remember to null(ify) all elements I make (timers, images, labels etc.) but I know I forget some but haven't noticed it getting worse (I never have to restart MTA unless I do ctrl+alt+del in window'ed mode and get the texture's mashing up).

BTW, what ARE you using 300 images for ? :)

Link to comment
Maybe, as you say, it's just the sheer number of image elements you've got. When coding I reconnect/restart numerous times but haven't really run into anything like this. I do try to remember to null(ify) all elements I make (timers, images, labels etc.) but I know I forget some but haven't noticed it getting worse (I never have to restart MTA unless I do ctrl+alt+del in window'ed mode and get the texture's mashing up).

BTW, what ARE you using 300 images for ? :)

Yes, it is most likely the insane amount of images that's causing my pc to vomit after a while :lol: . Although I must say the loading process does not take that long at all (maybe 15 seconds). Why? Just testing what's possible :mrgreen: .

Link to comment

You should not receive an onClientPlayerQuit event on the client of the player that quits, for the reason stated by tma. The server receives the fact that you've quit directly from the network layer. It's not a 'can I quit please' request, it's 'I've quit, bye!'. As such, once the server receives this, it can no longer send any data to that client, including a quit event. I can't really see what you would want to do on a client that's about to quit - you can't send anything to the server, you can't display anything on the screen...

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...