Scripting/Client
Contents
Client scripts are the .nut files marked client="1" in Script.xml. Each player's game downloads and runs them in its own sandbox when they join. They draw the interface, react to the keyboard and mouse, and talk to your server scripts with CallServerFunc / CallClientFunc.
- A client script cannot read or write files or use the network. Only the
stringandmathlibraries exist. - Entity properties are read-only except for a few settings on the local player and vehicles (listed below).
- Everything on the client can be tampered with: use it for presentation, never for rules.
- If a client script errors, that handler stops; the rest of the game keeps running.
- The values
ScreenWidthandScreenHeightare global integers that always hold the current game window size (updated on resize).
Client events
TipFinding model ids of a converted map (San Andreas, Vice City, Upstate ...): type
/debuglog on and shoot things - every hit shows [objshot] building 1205 "ind_customroad003" pos ... rot ... in the chat, and on PC the same lines are added to lu_objshot.log next to gta3.exe. /debuglog off stops it. (The PS3 has no /debuglog: use the event.)- onScriptLoad – All client scripts finished downloading and ran.
- onScriptUnload – The client is disconnecting or reloading.
- onClientSpawn – The local player spawned.
- onClientRender – Every frame.
- onClientCommand – The player typed a /command that the built-in chat does not know.
- onClientMouseMove – The mouse cursor moved.
- onClientMouseClick – button is KEY_MOUSE_LEFT (216), KEY_MOUSE_MIDDLE (217) or KEY_MOUSE_RIGHT (218); down is true on press and false on release.
- onClientMouseWheel – true when scrolling up/away.
- onClientKeyStateChange – The controls of the local player changed.
- onGameWindowResize – The window size settled (resize drag ended, Alt+Enter).
- onObjectShot – (0.6) A bullet of the local player hit a building, a map object or an object: the game's own map, the server's IPL maps and CreateObject objects (not ...
Messages and chat
- Message – Adds a local chat line (nobody else sees it).
- SmallMessage – Small bottom-of-screen game message (default 5000 ms).
- BigMessage – Big on-screen message; style 0-5 (default 2).
- HelpMessage – (0.6) The help box of the game (the one cheat codes and game hints use).
- ClearMessages – Clears big/small messages.
- ConsoleMessage – Prints a line to the client's script output (for debugging; not shown in chat).
Looking up entities
NoteThe client only knows about players, vehicles, objects and pickups the server has streamed to it. To list the connected players loop
FindPlayer(0 .. MAX_PLAYERS-1) and skip nulls.- FindLocalPlayer – The Player handle for yourself.
- FindPlayer – Player handle for any connected player including yourself, or null.
- FindVehicle – Vehicle handle for a vehicle that is currently streamed to you.
- FindObject / FindPickup / FindSphere – Handle or null.
- GetTickCount – Millisecond counter.
- IncludeScript – Runs a client script of the caller's own script folder, for example IncludeScript("lazy/shop.nut").
Input
- BindKey – Calls callback when the key goes down (BINDTYPE_DOWN) or up (BINDTYPE_UP).
- UnbindKey – Removes the bind(s).
- GetKeyStatus / GetKeyState – True while the key is currently held.
- ShowMouseCursor / IsMouseCursorShowing – Shows a script cursor.
- GetMouseCursorPos – Table {x=, y=} in screen pixels.
- SetMouseCursorPos – Moves the cursor (and the real pointer; v0.2.4+).
- SetDriveBy / IsDriveBy / IsDriveByActive – v0.2.4+: the native drive-by (server player.DriveBy).
- ToggleCameraMovement – false locks player and camera input (use it while a menu is open); true unlocks.
- ToggleMouseMovement – (v0.2.9-r2+) false stops the mouse from turning the camera or aiming while everything else (walking, buttons, the GUI cursor) keeps working.
- ToggleWaterShader – (v0.4.3) Realistic water: a real-time planar reflection of the scene on the sea (buildings, sky and cars mirrored in the water), distorted by animated...
- ToggleDynamicShadows – (v0.4.5) Dynamic shadows: peds, vehicles, objects and the buildings around (street lamps, signs, bins, houses, trees) cast a real shadow of their actu...
- ToggleBulletHoles – (v0.4.4) Bullet holes: every shot that hits something leaves a mark - dark holes on walls, ground, objects and vehicles (cracks in glass), blood on pe...
- SetCameraFov – (v0.4.4) Sets the camera field of view in degrees and moves there smoothly: it blends from the current value to fov over ms milliseconds (default 250,...
- GetCameraFov – (v0.4.4) The field of view in use right now, in degrees (the game default is about 70 on foot; it moves while a SetCameraFov blend runs).
- SetPlayerBlipStyle – (v0.5-beta+) The client version of the server function: BLIPSTYLE_DEFAULT (0), BLIPSTYLE_IMPROVED (1) or BLIPSTYLE_CENTRE (2, tinted radar_centre arro...
- ToggleImprovedPlayerBlips – (v0.3.3+) The same switch as the server function, for this client only: the radar blips of the other players become GTA V style circles with a chevron...
Screen, world and camera
- GetScreenWidth / GetScreenHeight – Current render size in pixels.
- WorldPosToScreen – Returns {x, y, z} where x/y are screen pixels and z is a scale factor (handy for sizing labels by distance), or null if the point is behind the camera...
- ScreenPosToWorld – Two arguments: the world point on the ground plane (z = 0) under a screen pixel as {x, y, z}, or null for sky.
- GetGroundZLevel – Ground height under the local player.
- GetGroundZLevelForPos – Ground height at that x/y (z is a search-start hint).
- GetGroundZLevelForPosLoad – v0.4-beta+: like GetGroundZLevelForPos, but when the place is not streamed in (far away, another island) it is loaded first, so the real ground height...
- Draw3DText – Draws a label in the world on the frame you call it - call it every frame from onClientRender.
- Draw3DSprite – Same for an image downloaded with <sprite>. Max 512 per frame.
- Draw3DTextWorld – v0.4+ (PC and Android): text as a real quad in the 3D world - it has a position, a rotation and a size in metres, is hidden by walls and cars (depth t...
- Draw3DSpriteWorld – v0.4+ (PC and Android): an image downloaded with <sprite> as a real quad in the 3D world, same rotation rules as Draw3DTextWorld.
- SetCameraMatrix – Fixed scripted camera at position looking at lookAt.
- SetCameraTarget – Points the game camera at a Player or Vehicle handle.
- RestoreCamera – Gives the camera back to the game.
- GetCameraAngle – The heading in degrees (the same convention as Player.Angle: forward is (-sin a, cos a)) the active game camera looks along - lets a script move the p...
- SetFollowCamera – true = keep the normal follow-the-ped camera (mouse look) although the engine would switch to its fixed falling camera - used while swimming.
- ShakeCamera – Shakes the camera.
- FadeCamera – fadeIn is an integer: 1 (default) fades the screen in, 0 fades out.
- SwapBuildingModel – Replaces every map building of model1 within radius with model2 (call again with the models reversed to swap back).
- IsLineOfSightClear – False if a building/vehicle/ped blocks the line.
- ProcessLineOfSight – Ray cast.
- SetNametagDrawDistance – Distance at which player nametags are shown (0-500 metres).
- SetHUDEnabled / GetHUDEnabled – Hide/show the whole HUD.
- SetHUDItemEnabled / GetHUDItemEnabled – item is HUD_ARMOUR HUD_CLOCK HUD_HEALTH HUD_MONEY HUD_RADAR HUD_WANTED HUD_WEAPON.
- GetRadarRect – (0.6) Where the radar is on the screen, in pixels: a table with x, y, w, h (the square around the round radar, or the GTA V rectangle of ToggleModernH...
- ToggleModernHUD – (0.6) true turns the radar into a GTA V style rectangle at the bottom left (on Android where the touch layout puts the radar) with a green health bar ...
Sound
- FindSound – Returns a Sound for a file the server declared with <sound> (stored on the player's machine), or null.
- sound.Open – Transport controls.
- sound.SetVolume / sound.Volume – Volume percentage (read and write).
- PlayFrontEndTrack / StopFrontEndTrack – Plays one background track (a new call replaces the old one).
- PlayFrontEndSound – Plays a GTA III frontend sound locally.
- PlaySuspectLastSeen – Police-radio "suspect last seen" from your position.
Utility
- Vector – Class with fields x y z.
- Colour – Class with fields r g b a (0-255).
- VectorScreen / ScreenSize / Vector2D – Two-number classes used for GUI positions and sizes (.x, .y).
- GetDistance – 3D distance.
- GetTok / NumTok / IsNum – Same as the server versions.
- IsIn – True if the array contains the value.
- InPoly – Point-in-polygon test.
- GetTime / GetFullTime – GetTime() is the local clock in seconds since 1970 (a number, for arithmetic); GetFullTime() is the local date and time as text, "YYYY-MM-DD HH:MM:SS"...
- date – Table {sec, min, hour, day, month, year, wday, yday}.
- GetVehicleModel / GetWeaponID – (v0.3-r2+) Same as on the server: the vehicle model or the weapon id (0-12) from a name, -1 if unknown.
- GetVehicleName / GetVehicleIDFromName / GetWeaponName – Names; GetVehicleIDFromName returns -1 if unknown.
- NewTimer – As on the server (0 = forever).
- HashTable / FindHashTable – Named in-memory key/value store, same methods as the server.
- SyncPlayerSkins – Enable/disable receiving other players' custom skins.
- CallServerFunc – Calls a server function that was whitelisted with RegisterRemoteFunc.
Categories: Client scripting