Scripting/Server/Functions

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

Finding and counting entities

NoteThere is no function that returns all players as an array. Loop the ids and test with FindPlayer(i):
for (local i = 0; i < GetMaxPlayers(); i++)
{
    local p = FindPlayer(i);
    if (p) MessagePlayer("Hello " + p.Name, p);
}

Creating world entities

World settings

Server information and administration

Camera and audio (per player)

Maths and strings

NoteSquirrel's own library is also available: string functions such as .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.

Constructors for helper objects

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

ConstantValueBody (`info`) and what the player sees
DIALOG_STYLE_MSGBOX0Plain text. Wrapped automatically; \n starts a new line.
DIALOG_STYLE_INPUT1Text with a one-line input box below it. The typed text arrives as inputtext (max 128 bytes).
DIALOG_STYLE_LIST2One selectable row per line (\n separated). listitem is the chosen row, starting at 0.
DIALOG_STYLE_PASSWORD3Like INPUT, but the typed characters are shown as *.
DIALOG_STYLE_TABLIST4Rows with columns: separate the cells of a row with \t (a tab). Columns are aligned automatically.
DIALOG_STYLE_TABLIST_HEADERS5Like 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.

NoteSafety: the server only accepts an answer for the dialog it actually opened (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.

Audio streams, object editor and object picker (v0.3)

Audio streams

Object editor and picker

ConstantValueMeaning
EDIT_RESPONSE_CANCEL0The player cancelled; the object is unchanged.
EDIT_RESPONSE_FINAL1The player saved: apply the values.
EDIT_RESPONSE_UPDATE2Live update while dragging (about every 50 ms) - use it for a preview if you like.
Noteobject.Scale (a Vector, default 1,1,1) stretches the object visually on every client. The collision keeps the model's original size.

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.

ConstantValueRegion painted
CLOTH_HAIR0hair (tint recolours the model's own hair)
CLOTH_SKIN1skin: head, hands, arms
CLOTH_TORSO2upper body: shirt and sleeves
CLOTH_JACKET3upper body, drawn over CLOTH_TORSO
CLOTH_LEGS4trousers
CLOTH_SHOES5feet
CLOTH_ACCESSORY / CLOTH_EXTRA6 / 7two 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);
}

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
}

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.

NoteThe server has no physics. A bot walks on a flat plane at the height it was created or teleported to (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); }
Categories: Server functions