diff --git a/server/classes/datastore.lua b/server/classes/datastore.lua index acef8514..de95b2cf 100644 --- a/server/classes/datastore.lua +++ b/server/classes/datastore.lua @@ -1,3 +1,15 @@ +function stringsplit(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t={} ; i=1 + for str in string.gmatch(inputstr, "([^"..sep.."]+)") do + t[i] = str + i = i + 1 + end + return t +end + function CreateDataStore(name, owner, data) local self = {} @@ -13,8 +25,42 @@ function CreateDataStore(name, owner, data) self.save() end - self.get = function(key) - return data[key] + self.get = function(key, i) + + local path = stringsplit(key, '.') + local obj = self.data + + for i=1, #path, 1 do + obj = obj[path[i]] + end + + if i == nil then + return obj + else + return obj[i] + end + + end + + self.count = function(key, i) + + local path = stringsplit(key, '.') + local obj = self.data + + for i=1, #path, 1 do + obj = obj[path[i]] + end + + if i ~= nil then + obj = obj[i] + end + + if obj == nil then + return 0 + else + return #obj + end + end self.save = function() diff --git a/server/main.lua b/server/main.lua index e4df6157..83644fae 100644 --- a/server/main.lua +++ b/server/main.lua @@ -138,3 +138,4 @@ AddEventHandler('esx:playerLoaded', function(source) xPlayer.set('dataStores', dataStores) end) +