Jump to content

Help - XML


xXMADEXx

Recommended Posts

I made this code, for my vehicle spawners. For some reason, it will only create the first marker in the XML file... Any reasons?

-- Server 

----------------------- XML

function createAfreeFile (player)

    if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 6" ) ) then

        local xmlFile = xmlCreateFile("free/freeSpawners.xml", "spawners" )

        xmlSaveFile(xmlFile)

        outputChatBox("You have created a free spawner xml in free/freeSpawner.xml",player,255,255,0)

    end

end

addCommandHandler("filefree",createAfreeFile) -- create file

 

function createSpawner(player)

    if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 6" ) ) then

        local x, y, z = getElementPosition(player)

        local zone = getZoneName(x, y, z)

        local city = getZoneName ( x, y, z, true )

        local file = xmlLoadFile("free/freeSpawners.xml", "spawners")

        local child = xmlCreateChild(file,"spawner")

        xmlNodeSetAttribute(child,"city",city)

        xmlNodeSetAttribute(child,"zone",zone)

        xmlNodeSetAttribute(child,"x",x)

        xmlNodeSetAttribute(child,"y",y)

        xmlNodeSetAttribute(child,"z",z-1)

        xmlSaveFile(file)

        xmlUnloadFile(file)

        local marker = createMarker ( tonumber ( x ), tonumber ( y ), tonumber ( z ), 'cylinder', 2, 255, 255, 255, 100)

        setElementData(marker,"spawner","free",true)

    end

end

addCommandHandler("spawnerfree",createSpawner) -- create marker

 

gResRoot = getResourceRootElement(getThisResource())

function loadAllHouses ()

    local root = xmlLoadFile ("free/freeSpawners.xml", "spawners")

    local houseroot = xmlFindChild (root,"spawner",0)

    local x = xmlNodeGetAttribute (houseroot,"x")

    local y = xmlNodeGetAttribute (houseroot,"y")

    local z = xmlNodeGetAttribute (houseroot,"z")

    local marker = createMarker ( tonumber ( x ), tonumber ( y ), tonumber ( z ), 'cylinder', 2, 255, 255, 255, 100)

    setElementData(marker,"spawner","free",true)

end

addEventHandler("onResourceStart",gResRoot, loadAllHouses)

-- XML

<spawners> 

    <spawner city="Los Santos" zone="Pershing Square" x="1535.9931640625" y="-1677.9462890625" z="12.3828125"></spawner><!-- This is the only one, that creates -->

    <spawner city="Los Santos" zone="Market" x="1209.3505859375" y="-1326.9345703125" z="12.3984375"></spawner>

</spawners>

 

Link to comment
  
-- Server 
----------------------- XML 
function createAfreeFile (player) 
    if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 6" ) ) then 
        local xmlFile = xmlCreateFile("free/freeSpawners.xml", "spawners" ) 
        xmlSaveFile(xmlFile) 
        outputChatBox("You have created a free spawner xml in free/freeSpawner.xml",player,255,255,0) 
    end 
end 
addCommandHandler("filefree",createAfreeFile) -- create file 
  
function createSpawner(player) 
    if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 6" ) ) then 
        local x, y, z = getElementPosition(player) 
        local zone = getZoneName(x, y, z) 
        local city = getZoneName ( x, y, z, true ) 
        local file = xmlLoadFile("free/freeSpawners.xml", "spawners") 
        local child = xmlCreateChild(file,"spawner") 
        xmlNodeSetAttribute(child,"city",city) 
        xmlNodeSetAttribute(child,"zone",zone) 
        xmlNodeSetAttribute(child,"x",x) 
        xmlNodeSetAttribute(child,"y",y) 
        xmlNodeSetAttribute(child,"z",z-1) 
        xmlSaveFile(file) 
        xmlUnloadFile(file) 
        local marker = createMarker ( tonumber ( x ), tonumber ( y ), tonumber ( z ), 'cylinder', 2, 255, 255, 255, 100) 
        setElementData(marker,"spawner","free",true) 
    end 
end 
addCommandHandler("spawnerfree",createSpawner) -- create marker 
  
gResRoot = getResourceRootElement(getThisResource()) 
function loadAllHouses () 
    local file = xmlLoadFile ("free/freeSpawners.xml", "spawners") 
    local houseroot = xmlFindChild (file,"spawner",0) 
    for k,v in ipairs (xmlNodeGetChildren(houseroot))do  
        local x = xmlNodeGetAttribute (v,"x") 
        local y = xmlNodeGetAttribute (v,"y") 
        local z = xmlNodeGetAttribute (v,"z") 
        local marker = createMarker ( tonumber ( x ), tonumber ( y ), tonumber ( z ), 'cylinder', 2, 255, 255, 255, 100) 
        setElementData(marker,"spawner","free",true) 
    end 
end 
addEventHandler("onResourceStart",gResRoot, loadAllHouses) 
  
  

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