Whenever a player logs out or dies, the system still attempts to run the onStepOut function.
If you kick the player before the onStepOut function can complete, it will crash the server.
This was my fault, as I didn't realize this.
In either case, this is my working version of the script.
Note: kick_player is a global table. I highly suggest to never use this table again, as you may cause error's in other scripts.
- If you want cohesion for multiple scripts using similar functions, I'd suggest numbering them kick_player_1, kick_player_2, et cetera.
- Edit
Translated to English, to make the system more readable for future users who stumble across this thread.
Code:
<movevent type="StepIn" actionid="45587" event="script" value="test47.lua"/>
<movevent type="StepOut" actionid="45587" event="script" value="test47.lua"/>
Code:
local config = {
timer = 0.1, -- time in minutes (0.1 = 6 seconds, for easy testing)
teleport = {x = 11111, y = 11111, z = 11} -- teleport position
}
kick_player = {}
local function kickPlayer(cid)
if not isPlayer(cid) then
return true
end
doTeleportThing(cid, config.teleport)
addEvent(doRemoveCreature, 0, cid)
return true
end
local function stopKick(cid)
if stopEvent(kick_player[cid]) then
if not isPlayer(cid) then
return true
end
doPlayerSendTextMessage(cid, 23, "You will no longer be forcibly logged out.")
end
return true
end
function onStepIn(cid, item, position, fromPosition)
kick_player[cid] = addEvent(kickPlayer, config.timer * 60 * 1000, cid)
doPlayerSendTextMessage(cid, 22, "[Trainer]: If you remain on this tile longer then " .. config.timer .. " minutes, the system will automatically log you out.")
return true
end
function onStepOut(cid, item, position, fromPosition)
addEvent(stopKick, 0, cid)
return true
end