• 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 Creating a global table to register stuff in

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,795
Solutions
581
Reaction score
5,359
I use 0.3.7, but TFS version doesn't really matter for this.

Let's say I want to register a table for each creature that touches a specific tile, but only from server save to server save.

If creature touches x tile, run movement script and register as true in global table for only that creature.
At the same time, register + 1 to how many times that cid has stepped on the tile.

So, basically once there's 3 people who have touched the tile, it would look like this or this..

Code:
--(1)
table_x = {
    [111111111] = {1}, -- hit 1 time
    [222222222] = {8}, -- hit 8 times
    [333333333] = {3}, -- hit 3 times
}

--(2)
table_x = {
    [111111111] = {true, 1}, -- hit 1 time
    [222222222] = {true, 8}, -- hit 8 times
    [333333333] = {true, 3}, -- hit 3 times
}



Okay.. after writing it I realise #1 makes more sense, as you can just assume that it's true, unless you want it to change from true/false, which then makes #2 make more sense.

In either case, I want to do method #2, but not really sure how.

-- My thinking is we create the table like this..?
Code:
if not table_x[cid] then
    table.insert[table_x, cid]
    table.insert[table_x[cid], true]
    table.insert[table_x[cid], 1]
    true
end

-- after this we can just alter the newly-existing table.. like this? (I'm just guessing.. cuz I'm not home to randomly try stuff. Dx)
Code:
if table_x[cid][1] == true then
    table_x[cid][1] = false
else
    table_x[cid][1] = true
end
if table_x[cid][2] == 9 then
    table_x[cid][2] = 0
else
    table_x[cid][2] = table_x[cid][2] + 1
end


Can someone guide me in the right direction?
 
do you want it to be saved with cid or guid? guid is a better way to store that information if you want the actual total of steps
i used guid here:

Code:
function onStepIn(args)
    local guid = getPlayerGUID(cid)
    t[guid] = (t[guid] or 0) + 1 -- add 1 if index already exists, otherwise assign it to 1
    return true
end
 
Last edited:
Well I have no idea what guid is. xD
I guess I'm just confused on how to add new stuff to an empty table. lol
Basically.. I want to make a global table that will store random information, and sort it based on cid, for the index?
lol
 
Well I have no idea what guid is. xD
I guess I'm just confused on how to add new stuff to an empty table. lol
Basically.. I want to make a global table that will store random information, and sort it based on cid, for the index?
lol
why cid if you want the total number of steps for that player?
guid is the player id in database like 1 is account manager for you 2 is the secnd character etc
what i posted should work fine
you can sort it with
Code:
table.sort(t, function(a, b) return a < b end)
 
Maybe I'm stupid, but I can never understand your explanations.
I'll just do my trial and error approach.
I know what I want to do, just don't know how to use empty tables properly.
 
Yeah thanks. I never thought to do that myself.
What would I do without you.
alright buddy
you're the one asking for help cause you don't know how to assign a value to a table index
what happened to you leaving otland?
 
Well I have no idea what guid is. xD
like he said
guid is the player id in database which is unique to every player ( every player have a ID and that ID belongs to only one player )
CID on the other hand is something generated when a player/creature login and it change, so in the long term 2 or more diffferents creature can hand the same CID.
 
Last edited:
Back
Top