Guest User

Untitled

a guest
Sep 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.38 KB | None | 0 0
  1. --[[local ablauf = false
  2. local gMe = getLocalPlayer()
  3. local ped
  4. local stat = {}
  5. local firetimer
  6. local timer = {}
  7. local jx, jy, jz
  8.  
  9. stat["jumping"] = false
  10.  
  11. local function on_damage_check()
  12.     local x, y, z = getElementPosition(gMe)
  13.     local x2, y2, z2 = getElementPosition(ped)
  14.     if(getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) < 2) then
  15.         setTimer(function()
  16.             setPedControlState(ped, "fire", true)
  17.             setPedControlState(ped, "aim_weapon", true)
  18.             if(isTimer(firetimer)) then killTimer(firetimer) end
  19.             firetimer = setTimer(function()
  20.                 setPedControlState(ped, "fire", false)
  21.                 setPedControlState(ped, "aim_weapon", false)
  22.             end, 1000, 1)
  23.         end, 500, 1)
  24.     end
  25. end
  26.  
  27.  
  28. local function functionscheck()
  29.     if(isElement(ped)) and (ablauf == true) then
  30.         local x, y, z = getElementPosition(gMe)
  31.         local x2, y2, z2 = getElementPosition(ped)
  32.         if(getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) > 2) then
  33.             stat["running"] = true
  34.             if(getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) > 10) then
  35.                 if(stat["jumping"] ~= true) then
  36.                     setPedAnimation(ped, "ped" , "sprint_civi", -1, true, true, false)
  37.                 end
  38.             else
  39.                 if(stat["jumping"] ~= true) then
  40.                     setPedAnimation(ped, "ped" , "JOG_maleA", -1, true, true, false)
  41.                 end
  42.             end
  43.             local x1, y1 = getElementPosition(ped)
  44.             local x2, y2 = getElementPosition(gMe)
  45.             local rot = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi
  46.             rot = rot-90
  47.             setPedRotation(ped, rot)
  48.             if((z-z2) > 0.8) and (getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) < 4) then
  49.                 stat["jumping"] = true
  50.                 setPedAnimation(ped)
  51.                 setPedControlState(ped, "jump", true)
  52.                 outputChatBox("Er ist oben")
  53.                 if(isTimer(timer["jump"])) then killTimer(timer["jump"]) end
  54.                 timer["jump"] = setTimer(function()
  55.                     stat["jumping"] = false
  56.                     setPedControlState(ped, "jump", false)
  57.                 end, 700, 1)
  58.             end
  59.         else
  60.             if (stat["running"] == true)then
  61.                 stat["running"] = false
  62.                 setPedAnimation(ped)
  63.             end
  64.         end
  65.     end
  66. end
  67.  
  68. setTimer(functionscheck, 200, -1)
  69.  
  70.  
  71. addCommandHandler("follower", function()
  72.     if(ablauf == true) then return end
  73.     ablauf = true
  74.     local x, y, z = getElementPosition(gMe)
  75.     ped = createPed(60, x, y+1, z)
  76.     addEventHandler("onClientPedDamage", ped, on_damage_check)
  77. end)
  78. ]]
  79.  
  80. addEvent("doPedJump", true)
  81. addEvent("doPedEnter", true)
  82. addEvent("doPedExitVeh", true)
  83.  
  84. addEventHandler("doPedJump", getLocalPlayer(), function(p, boolean)
  85.     setPedControlState(p, "jump", boolean)
  86. end)
  87.  
  88. addEventHandler("doPedEnter", getLocalPlayer(), function(p, boolean)
  89.     setPedControlState(p, "enter_passenger", boolean)
  90. end)
  91.  
  92. addEventHandler("doPedExitVeh", getLocalPlayer(), function(p, boolean)
  93.     setPedControlState(p, "enter_exit", boolean)
  94. end)
  95.  
  96.  
  97. -- DAMAGE ABFRAGE --
  98.  
  99. local pedTarget = {}
  100. local pedTimer = {}
  101. local pedShooting = {}
  102.  
  103. local function doPedAttackOtherPlayer(ped)
  104.     if(isTimer(pedTimer[ped])) or (isPedInVehicle(ped)) then
  105.         killTimer(pedTimer[ped])
  106.     end
  107.     if(isElement(ped)) then
  108.         pedTimer[ped] = setTimer(function()
  109.             if(isElement(ped)) then
  110.                 local target = pedTarget[ped]
  111.                 if(target) then
  112.                     local x, y, z = getElementPosition(ped)
  113.                     local x2, y2, z2 = getElementPosition(target)
  114.                     if(isLineOfSightClear(x, y, z, x2, y2, z2, true, false, false, false, false, false)) then
  115.                         if(pedShooting[ped]) and (pedShooting[ped] == true) then
  116.                             pedShooting[ped] = false
  117.                             setPedControlState(ped, "fire", false)
  118.                             setPedControlState(ped, "aim_weapon", false)
  119.                         else
  120.                             if(getElementHealth(target) > 1) then
  121.                                 pedShooting[ped] = true
  122.                                 local x1, y1 = getElementPosition(ped)
  123.                                 local x2, y2 = getElementPosition(target)
  124.                                 local rot = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi
  125.                                 rot = rot-90
  126.                                 setPedRotation(ped, rot)
  127.                                 setPedControlState(ped, "aim_weapon", true)
  128.                                 setPedControlState(ped, "fire", true)
  129.                                 setPedAimTarget(ped, x2, y2, z2)
  130.                             else
  131.                                 pedShooting[ped] = false
  132.                                 killTimer(pedTimer[ped])
  133.                             end
  134.                         end
  135.                     end
  136.                 else
  137.                     killTimer(pedTimer[ped])
  138.                 end
  139.             else
  140.                 killTimer(pedTimer[ped])
  141.             end
  142.         end, 500, -1)
  143.     else
  144.         killTimer(pedTimer[ped])
  145.     end
  146. end
  147.  
  148. addEventHandler("onClientPedDamage", getRootElement(), function(attacker)
  149.     if(getElementData(source, "bodyguard") == true) then
  150.         pedTarget[source] = attacker
  151.         doPedAttackOtherPlayer(source)
  152.     end
  153. end)
Add Comment
Please, Sign In to add comment