churchill Posted August 15, 2008 Share Posted August 15, 2008 (edited) https://community.multitheftauto.com/index.php?p= ... ils&id=203 This is mainly a replacement for the buggy getAccountData/setAccountData, but can also be used for storing data against other objects as well. Data can be stored in SQL or XML, which is configurable by the admin user using a console command (/datamanager XML or /datamanager SQL, while logged in as admin.) This might be useful to anyone who wants to do simple data storage along the lines of getAccountData/setAccountData without the fear of losing data when the server shuts down, but can't be bothered creating their own SQL Lite or XML system. When in XML storage mode, there are no checks to ensure your object and keys are named in a valid way for XML, so just don't do it! I know I should add some validation on the data being entered to ensure it doesn't happen, but for now just read up on XML element naming rules to find out what the rules are, or leave it in SQL mode if you have any bug reports or suggestions, feel free to post in here or comment on the resource in the resource library. Available exported functions (also available in HTTP): getData(objectid, key) returns false if an object/key can't be found, or a string value if it can. setData(objectid, key, value) returns false if the value couldn't be added/updated, or true if successful. removeData(objectid,key) returns false if the key could not be removed, or true if successful. I created the following code in another resource called "DMTester" to run the XML and SQL tests, it might be useful to look at if you plan to use this resource. There's also an example in the readme.txt file that comes with the resource. resourcename = getResourceName(getThisResource()) -- ensures that our data doesn't overwrite some other resources data tablename = "Players" uniqueplayerid = "1" -- ordinarily would be a player's account name, so that it's unique to that player -- this ensures that what we're storing is going to be unique to our resource, storing player data for player 1. uniquename = resourcename .. "_" .. tablename .. "_" .. uniqueplayerid keyfield = "money" -- we're going to store the bank balance for player 1. -- reduces the call line size a little function DMcall(functionName, name, key, value) return call(getResourceFromName("datamanager"), functionName, name, key, value) end function doTests() -- Check for data for first time outputChatBox("first test - check for data ('" .. uniquename .. "','" .. keyfield .. "')") result = DMcall("getData", uniquename, keyfield) outputChatBox("data exists = " .. tostring(result)) -- Write Data first time outputChatBox("second test - write data ('" .. uniquename .. "','" .. keyfield .. "','0')") result = DMcall("setData", uniquename, keyfield, "0") outputChatBox("test result = " .. tostring(result)) -- Check data value has been inserted outputChatBox("third test - check for data ('" .. uniquename .. "','" .. keyfield .. "')") result = DMcall("getData", uniquename, keyfield) outputChatBox("data exists = " .. tostring(result)) --Update value outputChatBox("fourth test - write data ('" .. uniquename .. "','" .. keyfield .. "','500')") result = DMcall("setData", uniquename, keyfield,"500") outputChatBox("test result = " .. tostring(result)) --Check data value has updated outputChatBox("fifth test - check for data ('" .. uniquename .. "','" .. keyfield .. "')") result = DMcall("getData", uniquename, keyfield) outputChatBox("data exists = " .. tostring(result)) --remove data value outputChatBox("sixth test - remove data ('" .. uniquename .. "','" .. keyfield .. "')") result = DMcall("removeData", uniquename, keyfield) outputChatBox("test result = " .. tostring(result)) --Check data value has gone outputChatBox("seventh test - check for data ('" .. uniquename .. "','" .. keyfield .. "')") result = DMcall("getData", uniquename, keyfield) outputChatBox("data exists = " .. tostring(result)) end addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()),doTests) Edited November 17, 2010 by Guest Link to comment
DakiLLa Posted November 6, 2008 Share Posted November 6, 2008 so, is anybody using this resource? and can anybody post there small example how to save..hmm, players money, when they will be disconnect from the server? it will be usefull to understand functions of this resource and how to realise them. Link to comment
Scarface Posted November 6, 2008 Share Posted November 6, 2008 so, is anybody using this resource? and can anybody post there small example how to save..hmm, players money, when they will be disconnect from the server? it will be usefull to understand functions of this resource and how to realise them. well you just bumped an over years old topic congragiolations! anyways i tried once but never figured it out but whats the point anyway, DP shall be soon here Link to comment
Willy Posted November 6, 2008 Share Posted November 6, 2008 the topic is less than 3 months old, and i wouldn't call it a bump - i'd call it asking for help... and wtf are "congragiolations"? Link to comment
Brophy Posted November 6, 2008 Share Posted November 6, 2008 I've actually been watching you scarface1994, you do seem to be increasing your posting lately and a few have been useless replies, even if someone does bump an old topic with something useless, I will clear it up, Posting a reply "YOU JUST BUMPED AN OLD TOPIC" does not help and does not contribute to the thread at all. You do not need to go about "saying you bumped a topic", "stop spamming" or reply to someone saying they are sorry for breaking the forum rules as thats our job (moderators), We have the report button if you need to report someone for breaking rules and we have a PM system. P.S. Willy is right, the topic is less than 3 months old and its a guy asking for help concerning a resource in the resource's actual thread and please just read this reply, you do not need to reply to it Link to comment
Mr.Hankey Posted November 7, 2008 Share Posted November 7, 2008 just a simple example of how it should work: function leave () local result = call(getResourceFromName("datamanager"), "setData", tostring(getPlayerMoney(source))) if result == true then outputChatBox ("Money amount successfully saved.") else outputChatBox ("Failed to save the data.") end end addEventHandler ("onPlayerQuit", getRootElement(), leave) Link to comment
Killerzz Posted October 17, 2010 Share Posted October 17, 2010 I want to know where does things gets saved by setAccountData? Link to comment
dzek (varez) Posted October 17, 2010 Share Posted October 17, 2010 this is almost 3 years old topic! better dont use this thing cause its probably for DP version of mta or at least outdated. from what i see nobody needs it before, nobody should need it now.. 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