Вопросы по Lua скриптингу

Общая тема для вопросов по разработке скриптов на языке программирования Lua, в частности под MoonLoader.
  • Задавая вопрос, убедитесь, что его нет в списке частых вопросов и что на него ещё не отвечали (воспользуйтесь поиском).
  • Поищите ответ в теме посвященной разработке Lua скриптов в MoonLoader
  • Отвечая, убедитесь, что ваш ответ корректен.
  • Старайтесь как можно точнее выразить мысль, а если проблема связана с кодом, то обязательно прикрепите его к сообщению, используя блок [code=lua]здесь мог бы быть ваш код[/code].
  • Если вопрос связан с MoonLoader-ом первым делом желательно поискать решение на wiki.

Частые вопросы

Как научиться писать скрипты? С чего начать?
Информация - Гайд - Всё о Lua скриптинге для MoonLoader(https://blast.hk/threads/22707/)
Как вывести текст на русском? Вместо русского текста у меня какие-то каракули.
Изменить кодировку файла скрипта на Windows-1251. В Atom: комбинация клавиш Ctrl+Shift+U, в Notepad++: меню Кодировки -> Кодировки -> Кириллица -> Windows-1251.
Как получить транспорт, в котором сидит игрок?
Lua:
local veh = storeCarCharIsInNoSave(PLAYER_PED)
Как получить свой id или id другого игрока?
Lua:
local _, id = sampGetPlayerIdByCharHandle(PLAYER_PED) -- получить свой ид
local _, id = sampGetPlayerIdByCharHandle(ped) -- получить ид другого игрока. ped - это хендл персонажа
Как проверить, что строка содержит какой-то текст?
Lua:
if string.find(str, 'текст', 1, true) then
-- строка str содержит "текст"
end
Как эмулировать нажатие игровой клавиши?
Lua:
local game_keys = require 'game.keys' -- где-нибудь в начале скрипта вне функции main

setGameKeyState(game_keys.player.FIREWEAPON, -1) -- будет сэмулировано нажатие клавиши атаки
Все иды клавиш находятся в файле moonloader/lib/game/keys.lua.
Подробнее о функции setGameKeyState здесь: lua - setgamekeystate | BlastHack — DEV_WIKI(https://www.blast.hk/wiki/lua:setgamekeystate)
Как получить id другого игрока, в которого целюсь я?
Lua:
local valid, ped = getCharPlayerIsTargeting(PLAYER_HANDLE) -- получить хендл персонажа, в которого целится игрок
if valid and doesCharExist(ped) then -- если цель есть и персонаж существует
  local result, id = sampGetPlayerIdByCharHandle(ped) -- получить samp-ид игрока по хендлу персонажа
  if result then -- проверить, прошло ли получение ида успешно
    -- здесь любые действия с полученным идом игрока
  end
end
Как зарегистрировать команду чата SAMP?
Lua:
-- До бесконечного цикла/задержки
sampRegisterChatCommand("mycommand", function (param)
     -- param будет содержать весь текст введенный после команды, чтобы разделить его на аргументы используйте string.match()
    sampAddChatMessage("MyCMD", -1)
end)
Крашит игру при вызове sampSendChat. Как это исправить?
Это происходит из-за бага в SAMPFUNCS, когда производится попытка отправки пакета определенными функциями изнутри события исходящих RPC и пакетов. Исправления для этого бага нет, но есть способ не провоцировать его. Вызов sampSendChat изнутри обработчика исходящих RPC/пакетов нужно обернуть в скриптовый поток с нулевой задержкой:
Lua:
function onSendRpc(id)
  -- крашит:
  -- sampSendChat('Send RPC: ' .. id)

  -- норм:
  lua_thread.create(function()
    wait(0)
    sampSendChat('Send RPC: ' .. id)
  end)
end
 
Последнее редактирование:

#Northn

Police Helper «Reborn» — уже ШЕСТЬ лет!
Всефорумный модератор
2,636
2,486
что я мог сделать, что при запуске гта вылезает ошибка

Посмотреть вложение 13437

Lua:
    function scm(param)
        collspd = -1442814209
        colfbi = -1436129537
        colarmy = -1426807712
        colmz = -1426102682
        colcn = -1429419008
        colym = -1432813568
        colprvo = -1426063361
        colcnn = -1426076570
        coltm = -1442827418
        colsfpd = -1442840448
        colrm = -1439485133
        colgrv = -1442788352
        colbal = -1432813364
        colvag = -1426076621
        colazt = -1442775041
        colrif = -1439458919
        colar = -1436142848
        colstr = -1429418855
        colbik = -1432787354
        collvpd = -1442827418
        colpriz = -1439485184
        colvvs = -1442788199
        colvmf = -1439458970
        local id = string.match(param, '(%d+)')
        if id ~= nil then
             if id == "1" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= collspd do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             end
             if id == "2" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colfbi do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             end
             if id == "3" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colarmy do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "4" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colmz do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "5" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colcn do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "6" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colym do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "7" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colprvo do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "8" then
                              sampAddChatMessage("[ {800000}HitMan {ffffff}]: Маскировка невозможна. Причина: 8 ID фракции - {800000}Hitman Agency.", -1)
                     end
             if id == "9" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colcnn do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "10" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= coltm do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "11" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colsfpd do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "12" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colrm do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "13" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colgrv do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "14" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colbal do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "15" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colvag do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "16" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colazt do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "17" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colrif do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "18" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colar do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "19" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colstr do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "20" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colbik do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "21" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= collvpd do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "22" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colpriz do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "23" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colvvs do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "24" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colvmf do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
                 else
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Скины фракций - [ {800000}/scm {ffffff}].", -1)
                     sampAddChatMessage("[ {800000}1 {ffffff}] - LSPD; [ {800000}2 {ffffff}] - FBI; [ {800000}3 {ffffff}] - NGSA; [ {800000}4 {ffffff}] - МинЗдрав ..", -1)
                     sampAddChatMessage(".. [ {800000}5 {ffffff}] - Cosa Nostra; [ {800000}6 {ffffff}] - Yakuza; [ {800000}7 {ffffff}] - Правительство ..", -1)
                     sampAddChatMessage(".. [ {800000}8 {ffffff}] - None; [ {800000}9 {ffffff}] - CNN; [ {800000}10 {ffffff}] - Triada  ..", -1)
                     sampAddChatMessage(".. [ {800000}11 {ffffff}] - SFPD; [ {800000}12 {ffffff}] - Russia; [ {800000}13 {ffffff}] - Grove ..", -1)
                     sampAddChatMessage(".. [ {800000}14 {ffffff}] - Ballas; [ {800000}15 {ffffff}] - Vagos; [ {800000}16 {ffffff}] - Aztecas ..", -1)
                     sampAddChatMessage(".. [ {800000}17 {ffffff}] - Rifa; [ {800000}18 {ffffff}] - Arabian; [ {800000}19 {ffffff}] - Street Racers ..")
                     sampAddChatMessage(".. [ {800000}20 {ffffff}] - Bikers; [ {800000}21 {ffffff}] - LVPD ..", -1)
                     sampAddChatMessage(".. [ {800000}22 {ffffff}]- Призывник; [ {800000}23 {ffffff}] - ВВС; [ {800000}24 {ffffff}] - ВМФ.", -1)
                 end
1. Табуляция.
2. Чекаешь концовки функций (end)
3. Берёшь свои циферки в ковычки.
 
  • Нравится
Реакции: штейн

imring

Ride the Lightning
Всефорумный модератор
2,354
2,516
что я мог сделать, что при запуске гта вылезает ошибка

Посмотреть вложение 13437

Lua:
    function scm(param)
        collspd = -1442814209
        colfbi = -1436129537
        colarmy = -1426807712
        colmz = -1426102682
        colcn = -1429419008
        colym = -1432813568
        colprvo = -1426063361
        colcnn = -1426076570
        coltm = -1442827418
        colsfpd = -1442840448
        colrm = -1439485133
        colgrv = -1442788352
        colbal = -1432813364
        colvag = -1426076621
        colazt = -1442775041
        colrif = -1439458919
        colar = -1436142848
        colstr = -1429418855
        colbik = -1432787354
        collvpd = -1442827418
        colpriz = -1439485184
        colvvs = -1442788199
        colvmf = -1439458970
        local id = string.match(param, '(%d+)')
        if id ~= nil then
             if id == "1" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= collspd do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             end
             if id == "2" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colfbi do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             end
             if id == "3" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colarmy do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "4" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colmz do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "5" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colcn do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "6" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colym do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "7" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colprvo do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "8" then
                              sampAddChatMessage("[ {800000}HitMan {ffffff}]: Маскировка невозможна. Причина: 8 ID фракции - {800000}Hitman Agency.", -1)
                     end
             if id == "9" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colcnn do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "10" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= coltm do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "11" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colsfpd do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "12" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colrm do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "13" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colgrv do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "14" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colbal do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "15" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colvag do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "16" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colazt do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "17" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colrif do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "18" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colar do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "19" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colstr do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "20" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colbik do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "21" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= collvpd do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "22" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colpriz do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "23" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colvvs do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
             if id == "24" then
                 players = 0
                 for id = 0, sampGetMaxPlayerId(false) do
                     if sampIsPlayerConnected(id) then
                         color = sampGetPlayerColor(id)
                                     math.randomseed(os.time())
                                         local id = math.random(0, sampGetMaxPlayerId(false))
                                         while sampGetPlayerColor(id) ~= colvmf do
                                         id = math.random(0, sampGetMaxPlayerId(false)) end
                             sampSendChat("/masked "..id)
                             players = players + 1
                             break
                         end
                     end
                 if players == 0 then
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.", -1)
                 end
                 else
                     sampAddChatMessage("[ {800000}HitMan {ffffff}]: Скины фракций - [ {800000}/scm {ffffff}].", -1)
                     sampAddChatMessage("[ {800000}1 {ffffff}] - LSPD; [ {800000}2 {ffffff}] - FBI; [ {800000}3 {ffffff}] - NGSA; [ {800000}4 {ffffff}] - МинЗдрав ..", -1)
                     sampAddChatMessage(".. [ {800000}5 {ffffff}] - Cosa Nostra; [ {800000}6 {ffffff}] - Yakuza; [ {800000}7 {ffffff}] - Правительство ..", -1)
                     sampAddChatMessage(".. [ {800000}8 {ffffff}] - None; [ {800000}9 {ffffff}] - CNN; [ {800000}10 {ffffff}] - Triada  ..", -1)
                     sampAddChatMessage(".. [ {800000}11 {ffffff}] - SFPD; [ {800000}12 {ffffff}] - Russia; [ {800000}13 {ffffff}] - Grove ..", -1)
                     sampAddChatMessage(".. [ {800000}14 {ffffff}] - Ballas; [ {800000}15 {ffffff}] - Vagos; [ {800000}16 {ffffff}] - Aztecas ..", -1)
                     sampAddChatMessage(".. [ {800000}17 {ffffff}] - Rifa; [ {800000}18 {ffffff}] - Arabian; [ {800000}19 {ffffff}] - Street Racers ..")
                     sampAddChatMessage(".. [ {800000}20 {ffffff}] - Bikers; [ {800000}21 {ffffff}] - LVPD ..", -1)
                     sampAddChatMessage(".. [ {800000}22 {ffffff}]- Призывник; [ {800000}23 {ffffff}] - ВВС; [ {800000}24 {ffffff}] - ВМФ.", -1)
                 end
Lua:
function scm(param)
    local colors = { -1442814209, -1436129537, -1426807712, -1426102682, -1429419008, -1432813568, -1426063361, -1426076570, -1442827418, -1442840448,
        -1439485133, -1442788352, -1432813364, -1426076621, -1442775041, -1439458919, -1436142848, -1429418855, -1432787354, -1442827418, -1439485184,
        -1442788199, -1439458970
    }
    local id = tonumber(param)
    if id and colors[id] then
        local color = colors[id]
        local select_col = false
        for i = 0, sampGetMaxPlayerId(false) do
            if sampIsPlayerConnected(i) and sampGetPlayerColor(i) == color then
                sampSendChat('/masked '..i)
                break
            end
        end
        if not select_col then sampAddChatMessage('[ {800000}HitMan {ffffff}]: Ни одного из членов данной органицзации нет в игре.', -1) end
    else
        sampAddChatMessage('[ {800000}HitMan {ffffff}]: Скины фракций - [ {800000}/scm {ffffff}].', -1)
        sampAddChatMessage('[ {800000}1 {ffffff}] - LSPD; [ {800000}2 {ffffff}] - FBI; [ {800000}3 {ffffff}] - NGSA; [ {800000}4 {ffffff}] - МинЗдрав ..', -1)
        sampAddChatMessage('.. [ {800000}5 {ffffff}] - Cosa Nostra; [ {800000}6 {ffffff}] - Yakuza; [ {800000}7 {ffffff}] - Правительство ..', -1)
        sampAddChatMessage('.. [ {800000}8 {ffffff}] - None; [ {800000}9 {ffffff}] - CNN; [ {800000}10 {ffffff}] - Triada  ..', -1)
        sampAddChatMessage('.. [ {800000}11 {ffffff}] - SFPD; [ {800000}12 {ffffff}] - Russia; [ {800000}13 {ffffff}] - Grove ..', -1)
        sampAddChatMessage('.. [ {800000}14 {ffffff}] - Ballas; [ {800000}15 {ffffff}] - Vagos; [ {800000}16 {ffffff}] - Aztecas ..', -1)
        sampAddChatMessage('.. [ {800000}17 {ffffff}] - Rifa; [ {800000}18 {ffffff}] - Arabian; [ {800000}19 {ffffff}] - Street Racers ..')
        sampAddChatMessage('.. [ {800000}20 {ffffff}] - Bikers; [ {800000}21 {ffffff}] - LVPD ..', -1)
        sampAddChatMessage('.. [ {800000}22 {ffffff}]- Призывник; [ {800000}23 {ffffff}] - ВВС; [ {800000}24 {ffffff}] - ВМФ.', -1)
    end
end
 
Последнее редактирование:
  • Нравится
Реакции: штейн

GORYCH

Известный
63
77
Если есть скрипт с реконнектом и после нескольких реконнектов крашит игру(картинка зависает и все). Как избавиться от этой ошибки? Заранее спасибо
 

Frapsy

Известный
Проверенный
393
226
Спасибо, но в этом случае мы получаем цель, по которой стреляет заданный игрок и оружие, из которого идет стрельба(кулак не ловит), вопрос состоит в том, как получить инфу о дамаге, который указанный игрок нанес :c Все гуглю информацию по BulletSyncData, onBulletSync и что-то ничего :c

Вопрос по RPC_GIVETAKEDAMAGE.. Суть вся та же, пытаюсь найти метод получения инфы о входящем/исходящем дамаге, который получает/отдает определенный игрок, но при этом, не только от меня или же мне, так вот.. Нарыл я тут это:

Код:
function onSendRpc(idP, bs)
    if idP == RPC_GIVETAKEDAMAGE then
        local dmgact = raknetBitStreamReadBool(bs)
        local dmgID = raknetBitStreamReadInt16(bs)
        local damage = raknetBitStreamReadFloat(bs)
        local gun = raknetBitStreamReadInt32(bs)
        local naxbp = raknetBitStreamReadInt32(bs)
        if dmgact == false then --получение урона
            dmgid = dmgID
            if dmgid == pID then      
                _, handle = sampGetCharHandleBySampPlayerId(dmgid)
                nickTo = sampGetPlayerNickname(dmgid)
                sampAddChatMessage(string.format("[DMG] %s получил +%d урона с оружия %d", nickTo, damage, gun), -1)
            end
        end
        if dmgact == true then --нанесение урона
            dmgid = dmgID
            if dmgid == pID then
                nickFrom = sampGetPlayerNickname(dmgid)
                sampAddChatMessage(string.format("[DMG] %s нанес -%d урона из оружия %d", nickFrom, damage, gun), -1)
            end
        end
    end
end
В данном случае, pID это переменная, которая задается мной, то есть, она содержит в себе ID игрока, кого нужно отслеживать на входящий/исходящий урон. НО, именно в этом коде, это будет работать лишь тогда, когда этот урон получаю и наношу только я, а не кто либо иной, чего собственно и пытаюсь добиться уже который день сидя на форуме и гугля инфу... Вопрос: как сделать, чтобы инфу о входящем дамаге принимал отовсех, а не только от меня? Ну и с исходящим тоже не помешало бы на всех принимать.. И вот так подумал, да, весь код выше, выходит что это тот же onSendGiveDamage/OnSendTakeDamage, которые мне не подходят.. Емае, вырви мозг одним словом.

Одна проблема, 2 варианта, не решено и тупо пролистывается мимо..
 
1,417
1,029

Hatiko

Известный
Проверенный
1,470
612
В чём может быть проблема. Создаю 3d текст, например, на игроке - он создаётся. Пытаюсь создать на себе - не создаётся. Такая же херня была и в cleo.
Lua:
sampCreate3dText("1", 0xFFFFFFFF, 0, 0, -0.5, 10, true, myid, -1)
 

itsLegend

Фонд борьбы за жуков 🐞
Администратор
2,696
1,460
В чём может быть проблема. Создаю 3d текст, например, на игроке - он создаётся. Пытаюсь создать на себе - не создаётся. Такая же херня была и в cleo.
Lua:
sampCreate3dText("1", 0xFFFFFFFF, 0, 0, -0.5, 10, true, myid, -1)
Такова особенность функции сампа.
 

for (;;)

Участник
71
31
В чём может быть проблема. Создаю 3d текст, например, на игроке - он создаётся. Пытаюсь создать на себе - не создаётся. Такая же херня была и в cleo.
Lua:
sampCreate3dText("1", 0xFFFFFFFF, 0, 0, -0.5, 10, true, myid, -1)
попробуй
Lua:
sampCreate3dTextEx(int id, zstring text, int color, float posX, float posY, float posZ, float distance, bool ignoreWalls, int playerId, int vehicleId)
 

Rowland

Новичок
114
2
Как запустить функцию, если в чате появилось определённое сообщение...