Maruchan Posted April 22, 2021 Share Posted April 22, 2021 Guys I really need your help, because of this feature my humble DAYZ server is not working well. I have problems when the survivor dies from an explosion, but I'm not sure if the overall function is failing or just part of it. I hope you can help me and I am very sorry if the code is a bit long. function playerGetDamageDayZ(attacker, weapon, bodypart, loss) cancelEvent() local occupiedvehicle = getPedOccupiedVehicle(localPlayer); if occupiedvehicle and getElementModel(occupiedvehicle) == 528 then return; end showPlayerDamageScreen(0,"up"); local headshot = false; if weapon == 37 then setElementData(localPlayer,"blood",getElementData(localPlayer,"blood")-10000) return end if attacker and getElementType(attacker) == "player" then setElementData(localPlayer,"lastattacker",attacker) end damage = 100 headshot = false if attacker then if isElement(sleepText) then setElementData(localPlayer,"isSleeping",false) destroyElement(sleepText) triggerServerEvent("getDamageSleep", localPlayer) end if attacker and getElementType(attacker) and getElementType(attacker) == "vehicle" and not getElementData(getLocalPlayer(), "godmode") and not getElementData(getLocalPlayer(), "greenzone") then speedx, speedy, speedz = getElementVelocity(attacker) actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) kmh = actualspeed * 180 if kmh >= 100 then setElementData(getLocalPlayer(),"blood",-10) else setElementData(getLocalPlayer(), "blood", getElementData(getLocalPlayer(), "blood") - 500) end setElementData(localPlayer,"lastattacker",getVehicleOccupant(attacker)) end if attacker then if getElementData(attacker, "zombie") then setElementData(getLocalPlayer(),"blood",getElementData(getLocalPlayer(),"blood")-gameplayVariables["zombiedamage"]) sendClientMessage ( '-'..gameplayVariables["zombiedamage"], 1, 'left' ) local number = math.random(1, 9) playSound("Sonidos/Ataque-Zombies/attack_"..number..".mp3") if number == 4 then setElementData(getLocalPlayer(),"infection",true) setElementData(getLocalPlayer(), "bleeding", getElementData(getLocalPlayer(), "bleeding") + math.floor(loss*10)) end end end end -- DAÑO DE LOS PUÑOS if attacker then if weapon == 0 and getElementType(attacker) == "player" then setElementData(localPlayer,"blood",getElementData(localPlayer,"blood")-150) end end -- if (weapon == 16) then local aX,aY,aZ = getElementPosition(attacker) local tX,tY,tZ = getElementPosition(localPlayer) if isLineOfSightClear(aX,aY,aZ,tX,tY,tZ,true,false,false,true) then setElementData(localPlayer, "blood", getElementData(localPlayer, "blood") - math.random(20000*0.8, 20000*1.2)); end end -- if weapon == 49 then if loss > 30 then setElementData(getLocalPlayer(),"brokenbone",true) setPedControlState ("jump",true) setElementData(getLocalPlayer(),"blood",getElementData(getLocalPlayer(),"blood")-math.floor(loss*10)) sendClientMessage ( '-'..math.floor(loss*10), 1, 'left' ) setElementData(getLocalPlayer(),"blood",getElementData(getLocalPlayer(),"blood")-math.floor(loss*5)) sendClientMessage ( '-'..math.floor(loss*5), 1, 'left' ) end end if weapon == 63 or weapon == 51 or weapon == 19 or weapon == 50 then local aX,aY,aZ = getElementPosition (localPlayer) local tX,tY,tZ = getElementPosition (localPlayer) if isLineOfSightClear(aX, aY, aZ, tX, tY, tZ, true, false, false, true) then setElementData(getLocalPlayer(), "blood", -300) if getElementData(getLocalPlayer(), "blood") <= 1 then if not getElementData(getLocalPlayer(), "isDead") == true then triggerServerEvent("kilLDayZPlayer",getLocalPlayer(), attacker, headshot) end end end if weapon and weapon > 1 and attacker and getElementType(attacker) == "player" then setElementData(localPlayer,"lastAttacker",attacker) damage = getWeaponDamage(weapon,attacker) local x1,y1,z1 = getElementPosition(localPlayer) local x2,y2,z2 = getElementPosition(attacker) local distancia = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2) local damage = math.random(distancia*5, distancia*6) if bodypart == 9 then damage = damage*gameplayVariables["headshotdamage_player"] sendClientMessage ( '-'..gameplayVariables["headshotdamage_player"], 1, 'left' ) headshot = true end if attacker then if weapon == 17 and getElementType(attacker) == "player" then setElementData(localPlayer,"blood",getElementData(localPlayer,"blood")-10) end end if bodypart == 7 or bodypart == 8 then setElementData(localPlayer,"brokenbone",true) end if getElementData(localPlayer,"humanity") >= 5000 then if damage <= 1000 then damage = 0 else damage = damage end end setElementData(localPlayer,"blood",getElementData(localPlayer,"blood")-math.floor(damage)) if damage >= 6000 then end local number = math.random(1,8) if number >= 6 and number <= 8 then if damage > 0 then setElementData(localPlayer,"bleeding",getElementData(localPlayer,"bleeding") + math.floor(loss*10)) end end local number = math.random(1,7) if number == 2 then setElementData(localPlayer,"pain",true) end ----------------------------------------- playRandomHitSound() local myKills = 200 - ((getElementData(localPlayer,"murders") / 3) * 150) local rawDamage = math.floor(math.sqrt((damage/55.55))) local humanityHit = -(myKills * rawDamage) if humanityHit > -800 then humanityHit = -800 end if not getElementData(localPlayer,"bandit") then triggerServerEvent("onPlayerChangeStatus",attacker,"humanity",math.floor(humanityHit)) if getElementData(attacker,"humanity") < 0 then setElementData(attacker,"bandit",true) end else triggerServerEvent("onPlayerChangeStatus",attacker,"humanity",math.floor(humanityHit)) if getElementData(attacker,"humanity") > 5000 then setElementData(attacker,"humanity",5000) end if getElementData(attacker,"humanity") > 2000 then setElementData(attacker,"bandit",false) end end if getElementData(localPlayer,"blood") <= 0 then if not getElementData(localPlayer,"isDead") then triggerServerEvent("kilLDayZPlayer",localPlayer,attacker,headshot,getWeaponNameFromID(weapon)) setElementData(localPlayer,"isDead",true) end end if weapon == 54 or weapon == 63 or weapon == 49 or weapon == 51 then local sangre = math.random( 100, 1000 ) setElementData(getLocalPlayer(),"blood",getElementData( getLocalPlayer(),"blood") - sangre ) sendClientMessage ( '-'..sangre, 1, 'left' ) local number = math.random(1,5) if loss > 30 then setElementData(localPlayer,"brokenbone",true) setPedControlState("jump",true) end if loss >= 100 then setElementData(localPlayer,"blood",49) setElementData(localPlayer,"bleeding",50) end local number = math.random(1,11) if number == 3 then setElementData(localPlayer,"pain",true) end end if getElementData(getLocalPlayer(),"blood")<= 0 and not getElementData(getLocalPlayer(),"isDead")== true then triggerServerEvent("kilLDayZPlayer",getLocalPlayer(),(getElementData(localPlayer, "lastattacker") or attacker),headshot,getWeaponNameFromID (weapon)) setElementData(getLocalPlayer(),"isDead",true) end end end addEventHandler("onClientPlayerDamage", getLocalPlayer(), playerGetDamageDayZ) [Click and drag to move] Link to comment
error403 ツ Posted April 28, 2021 Share Posted April 28, 2021 function playerGetDamageDayZ(attacker, weapon, bodypart, loss) cancelEvent() local occupiedvehicle = getPedOccupiedVehicle(localPlayer); if occupiedvehicle and getElementModel(occupiedvehicle) == 528 then return; end showPlayerDamageScreen(0,"up"); local headshot = false; if weapon == 37 then setElementData(localPlayer,"blood",getElementData(localPlayer,"blood")-10000) return elseif weapon == 51 or weapon == 59 or weapon == 63 or weapon == 16 then setElementData(localPlayer,"blood",getElementData(localPlayer,"blood")-12001) end if attacker and getElementType(attacker) == "player" then setElementData(localPlayer,"lastattacker",attacker) end damage = 100 headshot = false if attacker then if isElement(sleepText) then setElementData(localPlayer,"isSleeping",false) destroyElement(sleepText) triggerServerEvent("getDamageSleep", localPlayer) end if attacker and getElementType(attacker) and getElementType(attacker) == "vehicle" and not getElementData(getLocalPlayer(), "godmode") and not getElementData(getLocalPlayer(), "greenzone") then if loss >= 30 then setElementData(getLocalPlayer(),"blood",12001) end speedx, speedy, speedz = getElementVelocity(attacker) actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) kmh = actualspeed * 180 if kmh >= 100 then setElementData(getLocalPlayer(),"blood",-10) else setElementData(getLocalPlayer(), "blood", getElementData(getLocalPlayer(), "blood") - 500) end setElementData(localPlayer,"lastattacker",getVehicleOccupant(attacker)) end if attacker then if getElementData(attacker, "zombie") then setElementData(getLocalPlayer(),"blood",getElementData(getLocalPlayer(),"blood")-gameplayVariables["zombiedamage"]) sendClientMessage ( '-'..gameplayVariables["zombiedamage"], 1, 'left' ) local number = math.random(1, 9) playSound("Sonidos/Ataque-Zombies/attack_"..number..".mp3") if number == 4 then setElementData(getLocalPlayer(),"infection",true) setElementData(getLocalPlayer(), "bleeding", getElementData(getLocalPlayer(), "bleeding") + math.floor(loss*10)) end end end end -- DAÑO DE LOS PUÑOS if attacker then if weapon == 0 and getElementType(attacker) == "player" then setElementData(localPlayer,"blood",getElementData(localPlayer,"blood")-150) end end -- if (weapon == 16) then local aX,aY,aZ = getElementPosition(attacker) local tX,tY,tZ = getElementPosition(localPlayer) if isLineOfSightClear(aX,aY,aZ,tX,tY,tZ,true,false,false,true) then setElementData(localPlayer, "blood", getElementData(localPlayer, "blood") - math.random(20000*0.8, 20000*1.2)); end end -- if weapon == 49 then if loss > 30 then setElementData(getLocalPlayer(),"brokenbone",true) setPedControlState ("jump",true) setElementData(getLocalPlayer(),"blood",getElementData(getLocalPlayer(),"blood")-math.floor(loss*10)) sendClientMessage ( '-'..math.floor(loss*10), 1, 'left' ) setElementData(getLocalPlayer(),"blood",getElementData(getLocalPlayer(),"blood")-math.floor(loss*5)) sendClientMessage ( '-'..math.floor(loss*5), 1, 'left' ) end end if weapon == 63 or weapon == 51 or weapon == 19 or weapon == 50 then local aX,aY,aZ = getElementPosition (localPlayer) local tX,tY,tZ = getElementPosition (localPlayer) if isLineOfSightClear(aX, aY, aZ, tX, tY, tZ, true, false, false, true) then setElementData(getLocalPlayer(), "blood", -300) if getElementData(getLocalPlayer(), "blood") <= 1 then if not getElementData(getLocalPlayer(), "isDead") == true then triggerServerEvent("kilLDayZPlayer",getLocalPlayer(), attacker, headshot) end end end if weapon and weapon > 1 and attacker and getElementType(attacker) == "player" then setElementData(localPlayer,"lastAttacker",attacker) damage = getWeaponDamage(weapon,attacker) local x1,y1,z1 = getElementPosition(localPlayer) local x2,y2,z2 = getElementPosition(attacker) local distancia = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2) local damage = math.random(distancia*5, distancia*6) if bodypart == 9 then damage = damage*gameplayVariables["headshotdamage_player"] sendClientMessage ( '-'..gameplayVariables["headshotdamage_player"], 1, 'left' ) headshot = true end if attacker then if weapon == 17 and getElementType(attacker) == "player" then setElementData(localPlayer,"blood",getElementData(localPlayer,"blood")-10) end end if bodypart == 7 or bodypart == 8 then setElementData(localPlayer,"brokenbone",true) end if getElementData(localPlayer,"humanity") >= 5000 then if damage <= 1000 then damage = 0 else damage = damage end end setElementData(localPlayer,"blood",getElementData(localPlayer,"blood")-math.floor(damage)) if damage >= 6000 then end local number = math.random(1,8) if number >= 6 and number <= 8 then if damage > 0 then setElementData(localPlayer,"bleeding",getElementData(localPlayer,"bleeding") + math.floor(loss*10)) end end local number = math.random(1,7) if number == 2 then setElementData(localPlayer,"pain",true) end ----------------------------------------- playRandomHitSound() local myKills = 200 - ((getElementData(localPlayer,"murders") / 3) * 150) local rawDamage = math.floor(math.sqrt((damage/55.55))) local humanityHit = -(myKills * rawDamage) if humanityHit > -800 then humanityHit = -800 end if not getElementData(localPlayer,"bandit") then triggerServerEvent("onPlayerChangeStatus",attacker,"humanity",math.floor(humanityHit)) if getElementData(attacker,"humanity") < 0 then setElementData(attacker,"bandit",true) end else triggerServerEvent("onPlayerChangeStatus",attacker,"humanity",math.floor(humanityHit)) if getElementData(attacker,"humanity") > 5000 then setElementData(attacker,"humanity",5000) end if getElementData(attacker,"humanity") > 2000 then setElementData(attacker,"bandit",false) end end if getElementData(localPlayer,"blood") <= 0 then if not getElementData(localPlayer,"isDead") then triggerServerEvent("kilLDayZPlayer",localPlayer,attacker,headshot,getWeaponNameFromID(weapon)) setElementData(localPlayer,"isDead",true) end end if weapon == 54 or weapon == 63 or weapon == 49 or weapon == 51 then local sangre = math.random( 100, 1000 ) setElementData(getLocalPlayer(),"blood",getElementData( getLocalPlayer(),"blood") - sangre ) sendClientMessage ( '-'..sangre, 1, 'left' ) local number = math.random(1,5) if loss > 30 then setElementData(localPlayer,"brokenbone",true) setPedControlState("jump",true) end if loss >= 100 then setElementData(localPlayer,"blood",49) setElementData(localPlayer,"bleeding",50) end local number = math.random(1,11) if number == 3 then setElementData(localPlayer,"pain",true) end end if getElementData(getLocalPlayer(),"blood")<= 0 and not getElementData(getLocalPlayer(),"isDead")== true then triggerServerEvent("kilLDayZPlayer",getLocalPlayer(),(getElementData(localPlayer, "lastattacker") or attacker),headshot,getWeaponNameFromID (weapon)) setElementData(getLocalPlayer(),"isDead",true) end end end addEventHandler("onClientPlayerDamage", getLocalPlayer(), playerGetDamageDayZ) prueba esto. Y dime si te resulta. Link to comment
Maruchan Posted April 28, 2021 Author Share Posted April 28, 2021 (edited) 1 hour ago, error403 ツ said: prueba esto. Y dime si te resulta. Es que no comprendo porque jode cuando mueres cerca de un auto que explota... ¿sabes cúal es el error?, que si tu disparas aun auto lo dejas encendido fuego y te mueres cerca del auto... en la pantalla respawn, los segundos paran super rapidos... es como que se bugea.... ¿No sé si alguna vez has visto algo así?. Edited April 28, 2021 by Maruchan Link to comment
Fist Posted May 1, 2021 Share Posted May 1, 2021 What exactly is your problem? Is it bodies being duplicated when dying from explsion? i remember that bug when i was working with my server. If so, you just need to specify that specific player is dead after he dies, and in code make sure it checks that if it's dead, it returns and does nothing. That's how i fixed it. something like this somewhere at top of "kilLDayZPlayer" event function if (getElementData(source,"isDead")) then return; end and make sure you add setAccountData(account, "isDead", true); setElementData(source, "isDead", true); somewhere at the end of code, and once the player respawns remove isDead of course. 1 Link to comment
Maruchan Posted May 1, 2021 Author Share Posted May 1, 2021 2 hours ago, Fist said: The problem is that, when you die from a car explosion, the respawn seconds pass quickly like two at a time. I have the problem when you die from the explosion of a vehicle and I don't know how to solve it, this error really has me stressed :(. Link to comment
Tekken Posted May 2, 2021 Share Posted May 2, 2021 addEventHandler("onVehicleExplode", root, function() local occupants = getVehicleOccupants(source); for i = 0, #occupants do local player = occupants[i]; setElementData(player, "isDead", true); triggerEvent("killDayZPlayer", player); end end); server ^ This should work, if not let me know. I wrote it on phone. Link to comment
Maruchan Posted May 2, 2021 Author Share Posted May 2, 2021 (edited) Bro, I do not understand much, but, this does not fulfill the same function ? function notifyAboutExplosion2() for i, player in pairs(getVehicleOccupants(source)) do triggerEvent("kilLDayZPlayer", player) end end addEventHandler("onVehicleExplode", getRootElement(), notifyAboutExplosion2) SERVER spawn.lua DAYZ I use the typical free dayz game mode and they all come with the same function in the spawn.lua file Edited May 2, 2021 by Maruchan Link to comment
Tekken Posted May 2, 2021 Share Posted May 2, 2021 Just add the isDead element data before triggering the event, also can you send a debugscript 3 img of when a veh explode with you driving it? Link to comment
Maruchan Posted May 2, 2021 Author Share Posted May 2, 2021 (edited) Is that, when you are inside the vehicle and it explodes there is no error. The problem occurs when you explode because of a vehicle being outside ... But in debugscript 3 it does not show any errors. Edited May 2, 2021 by Maruchan Link to comment
Tekken Posted May 2, 2021 Share Posted May 2, 2021 Ohhh ok got it wait a sec Add this to onClientPlayerDamage if weapon == 51 then triggerEvent("killDayzPlayer", localPlayer); return; end This is already in your code but you don’t have the return thing, you mai just add that after the triggerEvent 1 Link to comment
Maruchan Posted May 2, 2021 Author Share Posted May 2, 2021 (edited) Hope it works Edited May 2, 2021 by Maruchan 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