BeamMP Lua Scripting
BeamMP has a built-in server-side Lua environment. Scripts in Resources/Server/ are loaded at startup and can react to player events, send messages, and control the server programmatically.
Core API Functions
Section titled “Core API Functions”Players
Section titled “Players”MP.GetPlayers() -- table of {id = name}MP.GetPlayerName(playerID) -- player's username stringMP.SendChatMessage(playerID, msg) -- send message; -1 = broadcast to allEvents
Section titled “Events”Register a Lua function to run when something happens:
MP.RegisterEvent("onPlayerConnecting", "myFunction")function myFunction(playerID) -- runs when a player connectsendEvent Reference
Section titled “Event Reference”| Event | Arguments | Description |
|---|---|---|
onPlayerConnecting | playerID | Player is connecting |
onPlayerConnected | playerID | Player fully joined |
onPlayerDisconnecting | playerID | Player is leaving |
onChatMessage | playerID, name, message | Player sent a chat message |
onVehicleSpawned | playerID, vehicleID, data | Vehicle spawned |
onVehicleEdited | playerID, vehicleID, data | Vehicle modified |
onVehicleDeleted | playerID, vehicleID | Vehicle deleted |
onVehicleReset | playerID, vehicleID | Vehicle reset |
Timers
Section titled “Timers”-- Run a function every 300 secondsMP.CreateTimer(300, function() MP.SendChatMessage(-1, "Remember to follow the server rules!")end)Example: /rules Command
Section titled “Example: /rules Command”local rules = { "1. No intentional ramming.", "2. Keep chat respectful.", "3. Listen to admins.",}
MP.RegisterEvent("onChatMessage", "handleChat")
function handleChat(playerID, playerName, message) if message == "/rules" then for _, rule in ipairs(rules) do MP.SendChatMessage(playerID, rule) end return 1 -- prevent "/rules" from appearing in chat endendExample: Join & Leave Messages
Section titled “Example: Join & Leave Messages”MP.RegisterEvent("onPlayerConnected", "onJoin")function onJoin(playerID) local name = MP.GetPlayerName(playerID) MP.SendChatMessage(-1, name .. " has joined the server!")end
MP.RegisterEvent("onPlayerDisconnecting", "onLeave")function onLeave(playerID) local name = MP.GetPlayerName(playerID) MP.SendChatMessage(-1, name .. " has left the server.")endDebugging
Section titled “Debugging”- Use
print("message")- output appears in the Console tab of your Vyper Hosting panel. - Syntax errors appear in the console on startup with the line number.
Deploying Your Script
Section titled “Deploying Your Script”- Write your script and save it as a
.luafile. - In your panel, go to Files → Resources → Server and upload the file. Or use SFTP - see SFTP guides.
- Restart the server - your script is active immediately.
Further Reading
Section titled “Further Reading” BeamMP Server API Docs Official API reference for all server-side Lua functions and events.
BeamMP Forums Community scripts, examples, and plugin discussions.