Kapil Posted May 22, 2008 Share Posted May 22, 2008 (edited) Description: With this you can save and load your players stats, information etc, whenever, whatever, wherever you want, even after server restarts. Script Feature - createData( name ) - existData( name ) - setData( name , key , value ) - getData( name , key , value ) Usage Guide - Firstly, copy all the code into the script you want to use it. - Once you have done, you can now use them just like you use functions. - Do createData( name ) to create a new user data , where name is users name. - Do existData( name ) to check if a user data exist, where name is users name. - Do setData( name , key , value ) to set a value for a existing user data key or a new user data key. - Do getData( name , key ) to get the value of a user data key. Examples createData( name ) local name = getClientlName( source ) createData( name ) existData( name ) local name = getClientName( source ) if not existData( name ) then createData( name ) end setData( name , key , value) local name = getClientName( source ) local health = getElementHealth( source ) setData( name , "health" , tostring(health) ) getData( name , key ) local name = getClientName( source ) local health = tonumber(getData( name , "health" )) setElementHealth( source , health ) Non-Sense I had to make a user data storage system for KIHC, it took a long time to make it, so i thought i would release it. Source function onLoad( ) if not xmlLoadFile( "database.xml" ) then xmlSaveFile( xmlCreateFile( "database.xml" , "main" ) ) end end addEventHandler( "onGamemodeStart" , getRootElement() , onLoad ) function createData( name ) local file = xmlLoadFile( "database.xml" ) local node = xmlCreateSubNode( file, "account" ) xmlNodeSetAttribute( node, "name" , name ) xmlSaveFile( file ) if node then return true else return false end end function existData( name ) local file = xmlLoadFile( "database.xml" ) local count = 0 local found = 1 local node = 2 while found ~= name do node = xmlFindSubNode( file, "account" , count ) if not node then return false end found = xmlNodeGetAttribute( node, "name" ) count = count + 1 if not found then return false end end return true end function setData( name , key , value) local file = xmlLoadFile( "database.xml" ) local count = 0 local found = 1 local node = 2 while found ~= name do node = xmlFindSubNode( file, "account" , count ) found = xmlNodeGetAttribute( node, "name" ) count = count + 1 if not found then return false end end xmlNodeSetAttribute( node, key , value ) xmlSaveFile( file ) return true end function getData( name , key ) local file = xmlLoadFile( "database.xml" ) local count = 0 local found = 1 local node = 2 while found ~= name do node = xmlFindSubNode( file, "account" , count ) found = xmlNodeGetAttribute( node, "name" ) count = count + 1 if not found then return false end end return xmlNodeGetAttribute( node , key ) end Edited May 23, 2008 by Guest Link to comment
Kapil Posted May 22, 2008 Author Share Posted May 22, 2008 (edited) Description: With this you can save and load your players stats, information etc, whenever, whatever, wherever you want, even after server restarts. Script Feature - createData( name ) - existData( name ) - setData( name , key , value ) - getData( name , key , value ) Usage Guide - Firstly, copy all the code into the script you want to use it. - Once you have done, you can now use them just like you use functions. - Do createData( name ) to create a new user data , where name is users name. - Do existData( name ) to check if a user data exist, where name is users name. - Do setData( name , key , value ) to set a value for a existing user data key or a new user data key. - Do getData( name , key ) to get the value of a user data key. Examples createData( name ) local name = getClientlName( source )createData( name ) existData( name ) local name = getClientName( source )if not existData( name ) then createData( name )end setData( name , key , value) local name = getClientName( source )local health = getElementHealth( source )setData( name , "health" , tostring(health) ) getData( name , key ) local name = getClientName( source )local health = tonumber(getData( name , "health" ))setElementHealth( source , health ) Non-Sense I had to make a user data storage system for KIHC, it took a long time to make it, so i thought i would release it. Source function onLoad( ) if not xmlLoadFile( "database.xml" ) then xmlSaveFile( xmlCreateFile( "database.xml" , "main" ) ) end endaddEventHandler( "onGamemodeStart" , getRootElement() , onLoad ) function createData( name ) local file = xmlLoadFile( "database.xml" ) local node = xmlCreateSubNode( file, "account" ) xmlNodeSetAttribute( node, "name" , name ) xmlSaveFile( file ) if node then return true else return false end end function existData( name ) local file = xmlLoadFile( "database.xml" ) local count = 0 local found = 1 local node = 2 while found ~= name do node = xmlFindSubNode( file, "account" , count ) if not node then return false end found = xmlNodeGetAttribute( node, "name" ) count = count + 1 if not found then return false end end return trueend function setData( name , key , value) local file = xmlLoadFile( "database.xml" ) local count = 0 local found = 1 local node = 2 while found ~= name do node = xmlFindSubNode( file, "account" , count ) found = xmlNodeGetAttribute( node, "name" ) count = count + 1 if not found then return false end end xmlNodeSetAttribute( node, key , value ) xmlSaveFile( file ) return trueend function getData( name , key ) local file = xmlLoadFile( "database.xml" ) local count = 0 local found = 1 local node = 2 while found ~= name do node = xmlFindSubNode( file, "account" , count ) found = xmlNodeGetAttribute( node, "name" ) count = count + 1 if not found then return false end end return xmlNodeGetAttribute( node , key )end Edited May 23, 2008 by Guest Link to comment
Ace_Gambit Posted May 22, 2008 Share Posted May 22, 2008 I have some general advice regarding data storage. It's better to use SQL instead of XML when dealing with large amounts of records or nodes. As a general rule you should try to avoid using XML as a database. Link to comment
Ace_Gambit Posted May 22, 2008 Share Posted May 22, 2008 I have some general advice regarding data storage. It's better to use SQL instead of XML when dealing with large amounts of records or nodes. As a general rule you should try to avoid using XML as a database. Link to comment
Kapil Posted May 22, 2008 Author Share Posted May 22, 2008 I have some general advice regarding data storage. It's better to use SQL instead of XML when dealing with large amounts of records or nodes. As a general rule you should try to avoid using XML as a database. rule that we should avoid xml for storage ? u must be kidding. i also heard files and much faster than sql for loading and unloading. Link to comment
Kapil Posted May 22, 2008 Author Share Posted May 22, 2008 I have some general advice regarding data storage. It's better to use SQL instead of XML when dealing with large amounts of records or nodes. As a general rule you should try to avoid using XML as a database. rule that we should avoid xml for storage ? u must be kidding. i also heard files and much faster than sql for loading and unloading. Link to comment
Ace_Gambit Posted May 22, 2008 Share Posted May 22, 2008 Actually searching in XML is slower than executing a query. I am just trying to point out that if you want to keep records of players with stats and all it is better to use SQL instead. You can always output it to an XML file in order to make it interchangeable between applications. Use XML files to store static data that is required to be loaded only once. This is just my point of view. Link to comment
Ace_Gambit Posted May 22, 2008 Share Posted May 22, 2008 Actually searching in XML is slower than executing a query. I am just trying to point out that if you want to keep records of players with stats and all it is better to use SQL instead. You can always output it to an XML file in order to make it interchangeable between applications. Use XML files to store static data that is required to be loaded only once. This is just my point of view. Link to comment
Kapil Posted May 22, 2008 Author Share Posted May 22, 2008 Actually searching in XML is slower than executing a query. I am just trying to point out that if you want to keep records of players with stats and all it is better to use SQL instead. You can always output it to an XML file in order to make it interchangeable between applications. Use XML files to store static data that is required to be loaded only once. This is just my point of view. ruied Link to comment
Kapil Posted May 22, 2008 Author Share Posted May 22, 2008 Actually searching in XML is slower than executing a query. I am just trying to point out that if you want to keep records of players with stats and all it is better to use SQL instead. You can always output it to an XML file in order to make it interchangeable between applications. Use XML files to store static data that is required to be loaded only once. This is just my point of view. ruied Link to comment
eAi Posted May 23, 2008 Share Posted May 23, 2008 Provide this as a resource With DP3, the 'call' syntax is much neater so this should work better. Link to comment
eAi Posted May 23, 2008 Share Posted May 23, 2008 Provide this as a resource With DP3, the 'call' syntax is much neater so this should work better. Link to comment
Kapil Posted May 23, 2008 Author Share Posted May 23, 2008 Provide this as a resource With DP3, the 'call' syntax is much neater so this should work better. sure thx Link to comment
Kapil Posted May 23, 2008 Author Share Posted May 23, 2008 Provide this as a resource With DP3, the 'call' syntax is much neater so this should work better. sure thx Link to comment
churchill Posted August 6, 2008 Share Posted August 6, 2008 Did this get provided as a release yet? Combined with Ace Gambit's suggestion that it's stored in SQL Lite instead of XML (which I agree with) this would have made for a nice resource until DP3 came out (which will fix the setAccountData, I hope? but even then, if DP3 still stores in XML, this might be better?) I was thinking of writing something similar anyway, so if someone has already done it, that'd save me a lot of time Link to comment
Gamesnert Posted August 6, 2008 Share Posted August 6, 2008 Hmmm... Well actually I have almost the same code, so I don't need this. It's good for starters though, and I think I'm going to start with SQL soon... Anyway, keep up the good work. Link to comment
churchill Posted August 6, 2008 Share Posted August 6, 2008 Hmmm... Well actually I have almost the same code, so I don't need this. It's good for starters though, and I think I'm going to start with SQL soon...Anyway, keep up the good work. Gamesnert: you have a resource that does this? With SQL storage? Export functions etc etc? Are you releasing it? so many questions, but it would save me some work and allow me to work on some other aspects of a game mode Link to comment
Gamesnert Posted August 6, 2008 Share Posted August 6, 2008 SQL storage is something I'll start with today. If I'll make an supporting resource, it OFCOURSE has export functions etc etc... Lol. I need to know the customers demand. But the forums has PM's for that. We're a little off-topic And well, I have a small "job" at a (little) bigger server and I shouldn't waste ALL of my time. But well, I'll start on it soon, the less time I "waste" ("" because I need it for my own scripts too ) Link to comment
churchill Posted August 7, 2008 Share Posted August 7, 2008 have you done it yet? hurry! No worries - If you're busy I can do it myself as I'm not working for any servers yet, and it shouldn't take very long as it has pretty simple requirements. Better finish my other resource off first though Link to comment
Gamesnert Posted August 7, 2008 Share Posted August 7, 2008 No I'm not that busy. "Employer" is on holiday. But we're a bit off-topic now so if you want to contact me, do it with PM's. Link to comment
DakiLLa Posted October 15, 2008 Share Posted October 15, 2008 why i have warnings in 26, 10, 11 and 12 lines when resource start ? Link to comment
aralmo Posted October 31, 2008 Share Posted October 31, 2008 Actually searching in XML is slower than executing a query. I am just trying to point out that if you want to keep records of players with stats and all it is better to use SQL instead. You can always output it to an XML file in order to make it interchangeable between applications. Use XML files to store static data that is required to be loaded only once. This is just my point of view. Thats true with complex search like joins. But if youre accessing subnodes inside a known node, its pretty fast, mostly the same than mySql. I find xml good enough to save this kind of things, maybe if u need more complex data with relations and stuff thats not the best way. 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