Jump to content

(REL) [ SEGET ] - [ User Database Management ]


Kapil

Recommended Posts

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 by Guest
Link to comment

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 by Guest
Link to comment
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
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

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

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
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 :P

Link to comment
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 :P

Link to comment
  • 2 months later...

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

SQL storage is something I'll start with today.

If I'll make an supporting resource, it OFCOURSE has export functions :P

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 :P)

Link to comment
  • 2 months later...
  • 3 weeks later...
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...