Rinart73 Posted September 29, 2018 Share Posted September 29, 2018 I have a script that is attached to sector. And I need to do stuff immediately after player login/logoff. if onClient() then return end -- namespace SectorTest SectorTest = {} function SectorTest.initialize() local server = Server() server:registerCallback("onPlayerLogIn", "onPlayerLogIn") server:registerCallback("onPlayerLogOff", "onPlayerLogOff") end function SectorTest.onPlayerLogIn(playerIndex) print("onPlayerLogIn", playerIndex) end function SectorTest.onPlayerLogOff(playerIndex) print("onPlayerLogOff", playerIndex) end But when I'm trying to register these callbacks nothing happens when player enters/leaves the game. And if server is launched from bat file, following message appears in server logs: warning: tried unregistering a callback from server to script mods/ServerGuard/scripts/sector/deferredtest.lua in sector (200:200), which is being generated Why it's not allowed? We can call other Server functions like "isOnline(playerIndex)" from Sector scripts just fine. Of course, I can just check if each player is online/offline every 10 seconds. But it will not produce immediate reponce and will not be performance-friendly. UPD: Apparently it works if you'll register callbacks after "initialize" function (in first update for example). But why? It's implied that Sector initialize function is called after everything is loaded. if onClient() then return end local callbacksRegistered = false -- namespace SectorTest SectorTest = {} function SectorTest.updateServer() if callbacksRegistered then return end local server = Server() server:registerCallback("onPlayerLogIn", "onPlayerLogIn") server:registerCallback("onPlayerLogOff", "onPlayerLogOff") callbacksRegistered = true end function SectorTest.onPlayerLogIn(playerIndex) print("onPlayerLogIn", playerIndex) end function SectorTest.onPlayerLogOff(playerIndex) print("onPlayerLogOff", playerIndex) end Link to comment Share on other sites More sharing options...
DrMasik Posted October 1, 2018 Share Posted October 1, 2018 Sorry for poor English. onPlayerLogIn/onPlayerLogOff it is Server callbacks. It is good idia call it from server.lua. If you want to canch player enternce to sector - try to use Sector():onPlayerEntered() and Sector():onPlayerLeft(). Link to comment Share on other sites More sharing options...
Rinart73 Posted October 1, 2018 Author Share Posted October 1, 2018 DrMasik, Hi. I disagree. There a plenty of examples when Entity scripts registered Sector callbacks. So why registering Server callbacks from Sector script is incorrect? If you want to canch player enternce to sector - try to use Sector():onPlayerEntered() and Sector():onPlayerLeft(). No, I specifically need to react when player logins/logoffs. I already found the solution: Server callbacks can be successfully registered in the first update tick. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now