script_name('Gambit Animation Manager') script_author('Joak') script_description('Animation manager for SA-MP') require 'lib.moonloader' local imgui = require 'mimgui' local ffi = require 'ffi' local menuOpen = imgui.new.bool(false) local favoritesOnly = imgui.new.bool(false) local searchBuf = ffi.new('char[128]') local nameBuf = ffi.new('char[128]') local commandBuf = ffi.new('char[128]') local animations = {} local cursorEnabled = false local configPath = getWorkingDirectory() .. '\\config\\gambit_anim_manager.txt' local function notify(text) sampAddChatMessage( '{66CCFF}[Anim Manager] {FFFFFF}' .. text, -1 ) end local function saveAnimations() local file = io.open(configPath, 'w') if not file then notify('Could not save configuration.') return end for _, anim in ipairs(animations) do local name = anim.name:gsub('[\r\n\t]', ' ') local command = anim.command:gsub('[\r\n\t]', ' ') file:write(name .. '\t' .. command .. '\t' .. (anim.favorite and '1' or '0') .. '\n') end file:close() end local function loadAnimations() animations = {} local file = io.open(configPath, 'r') if file then for line in file:lines() do local name, command, favorite = line:match('^(.-)\t(.-)\t([01])$') if name and command then table.insert(animations, { name = name, command = command, favorite = favorite == '1' }) end end file:close() else animations = { {name = 'Dance 1', command = '/dance 1', favorite = false}, {name = 'Dance 2', command = '/dance 2', favorite = false}, {name = 'Custom Animation', command = '/anim', favorite = false} } saveAnimations() end end local function containsText(text, search) text = string.lower(text or '') search = string.lower(search or '') return search == '' or string.find(text, search, 1, true) ~= nil end local function addAnimation() local name = ffi.string(nameBuf) local command = ffi.string(commandBuf) if name == '' or command == '' then notify('Enter both a name and a command.') return end table.insert(animations, { name = name, command = command, favorite = false }) ffi.fill(nameBuf, ffi.sizeof(nameBuf), 0) ffi.fill(commandBuf, ffi.sizeof(commandBuf), 0) saveAnimations() notify('Animation added.') end imgui.OnFrame( function() return menuOpen[0] end, function() imgui.SetNextWindowSize( imgui.ImVec2(620, 520), imgui.Cond.FirstUseEver ) local visible = imgui.Begin( 'Gambit Animation Manager', menuOpen ) if visible then imgui.Text('Search by name or command') imgui.InputText( '##search', searchBuf, ffi.sizeof(searchBuf) ) imgui.Checkbox('Favorites only', favoritesOnly) imgui.Separator() imgui.Text('Add animation') imgui.InputText( 'Name', nameBuf, ffi.sizeof(nameBuf) ) imgui.InputText( 'Command (example: /dance 1)', commandBuf, ffi.sizeof(commandBuf) ) if imgui.Button('Add Animation') then addAnimation() end imgui.Separator() imgui.Text('Animation List') local search = ffi.string(searchBuf) local deleteIndex = nil for i, anim in ipairs(animations) do local matchesName = containsText(anim.name, search) local matchesCommand = containsText(anim.command, search) if (matchesName or matchesCommand) and (not favoritesOnly[0] or anim.favorite) then imgui.Separator() imgui.Text(anim.name) imgui.SameLine() if imgui.Button('Play##play' .. i) then sampSendChat(anim.command) end imgui.SameLine() local star = anim.favorite and '*' or '+' if imgui.Button(star .. '##fav' .. i) then anim.favorite = not anim.favorite saveAnimations() end imgui.SameLine() if imgui.Button('Delete##del' .. i) then deleteIndex = i end imgui.TextDisabled(anim.command) end end if deleteIndex then table.remove(animations, deleteIndex) saveAnimations() end end imgui.End() end ) function main() repeat wait(0) until isSampAvailable() loadAnimations() sampRegisterChatCommand('animmanager', function() menuOpen[0] = not menuOpen[0] end) notify('Loaded. Type /animmanager to open.') notify('Script made by Joak') while true do wait(0) if isKeyDown(0x12) and wasKeyPressed(0x33) and not sampIsChatInputActive() and not sampIsDialogActive() then menuOpen[0] = not menuOpen[0] end if menuOpen[0] ~= cursorEnabled then sampSetCursorMode(menuOpen[0] and 0 or 0) cursorEnabled = menuOpen[0] end end end