lopezloo

Simple own damage system.

Sep 19th, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. SERVERSIDE:
  2. addEventHandler("onPlayerSpawn", root,
  3.     function()
  4.         setElementData(source, "hp", 100)
  5.     end
  6. )
  7.  
  8. function setElementHealthEx(element, health, attacker, weapon, bodypart)
  9.     if getElementType(element) == "ped" then
  10.         setElementData(element, "hp", health)
  11.         if hp <= 0 then
  12.             killPed(element, attacker, weapon, bodypart, false)
  13.         end
  14.     else setElementHealth(element, health)
  15. end
  16.  
  17. function killPedEx(ped, attacker, weapon, bodypart, stealth)
  18.     killPed(ped, attacker, weapon, bodypart, stealth)
  19. end
  20. addEvent("killPedEx", true)
  21. addEventHandler("killPedEx", root, killPedEx)
  22.  
  23. CLIENTSIDE:
  24. function setElementHealthEx(element, health, attacker, weapon, bodypart)
  25.     if getElementType(element) == "ped" then
  26.         setElementData(element, "hp", health)
  27.         if hp <= 0 then
  28.             triggerServerEvent("killPedEx", root, element, attacker, weapon, bodypart, false)
  29.         end
  30.     else setElementHealth(element, health)
  31. end
  32.  
  33. function damageFunc(attacker, weapon, bodypart, loss)
  34.     cancelEvent()
  35.     setElementData(source, "hp", getElementHealth(source) - loss)
  36.     setElementHealthEx(source, getElementHealth(source) - loss, attacker, weapon, bodypart)
  37. end
  38. addEventHandler("onClientPlayerDamage", localPlayer, damageFunc)
  39. addEventHandler("onClientPedDamage", root, damageFunc)
Advertisement
Add Comment
Please, Sign In to add comment