Jump to content

char ids


Castillo

Recommended Posts

Posted (edited)

hey there, im scripting a character system and im actually using account data functions for it, the problem is that when i make 1 character it sets the data already but when i want to make 2 characters the problem is that the data already exist so i would like to know how i can make somthing like a id for every character i create, here is code of creation.

Edited by Guest
Posted

i dont know if you want it,

but i think you can better use sql :)

you wont have the problem,

and you wont get problems later on with other scripts;)

in sql he just sorts it, and the accounts wont get bugged, :)

Posted
i dont know if you want it,

but i think you can better use sql :)

you wont have the problem,

and you wont get problems later on with other scripts;)

in sql he just sorts it, and the accounts wont get bugged, :)

SQL its hard for me, also XML, trying to make it via XML but dont get anything of how works.

Posted
You could do something like this:
setAccountData(getPlayerAccount(source), charid .. ".charname",nombre)

this dont actually works, but nevermind i started to make it using xml :D, if i need help with it i will re-post.

Posted (edited)

hey again, i started to build it with xml but i have a problem when loading the characters, i will post the code and the error i get (im noob at xml btw, just started to learn :D)

Edited by Guest
Posted

xmlNodeGetChildren(root) returns a table with all nodes in it.

But then you use this table again in the same function, which is your problem.

The function expects a node, not a table full of nodes.

So, this...

ipairs (xmlNodeGetChildren (db))

should just be...

ipairs (db)

Also, your function "findAccountChildInDB" will just return the node of the player's values, so you can't loop within it.

If you want to loop through all the characters, which are listed under the player's node, you have to again make use of xmlNodeGetChildren at this point and then loop through the returned table (if it is one, anyway) and get the attributes for every loop step.

Posted
xmlNodeGetChildren(root) returns a table with all nodes in it.

But then you use this table again in the same function, which is your problem.

The function expects a node, not a table full of nodes.

So, this...

ipairs (xmlNodeGetChildren (db))

should just be...

ipairs (db)

Also, your function "findAccountChildInDB" will just return the node of the player's values, so you can't loop within it.

If you want to loop through all the characters, which are listed under the player's node, you have to again make use of xmlNodeGetChildren at this point and then loop through the returned table (if it is one, anyway) and get the attributes for every loop step.

now i get a different error in that line, "bad argument #1 to "pairs" (table exptected, got userdata)"

Posted

As I said, you can't loop through the value returned by your function.

You still have to get all children from this value (which is a node) and THEN you can loop through the table holding the children of your player node.

Posted
As I said, you can't loop through the value returned by your function.

You still have to get all children from this value (which is a node) and THEN you can loop through the table holding the children of your player node.

Where do i have to use "xmlNodeGetChildren"?

Posted
local characterNodes = xmlNodeGetChildren(accountRoot)
 
for _,node in pairs(characterNodes) do
local atributes = xmlNodeGetAttributes(node)
local name = atributes.name
triggerClientEvent ( source, "addcharacter", getRootElement(), name)
end

That's how it should look like.

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