- 1,261
- 235
- Версия MoonLoader
- .026-beta
Короче видел скрипт, который перекрашивает машину в RGB цвета рандомно. хотел сделать такой же, но по выбору. сначала хотел первый и второй цвет, как в сампе, но как сказали и потом сам осознал, что цвета применяются на все материалы машины. Я потом хотел сделать хотя бы покраску по выбору, но тоже ничего не получился, вот короче свои гавнокоды. Может кто то скажет что я делаю не так? Или может сами переделаете или хз. Мой мозг уже больше не тянет такой сложности скрипт...
FYP code:
script_name('Vehicle Material Color Example')
local mad = require 'MoonAdditions'
function main()
while true do
wait(0)
if isPlayerPlaying(PLAYER_HANDLE) then
if isCharInAnyCar(PLAYER_PED) and testCheat('cc') then
local car = storeCarCharIsInNoSave(PLAYER_PED)
local new_r, new_g, new_b = math.random(0, 255), math.random(0, 255), math.random(0, 255)
for_each_vehicle_material(car, function(mat)
local r, g, b, a = mat:get_color()
if (r == 0x3C and g == 0xFF and b == 0x00) or (r == 0xFF and g == 0x00 and b == 0xAF) then
mat:set_color(new_r, new_g, new_b, a)
end
end)
end
end
end
end
function for_each_vehicle_material(car, func)
for _, comp in ipairs(mad.get_all_vehicle_components(car)) do
for _, obj in ipairs(comp:get_objects()) do
for _, mat in ipairs(obj:get_materials()) do
func(mat)
end
end
end
end
мой код с 2 цветами:
require "lib.moonloader"
local imgui = require "imgui"
local main_window_state = imgui.ImBool(false)
local Colors_Enabled = imgui.ImBool(false)
local Primary_Color = imgui.ImVec4(1, 0, 1, 1)
local Secondary_Color = imgui.ImVec4(1, 1, 0, 1)
function cmd_rgbcar(arg)
main_window_state.v = not main_window_state.v
imgui.Process = main_window_state.v
end
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand("rgbcar", cmd_rgbcar)
imgui.Process = false
while true do
wait(0)
if main_window_state.v == false then
imgui.Process = false
end
if Colors_Enabled.v and isCharInAnyCar(PLAYER_PED) then
changeCarColour(storeCarCharIsInNoSave(PLAYER_PED), Primary_Color.v, Secondary_Color.v)
end
end
end
function imgui.OnDrawFrame()
local sw, sh = getScreenResolution()
if isKeyDown(2) then imgui.ShowCursor = false else imgui.ShowCursor = true end -- for camera moving while imgui window is active
imgui.SetNextWindowSize(imgui.ImVec2(330, 110), imgui.Cond.FirstUseEver)
imgui.SetNextWindowPos(imgui.ImVec2(100, sh/2), imgui.Cond.FirstUseEver, imgui.ImVec2(0, 1/2))
imgui.Begin("RGB Car Colors", main_window_state, imgui.WindowFlags.NoResize)
imgui.SetCursorPosY(24)
imgui.Checkbox("Enable Script", Colors_Enabled)
imgui.Separator()
imgui.ColorEdit4('Primary Color', Primary_Color)
imgui.ColorEdit4('Secondary Color', Secondary_Color)
imgui.Separator()
imgui.End()
end
function apply_custom_style()
local style = imgui.GetStyle()
style.WindowRounding = 0
style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
style.Colors[imgui.Col.TitleBgActive] = imgui.ImVec4(0.5, 0, 0.25, 1.00)
style.Colors[imgui.Col.WindowBg] = imgui.ImVec4(0.1, 0.1, 0.1, 1.00)
end
apply_custom_style()
fyp переделка неудачная:
require "lib.moonloader"
local imgui = require "imgui"
local mad = require "MoonAdditions"
local main_window_state = imgui.ImBool(false)
local Colors_Enabled = imgui.ImBool(false)
local RGB_Color = imgui.ImVec4(1, 0, 1, 1)
function cmd_carr(arg)
main_window_state.v = not main_window_state.v
imgui.Process = main_window_state.v
end
function for_each_vehicle_material(car, func)
for _, comp in ipairs(mad.get_all_vehicle_components(car)) do
for _, obj in ipairs(comp:get_objects()) do
for _, mat in ipairs(obj:get_materials()) do
func(mat)
end
end
end
end
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand("carr", cmd_carr)
imgui.Process = false
while true do
wait(0)
if main_window_state.v == false then
imgui.Process = false
end
if Colors_Enabled.v and isCharInAnyCar(PLAYER_PED) then
local new_r, new_g, new_b = math.random(0, 255), math.random(0, 255), math.random(0, 255)
for_each_vehicle_material(car, function(mat)
local r, g, b, a = mat:get_color()
if (r == 0x3C and g == 0xFF and b == 0x00) or (r == 0xFF and g == 0x00 and b == 0xAF) then
mat:set_color(new_r, new_g, new_b, a)
end
end)
end
end
end
function imgui.OnDrawFrame()
local sw, sh = getScreenResolution()
if isKeyDown(2) then imgui.ShowCursor = false else imgui.ShowCursor = true end -- for camera moving while imgui window is active
imgui.SetNextWindowSize(imgui.ImVec2(330, 110), imgui.Cond.FirstUseEver)
imgui.SetNextWindowPos(imgui.ImVec2(100, sh/2), imgui.Cond.FirstUseEver, imgui.ImVec2(0, 1/2))
imgui.Begin("RGB Car Colors", main_window_state, imgui.WindowFlags.NoResize)
imgui.SetCursorPosY(24)
imgui.Checkbox("Enable Script", Colors_Enabled)
imgui.Separator()
imgui.ColorEdit4('RGB Color', RGB_Color)
imgui.Separator()
imgui.End()
end
function apply_custom_style()
local style = imgui.GetStyle()
style.WindowRounding = 0
style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
style.Colors[imgui.Col.TitleBgActive] = imgui.ImVec4(0.5, 0, 0.25, 1.00)
style.Colors[imgui.Col.WindowBg] = imgui.ImVec4(0.1, 0.1, 0.1, 1.00)
end
apply_custom_style()