• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Kick players from trainers after 30 min idle time

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,514
Solutions
27
Reaction score
867
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
[Movemevent] Using this script allows me to kick players on trainer who spend more that 30 minutes without moving.

12a177afcd.png


But i have this error when player logout and still having the efect of storage id

1297802009.png


Someone knows how to fix?
 
Solution
wait.. is there multiple monsters trying to step on the tile?
Try this.. for whatever it's worth.

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...
you have to create custom functions in cases for creature being nonexistant at the time of execution
for example;
Code:
function sendMessage(cid, text)
    if not isPlayer(cid) then
        return
    end
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
end

addEvent(sendMessage, 1000, cid, "test")
 
you have to create custom functions in cases for creature being nonexistant at the time of execution
for example;
Code:
function sendMessage(cid, text)
    if not isPlayer(cid) then
        return
    end
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
end

addEvent(sendMessage, 1000, cid, "test")
This.
I often use the same method of checking as this method returns only true or false, which won't throw back an error if player got logged out through normal or external means.

Every time a creature is spawned, whether that be a player/npc/monster, they are assigned a number such as 1623798162, which is stored as "cid" in most scripts. (CreatureID)
If a player dies or logs out, the number they were assigned will no longer exist as a creature within the world.
So if you have a script that checks things in the future, you'll get an error sent to console if the creature does not exist anymore.

You can see the difference in Xeraphus's example script by green texting the simple check, then logging out.
You'll get the same error as what your current script has.

Of course this error can just be ignored, but who wants to see error's in their console, amirite?
Ignoring errors is never a good option.
 
you have to create custom functions in cases for creature being nonexistant at the time of execution
for example;
Code:
function sendMessage(cid, text)
    if not isPlayer(cid) then
        return
    end
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
end

addEvent(sendMessage, 1000, cid, "test")

thanks, this is working if i found errors i will reply

This.
Every time a creature is spawned, whether that be a player/npc/monster, they are assigned a number such as 1623798162, which is stored as "cid" in most scripts. (CreatureID)

good to learn! i thought the assigned number on this function was the storage id by the use of setPlayerStorageValue, thanks too
 
@Xeraphus
sorry for asking this. i couldnt make script work, i really dont know how the order of functions should be. for some reason i cant paste the script here so i take picture again

@Xikini i cant ignore this error because it causes lots of lags :(

using this:
(image deleted)
edit: changed to this after thinking a while

407884a057.png


hope it works
 
Last edited:
Ignoring errors is never a good option.
lol.

God this was a pain to type out.. and then delete everything because it wasn't needed. xD


Untested.
I removed the storage values.. because they weren't required.
Code:
local config = {
    tempo = 30, -- minutos
    teleport = {x = 32369, y = 32241, z = 7} -- templo
}

function kickPlayer(cid)
    if not isPlayer(cid) then
        return true
    end
    doTeleportThing(cid, config.teleport)
    doRemoveCreature(cid)
    return true
end
   

function onStepIn(cid, item, frompos, topos)
    kickPlayer[cid] = addEvent(kickPlayer, config.tempo*60*1000, cid)
    doPlayerSentTextMessage(cid, 22, "[Trainer]: Muevete cada " .. config.tempo .. " minutos, en caso contrario, su character sera deslogueado.")
    return true
end

functiononStepOut(cid, item, frompos, topos)
    stopEvent(kickPlayer[cid])
    doPlayerSendTextMessage(cid, 23, "System kick off!")
    return true
end
 
@Xikini got this error when used your script, mine didnt work :/

@Xeraphus

Ralke said:
[22/1/2017 15:13:39] [Error - LuaInterface::loadFile] data/movements/scripts/autokick.lua:26: '<eof>' expected near 'end'
[22/1/2017 15:13:39] [Error - Event::checkScript] Cannot load script (data/movements/scripts/autokick.lua)
[22/1/2017 15:13:39] data/movements/scripts/autokick.lua:26: '<eof>' expected near 'end'
[22/1/2017 15:13:39] [Error - LuaInterface::loadFile] data/movements/scripts/autokick.lua:26: '<eof>' expected near 'end'
[22/1/2017 15:13:39] [Error - Event::checkScript] Cannot load script (data/movements/scripts/autokick.lua)
[22/1/2017 15:13:39] data/movements/scripts/autokick.lua:26: '<eof>' expected near 'end'
 
@Xikini hahaha think on same thing but u post first

fixed, changed this



to this


and now have this error on console
@Xikini @Xeraphus

53e2968b9c.png
error is because he tried to assign a table index to a function
Code:
local config = {
   tempo = 30, -- minutos
    teleport = {x = 32369, y = 32241, z = 7} -- templo
}

events = {}

function kickPlayer(cid)
    if not isPlayer(cid) then
        return true
    end
    doTeleportThing(cid, config.teleport)
    doRemoveCreature(cid)
    return true
end
   
function onStepIn(cid, item, frompos, topos)
    events[cid] = addEvent(kickPlayer, config.tempo*60*1000, cid)
    doPlayerSendTextMessage(cid, 22, "[Trainer]: Muevete cada " .. config.tempo .. " minutos, en caso contrario, su character sera deslogueado.")
    return true
end

function onStepOut(cid, item, frompos, topos)
    stopEvent(events[cid])
    doPlayerSendTextMessage(cid, 23, "System kick off!")
    return true
end
 
error is because he tried to assign a table index to a function
Code:
local config = {
   tempo = 30, -- minutos
    teleport = {x = 32369, y = 32241, z = 7} -- templo
}

events = {}

function kickPlayer(cid)
    if not isPlayer(cid) then
        return true
    end
    doTeleportThing(cid, config.teleport)
    doRemoveCreature(cid)
    return true
end
 
function onStepIn(cid, item, frompos, topos)
    events[cid] = addEvent(kickPlayer, config.tempo*60*1000, cid)
    doPlayerSendTextMessage(cid, 22, "[Trainer]: Muevete cada " .. config.tempo .. " minutos, en caso contrario, su character sera deslogueado.")
    return true
end

function onStepOut(cid, item, frompos, topos)
    stopEvent(events[cid])
    doPlayerSendTextMessage(cid, 23, "System kick off!")
    return true
end

@Xeraphus when using xeraphus script
@Xikini

544d7e8394.png
 
Last edited:
@Xikini @Xeraphus
i wonder if something like this could work in addition to stepOut

Code:
function onLogout(cid)
   stopEvent(events[cid])
    return true
end

to stop the event on console if player get logout by other causes (i mean, not kicked by script)
edit: tried again with Xeraphus script after shutdown my server and now server crashes when get kicked (i couldnt't get a picture of error)
 
Last edited:
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
 
Last edited:
@Xikini looks good!! I learned a lot of scripting with this thread thanks!! :) at this moment im on vacations and I cant test the script. anyways ill be back soon and reply with the test results

By the way, that thing about kick_player tables made me think about the trouble i had with idle.lua (other thread), maybe that bug is related to a problem on global tables ^^
 
@Xikini looks good!! I learned a lot of scripting with this thread thanks!! :) at this moment im on vacations and I cant test the script. anyways ill be back soon and reply with the test results

By the way, that thing about kick_player tables made me think about the trouble i had with idle.lua (other thread), maybe that bug is related to a problem on global tables ^^
global tables don't cause problems unless there's an error with the table itself, just like a regular table
 
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

ok lets get to work, im back ^^

@Xikini your script works perfectly! no errors on console and no lags on execution
@Xeraphus i will check my mysql database to see if my kick_player tables are missing or something

thank u booth, anything new I see i'll post here!
 
Back
Top