Al3grab Posted September 23, 2015 Share Posted September 23, 2015 Which one is the best for a medium size of data and for a better performance ? Link to comment
KariiiM Posted September 23, 2015 Share Posted September 23, 2015 Which one is the best for a medium size of data and for a better performance ? SQLite is perfect and with good execution, because it's able to get more size of data plus it's faster than other ways, it's creating an unique file and store all the things into it, instead of creating one for each resource. About XML it's just for saving normal stuffs but i recommend you to use sqlite in case you have more stuffs to save. Also you can use MySQL it's similar to SQLite but the advantage about MySQL is that you can use phpMyAdmin or any other PHP file and display the data to a web page. It's much more functional since, if you need, for example, to control your server from the web or from a smart phone, it's much easier to implement with MySQL than with SQLite, SQLite create a file complied so you can't manage it not like Mysql, but it still your choice. Link to comment
Al3grab Posted September 23, 2015 Author Share Posted September 23, 2015 Which one is the best for a medium size of data and for a better performance ? SQLite is perfect and with good execution, because it's able to get more size of data plus it's faster than other ways, it's creating an unique file and store all the things into it, instead of creating one for each resource. About XML it's just for saving normal stuffs but i recommend you to use sqlite in case you have more stuffs to save. Also you can use MySQL it's similar to SQLite but the advantage about MySQL is that you can use phpMyAdmin or any other PHP file and display the data to a web page. It's much more functional since, if you need, for example, to control your server from the web or from a smart phone, it's much easier to implement with MySQL than with SQLite, SQLite create a file complied so you can't manage it not like Mysql, but it still your choice. I have been using xml and file since forever and they're just fine. I was just wondering if using other methods would improve the performance of the script Link to comment
KariiiM Posted September 23, 2015 Share Posted September 23, 2015 I have been using xml and file since forever and they're just fine. I was just wondering if using other methods would improve the performance of the script Yes it will Link to comment
#meS Posted September 23, 2015 Share Posted September 23, 2015 Which one is the best for a medium size of data and for a better performance ? SQLite is perfect and with good execution, because it's able to get more size of data plus it's faster than other ways, it's creating an unique file and store all the things into it, instead of creating one for each resource. About XML it's just for saving normal stuffs but i recommend you to use sqlite in case you have more stuffs to save. Also you can use MySQL it's similar to SQLite but the advantage about MySQL is that you can use phpMyAdmin or any other PHP file and display the data to a web page. It's much more functional since, if you need, for example, to control your server from the web or from a smart phone, it's much easier to implement with MySQL than with SQLite, SQLite create a file complied so you can't manage it not like Mysql, but it still your choice. I have been using xml and file since forever and they're just fine. I was just wondering if using other methods would improve the performance of the script Just asking how do you save with using file? Example please Link to comment
Al3grab Posted September 23, 2015 Author Share Posted September 23, 2015 Just asking how do you save with using file? Example please Use fileWrite to write what you want, if it's a table use toJSON to convert it to a string; fileRead to read the file again; fromJSON will get your table back Oh and don't forget to flush and close the file each time you write into it Link to comment
#meS Posted September 23, 2015 Share Posted September 23, 2015 i'm trying to save pass word but not working code: function saveunp() if not (Muser) then if not (Mpass) then Muser = fileCreate("user.txt", true) Mpass = fileCreate("pass.txt", true) Xuser = fileOpen("user.txt", true) Xpass = fileOpen("pass.txt", true) fileWrite(Xuser, guiGetText(LOGIN_edit[1])) fileWrite(Xpass, guiGetText(LOGIN_edit[2])) fileClose(Muser) fileClose(Mpass) end end end addEvent("onClientPlayerLogin",true) addEventHandler("onClientPlayerLogin",root,saveunp) function putunp() Buser = fileOpen("user.txt", true) Bpass = fileOpen("pass.txt", true) user = fileRead(Buser, 500) pass = fileRead(Bpass, 500) if (Buser) then guiSetText(LOGIN_edit[1],user) guiSetText(LOGIN_edit[2],pass) fileClose(Buser) fileClose(Bpass) end end addEventHandler("onClientResourceStart",resourceRoot,putunp) Link to comment
Al3grab Posted September 23, 2015 Author Share Posted September 23, 2015 I made these functions long time ago to simplify things function FILEGetFile(name) if fileExists("Data/"..name..".data") then return fileOpen("Data/"..name..".data") else return fileCreate("Data/"..name..".data") end end function FILESet(what,to) if what and to then local file = FILEGetFile(what) if file then if fileExists("Data/"..what..".data") then fileClose(file) fileDelete("Data/"..what..".data") end local file = FILEGetFile(what) if file then fileWrite(file,to) fileFlush(file) fileClose(file) end end end end function FILEGet(what) if what then local file = FILEGetFile(what) if file then local data while not fileIsEOF(file) do if data then data = data..fileRead(file, 500) else data = fileRead(file, 500) end end fileClose(file) -- return data or false end end end function setData(data,key) if ( data and key ) then return FILESet(data,key) end end function getData(data) if ( data ) then return FILEGet(data) or false end end Use them like this PasswordTable = {"Username","Password"} -- or however you want to store your data .. function savePassword() setData("LoginInfo",toJSON(PasswordTable)) end function getPassword() local pTable = fromJSON(getData("LoginInfo")) or {} if pTable and #pTable > 0 then return pTable[1],pTable[2] -- user,password else return -- no password saved end end much more like setElementData right Link to comment
#meS Posted September 23, 2015 Share Posted September 23, 2015 so it should be like this still doesn't work PasswordTable = {guiGetText(LOGIN_edit[1]),guiGetText(LOGIN_edit[2])} -- or however you want to store your data .. function savePassword() setData("LoginInfo",toJSON(PasswordTable)) end addEvent("onClientPlayerLogin",true) addEventHandler("onClientPlayerLogin",root,savePassword) function getPassword() local pTable = fromJSON(getData("LoginInfo")) or {} if pTable and #pTable > 0 then guiSetText(LOGIN_edit[1],pTable[1]) guiSetText(LOGIN_edit[2],pTable[2]) return pTable[1],pTable[2] -- user,password else return end end addEventHandler("onClientResourceStart",root,getPassword) Link to comment
Al3grab Posted September 23, 2015 Author Share Posted September 23, 2015 The 'PasswordTable' table I wrote was just for example, function savePassword() setData("LoginInfo",toJSON({guiGetText(LOGIN_edit[1]),guiGetText(LOGIN_edit[2])})) end addEvent("onClientPlayerLogin",true) addEventHandler("onClientPlayerLogin",root,savePassword) function getPassword() local pTable = fromJSON(getData("LoginInfo")) or {} if pTable and #pTable > 0 then guiSetText(LOGIN_edit[1],pTable[1]) guiSetText(LOGIN_edit[2],pTable[2]) return pTable[1],pTable[2] -- user,password else return end end addEventHandler("onClientResourceStart",root,getPassword) Btw how are you triggering the 'onClientPlayerLogin' event ? Link to comment
#meS Posted September 23, 2015 Share Posted September 23, 2015 ^^ server side function trr() triggerClientEvent(source,"onClientPlayerLogin",source) end addEventHandler("onPlayerLogin",root,trr) still not working Link to comment
Al3grab Posted September 23, 2015 Author Share Posted September 23, 2015 Everything seems fine, do you get any error @ /debugscript 3 ? Link to comment
Al3grab Posted September 23, 2015 Author Share Posted September 23, 2015 Make sure that your edit box is already created when the event is triggered Link to comment
#meS Posted September 23, 2015 Share Posted September 23, 2015 Make sure that your edit box is already created when the event is triggered And how to do that? Link to comment
SkittlesAreFalling Posted September 23, 2015 Share Posted September 23, 2015 Use JSON: SavePlayer = function(player) if getElementType(player) ~= "player" then return false; end local data = {}; data.health = getElementHealth(player); data.armour = getPedArmor(player); data.money = getPlayerMoney(player); data.position = {}; data.position.dimension = getElementDimension(player); data.position.interior = getElementInterior(player); data.position.x, data.position.y, data.position.z = getElementPosition(player); data.position.rz, data.position.ry, data.position.rx = getElementRotation(player); data.isAdmin = getElementData(player, "isAdmin"); local file; if fileExists("Players\\" .. getPlayerName(player) .. ".json") == false then file = fileCreate("Players\\" .. getPlayerName(player) .. ".json"); else file = fileOpen("Players\\" .. getPlayerName(player) .. ".json"); end if file == false then return false; end fileWrite(file, toJSON(data, true)); fileClose(file); return true end LoadPlayer = function(player) if getElementType(player) ~= "player" then return false; end if fileExists("Players\\" .. getPlayerName(player) .. ".json") == false then return false; end local file = fileOpen("Players\\" .. getPlayerName(player) .. ".json", true); if file == false then return false; end local data = fromJSON(fileRead(file, fileGetSize(file))); fileClose(file); setElementHealth(player, data.health); setPedArmor(player, data.armour); setPlayerMoney(player, data.money, true); setElementDimension(player, data.position.dimension); setElementInterior(player, data.position.interior); setElementPosition(player, data.position.x, data.position.y, data.position.z); setElementRotation(player, data.position.rx, data.position.ry, data.position.rz); setElementData(player, "isAdmin", data.isAdmin); return true; end SavePlayer(player) - Saves Health, Armour, Position, and a custom value to ResourceName/Accounts/playerName.json. LoadPlayer(player) - Loads Health, Armour, Position, and a custom value from ResourceName/Accounts/playerName.json if exists. Link to comment
Al3grab Posted September 23, 2015 Author Share Posted September 23, 2015 Make sure that your edit box is already created when the event is triggered And how to do that? Send me the script and I'll check it for you Link to comment
#meS Posted September 25, 2015 Share Posted September 25, 2015 nvm i'm an idiot i didn't copy the other code : - ) Use JSON: SavePlayer = function(player) if getElementType(player) ~= "player" then return false; end local data = {}; data.health = getElementHealth(player); data.armour = getPedArmor(player); data.money = getPlayerMoney(player); data.position = {}; data.position.dimension = getElementDimension(player); data.position.interior = getElementInterior(player); data.position.x, data.position.y, data.position.z = getElementPosition(player); data.position.rz, data.position.ry, data.position.rx = getElementRotation(player); data.isAdmin = getElementData(player, "isAdmin"); local file; if fileExists("Players\\" .. getPlayerName(player) .. ".json") == false then file = fileCreate("Players\\" .. getPlayerName(player) .. ".json"); else file = fileOpen("Players\\" .. getPlayerName(player) .. ".json"); end if file == false then return false; end fileWrite(file, toJSON(data, true)); fileClose(file); return true end LoadPlayer = function(player) if getElementType(player) ~= "player" then return false; end if fileExists("Players\\" .. getPlayerName(player) .. ".json") == false then return false; end local file = fileOpen("Players\\" .. getPlayerName(player) .. ".json", true); if file == false then return false; end local data = fromJSON(fileRead(file, fileGetSize(file))); fileClose(file); setElementHealth(player, data.health); setPedArmor(player, data.armour); setPlayerMoney(player, data.money, true); setElementDimension(player, data.position.dimension); setElementInterior(player, data.position.interior); setElementPosition(player, data.position.x, data.position.y, data.position.z); setElementRotation(player, data.position.rx, data.position.ry, data.position.rz); setElementData(player, "isAdmin", data.isAdmin); return true; end SavePlayer(player) - Saves Health, Armour, Position, and a custom value to ResourceName/Accounts/playerName.json. LoadPlayer(player) - Loads Health, Armour, Position, and a custom value from ResourceName/Accounts/playerName.json if exists. one more question hmm players can edit the things from client place dunno how to say it .. or they can't? Link to comment
TAPL Posted September 25, 2015 Share Posted September 25, 2015 If you used client side xml then yes they can edit it as client side xml will be stored on players hard disk. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now