Shared Functions
Functions that can be used on both server and client.
GetRandomString
This function returns a random string in the specified length.
Arguments
- length:
number
- The length of the string to be generated.
Example
local randomName = ESX.GetRandomString(5)
print("Pomni's name could have been: " .. randomName)
GetConfig
This function returns the esx config.
GetWeapon
Get the weapon from the weapons config and it’s index in it using the weapon name.
Arguments
- weaponName:
string
- The name of the weapon to get.
Returns
- index:
number
- The index of the weapon in the weapons config.
- weapon:
table
- The weapon data from the weapons config.
Example
local index, weapon = ESX.GetWeapon("weapon_pistol")
print("The weapon is called " .. weapon.label .. " and can have a max of " .. weapon.ammo .. " bullets.")
GetWeaponFromHash
Get the weapon from the weapons config and it’s index using the weapon’s hash.
Arguments
- weaponHash:
number
- The hash of the weapon to get.
Returns
- index:
number
- The index of the weapon in the weapons config.
- weapon:
table
- The weapon data from the weapons config.
Example
local index, weapon = ESX.GetWeaponFromhash(joaat("weapon_pistol"))
print("The weapon is called " .. weapon.label .. " and can have a max of " .. weapon.ammo .. " bullets.")
GetWeaponList
Get all weapons either with the name or hash as key.
Arguments
- byHash:
boolean
- Should it return the weapon hashes instead of the key.
GetWeaponLabel
Get the specified weapon’s label
Arguments
- weaponName:
string
- The name of the weapon to get the label of.
Returns
- label:
string
- The label of the weapon.
Example
local label = ESX.GetWeaponLabel("weapon_pistol")
print("Weapon is a: " .. weaponLabel)
GetWeaponComponent
This function returns the possible data of the specified component for the specified weapon.
Arguments
- weaponName:
string
- The name of the weapon to get the component data for.
- componentName:
string
- The name of the component to get the data for.
Returns
- component:
table
- The component data from the weapons config.