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

Globalevent with storage comparison problem

jornthomas

New Member
Joined
Dec 16, 2013
Messages
14
Reaction score
1
TFS 1.2

We have this function on our server, where you pull 1 of 3 levers to set a global storage in db where each lever has its dedicated storage number.
What we need, is a global event to check which of the global storages that have the highest value, eg:

Lever 1 = 3201
Lever 2 = 3202
Lever 3 = 3203

This global storage increase its storage value by +1 each time it is used, but somehow I need to get the highest value back to do an action in-game.

We have tried to wrap our heads around this, without getting anywhere, so we kind of have a blank sheet by now. Really hope that somebody out there get the thought and might point us in the right way.



This sql query:
Lua:
SELECT * FROM `global_storage` ORDER BY `key` DESC
returns this result:
value.PNG



In advance, thanks!
 
Last edited:
Solution
Thanks for your reply,but adding this to interval function in globalevent,we get this in return;


Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/values.lua:onThink
data/globalevents/scripts/values.lua:10: attempt to compare number with string
stack traceback:
        [C]: in function '__lt'
        data/globalevents/scripts/values.lua:10: in function <data/globalevents/scripts/values.lua:7>
[Error - GlobalEvents::think] Failed to execute event: Values


Current globalevent script looks now like this:


Lua:
    local global_storages = {3201, 3202, 3203, 3204, 3205}
local highest_value, highest_storage = 0, 0

function onThink(interval)
for i = 1, #global_storages do
    local temp_storage =...
Lua:
local global_storages = {3201, 3202, 3203, 3204, 3205}
local highest_value, highest_storage = 0, 0

for i = 1, #global_storages do
    local temp_storage = getGlobalStorageValue(global_storages[i])
    if temp_storage > highest_value then
        highest_value = temp_storage
        highest_storage = global_storages[i]
    end
end

print("The highest storage is " .. highest_storage .. " with a value of " .. highest_value)
 
Lua:
local global_storages = {3201, 3202, 3203, 3204, 3205}
local highest_value, highest_storage = 0, 0

for i = 1, #global_storages do
    local temp_storage = getGlobalStorageValue(global_storages[i])
    if temp_storage > highest_value then
        highest_value = temp_storage
        highest_storage = global_storages[i]
    end
end

print("The highest storage is " .. highest_storage .. " with a value of " .. highest_value)


Thanks for your reply,but adding this to interval function in globalevent,we get this in return;


Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/values.lua:onThink
data/globalevents/scripts/values.lua:10: attempt to compare number with string
stack traceback:
        [C]: in function '__lt'
        data/globalevents/scripts/values.lua:10: in function <data/globalevents/scripts/values.lua:7>
[Error - GlobalEvents::think] Failed to execute event: Values


Current globalevent script looks now like this:


Lua:
    local global_storages = {3201, 3202, 3203, 3204, 3205}
local highest_value, highest_storage = 0, 0

 function onThink(interval)
for i = 1, #global_storages do
    local temp_storage = getGlobalStorageValue(global_storages[i])
    if temp_storage > highest_value then
        highest_value = temp_storage
        highest_storage = global_storages[i]
    end
end
    print("The highest storage is " .. highest_storage .. " with a value of " .. highest_value)
end
 
Thanks for your reply,but adding this to interval function in globalevent,we get this in return;


Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/values.lua:onThink
data/globalevents/scripts/values.lua:10: attempt to compare number with string
stack traceback:
        [C]: in function '__lt'
        data/globalevents/scripts/values.lua:10: in function <data/globalevents/scripts/values.lua:7>
[Error - GlobalEvents::think] Failed to execute event: Values


Current globalevent script looks now like this:


Lua:
    local global_storages = {3201, 3202, 3203, 3204, 3205}
local highest_value, highest_storage = 0, 0

function onThink(interval)
for i = 1, #global_storages do
    local temp_storage = getGlobalStorageValue(global_storages[i])
    if temp_storage > highest_value then
        highest_value = temp_storage
        highest_storage = global_storages[i]
    end
end
    print("The highest storage is " .. highest_storage .. " with a value of " .. highest_value)
end
Lua:
local global_storages = {3201, 3202, 3203, 3204, 3205}
local highest_value, highest_storage = 0, 0

function onThink(interval)
    for i = 1, #global_storages do
        local temp_storage = tonumber(getGlobalStorageValue(global_storages[i]))
        if temp_storage > highest_value then
            highest_value = temp_storage
            highest_storage = global_storages[i]
        end
    end
    print("The highest storage is " .. highest_storage .. " with a value of " .. highest_value)
    return true
end
 
Solution
Lua:
local global_storages = {3201, 3202, 3203, 3204, 3205}
local highest_value, highest_storage = 0, 0

function onThink(interval)
    for i = 1, #global_storages do
        local temp_storage = tonumber(getGlobalStorageValue(global_storages[i]))
        if temp_storage > highest_value then
            highest_value = temp_storage
            highest_storage = global_storages[i]
        end
    end
    print("The highest storage is " .. highest_storage .. " with a value of " .. highest_value)
    return true
end

Totally fixed it. We gotta read us up a bit more on LUA, giggles! Thanks alot, dude! :D :D
 
Back
Top