- 251
- 23
- Версия MoonLoader
- .026-beta
короче, делаю палитру цветов для замены текста в чате, но чёт пошло не так. помогите пожалуйста.
Сделал код немного по иначе, теперь отображает хотя бы. Но проблема новая - не красит строчку из чата.
Lua:
[00:23:22.408001] (error) custom chat argb.lua: E:\Games\16 pixeley\moonloader\custom chat argb.lua:69: bad argument #2 to 'ColorEdit4' (cannot convert 'number' to 'float *')
stack traceback:
[C]: in function 'ColorEdit4'
E:\Games\16 pixeley\moonloader\custom chat argb.lua:69: in function '_draw'
E:\Games\16 pixeley\moonloader\lib\mimgui\init.lua:107: in function <E:\Games\16 pixeley\moonloader\lib\mimgui\init.lua:91>
[00:23:22.409004] (error) custom chat argb.lua: Script died due to an error. (0991DB44)
Lua:
require('lib.moonloader')
local event = require('lib.samp.events')
local imgui = require 'mimgui'
local encoding = require 'encoding'
local ad = require 'ADDONS'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local new = imgui.new
local chatSettings = new.bool(false)
local directConfig = getWorkingDirectory()..'/config/customvipargb.json'
print(getWorkingDirectory())
local defaultTable =
{
['settings'] =
{
['color'] = 0xFFFF0000,
['active'] = false
}
}
local sconfig = {}
if not doesFileExist(directConfig) then
conf = assert(io.open(directConfig, 'w'), 'No permission to create file')
conf:write(encodeJson(defaultTable))
conf:close()
end
conf = io.open(directConfig, 'r')
local config = decodeJson(conf:read("*a"))
conf:close()
if type(config) ~= 'table' then config = defaultTable
else
for i, v in pairs(defaultTable) do
if type(config[i]) == 'table' then
for i1, v1 in pairs(defaultTable[i]) do
if type(config[i][i1]) ~= type(v1) then config[i][i1] = v1 end
end
elseif type(config[i]) ~= type(v) then config[i] = v end
end
end
conf = io.open(directConfig, 'w')
conf:write(encodeJson(config))
conf:close()
local elements =
{
value =
{
['color'] = 0xFFFF0000,
active = new.bool(config['settings']['active'])
}
}
imgui.OnInitialize(function()
imgui.GetIO().IniFilename = nil
local tmp = imgui.ColorConvertU32ToFloat4(config['settings']['color'])
color = new.float[4](tmp.x, tmp.y, tmp.z, tmp.w)
end)
local newFrame = imgui.OnFrame(function() return chatSettings[0] end, function(player)
local resX, resY = getScreenResolution()
local sizeX, sizeY = 415, 200
imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
imgui.Begin('Custom chat', chatSettings, imgui.WindowFlags.NoResize)
if ad.ToggleButton(u8'заменять цвет вип чата', elements.value.active) then
if imgui.ColorEdit4(u8"ебучий цвет вип чата", elements.value.color) then
config['settings']['color'] = imgui.ColorConvertFloat4ToU32(
imgui.ImVec4( color[0], color[1], color[2], color[3] )
)
end
end
imgui.End()
end)
function argb2abgr(argb)
local abgr = bit.bor(
bit.lshift(bit.band(bit.rshift(argb, 24), 0xFF), 24),
bit.lshift(bit.band(argb, 0xFF), 16),
bit.lshift(bit.band(bit.rshift(argb, 8), 0xFF), 8),
bit.band(bit.rshift(argb, 16), 0xFF)
)
return abgr
end
function main()
while not isSampAvailable() do wait(0) end
sampRegisterChatCommand('vvc', function() chatSettings[0] = not chatSettings[0] end)
while true do wait(0)
end
end
function event.onServerMessage(col, text)
if elements.value.active[0] then
if text:find('^%[Bronze VIP%]') then
local viptext = text:gsub("%[Bronze VIP%]", "%[Bronze VIP%]")
sampAddChatMessage(viptext, argb2abgr)
return false
end
if text:find('^%[Silver VIP%]') then
local viptext = text:gsub("%[Silver VIP%]", "%[Silver VIP%]")
sampAddChatMessage(viptext, argb2abgr)
return false
end
if text:find('^%[Gold VIP%]') then
local viptext = text:gsub("%[Gold VIP%]", "%[Gold VIP%]")
sampAddChatMessage(viptext, argb2abgr)
return false
end
end
end
function saveConfig()
conf = io.open(directConfig, 'w')
conf:write(encodeJson(config))
conf:close()
end
UPD:короче, делаю палитру цветов для замены текста в чате, но чёт пошло не так. помогите пожалуйста.
Lua:[00:23:22.408001] (error) custom chat argb.lua: E:\Games\16 pixeley\moonloader\custom chat argb.lua:69: bad argument #2 to 'ColorEdit4' (cannot convert 'number' to 'float *') stack traceback: [C]: in function 'ColorEdit4' E:\Games\16 pixeley\moonloader\custom chat argb.lua:69: in function '_draw' E:\Games\16 pixeley\moonloader\lib\mimgui\init.lua:107: in function <E:\Games\16 pixeley\moonloader\lib\mimgui\init.lua:91> [00:23:22.409004] (error) custom chat argb.lua: Script died due to an error. (0991DB44)
Lua:require('lib.moonloader') local event = require('lib.samp.events') local imgui = require 'mimgui' local encoding = require 'encoding' local ad = require 'ADDONS' encoding.default = 'CP1251' u8 = encoding.UTF8 local new = imgui.new local chatSettings = new.bool(false) local directConfig = getWorkingDirectory()..'/config/customvipargb.json' print(getWorkingDirectory()) local defaultTable = { ['settings'] = { ['color'] = 0xFFFF0000, ['active'] = false } } local sconfig = {} if not doesFileExist(directConfig) then conf = assert(io.open(directConfig, 'w'), 'No permission to create file') conf:write(encodeJson(defaultTable)) conf:close() end conf = io.open(directConfig, 'r') local config = decodeJson(conf:read("*a")) conf:close() if type(config) ~= 'table' then config = defaultTable else for i, v in pairs(defaultTable) do if type(config[i]) == 'table' then for i1, v1 in pairs(defaultTable[i]) do if type(config[i][i1]) ~= type(v1) then config[i][i1] = v1 end end elseif type(config[i]) ~= type(v) then config[i] = v end end end conf = io.open(directConfig, 'w') conf:write(encodeJson(config)) conf:close() local elements = { value = { ['color'] = 0xFFFF0000, active = new.bool(config['settings']['active']) } } imgui.OnInitialize(function() imgui.GetIO().IniFilename = nil local tmp = imgui.ColorConvertU32ToFloat4(config['settings']['color']) color = new.float[4](tmp.x, tmp.y, tmp.z, tmp.w) end) local newFrame = imgui.OnFrame(function() return chatSettings[0] end, function(player) local resX, resY = getScreenResolution() local sizeX, sizeY = 415, 200 imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5)) imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver) imgui.Begin('Custom chat', chatSettings, imgui.WindowFlags.NoResize) if ad.ToggleButton(u8'заменять цвет вип чата', elements.value.active) then if imgui.ColorEdit4(u8"ебучий цвет вип чата", elements.value.color) then config['settings']['color'] = imgui.ColorConvertFloat4ToU32( imgui.ImVec4( color[0], color[1], color[2], color[3] ) ) end end imgui.End() end) function argb2abgr(argb) local abgr = bit.bor( bit.lshift(bit.band(bit.rshift(argb, 24), 0xFF), 24), bit.lshift(bit.band(argb, 0xFF), 16), bit.lshift(bit.band(bit.rshift(argb, 8), 0xFF), 8), bit.band(bit.rshift(argb, 16), 0xFF) ) return abgr end function main() while not isSampAvailable() do wait(0) end sampRegisterChatCommand('vvc', function() chatSettings[0] = not chatSettings[0] end) while true do wait(0) end end function event.onServerMessage(col, text) if elements.value.active[0] then if text:find('^%[Bronze VIP%]') then local viptext = text:gsub("%[Bronze VIP%]", "%[Bronze VIP%]") sampAddChatMessage(viptext, argb2abgr) return false end if text:find('^%[Silver VIP%]') then local viptext = text:gsub("%[Silver VIP%]", "%[Silver VIP%]") sampAddChatMessage(viptext, argb2abgr) return false end if text:find('^%[Gold VIP%]') then local viptext = text:gsub("%[Gold VIP%]", "%[Gold VIP%]") sampAddChatMessage(viptext, argb2abgr) return false end end end function saveConfig() conf = io.open(directConfig, 'w') conf:write(encodeJson(config)) conf:close() end
Сделал код немного по иначе, теперь отображает хотя бы. Но проблема новая - не красит строчку из чата.
Lua:require('lib.moonloader') local event = require('lib.samp.events') local imgui = require 'mimgui' local encoding = require 'encoding' local ad = require 'ADDONS' encoding.default = 'CP1251' u8 = encoding.UTF8 local new = imgui.new local chatSettings = new.bool(false) local directConfig = getWorkingDirectory()..'/config/customvipargb.json' print(getWorkingDirectory()) local defaultTable = { ['settings'] = { ['color'] = 0xFFFF0000, ['active'] = false } } local sconfig = {} if not doesFileExist(directConfig) then conf = assert(io.open(directConfig, 'w'), 'No permission to create file') conf:write(encodeJson(defaultTable)) conf:close() end conf = io.open(directConfig, 'r') local config = decodeJson(conf:read("*a")) conf:close() if type(config) ~= 'table' then config = defaultTable else for i, v in pairs(defaultTable) do if type(config[i]) == 'table' then for i1, v1 in pairs(defaultTable[i]) do if type(config[i][i1]) ~= type(v1) then config[i][i1] = v1 end end elseif type(config[i]) ~= type(v) then config[i] = v end end end conf = io.open(directConfig, 'w') conf:write(encodeJson(config)) conf:close() local elements = { value = { ['color'] = 0xFFFF0000, active = new.bool(config['settings']['active']) } } imgui.OnInitialize(function() imgui.GetIO().IniFilename = nil local tmp = imgui.ColorConvertU32ToFloat4(config['settings']['color']) color = new.float[4](tmp.x, tmp.y, tmp.z, tmp.w) end) local newFrame = imgui.OnFrame(function() return chatSettings[0] end, function(player) local resX, resY = getScreenResolution() local sizeX, sizeY = 415, 200 imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5)) imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver) imgui.Begin('Custom chat', chatSettings, imgui.WindowFlags.NoResize) if ad.ToggleButton(u8'заменять цвет вип чата', elements.value.active) then end if elements.value.active[0] then if imgui.ColorEdit4(u8"ебучий цвет вип чата", color) then config['settings']['color'] = imgui.ColorConvertFloat4ToU32(imgui.ImVec4(color[0], color[1], color[2], color[3])) end end imgui.End() end) function argb2abgr(argb) local abgr = bit.bor( bit.lshift(bit.band(bit.rshift(argb, 24), 0xFF), 24), bit.lshift(bit.band(argb, 0xFF), 16), bit.lshift(bit.band(bit.rshift(argb, 8), 0xFF), 8), bit.band(bit.rshift(argb, 16), 0xFF) ) return abgr end function main() while not isSampAvailable() do wait(0) end sampRegisterChatCommand('vvc', function() chatSettings[0] = not chatSettings[0] end) while true do wait(0) end end function event.onServerMessage(col, text) if elements.value.active[0] then if text:find('^%[Bronze VIP%]') then local viptext = text:gsub("%[Bronze VIP%]", "%[Bronze VIP%]") sampAddChatMessage(viptext, config['settings']['color']) return false end if text:find('^%[Silver VIP%]') then local viptext = text:gsub("%[Silver VIP%]", "%[Silver VIP%]") sampAddChatMessage(viptext, config['settings']['color']) return false end if text:find('^%[Gold VIP%]') then local viptext = text:gsub("%[Gold VIP%]", "%[Gold VIP%]") sampAddChatMessage(viptext, config['settings']['color']) return false end end end function saveConfig() conf = io.open(directConfig, 'w') conf:write(encodeJson(config)) conf:close() end
Последнее редактирование: