Jump to content

xml question


Castillo

Recommended Posts

hi, i have a little problem on my "friends list" resource, i noticed that you aren't able to add a friend if someone else added him, i know why this happends but i have no idea how i can fix it, the problem must be that i'm checking all accounts not only mine.

here is part of code:

  
    local root = getResourceConfig("data.xml") 
    local index = getIndex (getPlayerSerial(client),root) 
    for i , v in pairs ( xmlNodeGetChildren ( root ) ) do 
        for s , t in pairs ( xmlNodeGetChildren ( v ) ) do 
            local att = xmlNodeGetAttribute ( t, "name" ) 
            local rn = string.lower ( tostring ( nametext ) ) 
            local ra = string.lower ( att ) 
            if ( rn == ra ) then outputChatBox ( "A friend with this name already exist." , client , 255 , 0 , 0 ) 
                return false 
            end 
        end 
    end 

i hope someone know how i can fix it.

Thanks in advance.

Link to comment

You just need to make an nodeattribute for the account name for the player who added the friend, like

when the players add another friend make it get the player's account who added the friend and check all the lines which has Account nodeattribute as ( e.g )"Static-X", then get the account of the player who I wanted to add, if the friendAccount is "Pulsar" it will return end.

Link to comment

<playerfriends> 
    <user account="2F71C8856F19CD2523627FFCE58BA3A1"> 
        <friend name="Chase_Oquinn" serial="B92D9BF5F9C1AE0A514F445EBFC63394" /> 
        <friend name="[MM]Castillo" serial="2F71C8856F19CD2523627FFCE58BA3A1" /> 
    </user> 
</playerfriends> 

that?

Link to comment
  
    local playerSerial = getPlayerSerial(client) -- added, fix if needed 
    local root = getResourceConfig("data.xml") 
    local index = getIndex (getPlayerSerial(client),root) 
    for i , v in pairs ( xmlNodeGetChildren ( root ) ) do 
        local xmlNodeUserSerial = xmlNodeGetAttribute(v,"account")  --- added 
        if (xmlNodeUserSerial==playerSerial) then  -- added 
            for s , t in pairs ( xmlNodeGetChildren ( v ) ) do 
                local att = xmlNodeGetAttribute ( t, "name" ) 
                local rn = string.lower ( tostring ( nametext ) ) 
                local ra = string.lower ( att ) 
                if ( rn == ra ) then outputChatBox ( "A friend with this name already exist." , client , 255 , 0 , 0 ) 
                    return false 
                end 
            end 
        end -- added, lol 
    end 
  

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