local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local window = imgui.ImBool(false)
local list_file = getWorkingDirectory()..'\\config\\ObjectMenu\\objects.json'
local list = {
-- {handle = nil, name = name, model = model, posX = posX, posY = posY, posZ = posZ, rotX = rotX, rotY = rotY, rotZ = rotZ, scale = scale, collision = false}
}
--==[JSON]==--
function jsonSave(t)
local jsonFilePath = list_file
file = io.open(jsonFilePath, "w")
file:write(encodeJson(t))
file:flush()
file:close()
end
function jsonRead()
local jsonFilePath = list_file
local file = io.open(jsonFilePath, "r+")
local jsonInString = file:read("*a")
file:close()
local jsonTable = decodeJson(jsonInString)
return jsonTable
end
local editor = {
name = imgui.ImBuffer('name', 256),
model = imgui.ImInt(14467),
posX = imgui.ImFloat(0.1),
posY = imgui.ImFloat(0.1),
posZ = imgui.ImFloat(0.1),
rotX = imgui.ImFloat(0.1),
rotY = imgui.ImFloat(0.1),
rotZ = imgui.ImFloat(0.1),
scale = imgui.ImFloat(0.1),
collision = imgui.ImBool(false),
}
function main()
while not isSampAvailable() do wait(200) end
sampRegisterChatCommand('objmenu', function()
sampAddChatMessage('as', -1)
window.v = not window.v
end)
if not doesDirectoryExist(getWorkingDirectory()..'\\config') then createDirectory(getWorkingDirectory()..'\\config') end
if not doesDirectoryExist(getWorkingDirectory()..'\\config\\ObjectMenu') then createDirectory(getWorkingDirectory()..'\\config\\ObjectMenu') end
if not doesFileExist(list_file) then
local t = {
{handle = nil, name = 'BigSmoke on groove street', model = 14467, posX = 2529, posY = -1675, posZ = 20, rotX = 0, rotY = 0, rotZ = 0, scale = 1, collision = false}
}
jsonSave(t)
end
list = jsonRead()
refreshObjects()
imgui.Process = false
window.v = true --show window
while true do
wait(0)
imgui.Process = window.v
end
end
local selected = 0
local add_name = imgui.ImBuffer('Object #'..tostring(#list + 1), 256)
function imgui.OnDrawFrame()
if window.v then
local resX, resY = getScreenResolution()
local sizeX, sizeY = 500, 400
imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
imgui.Begin('ObjectMenu', window, imgui.WindowFlags.NoResize)
local sizeY = 400 - 25
imgui.SetCursorPos(imgui.ImVec2(5, 25))
imgui.BeginChild('list', imgui.ImVec2(sizeX / 3, sizeY - 5 - 20 - 5), true)
for i = 1, #list do
local data = list[i]
if data.model then
if imgui.Selectable(tostring(i)..'. '..data.name..'('..data.model..')', selected == i) then
selected = i
editor.name.v = data.name
editor.model.v = data.model
editor.posX.v = data.posX
editor.posY.v = data.posY
editor.posZ.v = data.posZ
editor.rotX.v = data.rotX
editor.rotY.v = data.rotY
editor.rotZ.v = data.rotZ
editor.scale.v = data.scale
editor.collision.v = data.collision
end
if imgui.IsItemHovered() then
imgui.BeginTooltip()
imgui.Text('Object #'..tostring(i)..'\nName: '..data.name..'\nModel: '..data.model)
imgui.EndTooltip()
end
end
end
imgui.EndChild()
imgui.SetCursorPosX(5)
if imgui.Button('ADD', imgui.ImVec2(sizeX / 3, 20)) then
imgui.OpenPopup('Add new object')
end
if imgui.BeginPopupModal('Add new object', true, imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoResize) then
imgui.SetWindowSize(imgui.ImVec2(200, 100))
imgui.TextOffset('Name: ')
if imgui.InputText('##name', add_name) then saveAndRefresh() end
imgui.SetCursorPosX(5)
if imgui.Button('ADD', imgui.ImVec2(190, 20)) then
local x, y, z = getCharCoordinates(PLAYER_PED)
table.insert(list, {handle = nil, name = add_name.v, model = 14467, posX = x, posY = y, posZ = z, rotX = 0, rotY = 0, rotZ = 0, scale = 1, collision = false})
add_name.v = 'Object #'..tostring(#list + 1)
jsonSave(list)
imgui.CloseCurrentPopup()
end
imgui.SetCursorPosX(5)
if imgui.Button('CANCEL', imgui.ImVec2(190, 20)) then
imgui.CloseCurrentPopup()
end
imgui.EndPopup()
end
imgui.SameLine()
imgui.SetCursorPos(imgui.ImVec2(5 + sizeX / 3 + 5, 25))
local childSizeX = sizeX - sizeX / 3 - 5 - 5 - 5
imgui.BeginChild('editor', imgui.ImVec2(childSizeX, sizeY - 5), true)
if selected ~= 0 then
imgui.TextOffset('Name: ')
if imgui.InputText('##name', editor.name) then saveAndRefresh() end
imgui.TextOffset('Model ID: ')
if imgui.InputInt('##model', editor.model) then saveAndRefresh() end
--==[POS]==--
local x, y, z = getCharCoordinates(PLAYER_PED)
local min = {x = -1000, y = -1000, z = -1000}--{x = x - 50, y = y - 50, z = z - 5}
local max = {x = 1000, y = 1000, z = 1000}--{x = x + 50, y = y + 50, z = z + 5}
imgui.PushItemWidth(childSizeX - 150)
imgui.TextOffset('Pos X: ')
if imgui.SliderFloat('##posx', editor.posX, min.x, max.x) then saveAndRefresh() end
imgui.SameLine()
if imgui.Button('+##x', imgui.ImVec2(20, 20)) then editor.posX.v = editor.posX.v + 0.1 saveAndRefresh() end
imgui.SameLine()
if imgui.Button('-##x', imgui.ImVec2(20, 20)) then editor.posX.v = editor.posX.v - 0.1 saveAndRefresh() end
imgui.TextOffset('Pos Y: ')
if imgui.SliderFloat('##posy', editor.posY, min.y, max.y) then saveAndRefresh() end
imgui.SameLine()
if imgui.Button('+##y', imgui.ImVec2(20, 20)) then editor.posY.v = editor.posY.v + 0.1 saveAndRefresh() end
imgui.SameLine()
if imgui.Button('-##y', imgui.ImVec2(20, 20)) then editor.posY.v = editor.posY.v - 0.1 saveAndRefresh() end
imgui.TextOffset('Pos Z: ')
if imgui.SliderFloat('##posz', editor.posZ, min.z, max.z) then saveAndRefresh() end
imgui.SameLine()
if imgui.Button('+##z', imgui.ImVec2(20, 20)) then editor.posZ.v = editor.posZ.v + 0.1 saveAndRefresh() end
imgui.SameLine()
if imgui.Button('-##z', imgui.ImVec2(20, 20)) then editor.posZ.v = editor.posZ.v - 0.1 saveAndRefresh() end
if imgui.Button('ON MY POSITION', imgui.ImVec2(childSizeX - 10, 20)) then
editor.posX.v, editor.posY.v, editor.posZ.v = getCharCoordinates(PLAYER_PED)
saveAndRefresh()
end
imgui.PopItemWidth()
--==[ROTATION]==--
imgui.TextOffset('Rotation X: ')
if imgui.SliderFloat('##rotx', editor.rotX, 0, 360) then saveAndRefresh() end
imgui.TextOffset('Rotation Y: ')
if imgui.SliderFloat('##roty', editor.rotY, 0, 360) then saveAndRefresh() end
imgui.TextOffset('Rotation Z: ')
if imgui.SliderFloat('##porz', editor.rotZ, 0, 360) then saveAndRefresh() end
imgui.TextOffset('Scale: ')
if imgui.SliderFloat('##scale', editor.scale, 0.1, 10) then saveAndRefresh() end
if imgui.Checkbox('Collision', editor.collision) then saveAndRefresh() end
imgui.CenterText('TIP: Use CRTL + LMB on slider to use input')
imgui.SetCursorPos(imgui.ImVec2(5, sizeY - 5 - 20 - 5))
if imgui.Button('DELETE OBJECT', imgui.ImVec2(childSizeX - 10, 20)) then
imgui.OpenPopup('Delete object')
end
if imgui.BeginPopupModal('Delete object', true, imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoResize) then
imgui.SetWindowSize(imgui.ImVec2(400, 75))
imgui.CenterText('Are you shure want to delete object "'..list[selected].name..'"?')
imgui.SetCursorPosX(5)
if imgui.Button('DELETE', imgui.ImVec2(390, 20)) then
deleteObject(list[selected].handle)
table.remove(list, selected)
jsonSave(list)
selected = 0
imgui.CloseCurrentPopup()
end
imgui.SetCursorPosX(5)
if imgui.Button('CANCEL', imgui.ImVec2(390, 20)) then
imgui.CloseCurrentPopup()
end
imgui.EndPopup()
end
end
imgui.EndChild()
imgui.End()
end
end
function imgui.CenterText(text)
imgui.SetCursorPosX(imgui.GetWindowSize().x / 2 - imgui.CalcTextSize(text).x / 2)
imgui.Text(text)
end
function saveAndRefresh()
if list[selected] then
list[selected].name = editor.name.v
list[selected].model = editor.model.v
list[selected].posX = editor.posX.v
list[selected].posY = editor.posY.v
list[selected].posZ = editor.posZ.v
list[selected].rotX = editor.rotX.v
list[selected].rotY = editor.rotY.v
list[selected].rotZ = editor.rotZ.v
list[selected].scale = editor.scale.v
list[selected].collision = editor.collision.v
jsonSave(list)
refreshObjects()
end
end
function refreshObjects()
if list then
for i = 1, #list do
local data = list[i]
if doesObjectExist(data.handle) then deleteObject(data.handle) end
data.handle = createObject(data.model, data.posX, data.posY, data.posZ)
setObjectRotation(data.handle, data.rotX, data.rotY, data.rotZ)
setObjectScale(data.handle, data.scale)
setObjectCollision(data.handle, data.collision)
end
end
end
function onScriptTerminate(s, q)
if s == thisScript() then
for i = 1, #list do
local data = list[i]
if doesObjectExist(data.handle) then deleteObject(data.handle) end
end
end
end
function imgui.TextOffset(text)
imgui.SetCursorPosX(10)
imgui.Text(text)
imgui.SameLine()
imgui.SetCursorPosX(75)
end
function BH_theme()
imgui.SwitchContext()
local style = imgui.GetStyle()
local colors = style.Colors
local clr = imgui.Col
local ImVec4 = imgui.ImVec4
local ImVec2 = imgui.ImVec2
style.WindowPadding = ImVec2(6, 4)
style.WindowRounding = 5.0
style.ChildWindowRounding = 5.0
style.FramePadding = ImVec2(5, 2)
style.FrameRounding = 5.0
style.ItemSpacing = ImVec2(7, 5)
style.ItemInnerSpacing = ImVec2(1, 1)
style.TouchExtraPadding = ImVec2(0, 0)
style.IndentSpacing = 6.0
style.ScrollbarSize = 12.0
style.ScrollbarRounding = 5.0
style.GrabMinSize = 20.0
style.GrabRounding = 2.0
style.WindowTitleAlign = ImVec2(0.5, 0.5)
colors[clr.Text] = ImVec4(1.00, 1.00, 1.00, 1.00)
colors[clr.TextDisabled] = ImVec4(0.28, 0.30, 0.35, 1.00)
colors[clr.WindowBg] = ImVec4(0.16, 0.18, 0.22, 1.00)
colors[clr.ChildWindowBg] = ImVec4(0.19, 0.22, 0.26, 1)
colors[clr.PopupBg] = ImVec4(0.05, 0.05, 0.10, 0.90)
colors[clr.Border] = ImVec4(0.19, 0.22, 0.26, 1.00)
colors[clr.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
colors[clr.FrameBg] = ImVec4(0.16, 0.18, 0.22, 1.00)
colors[clr.FrameBgHovered] = ImVec4(0.22, 0.25, 0.30, 1.00)
colors[clr.FrameBgActive] = ImVec4(0.22, 0.25, 0.29, 1.00)
colors[clr.TitleBg] = ImVec4(0.19, 0.22, 0.26, 1.00)
colors[clr.TitleBgActive] = ImVec4(0.19, 0.22, 0.26, 1.00)
colors[clr.TitleBgCollapsed] = ImVec4(0.19, 0.22, 0.26, 0.59)
colors[clr.MenuBarBg] = ImVec4(0.19, 0.22, 0.26, 1.00)
colors[clr.ScrollbarBg] = ImVec4(0.20, 0.25, 0.30, 0.60)
colors[clr.ScrollbarGrab] = ImVec4(0.41, 0.55, 0.78, 1.00)
colors[clr.ScrollbarGrabHovered] = ImVec4(0.49, 0.63, 0.86, 1.00)
colors[clr.ScrollbarGrabActive] = ImVec4(0.49, 0.63, 0.86, 1.00)
colors[clr.ComboBg] = ImVec4(0.20, 0.20, 0.20, 0.99)
colors[clr.CheckMark] = ImVec4(0.90, 0.90, 0.90, 0.50)
colors[clr.SliderGrab] = ImVec4(1.00, 1.00, 1.00, 0.30)
colors[clr.SliderGrabActive] = ImVec4(0.80, 0.50, 0.50, 1.00)
colors[clr.Button] = ImVec4(0.41, 0.55, 0.78, 1.00)
colors[clr.ButtonHovered] = ImVec4(0.49, 0.62, 0.85, 1.00)
colors[clr.ButtonActive] = ImVec4(0.49, 0.62, 0.85, 1.00)
colors[clr.Header] = ImVec4(0.41, 0.55, 0.78, 1.00)
colors[clr.HeaderHovered] = ImVec4(0.43, 0.57, 0.80, 1.00)
colors[clr.HeaderActive] = ImVec4(0.43, 0.57, 0.80, 1.00)
colors[clr.Separator] = ImVec4(0.41, 0.55, 0.78, 1.00)
colors[clr.SeparatorHovered] = ImVec4(0.41, 0.55, 0.78, 1.00)
colors[clr.SeparatorActive] = ImVec4(0.41, 0.55, 0.78, 1.00)
colors[clr.ResizeGrip] = ImVec4(0.41, 0.55, 0.78, 1.00)
colors[clr.ResizeGripHovered] = ImVec4(0.49, 0.61, 0.83, 1.00)
colors[clr.ResizeGripActive] = ImVec4(0.49, 0.62, 0.83, 1.00)
colors[clr.CloseButton] = ImVec4(0.41, 0.55, 0.78, 1.00)
colors[clr.CloseButtonHovered] = ImVec4(0.50, 0.63, 0.84, 1.00)
colors[clr.CloseButtonActive] = ImVec4(0.41, 0.55, 0.78, 1.00)
colors[clr.PlotLines] = ImVec4(1.00, 1.00, 1.00, 1.00)
colors[clr.PlotLinesHovered] = ImVec4(0.90, 0.70, 0.00, 1.00)
colors[clr.PlotHistogram] = ImVec4(0.90, 0.70, 0.00, 1.00)
colors[clr.PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00)
colors[clr.TextSelectedBg] = ImVec4(0.41, 0.55, 0.78, 1.00)
colors[clr.ModalWindowDarkening] = ImVec4(0.16, 0.18, 0.22, 0.76)
end
BH_theme()