Scripting/Server/Functions
- 1Messages and chat
- 2Finding and counting entities
- 3Creating world entities
- 4World settings
- 5Server information and administration
- 6Camera and audio (per player)
- 7Maths and strings
- 8Constructors for helper objects
- 9Server dialogs (SA-MP style)
- 10Audio streams, object editor and object picker (v0.3)
- 11Custom weather / time-of-day colours (timecyc.dat, v0.3-r2)
- 12Ped clothing (v0.3.3)
- 13Graffiti (v0.5-beta, PC only)
- 14Bots - virtual players (v0.5-beta)
All functions below are global. "Player" means a Player handle (see chapter 5), and many take either a Vector or separate x, y, z numbers where noted.
Messages and chat
- Message – Sends a chat line to every player.
- MessagePlayer – Sends a chat line to one player.
- MessageAllExcept – Chat line to everyone except the player with this id (integer).
- SendPlayerMessage – Chat line to one player, styled like a normal chat line.
- SmallMessage – Shows a small game message at the bottom of that player's screen.
- BigMessage – Shows a big on-screen message.
- HelpMessage – Shows the help box of the game (cheat codes / game hints) to the player.
- PagerMessage – Shows text through the small-message area (pager style).
- ClearMessages – Removes the big/small messages currently on that player's screen.
- PlayFrontEndSound – Plays a GTA III frontend sound (the ids the game menus use) on that player's client.
- PlaySuspectLastSeen – Plays the police-radio "suspect last seen" report on every client.
Finding and counting entities
FindPlayer(i):for (local i = 0; i < GetMaxPlayers(); i++)
{
local p = FindPlayer(i);
if (p) MessagePlayer("Hello " + p.Name, p);
}- FindPlayer – Returns the Player with that integer id, or the player whose name equals the string (exact, case-sensitive).
- FindVehicle – Vehicle handle or null.
- FindObject – Object handle or null.
- FindPickup – Pickup handle or null.
- FindSphere – Sphere handle or null.
- FindBlip – Blip handle or null; same owner filter as FindSphere.
- FindNPC – NPC handle or null.
- GetPlayers / GetPlayerCount – Number of connected players.
- GetMaxPlayers – The max_players limit.
- GetClosestPlayer – The nearest other player, or null.
- GetVehicleCount – Number of vehicles that exist (script-removed ones are not counted).
- GetObjectCount / GetPickupCount / GetSphereCount – Counts of active entities of each kind.
- KickPlayer – Disconnects the player (reported as PARTREASON_KICKED).
- GetCheatName – (v0.4.9+) The name of an anti-cheat detection, e.g.
- BanPlayer – Bans the player and disconnects them.
Creating world entities
- CreateVehicle – Creates a vehicle everyone sees.
- CreateObject – Creates a map object visible to everyone.
- CreatePickup – Creates a pickup; model is a GTA III pickup model id (for example 1362).
- CreateWeaponPickup – (0.5-rc1) A pickup of a custom weapon (a <weapon> tag with a model, see 1.5).
- CreateSphere – Creates a coloured sphere marker that fires onPlayerEnterSphere/onPlayerExitSphere.
- CreateClientSphere – Same, but only that player sees it and only they trigger it.
- CreateCheckpoint – Creates a race-style checkpoint (the tall tube marker of the GTA III races and the Patriot Playground) that fires onPlayerEnterCheckpoint/onPlayerExit...
- CreateClientCheckpoint – Same, but only that player sees it and only they trigger it.
- FindCheckpoint – Checkpoint handle or null (spheres are not returned).
- GetCheckpointCount – Number of active checkpoints (GetSphereCount() does not count them).
- CreateBlip – Radar blip for everyone.
- CreateClientBlip – Radar blip only that player sees.
- GangZoneCreate – (v0.4-beta+) SA-MP style gang zone: a rectangle of the map that the clients draw on the radar, under the blips and clipped to the radar disc.
- GangZoneDestroy / IsValidGangZone – Removes a zone from every player's radar and frees its id / tells whether the id is in use.
- GangZoneShowForPlayer / GangZoneShowForAll – Shows the zone.
- GangZoneHideForPlayer / GangZoneHideForAll – Hides the zone again (also ends its flashing).
- GangZoneFlashForPlayer / GangZoneFlashForAll – The zone alternates between its colour and flashColour about every third of a second while it is shown (a flash set on a hidden zone starts when you s...
- GangZoneStopFlashForPlayer / GangZoneStopFlashForAll – Back to the steady colour.
- IsPlayerInGangZone / GetGangZoneAt / player.GangZone – (v0.4-beta+) Whether a player stands inside a zone, the id of the first zone containing a point (-1 = none) and the id of the zone a player is in (-1 ...
- GetRadioStationCount / GetRadioStationName – (v0.4-beta+) Custom radio stations: every folder of Radio/ next to the server is a station named like the folder, its .mp3 files are the songs.
- vehicle.Radio / SetPassengerRadio / GetPassengerRadio – (v0.4-beta+) The radio station of a car: 0 RADIO_DEFAULT, 1-9 the game's stations (RADIO_HEAD .. RADIO_CHATTERBOX), 10 RADIO_MP3 (a client without the...
- CreateFire – Starts a fire on every client (radius 0-25).
- CreateExplosion – Explosion on every client.
- ExtinguishFire – Puts out fires within the radius (0.1-100).
- ExtinguishAllFires – Puts out every fire.
- OpenGarage / CloseGarage – Opens/closes a garage door for everyone.
- OpenSSVBridge – Raises the Shoreside Vale - Staunton lift bridge and keeps it up (ships can pass, cars cannot cross).
- CloseSSVBridge – Lowers the lift bridge and keeps it down so cars can cross.
- SetSSVBridgeLock – true stops the bridge exactly where it is (even mid-move).
- SetSSVBridgeUpdateTime – Length of one full automatic cycle in milliseconds (default 60000, limited to 6000-3600000).
- CreateNPC – Creates a server NPC. See the NPC chapter.
- DestroyNPC – Removes an NPC.
World settings
- ToggleRealMoney / IsRealMoney – (v0.5.1+) Server-owner switch for the realistic money mode.
- SetTime / GetHour / GetMinute – Sets/reads the shared game clock.
- SetTimeLock – true freezes the clock at the current time.
- SetTimeScale – Real milliseconds per in-game minute (1000 is the normal speed).
- SetWeatherLock – true keeps the weather you set with SetWeather (re-sent every 3 s) instead of letting the game cycle it; false returns to the game's own weather.
- GetTime – Current Unix time in seconds as an integer (v0.2.0+).
- SetWeather / GetWeather – Sets/reads the weather id.
- SetVirtualWorldTime – (v0.3.1+) Time of day for ONE virtual world: only players whose VirtualWorld is that id see it, and a player who moves into that world gets it at once...
- SetVirtualWorldWeather – (v0.3.1+) Weather for one virtual world only (weatherid -1 removes the override).
- SetGamespeed / GetGamespeed – Game speed multiplier (1.0 = normal).
- SetGravity / GetGravity – World gravity (default 0.008).
- ToggleImprovedCarCam – (v0.2.9-r3+) Switches the improved vehicle camera on or off.
- SetPlayerBlipStyle – (v0.5-beta+) Chooses how the radar shows the other players, with the constants BLIPSTYLE_DEFAULT (0, the stock coloured squares in the player colours)...
- ToggleImprovedPlayerBlips – (v0.3.3+) GTA V style player blips on the radar: the default coloured square of another player becomes a circle with a black rim and a thin white ring...
- CreateCinema – (v0.5-rc3+) Creates a cinema screen: a flat screen in the 3D world that plays a video.
- PlayCinema – (v0.5-rc3+) Plays a video on that screen for everybody near it, replacing what played before.
- StopCinema / DeleteCinema / SetCinemaVolume – (v0.5-rc3+) StopCinema stops the video (the screen stays, empty).
- SetBurstableTyres – (v0.3.1-r2+) Turns the burstable tyres of the IIIBurstableTyres mod on or off for every car (a port of the mod, bullet hits on a wheel burst it).
- EnableTrains – Turns the game's trains (surface and subway) on or off for every player (v0.2.8+, default on).
- SetIslands / GetIslands – (v0.3.1-r5+) true = every island unlocked: the Portland - Staunton bridge is repaired (the default; islands on|off in server.conf sets the start value...
- SetDefaultWastedSettings / SetWastedSettings / ResetWastedSettings – (v0.5-rc2+) How every player's own death plays out.
- SetPassengerKey / SetTrafficPassenger / GetPassengerKey – (v0.3.1-r5+) The run-time versions of the server.conf options passenger_key and traffic_passenger.
- SetWeaponData – Changes weapon stats live on every client (and for future joiners).
- GetWeaponData – Returns the number last set by script or weapon.dat, or null if never set (vanilla value in use).
Server information and administration
- SetServerName / GetServerName – Name shown in the server browser.
- SetPassword – Sets the join password.
- SetServerRule / DeleteServerRule – Adds/updates/removes a key=value line shown in the server info (returned in browser queries).
- RemoveBuildingForPlayer – Hides every default map object of model within radius of the point on that player's game.
- SyncPlayerSkins – Turns custom player-skin synchronisation on or off (skin .bmp upload/broadcast).
- ReloadScripts – Restarts every script as if the server had just started.
- LoadScript – (v0.4.6+) Loads Scripts/<Folder>/Script.xml while the server runs, like a folder of LU/content.xml: its server scripts run, its custom models, client ...
- UnloadScript – (v0.4.6+) Takes a loaded script folder out again: the event handlers and global functions / variables / classes it defined, the timers it started and ...
- GetScripts – (v0.4.6+) Returns an array with the names of the loaded script folders.
- ToggleRagdollPhysics – (v0.4.8+) Switches ragdoll physics on or off for every player on the server (it is sent to everybody who is connected, and to everybody who joins).
- ToggleVehicleDents – (v0.4.8+) Switches realistic vehicle denting on or off for every player on the server (like ToggleRagdollPhysics).
- LoadModule – Loads the native module Modules/name.dll (Windows) or Modules/name.so (Linux) and calls its SQLoad.
- GetTickCount – Millisecond counter.
- time / clock / date – time() is Unix seconds, clock() is processor seconds as a float, date() returns a table {sec, min, hour, day, month, year, wday, yday}; pass the chara...
Camera and audio (per player)
- SetCameraMatrix – Takes over the camera.
- RestoreCamera – Gives the camera back to the player.
- SetCinematicBorder – Shows or hides the widescreen letterbox bars on that player's screen (v0.2.0+).
- ShakeCamera – Shakes the camera.
- FadeCamera – Fades the screen.
- FindSound / PlayFrontEndTrack / StopFrontEndTrack – Plays .mp3 files from the server's Sounds/ folder on the server computer (Windows only).
Maths and strings
.tointeger(), .len(), .find(), .slice(); math (sqrt, sin, cos, rand, srand, abs, floor...); the blob/io libraries (file, dofile, blob). Paths are relative to the server folder.- Vector / Vector2D – Creates a Vector.
- Colour – Creates a Colour (default alpha 128).
- GetDistance – Straight-line distance between two Vectors.
- GetDistance2D – Distance ignoring height.
- GetTok – Returns token n (1-based) of the string split by separator, or tokens n to m joined by the separator.
- NumTok – Number of tokens.
- IsNum – True if the value is a number or a string that fully parses as one.
- isstring – Type tests.
- GetWeaponID / GetVehicleModel – (v0.3-r2+) Reverse of GetWeaponName / GetVehicleName: the weapon id (0-12, or 13-64 for the custom weapons of a <weapon> tag, by their name) or the ve...
- GetVehicleName / GetWeaponName / GetBodyPartName – Friendly names.
Constructors for helper objects
- NewTimer – See "Timers" in chapter 2.
- HashTable / FindHashTable – Named key/value store shared by all scripts.
- XmlDocument / XmlElement – XML reading/writing helpers (chapter 5).
- RegisterRemoteFunc / UnRegisterRemoteFunc – Allows or forbids a client to call this global function with CallServerFunc.
- GetRemoteCaller – Inside a function that a client started with CallServerFunc: the Player who made the call.
- CallClientFunc – Runs a global function in that player's client script.
Server dialogs (SA-MP style)
Since v0.2.3 the server can open modal dialog windows on a player's screen without any client script. They work like SA-MP's ShowPlayerDialog. On a PC client the dialog is drawn by the game itself with plain RenderWare rectangles and text (no images); on Android it appears as a normal Android dialog (colour tags are removed there). While a dialog is open the player cannot move or open the chat, and the mouse cursor is shown.
Styles
| Constant | Value | Body (`info`) and what the player sees |
|---|---|---|
DIALOG_STYLE_MSGBOX | 0 | Plain text. Wrapped automatically; \n starts a new line. |
DIALOG_STYLE_INPUT | 1 | Text with a one-line input box below it. The typed text arrives as inputtext (max 128 bytes). |
DIALOG_STYLE_LIST | 2 | One selectable row per line (\n separated). listitem is the chosen row, starting at 0. |
DIALOG_STYLE_PASSWORD | 3 | Like INPUT, but the typed characters are shown as *. |
DIALOG_STYLE_TABLIST | 4 | Rows with columns: separate the cells of a row with \t (a tab). Columns are aligned automatically. |
DIALOG_STYLE_TABLIST_HEADERS | 5 | Like TABLIST, but the first line holds the column headers; it is shown on top and is not selectable. |
Controls (PC): Enter = left button, ESC = right button (if there is one), Up/Down/PageUp/PageDown/Home/End and the mouse wheel move through a list, a double click on a row confirms it, the mouse clicks the buttons. Android: the list items and buttons are tapped.
dialogid must match), a list answer must point at a real row, and control characters are removed from inputtext. inputtext and listitem still come from the player, so validate them (length, range) before using them - for example never build file names or commands from it.- ShowPlayerDialog – Opens a dialog.
- HidePlayerDialog – Closes the dialog on the player's screen.
- GetPlayerDialogID – The id of the dialog that is currently open for the player, or -1.
Audio streams, object editor and object picker (v0.3)
Audio streams
Object editor and picker
| Constant | Value | Meaning |
|---|---|---|
EDIT_RESPONSE_CANCEL | 0 | The player cancelled; the object is unchanged. |
EDIT_RESPONSE_FINAL | 1 | The player saved: apply the values. |
EDIT_RESPONSE_UPDATE | 2 | Live update while dragging (about every 50 ms) - use it for a preview if you like. |
object.Scale (a Vector, default 1,1,1) stretches the object visually on every client. The collision keeps the model's original size.- PlayAudioStreamForPlayer – Plays a network audio stream for one player, like SA-MP. url must start with http:// or https:// and may be an .mp3 file, an internet radio stream (MP...
- StopAudioStreamForPlayer – Stops the stream.
- PlaySFX – (v0.5-rc2+) Plays one of the stock game sounds of audio/SFX.SDT for every player - or, with player.PlaySFX(...) (same arguments), for one player.
- EditObject – Opens the built-in 3D editor for one object on that player's screen (SA-MP EditObject / BeginObjectEditing; also player.EditObject(object)).
- SelectObject – Gives the player a mouse/touch cursor and markers on the nearby objects; the object he clicks arrives in onPlayerSelectObject.
Custom weather / time-of-day colours (timecyc.dat, v0.3-r2)
Put your own imecyc.dat into LU/data/timecyc.dat on the server. Every client downloads it with the other content and uses it instead of the game's own table (sky, ambient light, fog, clouds, sun for each hour and each weather); players leave it behind when they disconnect. Start from the original data/timecyc.dat of GTA III: the file must keep its layout (4 weathers x 24 hours = 96 data lines of 40 numbers, comment lines start with /). A file that does not have that shape is ignored by the clients. Use SetWeather / SetTime as usual to pick the line.
Ped clothing (v0.3.3)
Dress players piece by piece - only the T-shirt, the jacket, the trousers or the shoes - and recolour the hair or the skin. The clothes are plain image files (png, bmp or jpg) in the folder LU/clothes of the server; they are sent to the clients with the other content, so there is nothing to install. A custom skin model (see Script.xml <skin>) has one texture atlas; every image in LU/clothes is a wardrobe item named like the file (without extension), drawn on the same atlas layout. A "<texture name>_parts" image next to them marks which part of the atlas is hair (red), skin (yellow), upper body (green), legs (blue) and feet (magenta); the client paints a private copy of the atlas for every player from that and the wardrobe, so players never share a texture. Magenta (255, 0, 255) in a bmp/jpg and transparency in a png mean "show what is below" (jackets). See CLOTHING.md for how to make clothes and a mask for your own model, and tools\gen_demo_clothes.ps1.
| Constant | Value | Region painted |
|---|---|---|
CLOTH_HAIR | 0 | hair (tint recolours the model's own hair) |
CLOTH_SKIN | 1 | skin: head, hands, arms |
CLOTH_TORSO | 2 | upper body: shirt and sleeves |
CLOTH_JACKET | 3 | upper body, drawn over CLOTH_TORSO |
CLOTH_LEGS | 4 | trousers |
CLOTH_SHOES | 5 | feet |
CLOTH_ACCESSORY / CLOTH_EXTRA | 6 / 7 | two free regions (cyan / orange in the mask) |
function onPlayerSpawn(player, classid)
{
player.Skin = 200;
player.SetClothing(CLOTH_TORSO, "tshirt_hawaii");
player.SetClothing(CLOTH_LEGS, "pants_camo");
player.SetClothingColour(CLOTH_HAIR, 0xD8B45A); // blond
player.SetClothingColour(CLOTH_SKIN, 0x8D5524);
}- player.SetClothing – Wears the item (a file name of LU/clothes without its extension) in that slot.
- player.SetClothingColour – Tints a slot (also SetClothingColor).
- player.GetClothing / player.GetClothingColour – The item name or null / the tint as 0xRRGGBB or -1.
- player.ResetClothing – Back to the model's own look: one slot, or everything without an argument.
- GetClothingItems / ClothingExists – The names of all items the server found in LU/clothes (array) / whether one exists.
Graffiti (v0.5-beta, PC only)
Pictures from the folder LU/decals of the server (png, jpg, bmp or gif, transparency is kept) painted flat onto the world. A graffiti is a quad of width x height metres at a world position with an Euler rotation. It belongs to one virtual world, is drawn 1.5 cm off whatever is there, depth tested and within 150 m. It does not bend round corners. Nothing is configured in server.conf. An Android player does not draw graffiti (and answers the editor with a cancel).
Rotation uses the same convention as the vehicle decals: 0, 0, 0 lies flat facing up and the picture reads from the front, rx = 90 stands it up. For a wall that faces the direction (nx, ny) use ry = atan2(nx, -ny) in degrees.
local id = AddGraffiti("clanlogo", 100.0, -200.0, 15.0,
90, 0, 0, 2.0, 1.0); // 2 x 1 m, standing up
function onPlayerEditGraffiti(player, id, response, pos, rot, width, height)
{
if (response == 1) Message("graffiti " + id + " saved"); // 1 = saved
}- AddGraffiti – Paints the image (a file name of LU/decals, with or without extension).
- RemoveGraffiti / ClearGraffiti – Removes one graffiti (returns true if it existed) / all of them.
- SetGraffiti / SetGraffitiWorld – Moves, turns and resizes a graffiti for everybody / moves it to another virtual world.
- IsGraffiti / GetGraffitiCount – Whether the id is in use / how many graffiti exist.
- GetGraffiti – Everything about one graffiti as an array [image, x, y, z, rx, ry, rz, width, height, alpha, world], or null.
- EditGraffiti – Opens the 3D editor for that player (the same gizmo as EditObject: 1 moves, 2 rotates, 3 scales, Enter saves, Esc cancels).
Bots - virtual players (v0.5-beta)
A bot is a player that has no connection. To every client it is an ordinary remote player: it runs, strafes, sprints, jumps, switches weapons and shoots like a human. It lives in a player slot above max_players, so it never takes a slot a real player could use and scripts that loop over 0 .. GetMaxPlayers() never see it. It gives no join or leave event, no chat line and no radar blip, is not in the player count and is hidden from the TAB scoreboard.
z of CreateBot / BotTeleport) and cannot climb or fall. Keep bots on flat ground, or move them with BotTeleport.local bot = CreateBot("Guard", 0, 100.0, -200.0, 15.0, 90.0);
BotWeapon(bot, WEP_AK47, 500);
BotAimAt(bot, 110.0, -200.0, 16.0);
BotKeys(bot, BOT_AIM | BOT_FIRE); // stands there and shoots at the point
function onBotDeath(bot, killer) { DestroyBot(bot); }- CreateBot – Creates a bot.
- DestroyBot / IsBot – Removes a bot / whether this Player handle is a bot.
- BotKeys – Sets what the bot is "holding down": add the BOT_* constants (appendix A.13), for example BOT_FORWARD | BOT_SPRINT. 0 stops it.
- BotAngle / BotTeleport – Turns the bot / puts it somewhere else (this also sets the height of the plane it walks on).
- BotWeapon – Gives the bot a weapon (WEP_*) and ammo and makes it the weapon it holds.
- BotAimAt – The bot looks at - and shoots at, while BOT_FIRE is held - that point.
- BotDamage – Hurts a bot (armour first).