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

TFS 1.X+ Question about Storing Info

zxmatzx

Advanced OT User
Joined
Dec 1, 2010
Messages
312
Solutions
27
Reaction score
155
Location
Brazil
GitHub
Mateuso8
Hello,
I'm developing a pet system, and don't sure how to store player pet info, i think using Storing Info to store a table with all pet info and request the data in onLogin and store in a global table like:
Lua:
PETS = {[playerGuid] = StoringInfoRequestedData}

function Player:requestPetInfo()
    if PETS[self:getGuid()] then
        return PETS[self:getGuid()]
    else
        return self:getSpecialStorage(storageId)
    end
end
and in onLogout, i send back the data using player:setSpecialStorage(storageId, PETS[player:getGuid()]) and maybe a onThink event with a certain interval to save the data or when a event trigger(pet level up, pet evolution, etc) to prevent data lost if server crash or something. What do you think? Have some better idea?

--Not sure if right section is suport or discution, sorry if i did wrong.
 
Solution
The thing is, if your server does crash it'll retain pet info and roll back everything else. I think it would be better to just include pet saves when the server runs a global save and in onLogout, that way all data is synced. Otherwise if you're okay with pets being out of sync with player info use an onThink event for the pet and let it run save at an interval.

Also, that code can be shortened to:
Lua:
function Player:requestPetInfo()
    return PETS[self:getGuid()] or self:getSpecialStorage(storageId)
end
The thing is, if your server does crash it'll retain pet info and roll back everything else. I think it would be better to just include pet saves when the server runs a global save and in onLogout, that way all data is synced. Otherwise if you're okay with pets being out of sync with player info use an onThink event for the pet and let it run save at an interval.

Also, that code can be shortened to:
Lua:
function Player:requestPetInfo()
    return PETS[self:getGuid()] or self:getSpecialStorage(storageId)
end
 
Solution
The thing is, if your server does crash it'll retain pet info and roll back everything else. I think it would be better to just include pet saves when the server runs a global save and in onLogout, that way all data is synced. Otherwise if you're okay with pets being out of sync with player info use an onThink event for the pet and let it run save at an interval.

Also, that code can be shortened to:
Lua:
function Player:requestPetInfo()
    return PETS[self:getGuid()] or self:getSpecialStorage(storageId)
end
Yeah, make sense and how about the save info method? U would do in another way?
 
Back
Top