Guest User

Client side

a guest
Aug 21st, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | None | 0 0
  1. local gMe = getLocalPlayer()
  2.  
  3. addEvent("doPedJump", true)
  4. addEvent("doPedEnter", true)
  5. addEvent("doPedExitVeh", true)
  6.  
  7. addEventHandler("doPedJump", getLocalPlayer(), function(p, boolean)
  8.     setPedControlState(p, "jump", boolean)
  9. end)
  10.  
  11. addEventHandler("doPedEnter", getLocalPlayer(), function(p, boolean)
  12.     setPedControlState(p, "enter_passenger", boolean)
  13. end)
  14.  
  15. addEventHandler("doPedExitVeh", getLocalPlayer(), function(p, boolean)
  16.     setPedControlState(p, "enter_exit", boolean)
  17. end)
  18.  
  19.  
  20. -- DAMAGE ABFRAGE --
  21.  
  22. local pedTarget = {}
  23. local pedTimer = {}
  24. local pedShooting = {}
  25.  
  26. local function doPedAttackOtherPlayer(ped)
  27.     if(isTimer(pedTimer[ped])) or (isPedInVehicle(ped)) then
  28.         killTimer(pedTimer[ped])
  29.     end
  30.     if(isElement(ped)) then
  31.         pedTimer[ped] = setTimer(function()
  32.             if(isElement(ped)) then
  33.                 local target = pedTarget[ped]
  34.                 if(target) then
  35.                     local x, y, z = getElementPosition(ped)
  36.                     local x2, y2, z2 = getElementPosition(target)
  37.                     if(isLineOfSightClear(x, y, z, x2, y2, z2, true, false, false, false, false, false)) then
  38.                         if(getElementHealth(target) > 1) then
  39.                             if(pedShooting[ped] ~= true) then
  40.                                 --[[
  41.                                 local x1, y1 = getElementPosition(ped)
  42.                                 local x2, y2 = getElementPosition(target)
  43.                                     local rot = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi
  44.                                     rot = rot-90
  45.                                     setPedRotation(ped, rot)
  46.                                     setPedAnimation(ped)
  47.                                     if(getPedControlState(ped, "fire") ~= true) then
  48.                                         setPedControlState(ped, "fire", true)
  49.                                     end
  50.                                     setPedAimTarget(ped, x2, y2, z2)]]
  51.                                 setPedControlState(ped, "fire", true)
  52.                                 pedShooting[ped] = true
  53.                             else
  54.                                 local x1, y1, z1 = getElementPosition(ped)
  55.                                 local x2, y2, z2 = getElementPosition(target)
  56.                                 local rot = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi
  57.                                 rot = rot-90
  58.                                 setPedRotation(ped, rot)
  59.                                 setPedAimTarget(ped, x2, y2, z2)
  60.                             end
  61.                         else
  62.                             killTimer(pedTimer[ped])
  63.                             pedShooting[ped] = false
  64.                             setPedControlState(ped, "fire", false)
  65.                         end
  66.                     else
  67.                         killTimer(pedTimer[ped])
  68.                         pedShooting[ped] = false
  69.                         setPedControlState(ped, "fire", false)
  70.                     end
  71.                 end
  72.             else
  73.                 killTimer(pedTimer[ped])
  74.             end
  75.         end, 500, -1)
  76.     else
  77.         killTimer(pedTimer[ped])
  78.     end
  79. end
  80.  
  81. addEventHandler("onClientPedDamage", getRootElement(), function(attacker)
  82.     if(getElementData(source, "bodyguard") == true) then
  83.         if(attacker) and (isElement(attacker)) then
  84.             if(getElementType(attacker) == "player") or (getElementType(attacker) == "vehicle") then
  85.                 pedTarget[source] = attacker
  86.                 doPedAttackOtherPlayer(source)
  87.             end
  88.         end
  89.     end
  90. end)
  91.  
  92. -- onClientRender Func --
  93.  
  94.  
  95. addEventHandler("onClientRender", getRootElement(), function()
  96.     for index, p in pairs(getElementsByType("ped", getRootElement(), true)) do
  97.         if(getElementData(p, "bodyguard") == true) then
  98.             local owner = getElementData(p, "besitzer")
  99.             if(owner) then
  100.                 local x, y, z = getElementPosition(p)
  101.                 local x2, y2, z2 = getElementPosition(gMe)
  102.                 if(isLineOfSightClear(x, y, z, x2, y2, z2, true, true, false, true)) then
  103.                     local sx, sy = getScreenFromWorldPosition(x, y, z+1)
  104.                     if(sx) and (sy) then
  105.                         local distance = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
  106.                         if(distance < 30) then
  107.                             dxDrawText(owner.."'s Bodyguard", sx+2, sy+2, sx, sy, tocolor(0, 0, 0, 200), 2-(distance/20), "arial", "center", "center")
  108.                             dxDrawText(owner.."'s Bodyguard", sx, sy, sx, sy, tocolor(0, 255, 0, 200), 2-(distance/20), "arial", "center", "center")
  109.                         end
  110.                     end
  111.                 end
  112.             end
  113.         end
  114.     end
  115. end)
Add Comment
Please, Sign In to add comment