Jump to content

set animation on killped


Recommended Posts

im not sure how to prevent the peds death from repating 
when player dies ped is spawned and the killer shoots the ped resulting in the ped dying over and over also turning the col into a zombie

 

function kilLDayZPlayer(killer,headshot,weapon,bag)
  if getElementData (source, "isDead") then return end
  setElementData(source,"isDead",true)
  if getPedOccupiedVehicle ( source ) then removePedFromVehicle ( source ) end
  pedCol = false
  local account = getPlayerAccount(source)
  if not account then
	return
  end
  killPed(source)
  triggerClientEvent(source,"hideInventoryManual",source)
  if 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)
		--setPedStat(ped,"MAX_HEALTH",999999)
      	triggerClientEvent("AddDeathPedClothes",source,ped,source)
		pedCol = createColSphere(x,y,z,1.5)
		setTimer(function()
			if headshot == true then
				setPedHeadless(ped, true)
				setPedAnimation(ped,"knife","KILL_Knife_Ped_Die",1600,false,false,false,true)
			elseif not headshot == true then
				setPedAnimation(ped,"PED","KO_shot_stom",1600,false,false,false,true)
			end
	end,50,1)
	setTimer(function()
	    killPed(ped)
	end,200,1)
    setTimer(destroyDeadPlayer,1800000,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. Killer: "..(getPlayerName(killer) or "Unknown")..". Time of death: "..hours..":"..minutes)
	end
  end
  if killer then
	if not getElementData(source,"bandit") then
	  addPlayerStats(killer,"humanity",math.random(-2500,-1000))
	else
	  addPlayerStats(killer,"humanity",math.random(1000,2500))
	end
	setElementData(killer,"murders",getElementData(killer,"murders")+ 1)
	if 0 > getElementData(killer,"humanity") then
	  setElementData(killer,"bandit",true)
	end
	if getElementData(source,"bandit")== true then
	  setElementData(killer,"banditskilled",getElementData(killer,"banditskilled")+ 1)
	end
	if headshot == true then
	  setElementData(killer,"headshots",getElementData(killer,"headshots")+ 1)
	end
  end
  if pedCol then
	for i,data in ipairs(playerDataTable)do
	  if tonumber(getElementData(source,data[1]))then
		setElementData(pedCol,data[1],getElementData(source,data[1]))
	  end
	end
	if getActiveVest(source) and getElementData(source,"vestLife") == getVestLife(getActiveVest(source)) then
	  setElementData(pedCol,getActiveVest(source),1)
	end
	if getActiveHelmet(source) and getElementData(source,"helmetLife") == getHelmetLife(getActiveHelmet(source)) then
	  setElementData(pedCol,getActiveHelmet(source),1)
	end
	local skinID = getElementData(source,"skin")
	local skin = getSkinNameFromID(skinID)
	setElementData(pedCol,skin,1)
	local backpackSlots = getElementData(source,"MAX_Slots")
	backpackName = getBackpackName(backpackSlots)
	if backpackName then
	  setElementData(pedCol,backpackName,1)
	end
  end
  setTimer(setElementPosition,50,1,source,6000,6000,0)
  triggerClientEvent(source,"refreshInventoryManual",source)
  for i,itemm in pairs(playerDataTable) do
    setElementData(source,itemm[1],itemm[2])
    end
  triggerClientEvent(source,"onClientPlayerDeathInfo",source)
  setAccountData(account,"isDead",true)
  setElementData(source,"isDead",true)
  triggerClientEvent("onRollMessageStart",getRootElement(),"#FFFFFF"..getPlayerName(source).." #FFFFFFwas killed",0,22,255,"died")
  setTimer(spawnDayZPlayer,5000,1,source)
end
addEvent("kilLDayZPlayer",true)
addEventHandler("kilLDayZPlayer",getRootElement(),kilLDayZPlayer)

 

Link to post
  • Moderators
14 hours ago, greentumbleweed said:

when player dies ped is spawned and the killer shoots the ped resulting in the ped dying over and over also turning the col into a zombie

You can make peds immortal like this:

 

Server:

-- top of the script
local immortalPedsParent = createElement("immortalPedsParent", "immortalPedsParent-" .. getResourceName(getThisResource()))

 

Client:

addEventHandler("onClientPedDamage", getElementByID("immortalPedsParent-" .. getResourceName(getThisResource())), 
function () 
	cancelEvent()  
end)

 

Server:

-- when creating an immortal ped
local ped = createPed(skin,x,y,z,rotZ)
setElementParent(ped, immortalPedsParent)

 

But keep in mind that other scripts might interfere.

Link to post

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