Joriku
Working in the mines, need something?
Hi,
I had enough and need to head to bed.. this took me a few hours to try and try and try over and over again trying to convert the script.
So far, it seems alright BUT. I can't find an solution for the doSendAnimatedText on line 98 and 49
Asking Otland for help once more while i take a nap to continue once i wake up. If any answer, thank you!
I had lots of guesses, the one's working started with:
Script:
I had enough and need to head to bed.. this took me a few hours to try and try and try over and over again trying to convert the script.
So far, it seems alright BUT. I can't find an solution for the doSendAnimatedText on line 98 and 49
Asking Otland for help once more while i take a nap to continue once i wake up. If any answer, thank you!
I had lots of guesses, the one's working started with:
Lua:
getTopCreature()
Script:
Lua:
local tiles = {
{x = 1010, y = 1002, z = 5, stackpos = STACKPOS_TOP_CREATURE},
{x = 1011, y = 1002, z = 5, stackpos = STACKPOS_TOP_CREATURE},
}
-- [gid] = score
local guildScores = nil
-- gid, time
local counter = nil
local function addBridgeScore(gid, amount)
local amount = amount or 1
db.query(string.format("UPDATE `guilds` SET `bridge` = `bridge` + %i WHERE `id` = %i;", amount, gid))
if guildScores[gid] then
guildScores[gid] = guildScores[gid] + amount
else
guildScores[gid] = amount
end
end
local function finishCurrentCounter()
if not(counter) then return true end
local amount = math.floor(counter[2] / 60)
if amount > 0 then
addBridgeScore(counter[1], amount)
end
counter = nil
end
local config = {
convertCounter = function(t) return math.floor(t / 60) end,
convertScore = function(t) return t end,
color = COLOR_TEAL,
showNoGuild = true
}
local function showCounter(cid, gid)
local pos = getThingPos(cid)
local t = config.convertCounter(counter[2])
if guildScores[gid] then
t = t + config.convertScore(guildScores[gid])
end
if t > 0 then
doSendAnimatedText(pos, t, config.color)
end
end
local globalevent = GlobalEvent("BridgeScores")
function globalevent.onThink(interval)
if not guildScores then
guildScores = { }
local res = db.storeQuery("SELECT `id`, `bridge` FROM `guilds`;")
if not res then
repeat
guildScores[res:getDataInt("id")] = res:getDataInt("bridge")
until not(res:next())
res:free()
end
end
local things = { }
for i = 1, #tiles do
local thing = getTopCreature(tiles[i])
if thing.uid > 0 and isPlayer(thing.uid) then
thing = thing.uid
else
thing = nil
end
table.insert(things, thing)
end
local lastThing = nil
for i = #things, 1, -1 do
local tmp = things[i]
if tmp then
lastThing = tmp
break
end
end
if not lastThing then
finishCurrentCounter()
return true
end
local gid = getPlayerGuildId(lastThing)
if not gid then
finishCurrentCounter()
if config.showNoGuild then
doSendAnimatedText(getThingPos(lastThing), "No Guild", config.color)
end
return true
end
if not(counter) then
counter = {gid, 0}
showCounter(lastThing, gid)
return true
end
if gid ~= counter[1] then
finishCurrentCounter()
counter = {gid, 0}
else
counter[2] = counter[2] + 1
end
showCounter(lastThing, gid)
return true
end
globalevent:interval(2000) -- will be executed every 1000ms
globalevent:register()