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

TFS 1.X | GlobalEvent? Change Item if getWorldLight()

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,837
Solutions
18
Reaction score
614
Location
Poland
Hello folks!
I have a simple one question about in-game time and changing specific itemID to another one when the condition is made.

First Question :
It's any possibility to make function like this in LUA: setTibianTime to set In-Game Time to specific hours and minutes?
ex. setTibianTime(23:00) , that will set the in-game time to 23:00 (night).

Request:
I need an globalevent which doing something like changing itemID on entire map to Y when getWorldLight() == 10 and changing back to itemID when getWorldLight() >= 250.

Need it to turn on all lamps on map while is night in-game and turn off when day comes.

Thanks in advance anyone,
Bless, F.
 
1. possible in sources, change it in game.h by making a function to set lighthour, add it to luascript.cpp/h and call that game function
2. possible but only if you want to freeze your server for a long time, see my post here: TFS 1.2 Change Map items by date
 
@Vulcan_ what you think about create a function that create the items in the map, loading the info from some table.. then call function to change that id with os.time()
then you don't need run the function from x, to x and check the ground, and the item then change it's ID ...
exemple:
Code:
local table = {
         {position = Position(x, y, z), itemid = 1000, changeid = 1001}
}
function test()
          for i = 1, #table do
                  local item = table[i]
                  if item then
                        Game.createItem(item.itemid, 1, item.position, true, true)
                        addEvent(revertItem, 10 * 1000, item.itemid, item.changeid, item.position)
                  end
          end
end
this was a very bad code, just to try be more clearly with it
 
of course it's different if you create them through a script instead of mapping them where the positions of those items are unknown, but that's not what he asked about
he said he wants to change all lamps on/off depending on the time and i don't think he wants to manually edit a table for every single lamp on his server
 
of course it's different if you create them through a script instead of mapping them where the positions of those items are unknown, but that's not what he asked about
he said he wants to change all lamps on/off depending on the time and i don't think he wants to manually edit a table for every single lamp on his server
yes ... I'll try be more specific, what take more time, load functions from x to x, from y to y in a big area or just do this table ?
to do this table the guy don't need do it manually
just create a function that check one time all the area, checking the tile, items from a little table, then took this id, position then create a new table with that info... i use it to do some job for ferumbras ascendant quest, that part of the habitats ..
Code:
for x = 33415, 33446 do
    for y = 31523, 31554 do
        local position = Position(x, y, 11)
        local tile = Tile(position)
        if not tile then
            return
        end
        local ground = tile:getGround()
        if not ground then
            return
        end
        local grounds = ground:getId()
        local name = player:getName()
        local file = io.open("data/newtable.txt", "a")
        local items = tile:getItems()
        if items then
            for i = 1, #items do
                local item = items[i]
                local itemId = item:getId()

                if not file then
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "error.")
                    return true
                end

                io.output(file)
                io.write("{itemid = " .. item:getId() .. ', position = Position('.. position.x .. ', ' .. position.y ..', 11)},\n')
            end
            io.output(file)
            io.write("{itemid = " .. grounds .. ', position = Position('.. position.x .. ',' .. position.y ..', 11)},\n')
            io.close(file)
        end
    end
end
this function take the items from the position and create a file with that table...
after all of this, my question, what took more time
1 - load a function that check all positions in that area and change lamp's id
2 - load a function that load the table with all marked positions
 
yes ... I'll try be more specific, what take more time, load functions from x to x, from y to y in a big area or just do this table ?
to do this table the guy don't need do it manually
just create a function that check one time all the area, checking the tile, items from a little table, then took this id, position then create a new table with that info... i use it to do some job for ferumbras ascendant quest, that part of the habitats ..
Code:
for x = 33415, 33446 do
    for y = 31523, 31554 do
        local position = Position(x, y, 11)
        local tile = Tile(position)
        if not tile then
            return
        end
        local ground = tile:getGround()
        if not ground then
            return
        end
        local grounds = ground:getId()
        local name = player:getName()
        local file = io.open("data/newtable.txt", "a")
        local items = tile:getItems()
        if items then
            for i = 1, #items do
                local item = items[i]
                local itemId = item:getId()

                if not file then
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "error.")
                    return true
                end

                io.output(file)
                io.write("{itemid = " .. item:getId() .. ', position = Position('.. position.x .. ', ' .. position.y ..', 11)},\n')
            end
            io.output(file)
            io.write("{itemid = " .. grounds .. ', position = Position('.. position.x .. ',' .. position.y ..', 11)},\n')
            io.close(file)
        end
    end
end
this function take the items from the position and create a file with that table...
after all of this, my question, what took more time
1 - load a function that check all positions in that area and change lamp's id
2 - load a function that load the table with all marked positions
didn't think about that, nice one
but if it were to be optimized it could be used in onStartup and create a global table with lamps and insert every lamp into the table instead of writing to an arbitrary file
 
didn't think about that, nice one
but if it were to be optimized it could be used in onStartup and create a global table with lamps and insert every lamp into the table instead of writing to an arbitrary file
yes, exactly.. that function will just create the file with that table, then you copy the table, and paste in a startup function and just make functions to check it based on time
exemple: do onThink() function that check the tibian time, if the time >= 250 call the function convert/revert id :)
 
yes, exactly.. that function will just create the file with that table, then you copy the table, and paste in a startup function and just make functions to check it based on time
exemple: do onThink() function that check the tibian time, if the time >= 250 call the function convert/revert id :)
yeah but there's no point in using a file because the map can get changed then the table will be outdated
better to just create a global table on startup with all of the items each time it restarts that way it's guaranteed the lamps are up to date
 
yeah but there's no point in using a file because the map can get changed then the table will be outdated
better to just create a global table on startup with all of the items each time it restarts that way it's guaranteed the lamps are up to date
as i said, you run just one time that function to get the positions... so you delete the file, you'll not use it anymore, after you copy it to the startup func
 
Back
Top