FS-Lib is a collection of Lua functions designed for FiveM scripts to streamline various common tasks. It is mainly used in FearlessStudios scripts. Below is a detailed guide on how to use each function exposed by FS-Lib.
Feel free to contribute to the docs.
- GetKeyString
- GetClosestObject
- GetClosestPed
- GetClosestVehicle
- GetClosestTrailerToHitch
- GetNearbyObjects
- GetNearbyPeds
- GetNearbyVehicles
- SetupModel
- DrawText3D
- DrawText2D
- HeadingToCardinal
- IsInInterior
- GetStreetName
- IsVehicleEmpty
- Notify
Retrieves the name of the key corresponding to the provided key ID. This function returns the key name based on the current input device (keyboard or controller).
keyID
: The ID of the key. For a list of key IDs, refer to the FiveM documentation.
- string with the KEY name
local keyName = exports['FS-Lib']:GetKeyString(38)
print("Key Name: " .. keyName)
Finds the closest object within a specified distance from the player's current location.
maxDistance
: The maximum distance within which to search for the model (number).
closestObj
: The object it foundclosestDist
: The distance to that objectclosestCoords
: The coords of the object
local closestPed, closestDist, closestCoords = exports['FS-Lib']:GetClosestObject(10.0)
Finds the closest pedestrian (NPC or player) within a specified distance from the player's current location.
maxDistance
: The maximum distance within which to search for pedestrians (number).searchType
: Type of pedestrian to search for. Use "players" to find players or "npcs" to find NPCs or "both" to find both (string).
closestPed
: The ped it foundclosestDist
: The distance to that pedclosestCoords
: The coords of the ped
local closestPed, closestDist, closestCoords = exports['FS-Lib']:GetClosestPed(10.0, "players")
Finds the closest vehicle within a specified distance from the player's current location.
maxDistance
: The maximum distance within which to search for pedestrians (number).
closestVeh
: The vehicle it foundclosestDist
: The distance to that pedclosestCoords
: The coords of the ped
local closestVeh, closestDist, closestCoords = exports['FS-Lib']:GetClosestVehicle(10.0)
Finds the closest trailer within a specified distance from the player's current location.
maxDistance
: The maximum distance within which to search for trailers (number).
closestTrailer
: The trailer it found
local closestTrailer = exports['FS-Lib']:GetClosestTrailerToHitch(10.0)
Finds the objects within a specified distance from the player's current location.
maxDistance
: The maximum distance within which to search for the model (number).
- A table of all objects
local objects = exports['FS-Lib']:GetNearbyObjects(10.0)
for _, data in ipairs(objects) do
print(data.object)
print(data.objCoords)
print(data.dist)
end
Finds the peds (NPC or player or both) within a specified distance from the player's current location.
maxDistance
: The maximum distance within which to search for pedestrians (number).searchType
: Type of pedestrian to search for. Use "players" to find players or "npcs" to find NPCs or "both" to find both (string).
- A table of all peds
local peds = exports['FS-Lib']:GetNearbyPeds(10.0, "players")
for _, data in ipairs(peds) do
print(data.ped)
print(data.dist)
print(data.pedCoords)
end
Finds the vehicles within a specified distance from the player's current location.
maxDistance
: The maximum distance within which to search for pedestrians (number).
- A table of all vehicles
local vehicles = exports['FS-Lib']:GetNearbyVehicles(10.0)
for _, data in ipairs(peds) do
print(data.vehicle)
print(data.dist)
print(data.vehCoords)
end
Loads and sets up a model for use in the game.
model
: The model to load (number or string).
exports['FS-Lib']:SetupModel(123456)
Draws 3D text at specified world coordinates.
x
: X coordinate of the text (number).y
: Y coordinate of the text (number).z
: Z coordinate of the text (number).scale
: Scale of the text (number).text
: The text to display (string).
exports['FS-Lib']:DrawText3D(100.0, 200.0, 300.0, 0.6, "3D Text")
Draws 2D text at specified screen coordinates.
x
: X coordinate of the text on the screen (number).y
: Y coordinate of the text on the screen (number).text
: The text to display (string).scale
: Scale of the text (number).center
: Whether to center the text (boolean).
exports['FS-Lib']:DrawText2D(0.5, 0.8, "2D Text", 0.6, true)
Converts a heading value to a cardinal direction.
heading
: The heading angle (number).
- The cardinal direction as a string (string).
local direction = exports['FS-Lib']:HeadingToCardinal(45)
print("Cardinal Direction: " .. direction)
Returns true or false if the current player is in a interior
local isInInterior = exports['FS-Lib']:IsInInterior()
print(tostring(isInInterior))
Returns the street name at the coords provided
x
: The x coordinatey
: The y coordinatez
: The z coordinate
- The street name at those coords
local streetName = exports['FS-Lib']:GetStreetName(0, 0, 0)
print("Street Name: " .. streetName)
Returns true or false depending on if the vehicle provided is empty
Vehicle
: The vehicle you would like to check
- True if the vehicle is empty otherwise it returns false
local isVehEmpty = exports['FS-Lib']:IsVehicleEmpty(veh)
print(tostring(isVehEmpty))
Sends a toast notification to the player
message
: The message you want to show to the player
duration
: The duration you want the message to be shown for in seconds (if not provided it will be default 5 seconds)type
: The type can be either 'success' or 'warn' or 'error' or 'police' or 'medic' or 'fire' anything else provided will just default to the info type
exports['FS-Lib']:Notify('This is a test message', 5, 'police')
Checks latest github release version vs the current resource version
resourceName
: The name of the resource for printing purposesgithubRepo
: This is the actual repo to check must be in'username/repo'
format
exports['FS-Lib']:VersionCheck('FS-Lib', 'fearlessnite345/fs-lib')
Your contributions are invaluable! If you encounter a bug or have a brilliant enhancement in mind, please don't hesitate to open an issue or submit a pull request. If you would like to write any of the documentation, I would greatly appreciate it!
This project is licensed under the MIT License, providing you with the freedom to integrate it seamlessly into your own projects.
Happy coding!