Jump to content

Clan system problem


TheIceman1

Recommended Posts

Posted

When i make clan "Military" then in clans.xml said this:

<clans> 
    <clans name="Military"></clans> 
</clans> 
  

But when other player make new clan then in clans.xml said this and remove my clan:

<clans> 
    <clans name="SWAT"></clans> 
</clans> 
  

But i want this:

<clans> 
    <clans name="Military"></clans> 
    <clans name="SWAT"></clans> 
</clans> 

Code

local root = xmlLoadFile ("clans.xml") 
    local clroot = xmlFindChild (root,"clans",0) 
    if (clroot) then 
      xmlNodeSetAttribute (clroot,"name", clan) 
    else 
     clroot = xmlCreateChild(root, "clans") 
     xmlNodeSetAttribute (clroot,"name", clan) 
    end 
    xmlSaveFile( root ) 
    xmlUnloadFile ( root ) 

Understand what i want?

Posted

Nothing is removed. Your script searches for existing clan node and changes its name instead of creating another node.

Posted (edited)

You mean this?But this dont work

local root = xmlLoadFile ("clans.xml") 
     clroot = xmlCreateChild(root, "clans") 
     xmlNodeSetAttribute (clroot,"name", clan) 
    end 
    xmlSaveFile( root ) 
    xmlUnloadFile ( root ) 

Edited by Guest
Posted

I have new problem.

Players make clans then in clans.xml said this :

<clans> 
    <clans name="Military"></clans> 
    <clans name="SWAT"></clans> 
    <clans name="FBI"></clans> 
</clans> 
  

But when i delete "Military" then in clans.xml said this(all clans are deleted):

<clans> 
</clans> 
  

But i want this,when i delete "Military" then in clans.xml said this:

<clans> 
    <clans name="SWAT"></clans> 
    <clans name="FBI"></clans> 
</clans> 
  

Code:

    local clansroot = xmlLoadFile ("clans.xml") 
    if ( clansroot ) then 
        for i,v in ipairs (xmlNodeGetChildren(clansroot)) do 
            local clanname = xmlNodeGetAttribute (v,"name") 
            xmlDestroyNode ( v ) 
            xmlSaveFile ( clansroot ) 
            xmlUnloadFile ( clansroot ) 

Posted

The reason it is deleting them all is because you are 'for' looping all the children of the xml file then using xmlDestroyNode, if you cannot figure it out, can you please post the full function handler.

Posted
function destroyclan () 
local clan = getElementData ( source, "clan" ) 
local acc = getPlayerAccount ( source ) 
    local clansroot = xmlLoadFile ("clans.xml") 
    if ( clansroot ) then 
        for i,v in ipairs (xmlNodeGetChildren(clansroot)) do 
            local xmlnumber = xmlNodeGetAttribute (v,"name") 
            xmlDestroyNode ( v ) 
            xmlSaveFile ( clansroot ) 
            xmlUnloadFile ( clansroot ) 
    exports ["guimessages"] : outputServer ( source, "You destroy your clan!", 255, 255, 0 ) 
setAccountData ( acc, "Clan", false ) 
removeElementData ( source, "clan" ) 
end 
end 
end 
addEvent ( "destroyclan", true ) 
addEventHandler ( "destroyclan", root, destroyclan ) 
  

Posted
function destroyclan () 
    local clan = getElementData ( source, "clan" ) 
    local acc = getPlayerAccount ( source ) 
    local clansroot = xmlLoadFile ("clans.xml") 
    if ( clansroot ) then 
        for i,v in ipairs (xmlNodeGetChildren(clansroot)) do 
            local clanName = xmlNodeGetAttribute (v,"name") 
            if clanName:lower() == clan:lower() then 
                xmlDestroyNode ( v ) 
                xmlSaveFile ( clansroot ) 
                xmlUnloadFile ( clansroot ) 
                exports ["guimessages"] : outputServer ( source, "You destroy your clan!", 255, 255, 0 ) 
                setAccountData ( acc, "Clan", false ) 
                removeElementData ( source, "clan" ) 
            end 
        end 
    end 
end 
  
addEvent ( "destroyclan", true ) 
addEventHandler ( "destroyclan", root, destroyclan ) 

Posted
function destroyclan () 
    local clan = getElementData ( source, "clan" ) 
    local acc = getPlayerAccount ( source ) 
    local clansroot = xmlLoadFile ("clans.xml") 
    if ( clansroot ) then 
        for i,v in ipairs (xmlNodeGetChildren(clansroot)) do 
            local clanName = xmlNodeGetAttribute (v,"name") 
            if clanName:lower() == clan:lower() then 
                xmlDestroyNode ( v ) 
                xmlSaveFile ( clansroot ) 
                xmlUnloadFile ( clansroot ) 
                exports ["guimessages"] : outputServer ( source, "You destroy your clan!", 255, 255, 0 ) 
                setAccountData ( acc, "Clan", false ) 
                removeElementData ( source, "clan" ) 
            end 
        end 
    end 
end 
  
addEvent ( "destroyclan", true ) 
addEventHandler ( "destroyclan", root, destroyclan ) 

You should break the loop after the data was found.

Posted

Yeah, add break to the loop, it was 1am when I wrote this one, I was tired. People miss things, I've seen Castillo miss many things in his codes, then 1 month later he fixes them, he still hasn't fixed his gang system bug I commented with.

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