xXMADEXx Posted February 15, 2013 Posted February 15, 2013 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> The Ultimate Lua Tutorial! | MTA PHP SDK
MR.S3D Posted February 15, 2013 Posted February 15, 2013 -- 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) Welcom to my server Q.5 Current game type in my server Drift my Email : [email protected] Programming level: 90%
Castillo Posted February 15, 2013 Posted February 15, 2013 That's because you aren't looping all the spawners, you are just getting the first one. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
xXMADEXx Posted February 15, 2013 Author Posted February 15, 2013 (edited) Thank you Castillo i have fixed. Edited February 15, 2013 by Guest The Ultimate Lua Tutorial! | MTA PHP SDK
Castillo Posted February 15, 2013 Posted February 15, 2013 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now