Вопросы по 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
 
Последнее редактирование:

RaMero

Известный
446
134
Может быть проблема с доступом к папке models? Учитывайте, что оно лезет именно в эту папку,а не в moonloader/modloader
В параметр get_txd не нужно указывать путь, только имя файла или его номер. Мб некоторые текстурки загружаются/выгружаются только при необходимости?
Например, fronten2.txd используется только в меню, мб она и подругажется только в открытом меню?
 

chromiusj

модерирую шмодерирую
Модератор
5,974
4,294
В параметр get_txd не нужно указывать путь, только имя файла или его номер. Мб некоторые текстурки загружаются/выгружаются только при необходимости?
Например, fronten2.txd используется только в меню, мб она и подругажется только в открытом меню?
Lua:
require 'lib.moonloader'
local imgui = require("mimgui")
local ffi   = require("ffi")
local mad   = require("MoonAdditions")
local enc   = require("encoding")
enc.default = 'CP1251'
local u8    = enc.UTF8
local new   = imgui.new

ffi.cdef[[
    typedef unsigned char RwUInt8;
    typedef int RwInt32;
    typedef struct RwLLLink { struct RwLLLink *next; struct RwLLLink *prev; } RwLLLink;
    typedef struct RwLinkList { RwLLLink link; } RwLinkList;
    typedef struct RwTexDictionary {
        void* object;
        RwLinkList texturesInDict;
        RwLinkList lInInstance;
    } RwTexDictionary;
    typedef struct RwTextureFull {
        void* raster;
        void* dict;
        RwLLLink inDictionary;
        char name[32];
        char mask[32];
        int refCount;
        unsigned int filterAddressing;
    } RwTextureFull;
    typedef struct RwRaster {
        void* parent;
        RwUInt8* cpPixels;
        RwUInt8* palette;
        RwInt32 width, height, depth;
        RwInt32 stride;
        short   nOffsetX, nOffsetY;
        RwUInt8 cType, cFlags, privateFlags, cFormat;
        RwUInt8* originalPixels;
        RwInt32 originalWidth, originalHeight, originalStride;
        void* texture_ptr;
    } RwRaster;
]]

local State = {
    WinState = new.bool(false),
    currentTXD = new.int(1),
    currentTexture = new.int(1),
    imageZoom = new.float(1.0),
    txdList = {},
    loadedTextures = {},
    didInitialAutoload = false,
    loadingStatus = u8"Жопа..."
}

local function isValidTextureName(name)
    if not name or #name == 0 or #name > 31 then return false end
    for i = 1, #name do
        if name:byte(i) < 32 then return false end
    end
    return true
end

local function getFilesInPath(path, mask)
    local res = {}
    local h, f = findFirstFile(path .. "\\" .. mask)
    if not h then return res end
    while f do
        if not f:match("^%.") then table.insert(res, f) end
        f = findNextFile(h)
    end
    findClose(h)
    return res
end

local OFFSETS = {4, 8, 0, 12}
local function findDict(ptr)
    for _, off in ipairs(OFFSETS) do
        local d = ffi.cast("RwTexDictionary*", ptr + off)
        if d ~= nil and d.texturesInDict.link.next ~= nil then
            return d
        end
    end
    return nil
end

local function extractAllTexturesData(txd)
    local base = txd:get_pointer()
    if base == 0 then return {} end
    local dict = findDict(base)
    if not dict then return {} end
    local head = dict.texturesInDict.link.next
    if not head then return {} end
    local texturesData, visited = {}, {}
    local first, count = head, 0
    while head ~= nil and count < 256 do
        local addr = tonumber(ffi.cast("uintptr_t", head))
        if visited[addr] then break end
        visited[addr] = true
        local tex = ffi.cast("RwTextureFull*", ffi.cast("char*", head) - ffi.offsetof("RwTextureFull", "inDictionary"))
        if tex then
            local success, name = pcall(ffi.string, tex.name)
            if success and isValidTextureName(name) and tex.raster ~= ffi.NULL then
                local raster = ffi.cast("RwRaster*", tex.raster)
                if raster.texture_ptr ~= ffi.NULL then
                    table.insert(texturesData, {
                        texture_ptr = raster.texture_ptr,
                        width  = raster.width,
                        height = raster.height,
                        name   = name
                    })
                end
            end
        end
        head = head.next
        count = count + 1
        if head == first then break end
    end
    return texturesData
end

local function rebuildLoadedTexturesFor(index)
    State.loadedTextures = {}
    local rec = State.txdList[index]
    if rec and rec.textures then
        State.loadedTextures = rec.textures
    end
    State.currentTexture[0] = #State.loadedTextures > 0 and 1 or 0
    State.imageZoom[0] = 1.0
end

local function scanTXD(folder)
    local files = getFilesInPath(folder, "*.txd")
    table.sort(files)
    local totalFiles = #files
    for i, file in ipairs(files) do
        State.loadingStatus = string.format(u8"Загрузка... (%d / %d): %s", i, totalFiles, file)
        local fullPath = folder .. "\\" .. file
        local name = file:gsub("%.txd$", "")
        local txd = mad.get_txd(name)
        if not txd then
            local status, result = pcall(mad.load_txd, fullPath)
            if status and result then txd = result end
        end
        if txd then
            local textures = extractAllTexturesData(txd)
            if #textures > 0 then
                table.insert(State.txdList, { name = file, textures = textures })
            end
        end
        wait(50)
    end
    State.loadingStatus = nil
end

imgui.OnFrame(function() return State.WinState[0] end, function()
    imgui.SetNextWindowSize(imgui.ImVec2(640, 520), imgui.Cond.FirstUseEver)
    imgui.Begin(u8'TXD Browser', State.WinState)
    if State.loadingStatus then
        imgui.Text(State.loadingStatus)
    elseif #State.txdList == 0 then
        imgui.Text(u8"TXD файлы не найдены")
    else
        if not State.didInitialAutoload then
            rebuildLoadedTexturesFor(State.currentTXD[0])
            State.didInitialAutoload = true
        end
        local currentTxdData = State.txdList[State.currentTXD[0]]
        if currentTxdData and imgui.BeginCombo("TXD", currentTxdData.name) then
            for i, rec in ipairs(State.txdList) do
                local isSelected = (State.currentTXD[0] == i)
                if imgui.Selectable(string.format("%s (%d)", rec.name, #rec.textures), isSelected) then
                    State.currentTXD[0] = i
                    rebuildLoadedTexturesFor(i)
                end
                if isSelected then imgui.SetItemDefaultFocus() end
            end
            imgui.EndCombo()
        end
        imgui.Separator()
        if #State.loadedTextures > 0 then
            local texIdx = State.currentTexture[0]
            if texIdx >= 1 and State.loadedTextures[texIdx] then
                local tex = State.loadedTextures[texIdx]
                local availableSpace = imgui.GetContentRegionAvail()
                local imageRegionHeight = availableSpace.y - 100
                local aspect = tex.width / tex.height
                local display_w, display_h = availableSpace.x, availableSpace.x / aspect
                if display_h > imageRegionHeight then
                    display_h = imageRegionHeight
                    display_w = display_h * aspect
                end
                local final_w, final_h = display_w * State.imageZoom[0], display_h * State.imageZoom[0]
                local pos_x = (availableSpace.x - final_w) / 2
                imgui.SetCursorPosX(imgui.GetCursorPosX() + pos_x)
                imgui.Image(tex.texture_ptr, imgui.ImVec2(final_w, final_h))
                if imgui.CollapsingHeader(u8'Информация') then
                    imgui.Text(string.format(u8"Имя: %s", tex.name))
                    imgui.Text(string.format(u8"Размер: %d x %d", tex.width, tex.height))
                    if imgui.Button(u8"Копировать имя") then setClipboardText(tex.name) end
                    imgui.Separator()
                    imgui.SliderFloat(u8"Масштаб", State.imageZoom, 0.1, 5.0)
                    if imgui.Button(u8"Сбросить масштаб") then State.imageZoom[0] = 1.0 end
                end
                imgui.Separator()
                if imgui.Button(u8"Предыдущая") then State.currentTexture[0] = math.max(1, texIdx - 1) end
                imgui.SameLine()
                if imgui.Button(u8"Следующая") then State.currentTexture[0] = math.min(#State.loadedTextures, texIdx + 1) end
                imgui.SameLine()
                imgui.Text(string.format("%d / %d", texIdx, #State.loadedTextures))
            end
        else
            imgui.Text(u8"В этом TXD-архиве нет доступных для чтения текстур")
        end
    end
    imgui.End()
end)

function main()
    while not isSampAvailable() do wait(100) end
    lua_thread.create(scanTXD, getGameDirectory() .. "\\models")
    sampRegisterChatCommand('txd', function()
        State.WinState[0] = not State.WinState[0]
        if State.WinState[0] and #State.txdList > 0 and not State.didInitialAutoload then
            rebuildLoadedTexturesFor(State.currentTXD[0])
        end
    end)
    wait(-1)
end
из побочек: не грузит misc.txd как бы оно не хотелось, почему-то стреялет в сам адишнс, не знаю как это решить, насчет остального думаю вкурите
1762121290952.png

также можно вкинуть такое решение без использование адишнса потому что @вайега52 тварь не хочет библиотека для рв делать
Lua:
local imgui = require("mimgui")
local ffi   = require("ffi")
local enc   = require("encoding")
enc.default = 'CP1251'
local u8    = enc.UTF8
local new   = imgui.new

ffi.cdef[[
    typedef unsigned char RwUInt8;
    typedef int RwInt32;
    typedef struct RwLLLink { struct RwLLLink *next; struct RwLLLink *prev; } RwLLLink;
    typedef struct RwLinkList { RwLLLink link; } RwLinkList;
    typedef struct RwTexDictionary {
        void* object;
        RwLinkList texturesInDict;
        RwLinkList lInInstance;
    } RwTexDictionary;
    typedef struct RwTextureFull {
        void* raster;
        void* dict;
        RwLLLink inDictionary;
        char name[32];
        char mask[32];
        int refCount;
        unsigned int filterAddressing;
    } RwTextureFull;
    typedef struct RwRaster {
        void* parent;
        RwUInt8* cpPixels;
        RwUInt8* palette;
        RwInt32 width, height, depth;
        RwInt32 stride;
        short   nOffsetX, nOffsetY;
        RwUInt8 cType, cFlags, privateFlags, cFormat;
        RwUInt8* originalPixels;
        RwInt32 originalWidth, originalHeight, originalStride;
        void* texture_ptr;
    } RwRaster;
    typedef enum RwStreamType {
        rwNASTREAM = 0,
        rwSTREAMFILE,
        rwSTREAMFILENAME,
        rwSTREAMMEMORY,
        rwSTREAMCUSTOM
    } RwStreamType;
    typedef enum RwStreamAccessType {
        rwNASTREAMACCESS = 0,
        rwSTREAMREAD,
        rwSTREAMWRITE,
        rwSTREAMAPPEND
    } RwStreamAccessType;
    typedef struct RwStream RwStream;
    typedef struct TxdDef {
        RwTexDictionary *txd_ptr;
        unsigned short ref_count;
        unsigned short flags;
        int name_hash;
    } TxdDef;
    RwStream* (*RwStreamOpen)(int type, int accessType, const void *pData);
    bool (*RwStreamClose)(RwStream *stream, void *pData);
    bool (*RwStreamFindChunk)(RwStream *stream, unsigned int type, unsigned int *lengthOut, unsigned int *versionOut);
    RwTexDictionary* (*RwTexDictionaryStreamRead)(RwStream *stream);
    bool (*RwTexDictionaryDestroy)(RwTexDictionary *txd);
    int (*CTxdStore_FindTxdSlot)(const char *name);
    TxdDef ***CTxdStore_ms_pTxdPool;
]]

local addresses = {
    RwStreamOpen = 0x7ECEF0,
    RwStreamClose = 0x7ECE20,
    RwStreamFindChunk = 0x7ED2D0,
    RwTexDictionaryStreamRead = 0x804C30,
    RwTexDictionaryDestroy = 0x7F36A0,
    CTxdStore_FindTxdSlot = 0x731850,
    CTxdStore_ms_pTxdPool = 0xC8800C
}

local RwStreamOpen = ffi.cast("RwStream* (*)(int, int, const void*)", addresses.RwStreamOpen)
local RwStreamClose = ffi.cast("bool (*)(RwStream*, void*)", addresses.RwStreamClose)
local RwStreamFindChunk = ffi.cast("bool (*)(RwStream*, unsigned int, unsigned int*, unsigned int*)", addresses.RwStreamFindChunk)
local RwTexDictionaryStreamRead = ffi.cast("RwTexDictionary* (*)(RwStream*)", addresses.RwTexDictionaryStreamRead)
local RwTexDictionaryDestroy = ffi.cast("bool (*)(RwTexDictionary*)", addresses.RwTexDictionaryDestroy)
local CTxdStore_FindTxdSlot = ffi.cast("int (*)(const char*)", addresses.CTxdStore_FindTxdSlot)
local CTxdStore_ms_pTxdPool = ffi.cast("TxdDef***", addresses.CTxdStore_ms_pTxdPool)[0]

local rwSTREAMFILENAME = 2
local rwSTREAMREAD = 1
local rpTEXDICTIONARY = 0x16
local RwTexDictionary_texturesInDict_offset = 0x0C

local State = {
    WinState = new.bool(false),
    currentTXD = new.int(1),
    currentTexture = new.int(1),
    imageZoom = new.float(1.0),
    txdList = {},
    loadedTextures = {},
    didInitialAutoload = false,
    loadingStatus = u8"Какашки..."
}

local function isValidTextureName(name)
    if not name or #name == 0 or #name > 31 then return false end
    for i = 1, #name do
        if name:byte(i) < 32 then return false end
    end
    return true
end

local function getFilesInPath(path, mask)
    local res = {}
    local h, f = findFirstFile(path .. "\\" .. mask)
    if not h then return res end
    while f do
        if not f:match("^%.") then table.insert(res, f) end
        f = findNextFile(h)
    end
    findClose(h)
    return res
end

local function loadTxd(filePath)
    local stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, filePath)
    if stream == ffi.NULL then return nil end
    local found = pcall(function()
        return RwStreamFindChunk(stream, rpTEXDICTIONARY, nil, nil)
    end)
    if found then
        local txd_ptr = RwTexDictionaryStreamRead(stream)
        RwStreamClose(stream, nil)
        if txd_ptr ~= ffi.NULL then
            return txd_ptr
        end
    else
        RwStreamClose(stream, nil)
    end
    return nil
end

local function getTxdByName(name)
    local slot = CTxdStore_FindTxdSlot(name)
    if slot ~= -1 and CTxdStore_ms_pTxdPool then
        local pool = CTxdStore_ms_pTxdPool[0]
        if pool ~= ffi.NULL then
            local txd_def = pool[slot]
            if txd_def ~= ffi.NULL and txd_def.txd_ptr ~= ffi.NULL then
                return txd_def.txd_ptr
            end
        end
    end
    return nil
end

local function extractAllTexturesData(dict)
    if not dict or dict == ffi.NULL then return {} end
    local list_head = ffi.cast("RwLLLink*", ffi.cast("char*", dict) + RwTexDictionary_texturesInDict_offset)
    local current_link = list_head.next
    if current_link == ffi.NULL then return {} end
    local texturesData, visited = {}, {}
    while current_link ~= list_head and current_link ~= ffi.NULL do
        local addr = tonumber(ffi.cast("uintptr_t", current_link))
        if visited[addr] then break end
        visited[addr] = true
        local tex = ffi.cast("RwTextureFull*", ffi.cast("char*", current_link) - ffi.offsetof("RwTextureFull", "inDictionary"))
        if tex ~= ffi.NULL then
            local ok, name = pcall(ffi.string, tex.name)
            if ok and isValidTextureName(name) and tex.raster ~= ffi.NULL then
                local raster = ffi.cast("RwRaster*", tex.raster)
                if raster.texture_ptr ~= ffi.NULL then
                    table.insert(texturesData, {
                        texture_ptr = raster.texture_ptr,
                        width  = raster.width,
                        height = raster.height,
                        name   = name
                    })
                end
            end
        end
        current_link = current_link.next
    end
    return texturesData
end

local function scanTXD(folder)
    local files = getFilesInPath(folder, "*.txd")
    table.sort(files)
    local totalFiles = #files
    for i, file in ipairs(files) do
        State.loadingStatus = string.format(u8"Загрузка... (%d / %d): %s", i, totalFiles, file)
        local fullPath = folder .. "\\" .. file
        local name = file:gsub("%.txd$", "")
        local txd_ptr = getTxdByName(name)
        local loaded_by_script = false
        if not txd_ptr then
            txd_ptr = loadTxd(fullPath)
            loaded_by_script = true
        end
        if txd_ptr and txd_ptr ~= ffi.NULL then
            local textures = extractAllTexturesData(txd_ptr)
            if #textures > 0 then
                table.insert(State.txdList, {
                    name = file,
                    textures = textures,
                    ptr = txd_ptr,
                    loaded_by_script = loaded_by_script
                })
            elseif loaded_by_script then
                RwTexDictionaryDestroy(txd_ptr)
            end
        end
        wait(10)
    end
    State.loadingStatus = nil
end

local function rebuildLoadedTexturesFor(index)
    State.loadedTextures = {}
    local rec = State.txdList[index]
    if rec and rec.textures then
        State.loadedTextures = rec.textures
    end
    State.currentTexture[0] = #State.loadedTextures > 0 and 1 or 0
    State.imageZoom[0] = 1.0
end

imgui.OnFrame(function() return State.WinState[0] end, function()
    imgui.SetNextWindowSize(imgui.ImVec2(640, 520), imgui.Cond.FirstUseEver)
    imgui.Begin(u8'TXD Browser', State.WinState)
    if State.loadingStatus then
        imgui.Text(State.loadingStatus)
    elseif #State.txdList == 0 then
        imgui.Text(u8"TXD файлы не найдены в папке")
    else
        if not State.didInitialAutoload then
            rebuildLoadedTexturesFor(State.currentTXD[0])
            State.didInitialAutoload = true
        end
        local currentTxdData = State.txdList[State.currentTXD[0]]
        if currentTxdData and imgui.BeginCombo("TXD", currentTxdData.name) then
            for i, rec in ipairs(State.txdList) do
                local isSelected = (State.currentTXD[0] == i)
                if imgui.Selectable(string.format("%s (%d)", rec.name, #rec.textures), isSelected) then
                    State.currentTXD[0] = i
                    rebuildLoadedTexturesFor(i)
                end
                if isSelected then imgui.SetItemDefaultFocus() end
            end
            imgui.EndCombo()
        end
        imgui.Separator()
        if #State.loadedTextures > 0 then
            local texIdx = State.currentTexture[0]
            if texIdx >= 1 and State.loadedTextures[texIdx] then
                local tex = State.loadedTextures[texIdx]
                local availableSpace = imgui.GetContentRegionAvail()
                local imageRegionHeight = availableSpace.y - 120
                local aspect = tex.width / tex.height
                local display_w, display_h = availableSpace.x, availableSpace.x / aspect
                if display_h > imageRegionHeight then
                    display_h = imageRegionHeight
                    display_w = display_h * aspect
                end
                local final_w, final_h = display_w * State.imageZoom[0], display_h * State.imageZoom[0]
                local pos_x = (availableSpace.x - final_w) / 2
                imgui.SetCursorPosX(imgui.GetCursorPosX() + pos_x)
                imgui.Image(tex.texture_ptr, imgui.ImVec2(final_w, final_h))
                imgui.Separator()
                if imgui.CollapsingHeader(u8'Информация', imgui.TreeNodeFlags.DefaultOpen) then
                    imgui.Text(string.format(u8"Имя: %s", tex.name))
                    imgui.Text(string.format(u8"Размер: %d x %d", tex.width, tex.height))
                    if imgui.Button(u8"Копировать имя") then setClipboardText(tex.name) end
                    imgui.Separator()
                    imgui.SliderFloat(u8"Масштаб", State.imageZoom, 0.1, 5.0)
                    if imgui.Button(u8"Сбросить масштаб") then State.imageZoom[0] = 1.0 end
                end
                imgui.Separator()
                if imgui.Button(u8"Предыдущая") then State.currentTexture[0] = math.max(1, texIdx - 1) end
                imgui.SameLine()
                if imgui.Button(u8"Следующая") then State.currentTexture[0] = math.min(#State.loadedTextures, texIdx + 1) end
                imgui.SameLine()
                imgui.Text(string.format("%d / %d", texIdx, #State.loadedTextures))
            end
        else
            imgui.Text(u8"В этом TXD-архиве нет доступных для чтения текстур")
        end
    end
    imgui.End()
end)

function main()
    while not isSampAvailable() do wait(100) end
    lua_thread.create(scanTXD, getGameDirectory() .. "\\models")
    sampRegisterChatCommand('txd', function()
        State.WinState[0] = not State.WinState[0]
    end)
    wait(-1)
end

function cleanShit()
    local count = 0
    for _, txdData in ipairs(State.txdList) do
        if txdData.loaded_by_script and txdData.ptr ~= ffi.NULL then
            RwTexDictionaryDestroy(txdData.ptr)
            txdData.ptr = ffi.NULL
            count = count + 1
        end
    end
end

function onScriptTerminate(script, quitGame)
    if script == thisScript() then
        cleanShit()
    end
end
-- full folder models (без папок внутри) = 0.17 секунд на загрузку 170 текстур
 
Последнее редактирование:

WOP

Участник
86
1
Как узнать какая анимация проигрывается у персонажа НЕ ОТ СЕРВЕРА?
 

kyrtion

Известный
1,342
508
И че мне с этим надо делать
Lua:
-- player
function sampev.onApplyPlayerAnimation(player_id, anim_lib, anim_name, frame_delta, loop, lock_x, lock_y, freeze, time) end
function sampev.onClearPlayerAnimation(player_id) end

-- any non-player (actor, char, npc, bot)
function sampev.onApplyActorAnimation(actor_id, anim_lib, anim_name, frame_delta, loop, lock_x, lock_y, freeze, time) end
function sampev.onClearActorAnimation(actor_id) end
Эти функция будут показаны если сервер заставит заиграть. А по собственному например клео писс, в таком случае зациклить в main() на получение анимку или следить анимку в синхронизацию игрока (это по лучше, что улучшает оптимизацию чем зациклить в пустую в main)
 

WOP

Участник
86
1
Lua:
-- player
function sampev.onApplyPlayerAnimation(player_id, anim_lib, anim_name, frame_delta, loop, lock_x, lock_y, freeze, time) end
function sampev.onClearPlayerAnimation(player_id) end

-- any non-player (actor, char, npc, bot)
function sampev.onApplyActorAnimation(actor_id, anim_lib, anim_name, frame_delta, loop, lock_x, lock_y, freeze, time) end
function sampev.onClearActorAnimation(actor_id) end
Эти функция будут показаны если сервер заставит заиграть. А по собственному например клео писс, в таком случае зациклить в main() на получение анимку или следить анимку в синхронизацию игрока (это по лучше, что улучшает оптимизацию чем зациклить в пустую в main)
А как мне синхру игрока узнать?
 

kyrtion

Известный
1,342
508
А как мне синхру игрока узнать?
Lua:
---@class VectorXYZ
---@field x number
---@field y number
---@field z number

---@class SampKeys
---@field primaryFire boolean
---@field horn_crouch boolean
---@field secondaryFire_shoot boolean
---@field accel_zoomOut boolean
---@field enterExitCar boolean
---@field decel_jump boolean
---@field circleRight boolean
---@field aim boolean
---@field circleLeft boolean
---@field landingGear_lookback boolean
---@field unknown_walkSlow boolean
---@field specialCtrlUp boolean
---@field specialCtrlDown boolean
---@field specialCtrlLeft boolean
---@field specialCtrlRight boolean
---@field _unknown boolean

---@class PlayerSyncData.AnimationFlags
---@field loop boolean
---@field lockX boolean
---@field lockY boolean
---@field freeze boolean
---@field time integer
---@field _unused integer
---@field regular boolean
---@field value integer

---@class PlayerSyncData.Animation
---@field id integer
---@field frameDelta integer
---@field flags PlayerSyncData.AnimationFlags?

---@class PlayerSyncData
---@field leftRightKeys integer
---@field upDownKeys integer
---@field keysData integer?
---@field keys SampKeys?
---@field position VectorXYZ
---@field quaternion { [1]: number, [2]: number, [3]: number, [4]: number }
---@field health integer
---@field armor integer
---@field weapon integer
---@field specialKey integer
---@field specialAction integer
---@field moveSpeed VectorXYZ
---@field surfingOffsets VectorXYZ
---@field surfingVehicleId integer
---@field animation PlayerSyncData.Animation? -- only self-ped?
---@field animationId integer?
---@field animationFlags integer?

function sampev.onPlayerSync(player_id, data)
    if data.specialAction then
        print(string.format(
            'player_id %d played special action - %d',
            player_id, data.specialAction
        ))
    end
    if data.animationId then
        print(string.format(
            'player_id %d played anim - %d, %d',
            player_id, data.animationId. data.animationFlags
        ))
    end
end
 

WOP

Участник
86
1
Lua:
---@class VectorXYZ
---@field x number
---@field y number
---@field z number

---@class SampKeys
---@field primaryFire boolean
---@field horn_crouch boolean
---@field secondaryFire_shoot boolean
---@field accel_zoomOut boolean
---@field enterExitCar boolean
---@field decel_jump boolean
---@field circleRight boolean
---@field aim boolean
---@field circleLeft boolean
---@field landingGear_lookback boolean
---@field unknown_walkSlow boolean
---@field specialCtrlUp boolean
---@field specialCtrlDown boolean
---@field specialCtrlLeft boolean
---@field specialCtrlRight boolean
---@field _unknown boolean

---@class PlayerSyncData.AnimationFlags
---@field loop boolean
---@field lockX boolean
---@field lockY boolean
---@field freeze boolean
---@field time integer
---@field _unused integer
---@field regular boolean
---@field value integer

---@class PlayerSyncData.Animation
---@field id integer
---@field frameDelta integer
---@field flags PlayerSyncData.AnimationFlags?

---@class PlayerSyncData
---@field leftRightKeys integer
---@field upDownKeys integer
---@field keysData integer?
---@field keys SampKeys?
---@field position VectorXYZ
---@field quaternion { [1]: number, [2]: number, [3]: number, [4]: number }
---@field health integer
---@field armor integer
---@field weapon integer
---@field specialKey integer
---@field specialAction integer
---@field moveSpeed VectorXYZ
---@field surfingOffsets VectorXYZ
---@field surfingVehicleId integer
---@field animation PlayerSyncData.Animation? -- only self-ped?
---@field animationId integer?
---@field animationFlags integer?

function sampev.onPlayerSync(player_id, data)
    if data.specialAction then
        print(string.format(
            'player_id %d played special action - %d',
            player_id, data.specialAction
        ))
    end
    if data.animationId then
        print(string.format(
            'player_id %d played anim - %d, %d',
            player_id, data.animationId. data.animationFlags
        ))
    end
end
Куда мне это вставить
 

WOP

Участник
86
1
Как сделать так чтобы скрипт сохранял айди модели и все позиции аттачнутого обьекта на игроке? (Например: аксессуаров)
 

Romka

Известный
9
1
Помогите как мне через луа сделать
/enter - сел в машину стандартной анимацией
я нахожусь возле машины
/enter еще раз вылез машины
интересует чтобы не тыкало клавишу f а делало в скрытом режиме
 

LdKrs

Участник
35
37
Можно ли как то получить(проверить существование) кость персонажа по её имени, а после вращать её?

( и вообще можно ли добавлять в модели педов свои кости )
 
Последнее редактирование:

Masayuki

Участник
92
36
Помогите как мне через луа сделать
/enter - сел в машину стандартной анимацией
я нахожусь возле машины
/enter еще раз вылез машины
интересует чтобы не тыкало клавишу f а делало в скрытом режиме
taskEnterCarAsDriver(Ped ped, Vehicle car, int timeMS)
taskLeaveCar(Ped ped, Vehicle car)
такое есть, но хз работает ли это