FG Spreadshirt Swag
Page 1 of 2 12 Last
  1. #1

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247

    Does User.onLogin Actually Trigger on a User Logging Out?

    The handler User.onLogin gives a signature of onLogin(username, activated).

    I have no problems overriding this and doing things on the login of a user (activated = true), however it is never triggered when the user is logging out.

    In addition, when a user logs out (quits the program) and I try to send an OOB message, that message is never sent (assuming that them quitting the program has unloaded all relevant classes).

    Any ideas on a work around to this? I am happy to use either option, just would like a log out trigger.

    ... And why some might ask? Because I have a set of windows open, one per user, and thus when they leave I wish to close that window.
    Thanks In Advance,
    D

  2. #2
    Yes, onUserLogin returns either true or false depending on whether a user is connecting or disconnecting. It will only fire on the GM client.

    At the point that the user is disconnecting, you can no longer send messages to the user; since the user is already disconnected at that point.

    Regards,
    JPG

  3. #3

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    I have tried the following scenarios ...

    In all cases it is the Host who is trying to check for login/logout - no one else (at this point)

    1. onInit/onClose
    The user sends a disconnect OOB message which is being listened for by the Host.
    The message is never received - it does receive the connect OOB message however without a problem in the onInit()

    2. onLogin
    The host is watching for login true/false using my own onLogin code ... it sees the connection/disconnection in that function, however it is not able to continue with some code that relies on the Session.IsHost and the activated being true/false - that is, can the host actually see the disconnection?
    Thanks In Advance,
    D

  4. #4
    That script event is fired on the GM client at the same time that the connected/disconnected messages are posted to chat. Here's a super simple extension that triggers on that event.

    Regards,
    JPG
    Attached Files Attached Files

  5. #5

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Thank you for that ... it looks (in essence) identical to what I have except I am setting onLogin within a loaded LUA file rather than in the extension.xml

    Would that make a difference?
    Thanks In Advance,
    D

  6. #6
    No, it shouldn’t. Put a debug statement at the top of your function, and test with a localhost player client.

    Does the extension trigger correctly?

    JPG

  7. #7

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Yes I was already Debugging the onLogin. It triggers on both instances

    I then have code in that function like this - note that onUserLoginPrev is a store of the previous User.onLogin function - this is mainly not to interfere with any onLogin functionality that the ruleset may have and/or another extension relies upon.

    The script is NOT seeing the "ATTEMPTING TO DISCONNECT" and "EXECUTING PREVIOUS LOGIN" sections.

    Code:
    function onLogin(username, activated)
        Debug.chat("MY ON LOGIN", username, activated)
    
        if activated and onUserLoginPrev then onUserLoginPrev(username, activated)
    
        if Session.IsHost
        then
            if activated
            then
                localTable.connect(username)
            else
                Debug.chat("ATTEMPTING TO DISCONNECT")
                localTable.disconnect(username)
            end
        end
    
        if not activated and onUserLoginPrev
        then
            Debug.chat("EXECUTING PREVIOUS LOGIN")
            onUserLoginPrev(username, activated)
        end
    
    end
    Should I not be testing for Session.IsHost? The problem is that the localTable variable is only instantiated for the Host as the Player does not need it.
    Thanks In Advance,
    D

  8. #8
    OnUserLogin is only for the GM client; not for running on player clients.

    JPG

  9. #9

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    And the code is not running on a user client technically ... that is why I have the Session.IsHost in the code ... to ensure that even if a IsUser gets in, it will not run the code. It might be redundant but it should not stop the code from executing should it?
    Thanks In Advance,
    D

  10. #10
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,402
    Quote Originally Posted by UrsaTeddy View Post
    Code:
    function onLogin(username, activated)
    ...
    
        if activated and onUserLoginPrev then onUserLoginPrev(username, activated)
    
    ...
    
    end
    There's no end for this if statement. I would have expected a LUA [ERROR] saying 'end' expected (to close 'function' at line XX)
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Character Create Playlist

Log in

Log in