### Real Examples Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/sampfuncs.md Practical examples demonstrating the usage of SAMPFUNCS functions for common tasks. ```APIDOC ## Send APPLYANIMATION RPC (ID 86) ### Description Makes the local player play an animation visible to all players on the server. ### Example ```lua local function sendApplyAnimRPC(animLib, animName) local bs = raknetNewBitStream() raknetBitStreamWriteString(bs, animLib) -- string8: anim library raknetBitStreamWriteString(bs, animName) -- string8: anim clip name raknetBitStreamWriteFloat(bs, 4.0) -- float: frame delta (speed) raknetBitStreamWriteBool(bs, false) -- bool: loop raknetBitStreamWriteBool(bs, false) -- bool: lockX raknetBitStreamWriteBool(bs, false) -- bool: lockY raknetBitStreamWriteBool(bs, true) -- bool: freeze raknetBitStreamWriteInt32(bs, -1) -- int32: time (-1 = natural) raknetEmitRpc(86, bs) raknetDeleteBitStream(bs) end ``` ``` ```APIDOC ## Send CLEARANIMATIONS RPC (ID 163) ### Description Stops the current animation on all remote clients. ### Example ```lua local function sendClearAnimRPC() local bs = raknetNewBitStream() raknetEmitRpc(163, bs) raknetDeleteBitStream(bs) end ``` ``` -------------------------------- ### Installing SAMP.Lua Dependency Source: https://github.com/mst-community/samp-lua-docs/blob/main/README.md This snippet explains how to install the SAMP.Lua library. Copy the 'samp' folder into the 'moonloader/lib/' directory. ```bash # SAMP.Lua — copy the samp/ folder into moonloader/lib/ moonloader/lib/samp/events.lua ← github.com/THE-FYP/SAMP.Lua/releases (v2.3.0) moonloader/lib/samp/raknet.lua ← same release ``` -------------------------------- ### Installing SAMPFUNCS Dependency Source: https://github.com/mst-community/samp-lua-docs/blob/main/README.md This snippet details the installation of SAMPFUNCS. Copy the appropriate .asi file for your SA-MP version into the game's root directory. ```bash # SAMPFUNCS — copy the correct .asi for your SA-MP version into the game root SAMPFUNCS.asi ← blast.hk/threads/17/ (version 5.7.1) ``` -------------------------------- ### Installing MoonLoader Dependency Source: https://github.com/mst-community/samp-lua-docs/blob/main/README.md This snippet shows the command or action for installing the MoonLoader dependency. Ensure you use the correct version for compatibility. ```bash # MoonLoader — run the installer or extract manually setup-moonloader-026.exe ← blast.hk/moonloader/files/setup-moonloader-026.exe ``` -------------------------------- ### SPAWN RPC Example Source: https://github.com/mst-community/samp-lua-docs/blob/main/rpc/rpc_ids.md Sends the RPC 52 (SPAWN) to request spawning after class selection. This RPC requires no additional fields. ```lua -- Example usage for SPAWN RPC (no fields required) -- local bs = raknetNewBitStream() -- raknetEmitRpc(52, bs) -- raknetDeleteBitStream(bs) ``` -------------------------------- ### CHAT RPC Example Source: https://github.com/mst-community/samp-lua-docs/blob/main/rpc/rpc_ids.md Sends the RPC 101 (CHAT) to display a message in the chat. Only the message string needs to be provided. ```lua local bs = raknetNewBitStream() raknetBitStreamWriteString(bs, "Hello!") raknetEmitRpc(101, bs) raknetDeleteBitStream(bs) ``` -------------------------------- ### File and Directory Operations Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/moonloader.md Utilities for checking file/directory existence, creating directories, searching for files, and getting game/working directory paths. ```lua bool = doesFileExist(string path) bool = doesDirectoryExist(string path) bool = createDirectory(string path) Filesearch h, string name = findFirstFile(string mask) string file = findNextFile(Filesearch h) findClose(Filesearch h) string = getWorkingDirectory() -- returns moonloader/ directory path string = getGameDirectory() -- returns GTA SA root directory path ``` -------------------------------- ### mimgui Utility Types Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/mimgui.md Explains the usage of `ImVec2` for 2D coordinates and `ImVec4` for colors or rectangles, and how to get display size from `imgui.GetIO()`. ```lua -- ImVec2: 2D position or size imgui.ImVec2(x, y) -- ImVec4: color or rect (RGBA, values 0.0–1.0) imgui.ImVec4(r, g, b, a) -- Get display size local io = imgui.GetIO() local w = io.DisplaySize.x local h = io.DisplaySize.y -- Get center of screen local cx = io.DisplaySize.x / 2 local cy = io.DisplaySize.y / 2 ``` -------------------------------- ### File / Directory Functions Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/moonloader.md Functions for checking the existence of files and directories, creating directories, searching for files, and getting directory paths. ```APIDOC ## File / directory ```lua bool = doesFileExist(string path) bool = doesDirectoryExist(string path) bool = createDirectory(string path) Filesearch h, string name = findFirstFile(string mask) string file = findNextFile(Filesearch h) findClose(Filesearch h) string = getWorkingDirectory() -- returns moonloader/ directory path string = getGameDirectory() -- returns GTA SA root directory path ``` ``` -------------------------------- ### Get and Set Game Time Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/moonloader.md Retrieves the current game time in hours and minutes, and allows setting the game time. Also provides the game timer in milliseconds since the game started. ```lua -- Time int hours, int mins = getTimeOfDay() setTimeOfDay(int hours, int minutes) int ms = getGameTimer() -- milliseconds since game start ``` -------------------------------- ### ImGui Window and Button Example Source: https://github.com/mst-community/samp-lua-docs/blob/main/prompt/base_prompt.md Demonstrates creating a simple ImGui window with a button that triggers a chat message. Requires the 'mimgui' library. ```lua local imgui = require 'mimgui' local showWindow = imgui.ImBool(false) imgui.OnFrame( function() return showWindow.v end, function(player) imgui.Begin("My Window", showWindow) if imgui.Button("Click me") then sampAddChatMessage("Button clicked!", 0xFFFFFF) end imgui.End() end ) ``` -------------------------------- ### mimgui Pattern: Centered Window on First Open Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/mimgui.md Demonstrates how to center a window on the screen the first time it appears using `imgui.SetNextWindowPos` with `imgui.Cond.FirstUseEver` and a pivot of `(0.5, 0.5)`. ```lua imgui.OnFrame(function() return showWindow[0] end, function() local io = imgui.GetIO() imgui.SetNextWindowPos( imgui.ImVec2(io.DisplaySize.x / 2, io.DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5) ) imgui.Begin('Centered', showWindow) imgui.End() end) ``` -------------------------------- ### Dear ImGui UI Window Example with mimgui Source: https://context7.com/mst-community/samp-lua-docs/llms.txt This snippet demonstrates how to create a Dear ImGui window with various widgets like checkboxes, sliders, combo boxes, text inputs, and color pickers. It requires FFI state allocation for mutable variables and registers a render callback using imgui.OnFrame. The window can be toggled via a chat command or a hotkey. ```lua local imgui = require 'mimgui' local ffi = require 'ffi' local vk = require 'vkeys' local new, str = imgui.new, ffi.string -- FFI state variables local showWindow = new.bool(false) local inputBuf = new.char[256]('') local sliderVal = new.float(0.5) local comboIdx = new.int(0) local checkState = new.bool(true) local colorVal = new.float[4](0.2, 0.6, 1.0, 1.0) local comboItems = {'Option A', 'Option B', 'Option C'} -- Load a custom font once DX9 is ready imgui.OnInitialize(function() local fontPath = getGameDirectory() .. '\arial.ttf' if doesFileExist(fontPath) then imgui.GetIO().Fonts:AddFontFromFileTTF(fontPath, 15.0) end end) -- Register render frame — only draws when showWindow[0] is true local sub = imgui.OnFrame( function() return showWindow[0] end, function() local io = imgui.GetIO() imgui.SetNextWindowPos( imgui.ImVec2(io.DisplaySize.x / 2, io.DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5) ) imgui.SetNextWindowSize(imgui.ImVec2(320, 280), imgui.Cond.FirstUseEver) imgui.Begin('My Panel', showWindow, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse) imgui.TextColored(imgui.ImVec4(0.2, 0.8, 0.2, 1), 'Settings') imgui.Separator() -- Checkbox imgui.Checkbox('Enable feature', checkState) -- Slider imgui.SliderFloat('Speed', sliderVal, 0.0, 5.0) -- Combo dropdown if imgui.BeginCombo('Mode', comboItems[comboIdx[0] + 1]) then for i, item in ipairs(comboItems) do if imgui.Selectable(item, comboIdx[0] == i - 1) then comboIdx[0] = i - 1 end end imgui.EndCombo() end -- Text input imgui.InputText('Message', inputBuf, ffi.sizeof(inputBuf)) -- Color picker imgui.ColorEdit4('Color', colorVal) imgui.Separator() -- Submit button if imgui.Button('Send', imgui.ImVec2(120, 0)) then local text = ffi.string(inputBuf) if #text > 0 then sampSendChat(text) imgui.StrCopy(inputBuf, '') end end imgui.SameLine() if imgui.Button('Close', imgui.ImVec2(120, 0)) then showWindow[0] = false end imgui.End() end ) sub.LockPlayer = true -- lock movement when window is open function main() while not isSampAvailable() do wait(100) end sampRegisterChatCommand('menu', function() showWindow[0] = not showWindow[0] end) while true do wait(0) if isKeyJustPressed(vk.VK_F7) then showWindow[0] = not showWindow[0] end end end ``` -------------------------------- ### Basic Window Creation Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/mimgui.md Demonstrates the most basic usage of creating a window with a title and ending it. Widgets are placed between Begin and End calls. ```lua -- Basic window imgui.Begin('Title') -- widgets here imgui.End() ``` -------------------------------- ### getTrainCaboose Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Gets the caboose of a train. ```APIDOC ## getTrainCaboose ### Description Gets the caboose of a train. ### Parameters - **train** (Vehicle) - The train. ### Returns - **int** - The ID of the caboose. ``` -------------------------------- ### SA-MP Helper Functions - Main Loop Source: https://context7.com/mst-community/samp-lua-docs/llms.txt Initializes SA-MP utilities by waiting for availability, retrieving player information, and processing chat messages. This example demonstrates reading chat history, checking player connections, sending chat messages and commands, and registering custom chat commands. ```lua function main() while not isSampAvailable() do wait(100) end local myId = sampGetLocalPlayerId() local myName = sampGetPlayerNickname(myId) sampAddChatMessage(string.format("{FFFF00}You are %s (ID %d)", myName, myId), 0xFFFFFF) -- Read last 5 chat lines for i = 0, 4 do local ok, text, color = sampGetChatString(i) if ok then print(string.format("Chat[%d]: %s", i, text)) end end -- Check connected players for id = 0, 999 do if sampIsPlayerConnected(id) then local name = sampGetPlayerNickname(id) print("Player " .. id .. ": " .. name) end end -- Send chat and commands sampSendChat("Hello everyone!") wait(500) sampSendCommand("/stats") -- Register custom command sampRegisterChatCommand('pos', function(args) local x, y, z = getCharCoordinates(PLAYER_PED) sampAddChatMessage(string.format("Pos: %.2f %.2f %.2f", x, y, z), 0x00FF00) end) while true do wait(0) end end ``` -------------------------------- ### getScriptFireCoords Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Gets the coordinates of a script fire. ```APIDOC ## getScriptFireCoords ### Description Gets the coordinates of a script fire. ### Parameters - **fire** (int) - The ID of the script fire. ### Returns - **float X, float Y, float Z** - The X, Y, and Z coordinates of the fire. ``` -------------------------------- ### getVehicleModType Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Gets the type of a vehicle modification. ```APIDOC ## getVehicleModType ### Description Gets the type of a vehicle modification. ### Parameters - **component** (Model) - The modification model. ### Returns - **int** - The type of the modification. ``` -------------------------------- ### Player Count Functions Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Functions to get player counts. ```APIDOC ## sampGetMaxPlayerId ### Description Gets the maximum player ID currently in the game. ### Method `int id = sampGetMaxPlayerId(bool streamed)` ### Parameters - **streamed** (bool) - If true, considers streamed players. ### Returns - **id** (int) - The maximum player ID. ## sampGetPlayerCount ### Description Gets the current number of players in the game. ### Method `int count = sampGetPlayerCount(bool streamed)` ### Parameters - **streamed** (bool) - If true, includes streamed players in the count. ### Returns - **count** (int) - The total number of players. ``` -------------------------------- ### imgui.OnInitialize Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/mimgui.md Registers a callback function that is executed once after the DX9 renderer is ready. This is typically used for loading fonts or textures. ```APIDOC ## imgui.OnInitialize ```lua imgui.OnInitialize(function() -- called once after DX9 renderer is ready -- use this to load fonts or textures local fontPath = getFolderPath(0x14) .. '\\consola.ttf' imgui.GetIO().Fonts:AddFontFromFileTTF(fontPath, 15.0) end) ``` ### Description Registers a callback function that is executed once after the DX9 renderer is ready. This is typically used for loading fonts or textures. ``` -------------------------------- ### SERVERCOMMAND RPC Example Source: https://github.com/mst-community/samp-lua-docs/blob/main/rpc/rpc_ids.md Sends the RPC 50 (SERVERCOMMAND) to execute a server command. The command string, including the leading slash, must be provided. ```lua -- Example usage for SERVERCOMMAND RPC (command string required) -- local bs = raknetNewBitStream() -- raknetBitStreamWriteString(bs, "/yourcommand arg1 arg2") -- raknetEmitRpc(50, bs) -- raknetDeleteBitStream(bs) ``` -------------------------------- ### Screen Resolution Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Function to get the current screen resolution. ```APIDOC ## getScreenResolution ### Description Retrieves the current screen resolution. ### Method `getScreenResolution()` ### Returns - `int resX`: The width of the screen. - `int resY`: The height of the screen. ``` -------------------------------- ### getNumAvailablePaintjobs Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Gets the number of available paint jobs for a vehicle. ```APIDOC ## getNumAvailablePaintjobs ### Description Gets the number of available paint jobs for a vehicle. ### Parameters - **car** (Vehicle) - The vehicle. ### Returns - **int** - The number of available paint jobs. ``` -------------------------------- ### Basic Script Structure and Lifecycle with MoonLoader Source: https://context7.com/mst-community/samp-lua-docs/llms.txt Defines the entry point `main()` and script metadata. Use `wait(ms)` to yield execution and avoid blocking. Includes event handlers for script exit and chat commands. ```lua script_name("MyScript") script_author("YourName") script_version("1.0") script_moonloader(26) -- minimum MoonLoader version required local sampev = require 'samp.events' local raknet = require 'samp.raknet' local vk = require 'vkeys' local enabled = false function main() -- Wait until SA-MP and SAMPFUNCS are both ready if not isSampLoaded() or not isSampfuncsLoaded() then return end while not isSampAvailable() do wait(100) end sampAddChatMessage("{00FF00}[MyScript] Loaded!", 0xFFFFFF) -- Register a chat command sampRegisterChatCommand('myscript', function(args) enabled = not enabled sampAddChatMessage(enabled and "{00FF00}Enabled" or "{FF0000}Disabled", -1) end) -- Frame loop — wait(0) yields once per frame while true do wait(0) if isKeyJustPressed(vk.VK_F5) then enabled = not enabled end end end function onExitScript(quitGame) sampAddChatMessage("[MyScript] Unloaded.", 0xFFFFFF) end ``` -------------------------------- ### getAvailableVehicleMod Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Gets the item ID of an available vehicle modification. ```APIDOC ## getAvailableVehicleMod ### Description Gets the item ID of an available vehicle modification. ### Parameters - **car** (Vehicle) - The vehicle. - **poolIndex** (int) - The index in the modification pool. ### Returns - **Model** - The model ID of the modification. ``` -------------------------------- ### Windows Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/mimgui.md Functions for creating and managing ImGui windows, including basic windows, windows with close buttons, and windows with specific flags. Also covers setting window position and size. ```APIDOC ## Windows ```lua -- Basic window imgui.Begin('Title') -- widgets here imgui.End() -- Window with close button (pass bool*) local open = new.bool(true) imgui.Begin('Title', open) -- open[0] becomes false when X is clicked imgui.End() -- Window with flags imgui.Begin('Title', nil, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoMove) imgui.End() -- Set position/size before Begin imgui.SetNextWindowPos(imgui.ImVec2(100, 100), imgui.Cond.FirstUseEver) imgui.SetNextWindowSize(imgui.ImVec2(300, 200), imgui.Cond.FirstUseEver) imgui.Begin('My Window') imgui.End() ``` ### Description Functions for creating and managing ImGui windows, including basic windows, windows with close buttons, and windows with specific flags. Also covers setting window position and size. ``` -------------------------------- ### getNumberOfFiresInRange Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Gets the number of fires within a specified radius. ```APIDOC ## getNumberOfFiresInRange ### Description Gets the number of fires within a specified radius. ### Parameters - **atX** (float) - The X coordinate of the center. - **atY** (float) - The Y coordinate of the center. - **atZ** (float) - The Z coordinate of the center. - **radius** (float) - The radius to check within. ### Returns - **int** - The number of fires in range. ``` -------------------------------- ### imgui.new Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/mimgui.md Provides functions to create FFI-allocated state variables required for ImGui widgets. Plain Lua variables are not compatible with ImGui widgets. ```APIDOC ## State variables (imgui.new) mimgui uses LuaJIT FFI types for all mutable state. Plain Lua variables will NOT work for ImGui widgets. ```lua local new = imgui.new -- Scalars local myBool = new.bool(false) -- checkbox, window open flag local myInt = new.int(0) -- sliders, combo index local myFloat = new.float(0.5) -- float sliders local myFloat3 = new.float[3](0) -- color/vector widgets -- Strings (text input buffers) local myText = new.char[256]('') -- InputText buffer -- Access and assign values myBool[0] = true myInt[0] = 5 local val = myFloat[0] -- Copy a Lua string into a char buffer imgui.StrCopy(myText, "hello") -- Read back from buffer local luaStr = ffi.string(myText) ``` ### Description Provides functions to create FFI-allocated state variables required for ImGui widgets. Plain Lua variables are not compatible with ImGui widgets. ``` -------------------------------- ### Get Vehicle Coordinates Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Retrieves the current coordinates of a vehicle. ```APIDOC ## getCarCoordinates ### Description Gets the coordinates of a vehicle. ### Method `float positionX, float positionY, float positionZ = getCarCoordinates(Vehicle car)` ### Parameters - **car** (Vehicle) - The vehicle object. ### Returns - **float positionX** - The X coordinate. - **float positionY** - The Y coordinate. - **float positionZ** - The Z coordinate. ``` -------------------------------- ### Initializing Fonts and Textures with imgui.OnInitialize Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/mimgui.md The imgui.OnInitialize function is called once after the DX9 renderer is ready. It's the recommended place to load custom fonts or textures for your GUI elements. ```lua imgui.OnInitialize(function() -- called once after DX9 renderer is ready -- use this to load fonts or textures local fontPath = getFolderPath(0x14) .. '\\consola.ttf' imgui.GetIO().Fonts:AddFontFromFileTTF(fontPath, 15.0) end) ``` -------------------------------- ### Get Character Coordinates Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Retrieves the current coordinates of a character. ```APIDOC ## getCharCoordinates ### Description Gets the coordinates of a character. ### Method `float positionX, float positionY, float positionZ = getCharCoordinates(Ped ped)` ### Parameters - **ped** (Ped) - The character object. ### Returns - **float positionX** - The X coordinate. - **float positionY** - The Y coordinate. - **float positionZ** - The Z coordinate. ``` -------------------------------- ### mimgui Font Loading and Usage Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/mimgui.md Demonstrates how to load custom fonts using `AddFontFromFileTTF` within an `OnInitialize` callback and apply them using `PushFont`/`PopFont`. ```lua imgui.OnInitialize(function() local fontPath = getFolderPath(0x14) .. '\arial.ttf' myFont = imgui.GetIO().Fonts:AddFontFromFileTTF(fontPath, 16.0) end) -- In draw callback: imgui.PushFont(myFont) imgui.Text('Custom font') imgui.PopFont() ``` -------------------------------- ### Vehicle Quaternion Functions Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Functions for getting and setting the quaternion of a vehicle. ```APIDOC ## getVehicleQuaternion ### Description Gets the quaternion (rotation) of a vehicle. ### Method `float x, float y, float z, float w = getVehicleQuaternion(Vehicle car)` ### Parameters - **car** (Vehicle) - The vehicle to get the quaternion from. ### Returns - **x, y, z, w** (float) - The components of the quaternion. ## setVehicleQuaternion ### Description Sets the quaternion (rotation) of a vehicle. ### Method `setVehicleQuaternion(Vehicle car, float x, float y, float z, float w)` ### Parameters - **car** (Vehicle) - The vehicle to set the quaternion for. - **x, y, z, w** (float) - The components of the quaternion. ``` -------------------------------- ### Object Quaternion Functions Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Functions for getting and setting the quaternion of an object. ```APIDOC ## getObjectQuaternion ### Description Gets the quaternion (rotation) of an object. ### Method `float x, float y, float z, float w = getObjectQuaternion(Object object)` ### Parameters - **object** (Object) - The object to get the quaternion from. ### Returns - **x, y, z, w** (float) - The components of the quaternion. ## setObjectQuaternion ### Description Sets the quaternion (rotation) of an object. ### Method `setObjectQuaternion(Object object, float x, float y, float z, float w)` ### Parameters - **object** (Object) - The object to set the quaternion for. - **x, y, z, w** (float) - The components of the quaternion. ``` -------------------------------- ### Cleo Library Function Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Function to get the version of the Cleo library. ```APIDOC ## getCleoLibraryVersion ### Description Retrieves the version of the Cleo library. ### Method `int version = getCleoLibraryVersion()` ### Returns - **version** (int) - The version number of the Cleo library. ``` -------------------------------- ### Registering Custom Incoming RPC Hook with raknet.RPC Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/samp.raknet.md Demonstrates how to register a custom incoming RPC hook using a raknet.RPC constant. This example shows how to intercept the PLAYSOUND RPC and optionally block it. ```lua local sampev = require 'samp.events' local raknet = require 'samp.raknet' -- Register a custom incoming RPC hook using a raknet.RPC constant sampev.INTERFACE.INCOMING_RPCS[raknet.RPC.PLAYSOUND] = { 'onPlaySound', {soundId = 'int32'}, {coordinates = 'vector3d'} } function sampev.onPlaySound(sound, coords) print(string.format('Sound %d at %.2f, %.2f, %.2f', sound, coords.x, coords.y, coords.z)) return false -- block the sound end ``` -------------------------------- ### Player Character Retrieval Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Function to get the character associated with a player. ```APIDOC ## getPlayerChar ### Description Retrieves the character (Ped) controlled by a specific player. ### Parameters - **player** (Player) - The player to get the character for. ### Returns - **bool result** - True if the character was retrieved successfully. - **Ped ped** - The character (Ped) associated with the player. ``` -------------------------------- ### Game Time Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Function to get the current game timer in milliseconds. ```APIDOC ## getGameTimer ### Description Returns the current game time in milliseconds since the game started. ### Returns - **int timeMs** - The current game time in milliseconds. ``` -------------------------------- ### Setting Window Position and Size Source: https://github.com/mst-community/samp-lua-docs/blob/main/libs/mimgui.md Use SetNextWindowPos and SetNextWindowSize before calling imgui.Begin to control the initial position and dimensions of a window. The imgui.Cond.FirstUseEver flag ensures these settings are applied only on the first frame the window appears. ```lua -- Set position/size before Begin imgui.SetNextWindowPos(imgui.ImVec2(100, 100), imgui.Cond.FirstUseEver) imgui.SetNextWindowSize(imgui.ImVec2(300, 200), imgui.Cond.FirstUseEver) imgui.Begin('My Window') imgui.End() ``` -------------------------------- ### Get Object Heading Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Retrieves the current heading (rotation) of an object. ```APIDOC ## getObjectHeading ### Description Gets the current heading (in degrees) of an object. ### Parameters - **object** (Object) - The object whose heading to retrieve. ### Returns - **angle** (float) - The heading of the object in degrees. ``` -------------------------------- ### Accessing Raw GitHub URLs for Documentation Source: https://github.com/mst-community/samp-lua-docs/blob/main/README.md You can directly use raw GitHub URLs to provide documentation files to AI models like Claude. No setup is required for this method. ```text https://raw.githubusercontent.com/MST-Community/samp-lua-docs/main/libs/samp.events.md https://raw.githubusercontent.com/MST-Community/samp-lua-docs/main/rpc/rpc_ids.md https://raw.githubusercontent.com/MST-Community/samp-lua-docs/main/prompt/base_prompt.md ``` -------------------------------- ### Get Car Heading Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Retrieves the current heading (rotation) of a vehicle. ```APIDOC ## getCarHeading ### Description Gets the current heading (in degrees) of a vehicle. ### Parameters - **car** (Vehicle) - The vehicle whose heading to retrieve. ### Returns - **angle** (float) - The heading of the vehicle in degrees. ``` -------------------------------- ### Get Char Heading Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Retrieves the current heading (rotation) of a character. ```APIDOC ## getCharHeading ### Description Gets the current heading (in degrees) of a character (ped). ### Parameters - **ped** (Ped) - The character whose heading to retrieve. ### Returns - **angle** (float) - The heading of the character in degrees. ``` -------------------------------- ### Basic RPC Sending in MoonLoader Source: https://github.com/mst-community/samp-lua-docs/blob/main/rpc/rpc_ids.md Demonstrates the fundamental steps for sending an RPC in MoonLoader: creating a bitstream, writing fields in the correct order, emitting the RPC with its ID, and cleaning up the bitstream. Always follow this pattern for outgoing RPCs. ```lua local bs = raknetNewBitStream() raknetBitStreamWriteString(bs, "PED") raknetBitStreamWriteString(bs, "IDLE_CHAT") -- ... more fields in exact order raknetEmitRpc(86, bs) raknetDeleteBitStream(bs) ``` -------------------------------- ### APPLYANIMATION RPC Example Source: https://github.com/mst-community/samp-lua-docs/blob/main/rpc/rpc_ids.md Sends the RPC 86 (APPLYANIMATION) to play an animation for a player. Ensure all fields, including animation library, name, speed, loop, lock flags, and freeze, are provided in the correct order. ```lua local bs = raknetNewBitStream() raknetBitStreamWriteString(bs, "PED") raknetBitStreamWriteString(bs, "IDLE_CHAT") raknetBitStreamWriteFloat(bs, 4.0) raknetBitStreamWriteBool(bs, false) raknetBitStreamWriteBool(bs, false) raknetBitStreamWriteBool(bs, false) raknetBitStreamWriteBool(bs, true) raknetBitStreamWriteInt32(bs, -1) raknetEmitRpc(86, bs) raknetDeleteBitStream(bs) ``` -------------------------------- ### Script Management Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Functions for loading, finding, listing, and getting script objects. ```APIDOC ## script.load ### Description Loads a script from a file and returns a script object. Returns nil if the script fails to load. ### Parameters - **file** (string) - The path to the script file. ### Returns - **s** (LuaScript) - The loaded script object, or nil. ``` ```APIDOC ## script.find ### Description Finds a loaded script by its name. Returns nil if the script is not found. ### Parameters - **name** (string) - The name of the script. ### Returns - **s** (LuaScript) - The script object, or nil. ``` ```APIDOC ## script.list ### Description Returns a list of all loaded scripts. ### Returns - **list** (table) - A table containing all loaded script objects. ``` ```APIDOC ## script.get ### Description Retrieves a script object by its ID. Returns nil if no script with the given ID exists. ### Parameters - **scriptId** (int) - The ID of the script. ### Returns - **script** (LuaScript) - The script object, or nil. ``` ```APIDOC ## script.this ### Description Returns the script object for the currently executing script. ``` -------------------------------- ### Module and Process Handling Source: https://github.com/mst-community/samp-lua-docs/blob/main/lib/moonloader_reference.txt Functions for getting module handles and process addresses. ```APIDOC ## getModuleHandle ### Description Retrieves the handle of a loaded module. ### Parameters - **module** (string) - The name of the module. ### Returns - **handle** (uint) - The handle of the module. ``` ```APIDOC ## getModuleProcAddress ### Description Retrieves the address of a procedure within a module. ### Parameters - **module** (string) - The name of the module. - **proc** (string) - The name of the procedure. ### Returns - **address** (uint) - The address of the procedure. ```