• 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!

isOnline?

Alonso knight

New Member
Joined
Jan 3, 2008
Messages
72
Reaction score
0
I am doing a jail system by Talkactions. It works like this...

For jail someone you must say !jail "name,reason,time, for example !jail "Alonso,botter,10sec.

Well, until here it's all OK, but when the char is sent to the jail, I use an addEvent(onTime) function for get the time the player must be jailed.

When that time has expired, the player should be teleported to the "unjailpos" using this....
PHP:
function onTime(a)
	if isPlayer(a.player) == TRUE then
		doTeleportThing(a.player,a.unjailpos,TRUE)
		doPlayerSendTextMessage(a.player, MESSAGE_INFO_DESCR, "You are free again!!")
	end
end
It works when the player hasn't logged out while he was jailed, but if the player logout while he is in the jail, he isn't teleported to the "unjailpos" again.

Could someone explain me what should I write for get the player teleported, although he had logged out?
 
When the player is getting jailed, set him a storage value with os.time(). And when he login, a onLogin script will check STORAGE-os.time(), if it's more than for example 30 minutes, the player will be released. If it's still under 30 minutes, the event will start ticking untill it's release time and so on :)
 
LoL, to make the jail a NonLogout zone is crazy! The jail would be full of afk players, lol. The other idea is good but I don't know why it isn't working for me...What's wrong here?


In the onSay function...
PHP:
elseif words == '!jail' then                 
   doPlayerSendTextMessage(player,MESSAGE_INFO_DESCR,'You got jailed by '..jailer..', Reason: '..reason..', Time: '..jailtime..'.')
   doTeleportThing(player,jailpos)
   doPlayerSendTextMessage(cid,21,"You just jailed "..name..", Reason: "..reason..", Time: "..jailtime..".")
	   if param3 == "10 sec" then
		   setPlayerStorageValue(cid, 1346, os.time())
	   end
end

The onLogin function...
PHP:
function onLogin (cid)
	local unjailpos = {x=531, y=608, z=7}
	local timejailed = getPlayerStorageValue(cid,1346)
	if timejailed - os.time > 10 then
		doTeleportThing(cid,unjailpos,TRUE)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You are free again!!")
	else doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "You are still jailed. Bad boy!")
	end
end
 
You didnt stated the time. Im not really sure if this should be like that or that:

os.time(x * 1000 * 60)
or
os.time() x * 1000 * 60
or
os.time() * x * 1000 * 60

x = minutes.
 
@Marcinek Paladinek: I don't think so, I think the function os.time doesn't need any variable, correct me if I'm wrong but I think it retuns the time of your os when you called the function or the number of seconds since some given start time (the "epoch"). But it doesn't need any variable, I think :S

From lua.org
Code:
os.time ([table])

Returns the current time when called without arguments, or a time representing the date and time specified by the given table. This table must have fields year, month, and day, and may have fields hour, min, sec, and isdst (for a description of these fields, see the os.date function).

The returned value is a number, whose meaning depends on your system. In POSIX, Windows, and some other systems, this number counts the number of seconds since some given start time (the "epoch"). In other systems, the meaning is not specified, and the number returned by time can be used only as an argument to date and difftime.

Anyway...if I add os.time(x * 1000 * 60) in the onSay function...what should I add in the onLogin function?

PHP:
if timejailed - os.time() > 10 then
How should this be?
 
If one of those which I posted will work, the storage value will be as high as the time is and will be going down every ms/s.

#
In onLogin you have to just specify what storage no. it should check, so I guess you already had it like that.

##
So just;
Code:
if getPlayerStorageValue(cid, urjail) < 10000 then

coz 1000 = 1 sec
 
Last edited:
Isn't os.time() return time in seconds? In TFS 0.2.6 it did.
So maybe:
jailtime - jailtime in seconds
Jail:
Code:
setPlayerStorageValue(cid, jail_end_time_id, os.time()+jailtime)
If you want send player back to position where he was jailed you can save in 3 storage IDs his position.
Unjail (login.lua or talkaction for "!leave" or other command):
Code:
if getPlayerStorageValue(cid, jail_end_time_id) < os.time() then
teleport to unjail position
end
I don't understand how can it work..
...the storage value will be as high as the time is and will be going down every ms/s.
It can't work after server restart? What if server crash before player will be unjailed? :>
Better save end_jail time in storage.
 
os.time() gives you the current time in seconds (from 1.1.1970). os.date(os.time(),"*t") converts the seconds to year, month (...) min and sec. Returns a table with those fields (table.year, table.month, table.day (...))
os.clock() gives you the time the program has been running in seconds WITH 3 decimals. Eg. 12.345
 
Ok, going to try it. I'll tell you if it works...

Edit: Ok, I have tried it, and it works a little better, but still have an error that I can't understand...

When I jail the player, it's all ok, he is teleported to the jailpos and, in 10 seconds, he goes back to the unjailpos, but then, when that player relog, he see a message "You are still jailed. Bad boy!" and it appears in every login <_<.

I've checked the scripts lots of times and I can't find any error.


This is the step of the talkaction's script where I add the storage to the player:
PHP:
                elseif words == '!jail' then                 
                    doPlayerSendTextMessage(player,MESSAGE_INFO_DESCR,'You got jailed by '..jailer..', Reason: '..reason..', Time: '..jailtime..'.')
                    doTeleportThing(player,jailpos)
                    doPlayerSendTextMessage(cid,21,"You just jailed "..name..", Reason: "..reason..", Time: "..jailtime..".")
                    if param3 == "10 sec" then
                        setPlayerStorageValue(player,1346,os.time()+10)
                    end
This is the Think script in the creaturescript folder.
PHP:
function onThink(cid, interval)
if getPlayerStorageValue(cid,1346) <= os.time() and getPlayerStorageValue(cid,1346) ~= -1 then
        doTeleportThing(cid,{x=531, y=608, z=7},TRUE)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You are free again!!")
        setPlayerStorageValue(cid,1346,-1)
    end
    return TRUE
end
And this is the Login script in the creaturescript folder:
PHP:
function onLogin(cid)
    registerCreatureEvent(cid, "PlayerDeath")
    dofile("./config.lua")
    if sqlType == "mysql" then
        env = assert(luasql.mysql())
        con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
    else -- sqlite
        env = assert(luasql.sqlite3())
        con = assert(env:connect(sqliteDatabase))
    end
    if serverStarted == FALSE then
        assert(con:execute("UPDATE `players` SET `online` = 0;"))
        serverStarted = TRUE
    end 

    if getPlayerStorageValue(cid,1346) > os.time() and getPlayerStorageValue(cid,1346) ~= -1 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "You are still jailed. Bad boy!")
    end 


    assert(con:execute("UPDATE `players` SET `online` = `online`+1 WHERE `id` = "..getPlayerGUID(cid)..";"))
    con:close()
    env:close()
    return TRUE
end
There must be something wrong with the storage values, but I don't know where is the error. If any of you know where it is, I whould be greatful. Thanks ;)
 
Last edited by a moderator:
Back
Top