xXMADEXx Posted December 24, 2012 Share Posted December 24, 2012 How can i make it so that when an admin types /addped it will save the ped to peds.xml somthink like this <peds> <ped x="posX" y="posY" z="posZ" rot="rotationZ" int="interitor" dim="dimenshin"></ped> </peds> -- Server side function pedfunc (player, cmd, id) if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "Admin" ) ) then local x, y, z = getElementPosition(player) local rx = getElementRotation(player) local int = getElementInterior(player) created = createPed ( id, x+1, y, z, rx, int, 0 ) setElementFrozen(created, true) outputChatBox("Ped-System: You have successfully made a ped with an ID of #ff0000".. id, player, 0, 255, 0, true ) if ( id == " " ) then outputChatBox("Ped-System: Error, the command is /addped ", player, 255, 0, 0 ) end else outputChatBox("Ped-System: This command is only for admins!", player, 255, 0, 0 ) end end addCommandHandler("addped", pedfunc) Link to comment
Castillo Posted December 24, 2012 Share Posted December 24, 2012 xmlLoadFile xmlCreateChild xmlNodeSetAttribute These are the functions you require to do it. Link to comment
xXMADEXx Posted December 24, 2012 Author Share Posted December 24, 2012 xmlLoadFile xmlCreateChild xmlNodeSetAttribute These are the functions you require to do it. Thank you! This was very usefull! Link to comment
xXMADEXx Posted December 24, 2012 Author Share Posted December 24, 2012 Since still kinda new to saving stuff to XML, can you help me make it so this will work: -- Create Peds.xml and insert tags -- function createFileHandler() local peds = xmlCreateFile("peds/peds.xml","peds") local ped = xmlCreateChild(peds, "ped") xmlSaveFile(peds) end addCommandHandler("addpedfile", createFileHandler) function pedfunc (player, cmd, id) if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 5" ) ) then local x, y, z = getElementPosition(player) local rx,ry,rz = getElementRotation(player) local int = getElementInterior(player) local dim = getElementDimension(player) local load = xmlLoadFile("peds/peds.xml") local oncreateped = xmlFindChild(load, "peds", 0) created = createPed ( id, x+1, y, z, rx, int, dim ) setElementInterior(created, int) setElementDimension(created, dim) setElementRotation(created, rx,ry,rz) setElementFrozen(created, true) outputChatBox("Ped-System: You have successfully made a ped with an ID of #ff0000".. id .."#00ff00!", player, 0, 255, 0, true ) xmlNodeSetAttribute(oncreateped, "ped", "id=".. id .. " x=" .. x .. " y=".. y .." z=".. z .." rotation=".. rx .." int=".. int .." dim=".. dim) if ( id == "" ) then outputChatBox("Ped-System: Error, the command is /addped ", player, 255, 0, 0 ) end else outputChatBox("Ped-System: This command is only for admins!", player, 255, 0, 0 ) end end addCommandHandler("addped", pedfunc) Link to comment
Castillo Posted December 24, 2012 Share Posted December 24, 2012 -- Create Peds.xml and insert tags -- function createFileHandler ( ) xmlCreateFile ( "peds/peds.xml", "peds" ) end addCommandHandler ( "addpedfile", createFileHandler ) function pedfunc ( player, cmd, id ) if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 5" ) ) then if ( id == "" ) then outputChatBox ( "Ped-System: Error, the command is /addped ", player, 255, 0, 0 ) return end local x, y, z = getElementPosition ( player ) local rot = getPedRotation ( player ) local int = getElementInterior ( player ) local dim = getElementDimension ( player ) local file = xmlLoadFile ( "peds/peds.xml" ) if ( file ) then local newChild = xmlFindChild ( file, "peds", 0 ) xmlNodeSetAttribute ( newChild, "id", id ) xmlNodeSetAttribute ( newChild, "x", x ) xmlNodeSetAttribute ( newChild, "x", x ) xmlNodeSetAttribute ( newChild, "y", y ) xmlNodeSetAttribute ( newChild, "z", z ) xmlNodeSetAttribute ( newChild, "rotation", rot ) xmlNodeSetAttribute ( newChild, "int", int ) xmlNodeSetAttribute ( newChild, "dim", dim ) created = createPed ( id, x+1, y, z, rot, int, dim ) setElementInterior ( created, int ) setElementDimension ( created, dim ) setPedRotation ( created, rot ) setElementFrozen ( created, true ) outputChatBox ( "Ped-System: You have successfully made a ped with an ID of #ff0000".. id .."#00ff00!", player, 0, 255, 0, true ) else outputChatBox ( "Ped-System: Failed to load XML file!", player, 255, 0, 0 ) end else outputChatBox ( "Ped-System: This command is only for admins!", player, 255, 0, 0 ) end end addCommandHandler ( "addped", pedfunc ) Link to comment
xXMADEXx Posted December 24, 2012 Author Share Posted December 24, 2012 Ped-System: Failed to load XML file! Link to comment
Vision Posted December 24, 2012 Share Posted December 24, 2012 -- Create Peds.xml and insert tags -- function createFileHandler ( ) local theFile = xmlCreateFile("peds/peds.xml", "peds") xmlCreateChild(theFile, "ped") xmlSaveFile(theFile) end addCommandHandler ( "addpedfile", createFileHandler ) function pedfunc ( player, cmd, id ) if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 5" ) ) then if ( id == "" ) then outputChatBox ( "Ped-System: Error, the command is /addped ", player, 255, 0, 0 ) return end local x, y, z = getElementPosition ( player ) local rot = getPedRotation ( player ) local int = getElementInterior ( player ) local dim = getElementDimension ( player ) local file = xmlLoadFile ( "peds/peds.xml" ) if ( file ) then local newChild = xmlFindChild ( file, "ped", 0 ) xmlNodeSetAttribute ( newChild, "id", id ) xmlNodeSetAttribute ( newChild, "x", x ) xmlNodeSetAttribute ( newChild, "y", y ) xmlNodeSetAttribute ( newChild, "z", z ) xmlNodeSetAttribute ( newChild, "rotation", rot ) xmlNodeSetAttribute ( newChild, "int", int ) xmlNodeSetAttribute ( newChild, "dim", dim ) xmlSaveFile ( file ) local created = createPed ( id, x+1, y, z, rot, int, dim ) setElementInterior ( created, int ) setElementDimension ( created, dim ) setPedRotation ( created, rot ) setElementFrozen ( created, true ) outputChatBox ( "Ped-System: You have successfully made a ped with an ID of #ff0000".. tonumber(id) .."#00ff00!", player, 0, 255, 0, true ) else outputChatBox ( "Ped-System: Failed to load XML file!", player, 255, 0, 0 ) end else outputChatBox ( "Ped-System: This command is only for admins!", player, 255, 0, 0 ) end end addCommandHandler ( "addped", pedfunc ) Link to comment
xXMADEXx Posted December 24, 2012 Author Share Posted December 24, 2012 @Castro That worked, but it will not load the file. Link to comment
Castillo Posted December 24, 2012 Share Posted December 24, 2012 Have you checked if the file is on the resource folder/peds? Link to comment
xXMADEXx Posted December 24, 2012 Author Share Posted December 24, 2012 Yes, the place were all the ped files are is "[ROG]Core/peds/{server, client, peds.xml} Link to comment
Castillo Posted December 24, 2012 Share Posted December 24, 2012 "[ROG]Core" is the resource name, right? Remove "peds.xml" and then, with the code I posted, execute "addpedfile", then create a ped. Link to comment
xXMADEXx Posted December 25, 2012 Author Share Posted December 25, 2012 "[ROG]Core" is the resource name, right?Remove "peds.xml" and then, with the code I posted, execute "addpedfile", then create a ped. /addpedfile will not work. It dosnt create the ped file, and when i insert a peds.xml (with the correct tags) it will say "Ped-System: Failed to load XML file!," How do i fix this? Link to comment
Castillo Posted December 25, 2012 Share Posted December 25, 2012 -- Create Peds.xml and insert tags -- function createFileHandler ( ) local file = xmlCreateFile ( "peds/peds.xml", "peds" ) xmlSaveFile ( file ) end addCommandHandler ( "addpedfile", createFileHandler ) function pedfunc ( player, cmd, id ) if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 5" ) ) then if ( id == "" ) then outputChatBox ( "Ped-System: Error, the command is /addped ", player, 255, 0, 0 ) return end local x, y, z = getElementPosition ( player ) local rot = getPedRotation ( player ) local int = getElementInterior ( player ) local dim = getElementDimension ( player ) local file = xmlLoadFile ( "peds/peds.xml" ) if ( file ) then local newChild = xmlFindChild ( file, "peds", 0 ) xmlNodeSetAttribute ( newChild, "id", id ) xmlNodeSetAttribute ( newChild, "x", x ) xmlNodeSetAttribute ( newChild, "x", x ) xmlNodeSetAttribute ( newChild, "y", y ) xmlNodeSetAttribute ( newChild, "z", z ) xmlNodeSetAttribute ( newChild, "rotation", rot ) xmlNodeSetAttribute ( newChild, "int", int ) xmlNodeSetAttribute ( newChild, "dim", dim ) xmlSaveFile ( file ) created = createPed ( id, x+1, y, z, rot, int, dim ) setElementInterior ( created, int ) setElementDimension ( created, dim ) setPedRotation ( created, rot ) setElementFrozen ( created, true ) outputChatBox ( "Ped-System: You have successfully made a ped with an ID of #ff0000".. id .."#00ff00!", player, 0, 255, 0, true ) else outputChatBox ( "Ped-System: Failed to load XML file!", player, 255, 0, 0 ) end else outputChatBox ( "Ped-System: This command is only for admins!", player, 255, 0, 0 ) end end addCommandHandler ( "addped", pedfunc ) xmlSaveFile was missing. Link to comment
xXMADEXx Posted December 26, 2012 Author Share Posted December 26, 2012 Well, It does not save the ped to the xml file. Link to comment
Castillo Posted December 26, 2012 Share Posted December 26, 2012 That's because I forgot to save the file after adding the new child, copy my code again. Link to comment
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