This outputs a line of text to the server's log. This could be useful for debugging.
log(string text)
- string text: The text to be output to the log.
Returns 'true' if successful, 'false' otherwise.
//SERVER
addEventHandler( "onScriptInit",
function()
{
log("server started");
});
This function is used to return the current date.
date()
- table - day, month, year and yearday
//SERVER
function init()
{
local currentDate = date();
log( currentDate["day"] + "," + currentDate["month"] + "," + currentDate["year"] + "," +currentDate["yearday"] );
}
addEventHandler( "onScriptInit", init );
This function is used to return the maximum amount of slots in the server.
getMaxPlayers()
- int: The maximum player slots
//SERVER
addCommandHandler( "run",
function( playerid )
{
local value = getMaxPlayers()
sendPlayerMessage( playerid, "getMaxPlayers: " + value + "." );
});
This function is used to return the current amount of players in the server.
getPlayerCount()
- int: Number of players
//SERVER
addCommandHandler( "run",
function( playerid )
{
local value = getPlayerCount()
sendPlayerMessage( playerid, "getPlayerCount: " + value + "." );
});
This function returns amount of time that your system has been running in milliseconds. By comparing two values of getTickCount, you can determine how much time has passed (in milliseconds) between two events. This could be used to determine how efficient your code is, or to time how long a player takes to complete a task.
getTickCount()
- int: Returns an integer containing the number of milliseconds since the system the server is running on started.
//SERVER
addEventHandler( "onScriptInit",
function()
{
log("Tick Count: " + getTickCount());
});
This function is used to return the name of the server.
getServerName()
- string: A string containing the server's name.
//SERVER
addEventHandler( "onScriptInit",
function()
{
log(getServerName());
});
This function is used to retrieve table (playerid : playerName) of all current connected players.
getPlayers()
- table: Table with all currently connected players. For each table entry 'key' is an playerId and 'value' is an player name.
//SERVER
addEventHandler("onPlayerDisconnected", function(playerid, reason) {
local players = getPlayers();
local list = "";
foreach (idx, name in players) {
list += ", " + name;
}
sendPlayerMessageToAll("Still active players: " + list);
});
This function is used to retrieve array of all created vehicle ids.
getVehicles()
- array: Array of all created vehicle ids.
//SERVER
addEventHandler("onScriptExit", function() {
local vehicles = getVehicles();
// call destoryVehicle for every id in array
vehicles.apply(destroyVehicle);
});
This function is used to add a command handler.
addCommandHandler(string command, function)
- string command: The command which would be typed into the chat
- function: The function to call when the command is typed
Returns 'true' if successful, 'false' otherwise.
//SERVER
addCommandHandler( "run",
function( playerid )
{
setPlayerHealth( playerid, 720.0 );
});
This function is used to create a function handler for an event.
addEventHandler(string event, function)
- string event: The name of the event
- function: The function which will be called when the event is triggered
Returns 'true' if successful, 'false' otherwise.
//SERVER
function init()
{
setGameModeText( "My GameMode Name" );
setMapName( "My Map Name" );
}
addEventHandler( "onScriptInit", init );
This function is used to call an event created by addEventHandler
callEvent(string event, ...)
- string event: The event name
- ... : (Optional) Arguments to pass onto the event
Returns 'true' if successful, 'false' otherwise.
//SERVER
function customEventFnc( total )
{
// This would output "Total Is: 53"
log( "Total is: " + total );
}
addEventHandler ( "customEvent", customEventFnc );
function init()
{
// Call customEvent and pass 53 as an argument
callEvent("customEvent", 53);
}
addEventHandler( "onScriptInit", init );
This function is used to remove a function event handler
removeEventHandler(string event, function)
- string event: The name of the event to be removed
- function: The function linked to the event
Returns 'true' if successful, 'false' otherwise.
//SERVER
function customEventFnc( total )
{
// This would output "Total Is: 53"
log( "Total is: " + total );
}
addEventHandler ( "customEvent", customEventFnc );
function init()
{
removeEventHandler("customEvent", customEventFnc);
}
addEventHandler( "onScriptInit", init );
This function is used to create a blip on the mini-map.
createBlip(float x, float y, int library, int icon)
- float x: The X position of the blip
- float y: The Y position of the blip
- int library: The ID of the icon's library
- int icon: The ID of the icon
- int - The created blipid
//SERVER
function init()
{
createBlip( -300.0, 120.0, 0, 1 );
}
addEventHandler( "onScriptInit", init );
This function is used to destroy a blip.
destroyBlip(int blipid)
- int blipid: The ID of the blip you want to destroy
Returns 'true' if successful, 'false' otherwise.
//SERVER
function init()
{
local blipid = createBlip( -300.0, 120.0, 0, 1 );
destroyBlip(blipid)
}
addEventHandler( "onScriptInit", init );
This function is used to attach a blip to a ped.
attachBlipToPed(int blipid, int pedid)
- int blipid: The ID of the blip you want to establish
- int pedid: The ID of the ped
Returns 'true' if successful, 'false' otherwise.
//CLIENT
addCommandHandler ( "run",
function ( playerid )
{
local pedid = createPed( 0, 100.0, 100.0, -20.0, 0.0, 0.0, 0.0 );
local blipid = createBlip( -300.0, 120.0, 0, 1 );
attachBlipToPed( blipid, pedid );
return 1;
});
This function is used to attach a blip to a player.
attachBlipToPlayer(int blipid, int playerid)
- int blipid: The ID of the blip you want to establish
- int playerid: The ID of the player
Returns 'true' if successful, 'false' otherwise.
//SERVER
addCommandHandler ( "run",
function ( playerid )
{
local blipid = createBlip( -300.0, 120.0, 0, 1 );
attachBlipToPlayer( blipid, playerid );
return 1;
});
This function is used to attach a blip to a vehicle.
attachBlipToVehicle(int blipid, int vehicleid)
- int blipid: The ID of the blip you want to establish
- int vehicleid: The ID of the vehicle
Returns 'true' if successful, 'false' otherwise.
//SERVER
addCommandHandler ( "run",
function ( playerid )
{
local vehicleid = createVehicle( 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 );
local blipid = createBlip( -300.0, 120.0, 0, 1 );
attachBlipToVehicle( blipid, vehicleid );
return 1;
});
This function is used to clamp a value between a minimum float and maximum float value.
clamp(float minimum, float value, float maximum)
- float minimum: The minimum float
- float value: The value
- float maximum: The maximum float
- float - The clamped value
//SERVER
function init()
{
// This would output: Clamp: 3
log("Clamp: " + clamp(1.0, 10.0, 3.0) );
}
addEventHandler( "onScriptInit", init );
This function is used to convert a RGB(A) colour.
fromRGB(int r, int g, int b[, a = 255])
- int r: The red (RGB) colour
- int g: The green (RGB) colour
- int b: The blue (RGB) colour
- int a: (Optional) The alpha, default 255
- array - R, G, B and A colours
//CLIENT
addEventHandler( "onClientFrameRender",
function( post )
{
dxDrawText("hello world", 0.0, 0.0, fromRGB(255, 255, 255, 255), true, "tahoma-bold", 1.0);
});
This function is used to return the distance between two 2D points.
getDistanceBetweenPoints2D(float PointX, float PointY, float pointX2, float pointY2)
- float PointX: The X coordinate of the first point
- float PointY: The Y coordinate of the first point
- float pointX2: The X coordinate of the second point
- float pointY2: The Y coordinate of the second point
- float - distance
//SERVER
addCommandHandler( "run",
function( playerid )
{
local myPos = getPlayerPosition(playerid)
local dis = getDistanceBetweenPoints2D( 400.0, 200.0, myPos[0], myPos[1] );
sendPlayerMessage( playerid, "Distance between points: " + dis + "." );
});
This function is used to return the distance between two 3D points.
getDistanceBetweenPoints3D(float PointX, float PointY, float PointZ, float pointX2, float pointY2, float pointZ2)
- float PointX: The X coordinate of the first point
- float PointY: The Y coordinate of the first point
- float PointZ: The Z coordinate of the first point
- float pointX2: The X coordinate of the second point
- float pointY2: The Y coordinate of the second point
- float pointZ2: The Z coordinate of the second point
- float - distance
//SERVER
addCommandHandler( "run",
function( playerid )
{
local myPos = getPlayerPosition(playerid)
local dis = getDistanceBetweenPoints3D( 400.0, 200.0, -14.0, myPos[0], myPos[1], myPos[2] );
sendPlayerMessage( playerid, "Distance between points: " + dis + "." );
});
This function is used to explode vehicle.
explodeVehicle(int vehicleid)
- int vehicleid: The ID of the vehicle
Returns 'true' if successful, 'false' otherwise.
//SERVER
addCommandHandler( "run",
function( playerid )
{
local myPos = getPlayerPosition(playerid)
local vehicleid = createVehicle( 0, myPos[0], myPos[1], myPos[2], 0.0, 0.0, 0.0 );
explodeVehicle( vehicleid );
});
This function can be used to get vehicle indicator lights state.
getIndicatorLightState(int vehicleid, int indicatorSide)
- int vehicleid: The ID of the vehicle
- int indicatorSide: side of the indicator, possible values: INDICATOR_LEFT, INDICATOR_RIGHT
Boolean result of getting vehicle indicator lights state (true/false)
//SERVER
addCommandHandler( "run",
function( playerid )
{
local myPos = getPlayerPosition(playerid)
local vehicleid = createVehicle( 0, myPos[0], myPos[1], myPos[2], 0.0, 0.0, 0.0 );
local prevState = getIndicatorLightState(vehicleid, INDICATOR_LEFT);
sendPlayerMessage( playerid, "getIndicatorLightState: " + prevState + "." );
});
This function is used to return the players health.
getPlayerHealth(int playerid)
- int playerid: The ID of the player
- float: The amount of health
//SERVER
addCommandHandler( "run",
function( playerid )
{
local value = getPlayerHealth(playerid)
sendPlayerMessage( playerid, "getPlayerHealth: " + value + "." );
});