• 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 Lever that counts time.

DukeeH

Active Member
Joined
Dec 6, 2010
Messages
550
Solutions
3
Reaction score
39
I'm trying to make a system, and a part of my idea, would be a lever, that can be pushed by the members of 4 different guilds.

If Guild A member pushes the lever, it starts counting time for his guild.
If Guild B goes to this lever and clicks it, it will stop Guild A time, and start counting for his.
If Guild A goes to it again, and clicks, it will return to his paused time, and continue, not restart.
By the end, who has more time, wins.

There will be 4 guilds, and only one lever for all.

I was thinking about a storage for each guild, and ostime comparation, but it's a bit hard for me to think of everything.

If someone can help me with a way, or the script, i'd be thankful.

It's OTX2, 0.3.7 based.
 
Last edited:
Solution
5 global storages.

1 for each guild, 1 for lever.

when click lever, change lever global storage to 1,2,3,4 depending on guild that touched it.

in onThink event, add +1 to the total of the guild global storage that's associated with that number.

done
5 global storages.

1 for each guild, 1 for lever.

when click lever, change lever global storage to 1,2,3,4 depending on guild that touched it.

in onThink event, add +1 to the total of the guild global storage that's associated with that number.

done
 
Solution
5 global storages.

1 for each guild, 1 for lever.

when click lever, change lever global storage to 1,2,3,4 depending on guild that touched it.

in onThink event, add +1 to the total of the guild global storage that's associated with that number.

done
Done something like this and i'm currently testing, it worked.
How to compare those 4 storages on the end to define the winner?
 
Done something like this and i'm currently testing, it worked.
How to compare those 4 storages on the end to define the winner?
Just loop through the 4 storages and store the value in a variable if it's higher then the previous score recorded.
 
Done something like this and i'm currently testing, it worked.
How to compare those 4 storages on the end to define the winner?

This might not be the right function calls, its more of a pseudo example.

This is a simple way to get track of who got the highest "score"

Lua:
local winner = 0
local winnerScore = 0
local guildStorages =
{
    [1] = 1234,
    [2] = 1235,
    [3] = 1236,
    [4] = 1237
}

for i, #guildStorages then
    if getstorage(guildStorage[i]) > winnerScore then
        winnerScore = getstorage(guildStorages[i])
        winner = guildStorages[i]
    end
end
 
This might not be the right function calls, its more of a pseudo example.

This is a simple way to get track of who got the highest "score"

Lua:
local winner = 0
local winnerScore = 0
local guildStorages =
{
    [1] = 1234,
    [2] = 1235,
    [3] = 1236,
    [4] = 1237
}

for i, #guildStorages then
    if getstorage(guildStorage[i]) > winnerScore then
        winnerScore = getstorage(guildStorages[i])
        winner = guildStorages[i]
    end
end
Just loop through the 4 storages and store the value in a variable if it's higher then the previous score recorded.

Got this part okay.
Thanks both of you!

One more question.

Why if I use this:
Lua:
wzGuildName = {
getGuildName(getGlobalStorageValue(050521)),
getGuildName(getGlobalStorageValue(050522)),
getGuildName(getGlobalStorageValue(050523)),
getGuildName(getGlobalStorageValue(050524))
}
On a lib, and on script I use this:
Lua:
wzGuildName[1]

I'm getting:
data/globalevents/scripts/warzoneOpen.lua:9: attempt to concatenate a boolean value

But If I use
Lua:
getGuildName(getGlobalStorageValue(050521))
On script, it works?

I'm trying to make it cleaner.
 
Got this part okay.
Thanks both of you!

One more question.

Why if I use this:
Lua:
wzGuildName = {
getGuildName(getGlobalStorageValue(050521)),
getGuildName(getGlobalStorageValue(050522)),
getGuildName(getGlobalStorageValue(050523)),
getGuildName(getGlobalStorageValue(050524))
}
On a lib, and on script I use this:
Lua:
wzGuildName[1]

I'm getting:


But If I use
Lua:
getGuildName(getGlobalStorageValue(050521))
On script, it works?

I'm trying to make it cleaner.

I would avoid having a global variable like that, just do something like this getGuildName(getGlobalStorageValue(guildStorages[1]))
if you want it to be less typing you could make a local function in the wz script

Lua:
local function WZGuildName(index)
    return getGuildName(getGlobalStorageValue(guildStorages[index]))
end

then you could call the function inside the script by simply typing this when you want the guild name
Lua:
WZGuildName(1)

Im not sure what getGuildName(...) needs for its parameters, it should be some kind of guild id.
and if you input a storageValue that isnt a valid guild id you would get errors
 
I would avoid having a global variable like that, just do something like this getGuildName(getGlobalStorageValue(guildStorages[1]))
if you want it to be less typing you could make a local function in the wz script

Lua:
local function WZGuildName(index)
    return getGuildName(getGlobalStorageValue(guildStorages[index]))
end

then you could call the function inside the script by simply typing this when you want the guild name
Lua:
WZGuildName(1)

Im not sure what getGuildName(...) needs for its parameters, it should be some kind of guild id.
and if you input a storageValue that isnt a valid guild id you would get errors
Yes, it was guild id, I changed your function a bit and it worked.
Thank you so much once again.
I'll continue with the system, anything can I reply here?
 
Yes, it was guild id, I changed your function a bit and it worked.
Thank you so much once again.
I'll continue with the system, anything can I reply here?
Feel free to tag or pm me, im not available all the time. But if i do have time i like to help out, especially when someone is trying to build a system himself :)
 
Back
Top