Jump to content

help with XML


xXMADEXx

Recommended Posts

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

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
-- 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
-- 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
"[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
-- 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

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