Jump to content

Changing names of specific nodes


myonlake

Recommended Posts

Hello there,

I am continuing my character kill script with a burying function, however, it doesn't output what I want.

I wanted this to find the correct ped from the colShape and delete the ped and change the node's name from 'p' to 'buried'. But it doesn't actually output any errors either. Any help?

function buryPeds(player, cmd, id) 
    if hasObjectPermissionTo(player, "command.ban") then 
        local x, y, z = getElementPosition(player) 
        local mark = createColSphere(x, y, z, 30) 
        for i,v in ipairs(getElementsWithinColShape(mark, "ped")) do 
            for i,v in ipairs(getElementsByType("p")) do 
                local xml = xmlLoadFile("peds.map") 
                local d = xmlFindChild(xml, "p", 0) 
                if xmlNodeGetAttribute(d, "id") == id then 
                    xmlNodeSetName(d, "buried") 
                    xmlNodeSetAttribute(d, "buriedBy", getPlayerName(player)) 
                    xmlSaveFile(xml) 
                    xmlUnloadFile(xml) 
                    outputChatBox("Body with ID: " .. id .. " buried successfully.", player, 255, 255, 255, false) 
                    destroyElement(v) 
                end 
            end 
        end 
        setTimer(destroyElement, 2000, 1, mark) 
    end 
end 
addCommandHandler("bury", buryPeds) 
 
Edited by myonlake
Link to comment

This is messed up, why are you trying to get near peds, and you have an id argument.

Don't you want to bury the ped with the specified id?

If so..try this:

function buryPeds(player, cmd, id) 
    if hasObjectPermissionTo(player, "command.ban") then 
        if not id then return outputChatBox("Wrong ID specified",player) end 
        local xml = xmlLoadFile("peds.map") 
           for index,node in ipairs(xmlNodeGetChildren(xml)) do 
                if xmlNodeGetAttribute(node, "id") == id then 
                    xmlNodeSetName(node, "buried") 
                    xmlNodeSetAttribute(node, "buriedBy", getPlayerName(player)) 
                    xmlSaveFile(xml) 
                    xmlUnloadFile(xml) 
                    outputChatBox("Body with ID: " .. id .. " buried successfully.", player, 255, 255, 255, false) 
                    for index , ped in ipairs ( getElementsByType ( "ped" , resourceRoot ) ) do 
                        if getElementData ( ped , "id" ) == id or getElementID ( ped ) == id then 
                            destroyElement(ped) 
                            break 
                        end 
                    end 
                    break 
                end 
            end 
        end 
    end 
addCommandHandler("bury", buryPeds) 

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