DaBOSS54320

Bully LUA: Grapple Speed Sync

Sep 25th, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. function T_GrappleSync()
  2.     -- This thread will syncronize ped speeds when they are grappling each other.
  3.     -- If the ped's speed is changed while in grapple by something else, that change may be lost when the ped is out of the grapple and the original speed is restored.
  4.     -- Usage: CreateThread("T_GrappleSync")
  5.    
  6.     -- Variables:
  7.     local peds = {}
  8.    
  9.     -- Main loop:
  10.     while true do
  11.         -- Process peds:
  12.         for i,ped in ipairs({PedFindInAreaXYZ(0,0,0,9999999)}) do
  13.             if i > 1 then
  14.                 local s = peds[ped]
  15.                 local target = PedGetGrappleTargetPed(ped)
  16.                 if s then
  17.                     if target ~= s[1] then
  18.                         GameSetPedStat(ped,20,s[2])
  19.                         peds[ped] = nil
  20.                     elseif GameGetPedStat(ped,20) ~= GameGetPedStat(target,20) then
  21.                         GameSetPedStat(ped,20,GameGetPedStat(target,20))
  22.                     end
  23.                 elseif PedIsValid(target) and not PedIsDead(target) and GameGetPedStat(ped,20) ~= GameGetPedStat(target,20) then
  24.                     peds[ped] = {target,GameGetPedStat(ped,20)}
  25.                     GameSetPedStat(ped,20,GameGetPedStat(target,20))
  26.                 end
  27.             end
  28.         end
  29.        
  30.         -- Wait:
  31.         Wait(0)
  32.        
  33.         -- Clean:
  34.         for ped,s in pairs(peds) do
  35.             if not PedIsValid(ped) then
  36.                 peds[ped] = nil
  37.             end
  38.         end
  39.     end
  40. end
Add Comment
Please, Sign In to add comment