• Я зарабатываю 100 000 RUB / месяц на этом сайте!

    А знаешь как? Я всего-лишь публикую (создаю темы), а админ мне платит. Трачу деньги на мороженое, робуксы и сервера в Minecraft. А ещё на паль из Китая. 

    Хочешь так же? Пиши и узнавай условия: https://t.me/alex_redact
    Реклама: https://t.me/yougame_official

Вопрос [GS] Помогите пофиксить луашку(viewmodel changer;arms model changer)

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
12 Авг 2019
Сообщения
6
Реакции
0
[gamesense] .\arms modelchanger.lua:43: attempt to call field 'get_entity_by_index' (a nil value)


Код:
Expand Collapse Copy
local ffi = require("ffi")

local class_ptr = ffi.typeof("void***")

-- Интерфейсы
local rawivmodelinfo = client.create_interface("engine.dll", "VModelInfoClient004")
local ivmodelinfo = ffi.cast(class_ptr, rawivmodelinfo)
local get_model_index = ffi.cast("int(__thiscall*)(void*, const char*)", ivmodelinfo[0][2])

local rawnetworkstringtablecontainer = client.create_interface("engine.dll", "VEngineClientStringTable001")
local networkstringtablecontainer = ffi.cast(class_ptr, rawnetworkstringtablecontainer)
local find_table = ffi.cast("void*(__thiscall*)(void*, const char*)", networkstringtablecontainer[0][3])

-- Функция загрузки модели
local function precache_model(modelname)
    if not modelname or modelname == "" then return end
    local precache_table = ffi.cast(class_ptr, find_table(networkstringtablecontainer, "modelprecache"))
    if precache_table then
        local add_string = ffi.cast("int(__thiscall*)(void*, bool, const char*, int, const void*)", precache_table[0][8])
        add_string(precache_table, false, modelname, -1, nil)
    end
end

-- UI меню выбора модели рук и оружия
local hands_models = {
    ["Default"] = "",
    ["Master Chief"] = "models/player/custom_player/kolka/master_chief_arms.mdl"
}

local weapon_models = {
    ["Default"] = "",
    ["Custom Rifle"] = "models/weapons/custom_rifle.mdl"
}

local hands_selector = ui.new_combobox("LUA", "A", "Hands Model", {"Default", "Master Chief"})
local weapon_selector = ui.new_combobox("LUA", "A", "Weapon Model", {"Default", "Custom Rifle"})

local last_hands_model = ""
local last_weapon_model = ""

-- Function to safely get entity by index
local function get_entity_by_index(index)
    return entity.get_entity_by_index(index) -- Ensure this function is accessible
end

local function change_hands_model()
    local me = entity.get_local_player()
    if not me or not entity.is_alive(me) then return end
    local weapon = entity.get_player_weapon(me) -- Получаем оружие

    if not weapon then return end

    local view_model_index = entity.get_prop(weapon, "m_hViewModel")
    if view_model_index == 0 then return end

    local view_model = get_entity_by_index(view_model_index) -- Use the defined function here
    if not view_model then return end

    local selected_model = ui.get(hands_selector)
    local model_path = hands_models[selected_model]

    if model_path and model_path ~= "" and model_path ~= last_hands_model then
        precache_model(model_path)
        local model_index = get_model_index(ivmodelinfo, model_path)

        if model_index > 0 then
            entity.set_prop(view_model, "m_nModelIndex", model_index)
            last_hands_model = model_path
            print("Changed hands model to:", model_path)
        else
            print("Failed to get model index for:", model_path)
        end
    end
end

local function change_weapon_model()
    local me = entity.get_local_player()
    if not me or not entity.is_alive(me) then return end
    local weapon = entity.get_player_weapon(me)

    if not weapon then return end

    local selected_model = ui.get(weapon_selector)
    local model_path = weapon_models[selected_model]

    if model_path and model_path ~= "" and model_path ~= last_weapon_model then
        precache_model(model_path)
        local model_index = get_model_index(ivmodelinfo, model_path)

        if model_index > 0 then
            entity.set_prop(weapon, "m_nModelIndex", model_index)
            last_weapon_model = model_path
            print("Changed weapon model to:", model_path)
        else
            print("Failed to get model index for:", model_path)
        end
    end
end

local function on_ui_change()
    change_hands_model()
    change_weapon_model()
end

-- Вызываем функцию изменения только при изменении в UI
ui.set_callback(hands_selector, on_ui_change)
ui.set_callback(weapon_selector, on_ui_change)
 

Вложения

  • model_changer.txt
    model_changer.txt
    5.7 KB · Просмотры: 29
  • csgo_vOuuRNZxUL.png
    csgo_vOuuRNZxUL.png
    1.7 MB · Просмотры: 91
Назад
Сверху Снизу