Skip to content

Commit

Permalink
fix: Lua error on getWorldTime function (#4606)
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires authored Dec 16, 2023
1 parent b8e69c2 commit 36b3c89
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
6 changes: 0 additions & 6 deletions data/actions/actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,10 @@
<action itemid="486" script="others/snow_heap.lua" />
<action itemid="1369" script="others/draw_well.lua" />
<action itemid="1386" script="others/teleport.lua" />
<action fromid="1728" toid="1731" script="others/watch.lua" />
<action fromid="1816" toid="1817" script="others/wall_mirror.lua" />
<action fromid="1843" toid="1844" script="others/wall_mirror.lua" />
<action fromid="1846" toid="1847" script="others/wall_mirror.lua" />
<action fromid="1849" toid="1850" script="others/wall_mirror.lua" />
<action itemid="2036" script="others/watch.lua" />
<action itemid="2093" script="others/water_pipe.lua" />
<action itemid="2095" script="others/bird_cage.lua" />
<action itemid="2099" script="others/water_pipe.lua" />
Expand All @@ -170,16 +168,12 @@
<action itemid="2694" script="others/create_bread.lua" />
<action itemid="2785" script="others/blueberry_bush.lua" />
<action itemid="3678" script="others/teleport.lua" />
<action itemid="3900" script="others/watch.lua" />
<action itemid="5543" script="others/teleport.lua" />
<action fromid="5792" toid="5797" script="others/die.lua" />
<action itemid="6092" script="others/watch.lua" />
<action itemid="6576" script="others/fireworks_rocket.lua" />
<action itemid="6578" script="others/party_hat.lua" />
<action itemid="7552" script="others/large_seashell.lua" />
<action itemid="7828" script="others/watch.lua" />
<action fromid="7904" toid="7907" script="others/bed_modification_kits.lua" />
<action fromid="9443" toid="9444" script="others/watch.lua" />
<action fromid="18488" toid="18492" script="others/skill_trainer.lua" />
<action itemid="20252" script="others/bed_modification_kits.lua" />
<action fromid="22845" toid="22846" script="others/teleport.lua" />
Expand Down
4 changes: 0 additions & 4 deletions data/actions/scripts/others/watch.lua

This file was deleted.

11 changes: 0 additions & 11 deletions data/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,6 @@ function getDistanceBetween(firstPosition, secondPosition)
return posDif
end

function getFormattedWorldTime()
local worldTime = getWorldTime()
local hours = math.floor(worldTime / 60)

local minutes = worldTime % 60
if minutes < 10 then
minutes = '0' .. minutes
end
return hours .. ':' .. minutes
end

function getLootRandom()
return math.random(0, MAX_LOOTCHANCE) / configManager.getNumber(configKeys.RATE_LOOT)
end
Expand Down
4 changes: 4 additions & 0 deletions data/lib/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1639,3 +1639,7 @@ function table.maxn(t)
end
return max
end

function getFormattedWorldTime()
return Game.getFormattedWorldTime()
end
18 changes: 16 additions & 2 deletions data/lib/core/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ end
do
local worldLightLevel = 0
local worldLightColor = 0

function Game.getWorldLight()
return worldLightLevel, worldLightColor
end

function Game.setWorldLight(color, level)
if not configManager.getBoolean(configKeys.DEFAULT_WORLD_LIGHT) then
return
Expand Down Expand Up @@ -232,3 +232,17 @@ do
end
end
end

function Game.getFormattedWorldTime()
local worldTime = Game.getWorldTime()
local hours = math.floor(worldTime / 60)

local minutes = worldTime % 60
if minutes < 10 then
minutes = '0' .. minutes
end

minutes = math.floor(minutes)

return hours .. ':' .. minutes
end
9 changes: 9 additions & 0 deletions data/scripts/actions/tools/watch.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local watch = Action()

function watch.onUse(player, item, fromPosition, target, toPosition, isHotkey)
player:sendTextMessage(MESSAGE_INFO_DESCR, "The time is " .. Game.getFormattedWorldTime() .. ".")
return true
end

watch:id(1728, 1729, 1730, 1731, 2036, 3900, 6092, 7828, 9443, 9444)
watch:register()

0 comments on commit 36b3c89

Please sign in to comment.