Jump to content

DestroyElement Problem


ksTakor

Recommended Posts

I want when I click a gui button destroy the body of the dead player, but when I execute the function only destroy the ped and not the colision.

debugscript: Bad argument @ 'destroyElement' [Expected element at argument 1, got boolean]

spawn.lua: where is the function that create the ped and the colision when the players die. Server Side

function kilLDayZPlayer(killer, headshot, weapon) 
  pedCol = false 
  local account = getPlayerAccount(source) 
  if not account then 
    return 
  end 
  killPed(source) 
  triggerClientEvent(source, "hideInventoryManual", source) 
  if getElementData(source, "alivetime") > 0 and not isElementInWater(source) then 
    local x, y, z = getElementPosition(source) 
    if getDistanceBetweenPoints3D(x, y, z, 6000, 6000, 0) > 200 then 
      local x, y, z = getElementPosition(source) 
      local rotX, rotY, rotZ = getElementRotation(source) 
      local skin = getElementModel(source) 
      local ped = createPed(skin, x, y, z, rotZ) 
      pedCol = createColSphere(x, y, z, 1.5) 
      killPed(ped) 
      setTimer(destroyDeadPlayer, 2700000, 1, ped, pedCol) 
      attachElements(pedCol, ped, 0, 0, 0) 
      setElementData(pedCol, "parent", ped) 
      setElementData(pedCol, "playername", getPlayerName(source)) 
      setElementData(pedCol, "deadman", true) 
      setElementData(pedCol, "MAX_Slots", getElementData(source, "MAX_Slots")) 
      local time = getRealTime() 
      local hours = time.hour 
      local minutes = time.minute 
      setElementData(pedCol, "deadreason", getPlayerName(source) .. " is dead. Cause of death: " .. (weapon or "Unknown") .. ". Time of death: " .. hours .. ":" .. minutes .. " o'clock.") 
    end 
  end 

menu_client.lua: where the gui is. ClientSide

if itemName == "hide" then 
      local col = getElementData(getLocalPlayer(), "currentCol") 
      local gearName = "Hide Body" 
      triggerServerEvent("removeBody", getLocalPlayer(), getElementData(col, "parent")) 
      disableMenu() 
      return 
    end 

survivorSystem.lua: where the function that removes the body is. ServerSide

function removeBody(object) 
  setPedAnimation(source, "BOMBER", "BOM_Plant", nil, false, false, nil, false) 
   destroyElement(getElementData(object, "parent")) 
   destroyElement(object) 
  end 
    addEvent("removeBody", true) 
    addEventHandler("removeBody", getRootElement(), removeBody) 

Thanks in Advance

Link to comment
I want when I click a gui button destroy the body of the dead player, but when I execute the function only destroy the ped and not the colision.

debugscript: Bad argument @ 'destroyElement' [Expected element at argument 1, got boolean]

spawn.lua: where is the function that create the ped and the colision when the players die. Server Side

function kilLDayZPlayer(killer, headshot, weapon) 
  pedCol = false 
  local account = getPlayerAccount(source) 
  if not account then 
    return 
  end 
  killPed(source) 
  triggerClientEvent(source, "hideInventoryManual", source) 
  if getElementData(source, "alivetime") > 0 and not isElementInWater(source) then 
    local x, y, z = getElementPosition(source) 
    if getDistanceBetweenPoints3D(x, y, z, 6000, 6000, 0) > 200 then 
      local x, y, z = getElementPosition(source) 
      local rotX, rotY, rotZ = getElementRotation(source) 
      local skin = getElementModel(source) 
      local ped = createPed(skin, x, y, z, rotZ) 
      pedCol = createColSphere(x, y, z, 1.5) 
      killPed(ped) 
      setTimer(destroyDeadPlayer, 2700000, 1, ped, pedCol) 
      attachElements(pedCol, ped, 0, 0, 0) 
      setElementData(pedCol, "parent", ped) 
      setElementData(pedCol, "playername", getPlayerName(source)) 
      setElementData(pedCol, "deadman", true) 
      setElementData(pedCol, "MAX_Slots", getElementData(source, "MAX_Slots")) 
      local time = getRealTime() 
      local hours = time.hour 
      local minutes = time.minute 
      setElementData(pedCol, "deadreason", getPlayerName(source) .. " is dead. Cause of death: " .. (weapon or "Unknown") .. ". Time of death: " .. hours .. ":" .. minutes .. " o'clock.") 
    end 
  end 

menu_client.lua: where the gui is. ClientSide

if itemName == "hide" then 
      local col = getElementData(getLocalPlayer(), "currentCol") 
      local gearName = "Hide Body" 
      triggerServerEvent("removeBody", getLocalPlayer(), getElementData(col, "parent")) 
      disableMenu() 
      return 
    end 

survivorSystem.lua: where the function that removes the body is. ServerSide

function removeBody(object) 
  setPedAnimation(source, "BOMBER", "BOM_Plant", nil, false, false, nil, false) 
   destroyElement(getElementData(object, "parent")) 
   destroyElement(object) 
  end 
    addEvent("removeBody", true) 
    addEventHandler("removeBody", getRootElement(), removeBody) 

Thanks in Advance

As far as I know you can't destroy a players ped. Dead players bodies only disappear after they respawned.

So maybe you could just change the alpha of the player and disable its collisions.

Else you would have to spawn the player or change its position.

Link to comment

in the removeBody function, source is the localPlayer, first argument is the ped. You're trying to get the element data 'parent' of the ped, while what you need is to get the 'parent' from the collision.

Try this:

if itemName == "hide" then 
      local col = getElementData(getLocalPlayer(), "currentCol") 
      local gearName = "Hide Body" 
      triggerServerEvent("removeBody", getLocalPlayer(), col, getElementData(col, "parent")) 
      disableMenu() 
      return 
    end 

function removeBody(col, ped) 
  setPedAnimation(source, "BOMBER", "BOM_Plant", nil, false, false, nil, false) --not sure whether u mean to set the animation of the ped or the localPlayer 
   destroyElement(col) 
   destroyElement(ped) 
  end 
    addEvent("removeBody", true) 
    addEventHandler("removeBody", getRootElement(), removeBody) 

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