SlonPvpru

[For All] WH-Sync

Jun 4th, 2020
1,222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. -- Author: Azller Lollison (in public this source is missing)
  2.  
  3. local sampev = require 'lib.samp.events'
  4.  
  5. wh = {
  6.     activate = false,
  7.     players = {}
  8. }
  9.  
  10. local font = renderCreateFont("Arial", 8, 5)
  11.  
  12. function main()
  13.     while not isSampAvailable() do wait(0) end
  14.     sampRegisterChatCommand('syncwh', function() wh.activate = not wh.activate; sampAddChatMessage(wh.activate and 'Activate' or 'OFF', -1) end)
  15.  
  16.     while true do wait(0)
  17.         if wh.activate then
  18.             for i = 1, #wh.players do
  19.                 if wh.players[i] then
  20.                     if isPointOnScreen(wh.players[i]["coords"].x, wh.players[i]["coords"].y, wh.players[i]["coords"].z, 1) then
  21.                         if sampIsPlayerConnected(wh.players[i].id) then
  22.                             local wPosX, wPosY = convert3DCoordsToScreen(wh.players[i]["coords"].x + (wh.players[i]["speed"].x * 2), wh.players[i]["coords"].y + (wh.players[i]["speed"].y * 2), wh.players[i]["coords"].z + (wh.players[i]["speed"].z * 2))
  23.                             renderFontDrawText(font, sampGetPlayerNickname(wh.players[i].id).."["..wh.players[i].id.."]", wPosX, wPosY + 3, 0xFFFFFFFF, false)
  24.                         else
  25.                             wh.players[i] = nil
  26.                         end
  27.                     end
  28.                 end
  29.             end
  30.         end
  31.     end
  32.     wait(-1)
  33. end
  34.  
  35. local function registerPlayerIdInSystem(num)
  36.     wh.players[#wh.players + 1] = {id = num,
  37.         ["coords"] = {0, 0, 0},
  38.         ["speed"] = {1, 1, 1}
  39.     }
  40. end
  41.  
  42. local function playerIdRegisteredInSystem(id)
  43.     for i = 1, #wh.players do
  44.         if wh.players[i] then
  45.             if wh.players[i].id == id then return true end
  46.         end
  47.     end
  48.     return false
  49. end
  50.  
  51. function sampev.onPlayerStreamOut(id)
  52.     for i = 1, #wh.players do
  53.         if wh.players[i] then
  54.             if wh.players[i].id == id then wh.players[i] = nil end
  55.         end
  56.     end
  57. end
  58.  
  59. function sampev.onPlayerQuit(id)
  60.     for i = 1, #wh.players do
  61.         if wh.players[i] then
  62.             if wh.players[i].id == id then wh.players[i] = nil end
  63.         end
  64.     end
  65. end
  66.  
  67.  
  68. function sampev.onVehicleSync(id, vehicleID, data)
  69.  
  70.     if playerIdRegisteredInSystem(id) then
  71.         for a = 1, #wh.players do
  72.             if wh.players[a] then
  73.                 if wh.players[a].id == id then
  74.                     wh.players[a]["coords"] = data.position
  75.                     wh.players[a]["speed"] = data.moveSpeed
  76.                 end
  77.             end
  78.         end
  79.     else
  80.         registerPlayerIdInSystem(id);
  81.     end
  82.  
  83. end
  84.  
  85. function sampev.onPlayerSync(id, data)
  86.  
  87.     if playerIdRegisteredInSystem(id) then
  88.         for a = 1, #wh.players do
  89.             if wh.players[a] then
  90.                 if wh.players[a].id == id then
  91.                     wh.players[a]["coords"] = data.position
  92.                     wh.players[a]["speed"] = data.moveSpeed
  93.                 end
  94.             end
  95.         end
  96.     else
  97.         registerPlayerIdInSystem(id);
  98.     end
  99.  
  100. end
Advertisement
Add Comment
Please, Sign In to add comment