### Example Usage of NPC_StartPlayback Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/NPC_StartPlayback.md This example demonstrates how to use NPC_StartPlayback within a command handler to start playing a recording for an NPC. It includes checks for valid NPC and recording name, retrieves the NPC's current position for starting playback, and provides feedback on success or failure. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/startplayback ", true, 15)) { new npcid = PlayerNPC[playerid]; if (npcid == INVALID_NPC_ID) return SendClientMessage(playerid, 0xFF0000FF, "You are not debugging a NPC."); if (!NPC_IsValid(npcid)) return SendClientMessage(playerid, 0xFF0000FF, "Invalid NPC."); new recordName[64]; new len = strlen(cmdtext); if (len <= 15) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /startplayback [recordname]"); strmid(recordName, cmdtext, 15, len); new Float:x, Float:y, Float:z; NPC_GetPos(npcid, x, y, z); new bool:success = NPC_StartPlayback(npcid, recordName, true, x, y, z, 0.0, 0.0, 0.0); if (success) SendClientMessage(playerid, 0x00FF00FF, "NPC %d started playback: %s", npcid, recordName); else SendClientMessage(playerid, 0xFF0000FF, "Failed to start playback for NPC %d", npcid); return 1; } return 0; } ``` -------------------------------- ### Start Recording Playback Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/StartRecordingPlayback.md This example demonstrates how to start playing back a recorded NPC action file when an NPC enters a vehicle. The function takes the playback type and the record name as arguments. ```c public OnNPCEnterVehicle(vehicleid, seatid) { StartRecordingPlayback(PLAYER_RECORDING_TYPE_DRIVER, "at400_lv_to_sf_x1"); } ``` -------------------------------- ### Show Menu for Player Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/ShowMenuForPlayer.md This example demonstrates how to create a menu and then display it to a player when they use a specific command. Ensure the menu is created before attempting to show it. ```c new Menu:exampleMenu; public OnGameModeInit() { exampleMenu = CreateMenu("Example Menu", 2, 200.0, 100.0, 150.0, 150.0); return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { if (strcmp(cmdtext, "/menu", true) == 0) { ShowMenuForPlayer(exampleMenu, playerid); return 1; } return 0; } ``` -------------------------------- ### Get Player Pickup Model Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetPlayerPickupModel.md This example demonstrates how to create a player-pickup and then retrieve its model ID using GetPlayerPickupModel. Ensure CreatePlayerPickup is called before attempting to get the model. ```c new PlayerPickup[MAX_PLAYERS]; public OnPlayerConnect(playerid) { PlayerPickup[playerid] = CreatePlayerPickup(playerid, 1239, 1, 2010.0979, 1222.0642, 10.8206, -1); new model = GetPlayerPickupModel(playerid, PlayerPickup[playerid]); // model = 1239 return 1; } ``` -------------------------------- ### Get Weapon Slot Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetWeaponSlot.md This example demonstrates how to get the weapon ID the player is currently holding, then use GetWeaponSlot to find its corresponding slot, and finally inform the player of the slot number. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (strcmp(cmdtext, "/weaponslot", true) == 0) { new WEAPON:weaponid = GetPlayerWeapon(playerid); // will store the id of the weapon the player is currently holding new WEAPON_SLOT:slot = GetWeaponSlot(weaponid); // will store the id of the weapon slot SendClientMessage(playerid, -1, "Your weapon is occupying the slot %d.", slot); // sends a formatted message to the player return 1; } return 0; } ``` -------------------------------- ### Show Pickup for Player Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/ShowPickupForPlayer.md This example demonstrates how to create a pickup and then show it to a player when they spawn. Ensure the pickup is created before attempting to show it to players. ```c new g_Pickup; public OnGameModeInit() { g_Pickup = CreatePickup(1239, 1, 1686.6160, 1455.4277, 10.7705, -1); return 1; } public OnPlayerSpawn(playerid) { ShowPickupForPlayer(playerid, g_Pickup); return 1; } ``` -------------------------------- ### Get Actor Health Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetActorHealth.md This example demonstrates how to create an actor, set its health, retrieve its health using GetActorHealth, and then print the retrieved health value. Ensure the actor is created before attempting to get its health. ```c new gMyActor; public OnGameModeInit() { gMyActor = CreateActor(179, 316.1, -134.0, 999.6, 90.0); // Actor as salesperson in Ammunation SetActorHealth(gMyActor, 100.0); new Float:actorHealth; GetActorHealth(gMyActor, actorHealth); printf("Actor ID %d has %.2f health.", gMyActor, actorHealth); return 1; } ``` -------------------------------- ### Get NPC Health Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/NPC_GetHealth.md This example demonstrates how to get an NPC's health using NPC_GetHealth within a player command. It includes checks for valid NPC debugging and NPC existence before retrieving and displaying the health. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/checkhealth", true)) { new npcid = PlayerNPC[playerid]; if (npcid == INVALID_NPC_ID) return SendClientMessage(playerid, 0xFF0000FF, "You are not debugging a NPC."); if (!NPC_IsValid(npcid)) return SendClientMessage(playerid, 0xFF0000FF, "Invalid NPC."); new Float:health = NPC_GetHealth(npcid); SendClientMessage(playerid, 0x00FF00FF, "NPC %d health: %.2f", npcid, health); return 1; } return 0; } ``` -------------------------------- ### Start Development API Server Source: https://github.com/openmultiplayer/web/blob/master/README.md Use Taskfile to build and run the API server for backend development. Assumes execution from the repository root. ```bash task ``` -------------------------------- ### API Module Structure Example Source: https://github.com/openmultiplayer/web/blob/master/app/README.md Illustrates the typical file organization for an API module within the project. Each module has an 'api.go' file for setup and handler files prefixed with 'h_' followed by a description or HTTP method. ```tree api/ ├module1/ │ ├api.go │ ├h_get.go │ └h_post.go └module2/ ├api.go ├h_get.go ├h_post.go └h_search.go ``` -------------------------------- ### Get NPC Position Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/NPC_GetPos.md This example demonstrates how to get an NPC's position using NPC_GetPos within a player command. It first checks if the player is debugging an NPC and if the NPC is valid before calling NPC_GetPos and displaying the coordinates. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/checkpos", true)) { new npcid = PlayerNPC[playerid]; if (npcid == INVALID_NPC_ID) return SendClientMessage(playerid, 0xFF0000FF, "You are not debugging a NPC."); if (!NPC_IsValid(npcid)) return SendClientMessage(playerid, 0xFF0000FF, "Invalid NPC."); new Float:x, Float:y, Float:z; NPC_GetPos(npcid, x, y, z); SendClientMessage(playerid, 0x00FF00FF, "NPC %d position: %.2f, %.2f, %.2f", npcid, x, y, z); return 1; } return 0; } ``` -------------------------------- ### GetVehicleSeats Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetVehicleSeats.md This example demonstrates how to get the number of seats for the vehicle a player is currently in. It first retrieves the player's vehicle ID, then the vehicle's model ID, and finally uses GetVehicleSeats to get the seat count. The result is then formatted into a string and sent to the player. ```c new vehicleid = GetPlayerVehicleID(playerid); new modelid = GetVehicleModel(vehicleid); new seats = GetVehicleSeats(modelid); new string[64]; format(string, sizeof(string), "Number of seats in this vehicle: %d", seats); SendClientMessage(playerid, -1, string); ``` -------------------------------- ### 'Hello world' in Pawn (C-style syntax) Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/language/reference/02-A-tutorial-introduction.md This example shows a more C-like syntax for Pawn, including include directives, braces, and semicolons. This style is also valid and functionally equivalent to the basic version. ```pawn #include main() { printf("Hello world\n"); } ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/openmultiplayer/web/blob/master/frontend/README.md Run this command to install all necessary project dependencies. ```bash $ npm i ``` -------------------------------- ### HTTP Function Usage Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/HTTP.md Provides a practical example of how to use the HTTP function to send a GET request and handle the response in a callback function. ```APIDOC ## Example Usage ```c forward MyHttpResponse(index, response_code, data[]); public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp("/hello", cmdtext, true)) { HTTP(playerid, HTTP_GET, "assets.open.mp/hello.txt", "", "MyHttpResponse"); return 1; } return 0; } public MyHttpResponse(index, response_code, data[]) { // In this callback "index" would normally be called "playerid" ( if you didn't get it already ) new buffer[128]; if (response_code == 200) // Did the request succeed? { // Yes! format(buffer, sizeof(buffer), "The URL replied: %s", data); SendClientMessage(index, 0xFFFFFFFF, buffer); } else { // No! format(buffer, sizeof(buffer), "The request failed! The response code was: %d", response_code); SendClientMessage(index, 0xFF0000FF, buffer); } } ``` ``` -------------------------------- ### Basic "Hello World" Script Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/resources/start.md This is a minimal script that prints "Hello World!" to the server console. It requires the a_samp include for basic functionality. ```c #include main() { print("Hello World!"); return 1; } ``` -------------------------------- ### Get Vehicle Driver Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetVehicleDriver.md This example demonstrates how to use GetVehicleDriver within an OnPlayerExitVehicle callback. It checks if a driver exists and sends a message to the driver if they do. ```c public OnPlayerExitVehicle(playerid, vehicleid) { new driverid = GetVehicleDriver(vehicleid); if (driverid != INVALID_PLAYER_ID) { SendClientMessage(driverid, -1, "Someone is exiting your vehicle."); } return 1; } ``` -------------------------------- ### Running the backend Source: https://context7.com/openmultiplayer/web/llms.txt Starts development dependencies using Docker Compose. Builds and runs the Go API server using 'task' (which uses Taskfile.yml). Use 'docker-compose up' for the full production stack. ```bash # Start development dependencies (database, etc.) docker-compose -f docker-compose.dev.yml up -d # Build and run the Go API server (from repo root) task # uses Taskfile.yml, default task = build + run # Run full production stack docker-compose up ``` -------------------------------- ### Sample Launch Command for open.mp Launcher Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/client/ClientOnLinux.md Use this command to launch the open.mp launcher with specified server details and game path within a Wine prefix. Ensure paths are correct for your Wine prefix. ```bash Z:\path\to\omp-launcher.exe -h server.ip -p port -n user.name -g Z:\home\yourname\path\to\gta-san-andreas\install\ ``` -------------------------------- ### Get Vehicle Occupied Tick Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetVehicleOccupiedTick.md This example demonstrates how to create a vehicle and then retrieve its occupied tick using GetVehicleOccupiedTick. The occupied tick is then printed to the console. ```c public OnGameModeInit() { new vehicleid = CreateVehicle(560, 2096.1917, -1328.5150, 25.1059, 0.0000, 1, 8, 60); new occupiedTick = GetVehicleOccupiedTick(vehicleid); printf("Vehicle ID %d occupied tick: %d ms", vehicleid, occupiedTick); return 1; } ``` -------------------------------- ### GetVehicleModelsUsed Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetVehicleModelsUsed.md This example demonstrates how to use GetVehicleModelsUsed within the OnGameModeInit callback to log the number of vehicle models currently in use when the game mode starts. ```c public OnGameModeInit() { printf("Used vehicle models: %d", GetVehicleModelsUsed()); } ``` -------------------------------- ### Compiling a PAWN file Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/language/reference/13-Appendices.md Example of compiling a 'hello world' script named 'hello.pawn' using the PAWN compiler. Ensure the compiler is in your system's search path. ```bash pawncc hello ``` -------------------------------- ### Database Connection and Initialization Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/db_num_rows.md This example shows how to initialize a database connection in the OnGameModeInit function and close it in OnGameModeExit. It includes basic error handling for opening and closing the connection and calls a function to process query results. ```c // mode.pwn // ... #include static DB:gDBConnectionHandle; // ... public OnGameModeInit() { // ... // Create a connection to a database gDBConnectionHandle = db_open("example.db"); // If connection to the database exists if (gDBConnectionHandle) { // Successfully created a connection to the database print("Successfully created a connection to database \"example.db\"."); Examples_ListNames(gDBConnectionHandle); } else { // Failed to create a connection to the database print("Failed to open a connection to database \"example.db\"."); } // ... return 1; } public OnGameModeExit() { // Close the connection to the database if connection is open if (db_close(gDBConnectionHandle)) { // Extra cleanup gDBConnectionHandle = DB:0; } // ... return 1; } ``` -------------------------------- ### Get Player Facing Angle Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetPlayerFacingAngle.md This snippet demonstrates how to get a player's facing angle and display it to them. Ensure the player ID is valid before calling the function. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/angle", true)) { new string[64]; new Float:angle; GetPlayerFacingAngle(playerid, angle); format(string, sizeof(string), "Your facing angle: %0.2f", angle); SendClientMessage(playerid, 0xFFFFFFFF, string); return 1; } return 0; } ``` -------------------------------- ### ShowVehicle Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/ShowVehicle.md This example demonstrates how to use ShowVehicle. It first creates and hides a vehicle, then shows it when a player uses the /showvehicle command. Ensure the vehicle is hidden before attempting to show it. ```c new g_Vehicle; public OnGameModeInit() { g_Vehicle = CreateVehicle(536, 2496.5034, 5.6658, 27.2247, 180.0000, -1, -1, 60); HideVehicle(g_Vehicle); return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/showvehicle", true)) { if (IsVehicleHidden(g_Vehicle)) { ShowVehicle(g_Vehicle); } return 1; } return 0; } ``` -------------------------------- ### Example Usage of NPC_GetNodeType Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/NPC_CloseNode.md This example demonstrates how to get the type of a node using NPC_GetNodeType within a player command handler. It includes input validation for the node ID. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/checknodetype ", true, 15)) { new nodeid = strval(cmdtext[15]); if (nodeid < 0 || nodeid > 63) return SendClientMessage(playerid, 0xFF0000FF, "Invalid node ID. Must be between 0 and 63."); new nodetype = NPC_GetNodeType(nodeid); SendClientMessage(playerid, 0x00FF00FF, "Node %d type: %d", nodeid, nodetype); return 1; } return 0; } ``` -------------------------------- ### Get Server Hostname Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetServerVarAsString.md This example demonstrates how to retrieve the server's hostname using GetServerVarAsString and print it to the console. Ensure the 'hostname' variable exists on the server. ```c public OnGameModeInit() { new hostname[64]; GetServerVarAsString("hostname", hostname, sizeof(hostname)); printf("Hostname: %s", hostname); } ``` -------------------------------- ### BeginPlayerObjectEditing Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/BeginPlayerObjectEditing.md This example demonstrates how to use BeginPlayerObjectEditing to allow a player to edit an object they created. It hooks into player spawn to create an object and player command text to trigger the editing mode. ```c new gPlayerObject[MAX_PLAYERS]; public OnPlayerSpawn(playerid) { gPlayerObject[playerid] = CreatePlayerObject(playerid, 1337, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); } public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/edit", true)) { BeginPlayerObjectEditing(playerid, gPlayerObject[playerid]); SendClientMessage(playerid, 0xFFFFFFFF, "SERVER: You now edit your object!"); return 1; } return 0; } ``` -------------------------------- ### GetMaxPlayers Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetMaxPlayers.md This example demonstrates how to use GetMaxPlayers to get the server's player limit and display it to a player. Ensure the server's 'max_players' is set in config.json. ```c new string[128]; format(string, sizeof(string), "There are %i slots on this server!", GetMaxPlayers()); SendClientMessage(playerid, 0xFFFFFFFF, string); ``` -------------------------------- ### Launcher Release Markdown Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/content/releases/README.md Example frontmatter and markdown structure for a launcher release. Verify tag, URLs, and asset details for accuracy. ```markdown --- tag: v1.6.2 publishedAt: "2026-02-14T12:00:00Z" htmlUrl: https://github.com/openmultiplayer/launcher/releases/tag/v1.6.2 highlights: - Better stability - Better favorites management admonition: type: warning title: Antivirus false positive body: "Example warning text." assets: - label: "Download Launcher (.exe)" url: https://github.com/openmultiplayer/launcher/releases/download/v1.6.2/omp-launcher-setup.exe size: "5.2 MB" --- ## What's Changed ... ``` -------------------------------- ### Get Console Variable as Float Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetConsoleVarAsFloat.md This example demonstrates how to retrieve the integer value of a console variable using GetConsoleVarAsInt. Note that the function name in the example does not match the page title, suggesting a potential discrepancy or a related function usage. ```c new Float:radius = GetConsoleVarAsInt("game.nametag_draw_radius"); printf("Nametag Draw Radius: %i", radius); ``` -------------------------------- ### Print "Hello World" in Greek Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/language/reference/12-Assorted-tips.md Demonstrates how to print a string in Greek characters using the PAWN language. Ensure your environment supports Greek character display. ```c main() printf "Γειάσου κόσμος\n" ``` -------------------------------- ### Get and Set World Time Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetWorldTime.md Use SetWorldTime to change the world time and GetWorldTime to retrieve it. This example demonstrates setting the time to 12 and then printing the current time. ```c SetWorldTime(12); printf("Current world time: %d", GetWorldTime()); // The output will be 'Current world time: 12' ``` -------------------------------- ### Get Pickup Virtual World Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetPickupVirtualWorld.md This example demonstrates how to create a pickup and then retrieve its virtual world ID using GetPickupVirtualWorld. Ensure a pickup is created before calling this function. ```c new g_Pickup; public OnGameModeInit() { g_Pickup = CreatePickup(1239, 1, 1686.6160, 1455.4277, 10.7705, 20); new worldid = GetPickupVirtualWorld(g_Pickup); // worldid = 20 return 1; } ``` -------------------------------- ### Initialize Database Connection and Calculate Sum Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/DB_GetFieldInt.md This example shows how to initialize a database connection, call a function to calculate the sum of an integer field, and handle potential connection errors. It also demonstrates closing the database connection when the game mode exits. Ensure that the database file exists and is accessible. ```c // mode.pwn // ... #include static DB:gDBConnectionHandle; // ... public OnGameModeInit() { // ... // Create a connection to a database gDBConnectionHandle = DB_Open("example.db"); // If connection to the database exists if (gDBConnectionHandle) { // Successfully created a connection to the database print("Successfully created a connection to database \"example.db\"."); printf("Calculated sum: %d", Examples_CalculateSum(gDBConnectionHandle)); } else { // Failed to create a connection to the database print("Failed to open a connection to database \"example.db\"."); } // ... return 1; } public OnGameModeExit() { // Close the connection to the database if connection is open if (DB_Close(gDBConnectionHandle)) { // Extra cleanup gDBConnectionHandle = DB:0; } // ... return 1; } ``` -------------------------------- ### Database Connection and Query Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/db_free_result.md This snippet shows the initialization of a database connection using db_open, followed by calling a function that utilizes db_query and db_free_result. It also includes handling the connection closing in OnGameModeExit. ```c // mode.pwn #include static DB:gDBConnectionHandle; // ... public OnGameModeInit() { // ... // Create a connection to a database gDBConnectionHandle = db_open("example.db"); // If connection to the database exists if (gDBConnectionHandle) { // Successfully created a connection to the database print("Successfully created a connection to database \"example.db\"."); EntityStorage_SpawnAll(gDBConnectionHandle); } else { // Failed to create a connection to the database print("Failed to open a connection to database \"example.db\"."); } // ... return 1; } public OnGameModeExit() { // Close the connection to the database if connection is open if (db_close(gDBConnectionHandle)) { // Extra cleanup gDBConnectionHandle = DB:0; } // ... return 1; } ``` -------------------------------- ### Get Function ID using funcidx Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/funcidx.md Use funcidx to find the ID of a function by its name. This example demonstrates how to get the ID of 'OnFilterScriptInit' and print it. Returns -1 if the function does not exist. ```c public OnFilterScriptInit() { printf("ID of OnFilterScriptInit: %d", funcidx("OnFilterScriptInit")); return 1; } ``` -------------------------------- ### SendClientMessageToAllf Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/SendClientMessageToAllf.md This example demonstrates how to use SendClientMessageToAllf to send a formatted "Hello World" message to all players when a specific command is used. Note that this function is deprecated. ```c #define HELLO_WORLD "Hello World" public OnPlayerCommandText(playerid, cmdtext[]) { if (strcmp(cmdtext, "/helloworld", true) == 0) { // Send a message to everyone. SendClientMessageToAllf(-1, "%s!", HELLO_WORLD); return 1; } return 0; } ``` -------------------------------- ### Get Current File Position with ftell Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/ftell.md This example demonstrates how to open a file, get its current position using ftell, and then close the file. It includes error handling for file opening. ```c new File:handle = fopen("file.txt", io_read); if (handle) { printf("Current position: %d", ftell(handle)); fclose(handle); } else { print("The file \"file.txt\" does not exists, or can't be opened."); } ``` -------------------------------- ### Get PlayerTextDraw Letter Size Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/PlayerTextDrawGetLetterSize.md This example demonstrates how to get the letter size of a player-textdraw after it has been created and its size set. The retrieved width and height are stored in float variables for potential further use. ```c new PlayerText:welcomeText[MAX_PLAYERS]; public OnPlayerConnect(playerid) { welcomeText[playerid] = CreatePlayerTextDraw(playerid, 320.0, 240.0, "Welcome to my OPEN.MP server"); PlayerTextDrawLetterSize(playerid, welcomeText[playerid], 3.2, 5.1); PlayerTextDrawShow(playerid, welcomeText[playerid]); new Float:width, Float:height; PlayerTextDrawGetLetterSize(playerid, welcomeText[playerid], width, height); // width = 3.2 // height = 5.1 return 1; } ``` -------------------------------- ### Game Mode Initialization and Database Connection Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/DB_GetFieldFloatByName.md This snippet shows how to initialize a game mode, establish a database connection using DB_Open, call a function to process database data (Examples_CalculateSum), and print the results. It also includes error handling for the database connection. ```c // mode.pwn // ... #include static DB:gDBConnectionHandle; // ... public OnGameModeInit() { // ... // Create a connection to a database gDBConnectionHandle = DB_Open("example.db"); // If connection to the database exists if (gDBConnectionHandle) { // Successfully created a connection to the database print("Successfully created a connection to database \"example.db\"."); printf("Calculated sum: %f", Examples_CalculateSum(gDBConnectionHandle)); } else { // Failed to create a connection to the database print("Failed to open a connection to database \"example.db\"."); } // ... return 1; } public OnGameModeExit() { // Close the connection to the database if connection is open if (DB_Close(gDBConnectionHandle)) { // Extra cleanup gDBConnectionHandle = DB:0; } // ... return 1; } ``` -------------------------------- ### Get Vehicle Velocity Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetVehicleVelocity.md This snippet demonstrates how to get the current velocity of the vehicle a player is in and display it to the player. It checks if the player is in a vehicle before attempting to retrieve and format the velocity data. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp("/GetMyCarVelocity", cmdtext)) { if (!IsPlayerInAnyVehicle(playerid)) { return 1; } new Float: vehVelocity[3], string[128]; GetVehicleVelocity(GetPlayerVehicleID(playerid), vehVelocity[0], vehVelocity[1], vehVelocity[2]); format(string, sizeof(string), "You are going at a velocity of X%f, Y%f, Z%f", vehVelocity[0], vehVelocity[1], vehVelocity[2]); SendClientMessage(playerid, 0xFFFFFFFF, string); return 1; } return 0; } ``` -------------------------------- ### GangZoneShowForAll Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GangZoneShowForAll.md This example demonstrates how to create a gang zone and then show it to all players when they spawn, provided they have admin privileges. The gang zone is created in OnGameModeInit and shown in OnPlayerSpawn. ```c new gGangZoneId; public OnGameModeInit() { gGangZoneId = GangZoneCreate(1248.011, 2072.804, 1439.348, 2204.319); return 1; } public OnPlayerSpawn(playerid) { if (IsPlayerAdmin(playerid)) { GangZoneShowForAll(gGangZoneId, 0xFF0000FF); } return 1; } ``` -------------------------------- ### Get Vehicle Z Angle Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetVehicleZAngle.md This snippet demonstrates how to get the Z angle of the vehicle a player is currently in and display it to the player. Ensure the vehicle ID is valid before calling the function. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (strcmp(cmdtext, "/vehrot", true) == 0) { new vehicleid, Float:rotZ, string[64]; vehicleid = GetPlayerVehicleID(playerid); GetVehicleZAngle(vehicleid, rotZ); format(string, sizeof(string), "The current vehicle rotation is: %.0f", rotZ); SendClientMessage(playerid, 0xFFFFFFFF, string); return 1; } return 0; } ``` -------------------------------- ### SetPickupModel Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/SetPickupModel.md This example demonstrates how to create a pickup and then change its model using SetPickupModel. The pickup is created with a default model and then updated to a new model. The update is applied to all players by default. ```c new g_Pickup; public OnGameModeInit() { g_Pickup = CreatePickup(1239, 1, 1686.6160, 1455.4277, 10.7705, -1); SetPickupModel(g_Pickup, 1210); return 1; } ``` -------------------------------- ### Get Player Siren State Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/GetPlayerSirenState.md This example demonstrates how to check if a player is in a vehicle and then retrieve and display the state of their vehicle's siren. It uses SendClientMessage to output the result to the player. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/siren", true)) { if (!IsPlayerInAnyVehicle(playerid)) { return 1; } new bool:sirenState = GetPlayerSirenState(playerid); SendClientMessage(playerid, 0xFFFF00FF, "Vehicle siren state: %s", sirenState ? "On" : "Off"); return 1; } return 0; } ``` -------------------------------- ### Game Mode Initialization and Database Connection Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/DB_GetFieldCount.md Initializes the game mode by opening a database connection and then calls Examples_CalculateSum to print the sum of values from the 'value' field. It demonstrates the usage of DB_Open, DB_ExecuteQuery (indirectly via Examples_CalculateSum), and DB_Close. ```c // mode.pwn // ... #include static DB:gDBConnectionHandle; // ... public OnGameModeInit() { // ... // Create a connection to a database gDBConnectionHandle = DB_Open("example.db"); // If connection to the database exists if (gDBConnectionHandle) { // Successfully created a connection to the database print("Successfully created a connection to database \"example.db\"."); printf("Calculated sum: %f", Examples_CalculateSum(gDBConnectionHandle)); } else { // Failed to create a connection to the database print("Failed to open a connection to database \"example.db\"."); } // ... return 1; } public OnGameModeExit() { // Close the connection to the database if connection is open if (DB_Close(gDBConnectionHandle)) { // Extra cleanup gDBConnectionHandle = DB:0; } // ... return 1; } ``` -------------------------------- ### Get NPC Path Count Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/NPC_GetPathCount.md This example demonstrates how to get the total number of NPC paths on the server and display it to the player. It checks for a specific chat command to trigger the path count retrieval. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/checkpathcount", true)) { new count = NPC_GetPathCount(); SendClientMessage(playerid, 0x00FF00FF, "Total NPC paths: %d", count); return 1; } return 0; } ``` -------------------------------- ### SetActorSkin Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/SetActorSkin.md This example demonstrates how to create an actor and then change its skin using SetActorSkin. Ensure the actor is created before attempting to set its skin. ```c new gMyActor; public OnGameModeInit() { gMyActor = CreateActor(179, 1153.9640, -1772.3915, 16.5920, 0.0000); SetActorSkin(gMyActor, 270); // Change actor skin from 179 to 270 return 1; } ``` -------------------------------- ### Running the frontend Source: https://context7.com/openmultiplayer/web/llms.txt Installs frontend dependencies and starts the Docusaurus development server. Use 'npm run build' and 'npm run serve' for production builds. ```bash cd frontend npm install npm run dev # starts Docusaurus dev server at http://localhost:3000 # Build for production npm run build npm run serve ``` -------------------------------- ### Get NPC Ammo Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/NPC_GetAmmo.md This example demonstrates how to get the total ammunition count for an NPC using NPC_GetAmmo. It includes checks to ensure the player is debugging a valid NPC before retrieving the ammo count. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/checkammo", true)) { new npcid = PlayerNPC[playerid]; if (npcid == INVALID_NPC_ID) return SendClientMessage(playerid, 0xFF0000FF, "You are not debugging a NPC."); if (!NPC_IsValid(npcid)) return SendClientMessage(playerid, 0xFF0000FF, "Invalid NPC."); new ammo = NPC_GetAmmo(npcid); SendClientMessage(playerid, 0x00FF00FF, "NPC %d has %d bullets remaining on total ammo", npcid, ammo); return 1; } return 0; } ``` -------------------------------- ### SetPlayerPickupModel Example Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/SetPlayerPickupModel.md This example demonstrates how to create a player-pickup and then change its model using SetPlayerPickupModel. Ensure the pickup is created before attempting to set its model. ```c new PlayerPickup[MAX_PLAYERS]; public OnPlayerConnect(playerid) { PlayerPickup[playerid] = CreatePlayerPickup(playerid, 1242, 2, 2010.0979, 1222.0642, 10.8206, -1); SetPlayerPickupModel(playerid, PlayerPickup[playerid], 1210); return 1; } ``` -------------------------------- ### Get NPC Weapon Source: https://github.com/openmultiplayer/web/blob/master/frontend/docs/scripting/functions/NPC_GetWeapon.md This example demonstrates how to get the current weapon of a specific NPC using NPC_GetWeapon. It includes checks for valid NPC debugging and NPC existence before retrieving and displaying the weapon ID. ```c public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp(cmdtext, "/checkweapon", true)) { new npcid = PlayerNPC[playerid]; if (npcid == INVALID_NPC_ID) return SendClientMessage(playerid, 0xFF0000FF, "You are not debugging a NPC."); if (!NPC_IsValid(npcid)) return SendClientMessage(playerid, 0xFF0000FF, "Invalid NPC."); new weapon = NPC_GetWeapon(npcid); SendClientMessage(playerid, 0x00FF00FF, "NPC %d weapon: %d", npcid, weapon); return 1; } return 0; } ``` -------------------------------- ### Start Local Development Server Source: https://github.com/openmultiplayer/web/blob/master/frontend/README.md Starts a local development server. Changes are reflected live without server restarts. ```bash $ npm start ```