What does a script look like?
A resource is a server script, a client script and meta.xml. Below: a car on command with an RGB colour and plate, time of day, weather, Definitive Edition slow motion and a client-side dialog box.
-- Car on command: RGB colour, headlights, custom plate
addCommandHandler("auto", function(player)
local x, y, z = getElementPosition(player)
local car = createVehicle(536, x + 3, y, z) -- Blade
setVehicleColor(car, 255, 122, 34, 20, 20, 20)
setVehicleHeadLightColor(car, 255, 180, 90)
setVehiclePlateText(car, "GROVE 4L")
warpPedIntoVehicle(player, car)
end)
-- Sunset over Los Santos
setTime(19, 30)
setWeatherBlended(1)
-- Weapon wheel slow motion from Definitive Edition
setSlowMotionEnabled(true, "wheel")
-- UI theme, notification and dialog box
guiSetTheme("sunset")
addEventHandler("onClientResourceStart", resourceRoot, function()
guiNotify("Welcome to Los Santos!", "success", 4000)
end)
bindKey("F2", "down", function()
local box = guiMessageBox("Faction", "Join Grove Street?", { "Yes", "No" })
addEventHandler("onClientGUIAccepted", box, function(label)
if label == "Yes" then triggerServerEvent("faction:join", localPlayer) end
end, false)
end)
<meta>
<info author="You" name="grove" version="1.0" type="gamemode" />
<script src="server.lua" type="server" />
<script src="client.lua" type="client" />
</meta>
What works the same as in MTA?
- A bad argument does not stop the script. The function returns
falseand logs aBad argument @ 'setPlayerMoney'warning. - Coordinates as
x, y, zor aVector3. - Custom events with
addEvent, client-to-server events withaddEvent('name', true). - Exports:
exports.resource:function()andcall(). - Numbering: GUI list rows from 0, columns from 1, weapon slots 0 to 12.
What is ready out of the box?
setSlowMotionEnabled: slow motion on the weapon wheel and during stunts, from Definitive Edition.- Built-in UI themes switched with one function:
guiSetTheme,guiRegisterTheme. - Ready-made elements: a
guiNotifynotification, aguiMessageBoxdialog, aguiCreateSliderslider. setLoadingScreen: image, name and tips on the server loading screen, with one function.
What does the API cover?
- Players
- Peds
- Clothes
- Vehicles
- Weapons
- Projectiles
- Objects
- Pickups
- Markers
- Blips
- Collision shapes
- World
- Lights
- Fire
- Effects
- Camera
- Audio
- Interface (GUI)
- Drawing (dx)
- Text displays
- Cursor
- Input and controls
- Chat and console
- Teams
- Accounts
- Permissions (ACL)
- Admin and bans
- Database
- Files
- XML
- Resources
- Events
- Timers
- Maps
- Math and vectors
Every function is described in the Lua documentation.
Tools
The collision generator makes a .col file from an FBX, OBJ, glTF, DFF or 3DS model: you set the triangle count, the mode and the surface, and see the result in 3D before it goes into your resource.
Questions
How is Trilogy Hub different from MTA:SA?
They are two separate projects for different versions of the game. MTA:SA runs on the original GTA San Andreas, while Trilogy Hub runs on Definitive Edition (Unreal Engine 4). Scripting works in a similar way, and the Trilogy Hub launcher also gives you an account, friends and chat.
Will my MTA:SA scripts work?
Partly. The Trilogy Hub API uses a similar model: resources with meta.xml, events, exports and the same names for many functions. A ready-made resource needs reviewing, because not every function has a counterpart.