Skip to main content

JC4MP scripting reference

JC4MP servers run Lua resources: gamemodes, menus, UIs and tools. Each resource can have server scripts, client scripts and shared scripts, and players download the client and shared parts when they join. This reference covers everything a resource can use: the Lua API on both sides, every event, every enum, the JavaScript bridge for web UIs, and lists of the game names scripts pass in (vehicles, weapons, skins, NPCs, effects and more).

Scripts run on LuaJIT (Lua 5.1 syntax). The reference is grouped by where the API runs:

  • Shared: available to both server and client scripts, plus the concepts that apply to both
  • Server: only available to server scripts
  • Client: only available to client scripts

Many types have a page on each side: the shared page explains the type and its common methods, and the server and client pages add what only that side can do.

New to JC4MP scripting? Start with Getting started, then read Resources and Net. Porting resources written for the old JC4MP API? See Porting.

Shared​

PageWhat it covers
ResourcesFolder layout, client/server/shared, lifecycle, require, downloads, the Resources table
SandboxWhich Lua libraries and globals exist on each side, limits, error reporting
EventsEvent.Add, Event.Remove, Event.Fire, Event.Cancel and how dispatch works
NetHow messages between client and server scripts work, Net.AddEvent, what values can be sent
TimerDelayed and repeating callbacks
HashHash, the game's 32-bit hash of a name
JSONParsing and writing JSON
Math typesvec2, vec3, vec4, quat, mat4, AABB
WorldHandles, streaming, ownership, what is synced, finding objects
WeatherHow weather sync works, sandstorms
ObjectHandleMethods every networked object has, casting to typed handles
PlayerPlayerHandle (the connection) and PlayerObjectHandle (the character)
PlayersFinding players
VehicleHandleVehicle id, paint, dirt and parts
MountedGunHandleMounted guns
RigidObjectHandlePhysics props
NPCHandleNPCs and how they are driven
TetherHandleGrappling tethers
SandstormHandleSandstorms
EnumsIndex of every enum table on both sides

Shared enums: AclLevel, Key, NetObjectType, MoveType, MoveStyle, LookType, POIType, POIDisplayMode, Resource, ResourceAction, ResourceStatus, RigidObjectMotionType, VehiclePart, VehiclePartState, VehicleSeat, VehicleType, WeaponSlot, WeaponMode, AmmoType, WeatherAct, WeatherProperty, TornadoState.

Server​

PageWhat it covers
Server eventsEvery event fired on the server
ResourcesStarting, stopping and restarting resources, startup configuration
NetSending messages to players, Net.Sender
HTTPNet.Fetch web requests
SQLThe server's SQLite database
ServerServer information
ChatChat messages
Server consoleConsole commands
WorldSpawning and destroying objects, explosions
WeatherSyncing tornadoes, clouds and weather properties
ObjectHandleMoving objects, setting health, velocity and data
PlayerKicking, banning, permissions, skins, weapons, animations, teleporting
VehicleHandlePaint, locking, parts and drones
RigidObjectHandleMotion type and collision
NPCHandleNPC orders: move, follow, aim, fire, throw grenades, melee

Client​

PageWhat it covers
Client eventsEvery event fired on the client
NetSending messages to the server
CommandsConsole commands (Cmd)
WorldTime, gravity, waypoints, water and client-side objects
WeatherLightning
ObjectHandleClient-side data
PlayerCharacter state, bones, effects and appearance
PlayersThe local player and name tags
VehicleHandleClient-only vehicle methods
RigidObjectHandleBounding boxes
NPCHandleBounding boxes
LocalThe local player
ClientClient version, uptime and network statistics
GameGame state
Game objectsClient-side objects: POIs, water boxes, force pulses, effects and their base types
InputKeyboard, mouse, game input and the clipboard
CameraCamera position, direction and shakes
RenderScreen size and debug drawing
FXPlaying particle effects
SoundPlaying sounds and controlling channels
PhysicsRaycasts
TerrainTerrain information and vegetation shockwaves
NavMeshNavigation mesh queries
RoadGraphRoads, sea and air routes, paths and railways
WeaponThe weapon a player holds
GameUIThe game's own HUD
AssetChecking whether game assets are loaded
UI and WebViewWeb UIs from Lua: creating, showing and messaging webviews
WebView pages (JavaScript)The JC4MP bridge inside a webview page

Client enums: Ability, Action, InputAction, Bone, CameraShakeType, CharacterAttachedEffect, ForcePulseCategory, ForcePulseTuning, GameState, PfxLayer, RoadGraphType, WaterBoxStyle.

Game name lists​

Names that scripts pass to spawn and play functions. See the lists index.

PageUsed by
VehiclesWorld.SpawnVehicle
Mounted gunsWorld.SpawnMountedGun
WeaponsGiveWeapon
SkinsSetSkin
NPCsWorld.SpawnNPC
AnimationsPlayAnimation
EffectsFX.Spawn
ExplosionsWorld.SpawnExplosion
Rigid objectsWorld.SpawnRigidObject
SoundsSound