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

Lua Trying to use getWorldTime tfs 1.1

Jfrye

Mapper, trying to learn scripting
Joined
Jan 8, 2009
Messages
366
Solutions
5
Reaction score
86
Location
Mexico Missouri
Code:
local light = 1479
local spawnpos = {x=477, y=557, z=7}


function onTime()
for i = 1, #t do
    if getWorldTime() < 1435 > 0600 then
    doTransformItem(light, 1480)
    end
return true
end  
end

Using this code, I am trying to transform a light from id 1479, to id 1480 at a certain tibia time. I tried using this https://otland.net/threads/light-up-the-streets-at-night.197060/ but that script isnt working on my server. So I thought I would try my own, and it seems like I have no idea what I am doing. Ive tried searching the right way to use getWorldTime(), and havent had much luck. Any help is appreciated, but it would also be nice if an explanation could be included.
 
Code:
local item = Item(pos):getItemById(removeItem)
change to
Code:
local item = Tile(pos):getItemById(removeItem)

now it works, enjoy :)
 
@Ahilphino that made the lights change, but it did it before the world time that has been set. For testing purposes, the lights are set to come on at 14:35. The lights came on at 14:28.
 
ok idk the getWorldTime() function, try print(getWorldTime()) somewhere and tell us what it returns. maybe it's in some other timezone? idk ^^
 
@Ahilphino I did that, and this is what its doing in server console
Code:
The Forgotten Server - Version 1.1
Compiled with Microsoft Visual C++ version 12.0
Compiled on May 14 2015 22:47:50 for platform x64

A server developed by Mark Samman
Visit our forum for updates, support, and resources: http://otland.net/.


GOD Justin has logged in.
867
871
871
875
879
883
883
887
891
895

Its just spamming numbers every few seconds.
 
ok, thats good as u see it gives us some wrong numbers, not some actual time stamp like we need for the if check. or maybe it is some actual time but stored in some weird way... idk :p
now u try with
print(getFormattedWorldTime())
instead
 
Last edited:
@Ahilphino

Code:
The Forgotten Server - Version 1.1
Compiled with Microsoft Visual C++ version 12.0
Compiled on May 14 2015 22:47:50 for platform x64

A server developed by Mark Samman
Visit our forum for updates, support, and resources: http://otland.net/.



GOD Justin has logged in.
14:27

This is the formatted world time. So even though the script says to start at 14:35, it still starts at 14:27
 
Go search Otland for the code to call an item from a position. Its not that hard man. Thats the only problem u are having.
 
The issue is with the time now. It has been fixed for the most part. I have sat here for the last 2 hours watching this thing, and if I change the times in this script
Code:
    if getWorldTime() < 1435 and getWorldTime() > 0600 then
then it doesnt seem to turn the lights on. Using these times stated, it will turn the light on at 14:27, and not 14:35 like it should. It turns them off at 23:55, and not 06:00 like it should. So it seems to be something within the code line I listed above.
 
Sheesh how can this many people not know how tibia time works. @Ahilphino I am disappointed :(

Tibia time works on seconds where each second = 1 minute.
6 AM (6:00) would be 360
6 PM (18:00) would be 1080

At midnight the day will start over from 0 and start counting up again.
 
@Xagul , even using those time values, the script still turns the light on at 14:27. No matter what Time I put in the script, its always at 14:27, and then turns them off at 23:55.


Script
Code:
local positions = { --Each light that will be changed
    [1] = {x = 435, y = 565, z = 7}

}

local no_light_itemid = 2037
local light_itemid = 2038


function swapLights(pos, removeItem, makeItem)
        local item = Tile(pos):getItemById(removeItem)
        if item ~= nil then
            if item.itemid == removeItem then
                doTransformItem(item.uid, makeItem)
                        print(getFormattedWorldTime())
            end
        end
end

function onThink(interval)
    if getWorldTime() < 900 and getWorldTime() > 360 then
        for i = 1, #positions do
        swapLights(positions[i], no_light_itemid, light_itemid)               
        end
    else
        for i = 1, #positions do
        swapLights(positions[i], light_itemid, no_light_itemid)
        end
    end 
    return true
end
 
The script works good, except for the time. Does anyone have anymore Input on the time values that I should be placing in this line?
Code:
if getWorldTime() < 900 and getWorldTime() > 360 then

Using this time value, the lights will turn on at 14:27. My server starts at 14:25, so 2 seconds after the server turns on, this script is turning these lights on.

Using print(getWorldTime()), the the server console says 867 when the script turns on. The script will show 903 and shut the lights off.

If I use print(getFormattedWorldTime()), it will show 14:27 in server console.
 
Back
Top