Jump to content

Need help about xml


Aron800

Recommended Posts

Hello,

I want to make a script that if you join and you are in a xml list as a member of the gang. That you will join the team.

But i got a problem. It is not returning any errors.

This is my script:

teams.lua:

gResRoot = getResourceRootElement(getThisResource()) 
function loadGangs () 
    local root = xmlLoadFile("gangs.xml") 
    if (gangRoot) then 
        for i,gang in ipairs (xmlNodeGetChildren(root)) do 
            local info = xmlFindChild(gang, "info", 0) 
            if info then 
                local colorR = xmlNodeGetAttribute(gang, "colorR") 
                local colorG = xmlNodeGetAttribute(gang, "colorG") 
                local colorB = xmlNodeGetAttribute(gang, "colorB") 
                local name = xmlNodeGetAttribute(gang, "gangName") 
                createTeam(gangName, colorR, colorG, colorB) 
            end 
        end 
    end 
end 
addEventHandler("onResourceStart",gResRoot, loadGangs) 
  
function onLogin () 
    local root = xmlLoadFile("gangs.xml") 
    local play = getPlayerAccount(source) 
    local player = getAccountName(play) 
  
    for i,gang in ipairs (xmlNodeGetChildren(root)) do 
        local member = xmlNodeGetAttribute(gang, "name") 
        local gangName = xmlNodeGetAttribute(gang, "gangName") 
        if (member == player) then 
            local theTeam = getTeamFromName(gangName) 
            setPlayerTeam(source, theTeam) 
        end 
    end 
    xmlUnloadFile(root) 
end 
  
addEventHandler ("onPlayerLogin", getRootElement(), onLogin) 

gangs.xml:

<gangs> 
    <Grove Street> 
    <info gangName="Grove Street" colorR="0" colorG="255" colorB="0" /> 
        <member name="Aron" rank="3" /> 
    </Grove Street> 
</gangs> 

So what do i need to do?

Link to comment

it's stopping on 4th line, gangRoot is never defined. It is your script? It's extremly simple script, and this error is SO EASY to spot.

Also your xml "idea" is a bit wrong. It's valid, but.. not really good one.

  
<gangs> 
  <gang name="Grove Street" colorR="0" colorG="255" colorB="0"> 
    <members> 
      <member name="Aron" rank="3" /> 
    </members> 
  </gang> 
  <gang name="varez gang" colorR="255" colorG="255" colorB="0"> 
    <members> 
      <member name="varez" rank="666" /> 
      <member name="varez clone" rank="69" /> 
    </members> 
  </gang> 
</gangs> 
  

seems much better and well-organised

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