Advertisement
sheredega

setcolor

Sep 20th, 2023
1,231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. local sa = require "lib.samp.events"
  2. local state = true
  3.  
  4. local friends = {}
  5.  
  6.  
  7. function main()
  8.     if not isSampfuncsLoaded() or not isSampLoaded() then return end
  9.     while not isSampAvailable() do wait(100) end
  10.     sampRegisterChatCommand("setcolor", setid)
  11.     sampRegisterChatCommand("set", function()
  12.     state = not state
  13.     sampAddChatMessage(state and "ON" or "off", -1)
  14.     end)
  15. end
  16.  
  17. function setcolor(id)
  18.     local bs = raknetNewBitStream()
  19.     raknetBitStreamWriteInt16(bs, id) -- ID - РёРґ РёРіСЂРѕРєР°
  20.     raknetBitStreamWriteInt32(bs, -16738047) -- color - цвет
  21.     raknetEmulRpcReceiveBitStream(72,bs)
  22.     raknetDeleteBitStream(bs)
  23.  
  24.     sampAddChatMessage("Цвет игрока с ID "..id.." изменён!", -1)
  25. end
  26.  
  27. function setid(arg)
  28.     if state then
  29.         if #arg > 0 then -- Если указан аргумент у команды
  30.             if arg:find("[^%d]+") then -- Если указаны не только цифры
  31.                 _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
  32.                 if sampGetPlayerNickname(myid) == arg then
  33.                     sampAddChatMessage("Ты указал свой Nick_Name!", -1)
  34.                 else
  35.                     maxId = sampGetMaxPlayerId()
  36.                     for i = 0, maxId do
  37.                         if sampIsPlayerConnected(i) and sampGetPlayerNickname(i) == arg then
  38.                             friends[sampGetPlayerNickname(i)] = true
  39.                             setcolor(i)
  40.                             return true
  41.                         end
  42.                     end
  43.                     sampAddChatMessage("Игрока с таким ником нет в игре!", -1)
  44.                 end
  45.             else
  46.                 id = tonumber(arg)
  47.                 _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
  48.                 if myid == id then
  49.                     sampAddChatMessage("Ты указал свой ID!", -1)
  50.                 elseif sampIsPlayerConnected(id) then
  51.                     friends[sampGetPlayerNickname(id)] = true
  52.                     setcolor(id)
  53.                 else
  54.                     sampAddChatMessage("Игрока с ID " .. arg .. " нет в игре", -1)
  55.                 end
  56.             end
  57.         else
  58.             sampAddChatMessage("Не указан ник/id. Пример: /setcolor [id/Nick_Name]", -1)
  59.         end
  60.     end
  61. end
  62.  
  63. function sa.onSetPlayerColor(id, color)
  64.     if friends[sampGetPlayerNickname(id)] then
  65.         return false
  66.     end
  67. end
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement