mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
Merge pull request #747 from fivemland/refactor-weapons
refactor: es_extended weapon functions
This commit is contained in:
@@ -4,6 +4,16 @@ for i = 48, 57 do table.insert(Charset, string.char(i)) end
|
|||||||
for i = 65, 90 do table.insert(Charset, string.char(i)) end
|
for i = 65, 90 do table.insert(Charset, string.char(i)) end
|
||||||
for i = 97, 122 do table.insert(Charset, string.char(i)) end
|
for i = 97, 122 do table.insert(Charset, string.char(i)) end
|
||||||
|
|
||||||
|
local weaponsByName = {}
|
||||||
|
local weaponsByHash = {}
|
||||||
|
|
||||||
|
CreateThread(function()
|
||||||
|
for index, weapon in pairs(Config.Weapons) do
|
||||||
|
weaponsByName[weapon.name] = index
|
||||||
|
weaponsByHash[joaat(weapon.name)] = weapon
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
function ESX.GetRandomString(length)
|
function ESX.GetRandomString(length)
|
||||||
math.randomseed(GetGameTimer())
|
math.randomseed(GetGameTimer())
|
||||||
|
|
||||||
@@ -17,19 +27,16 @@ end
|
|||||||
function ESX.GetWeapon(weaponName)
|
function ESX.GetWeapon(weaponName)
|
||||||
weaponName = string.upper(weaponName)
|
weaponName = string.upper(weaponName)
|
||||||
|
|
||||||
for k,v in ipairs(Config.Weapons) do
|
assert(weaponsByName[weaponName], "Invalid weapon name!")
|
||||||
if v.name == weaponName then
|
|
||||||
return k, v
|
local index = weaponsByName[weaponName]
|
||||||
end
|
return index, Config.Weapons[index]
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ESX.GetWeaponFromHash(weaponHash)
|
function ESX.GetWeaponFromHash(weaponHash)
|
||||||
for k,v in ipairs(Config.Weapons) do
|
weaponHash = type(weaponHash) == "string" and joaat(weaponHash) or weaponHash
|
||||||
if joaat(v.name) == weaponHash then
|
|
||||||
return v
|
return weaponsByHash[weaponHash]
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ESX.GetWeaponList()
|
function ESX.GetWeaponList()
|
||||||
@@ -39,24 +46,21 @@ end
|
|||||||
function ESX.GetWeaponLabel(weaponName)
|
function ESX.GetWeaponLabel(weaponName)
|
||||||
weaponName = string.upper(weaponName)
|
weaponName = string.upper(weaponName)
|
||||||
|
|
||||||
for k,v in ipairs(Config.Weapons) do
|
assert(weaponsByName[weaponName], "Invalid weapon name!")
|
||||||
if v.name == weaponName then
|
|
||||||
return v.label
|
local index = weaponsByName[weaponName]
|
||||||
end
|
return Config.Weapons[index].label or ""
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ESX.GetWeaponComponent(weaponName, weaponComponent)
|
function ESX.GetWeaponComponent(weaponName, weaponComponent)
|
||||||
weaponName = string.upper(weaponName)
|
weaponName = string.upper(weaponName)
|
||||||
local weapons = Config.Weapons
|
|
||||||
|
|
||||||
for k,v in ipairs(Config.Weapons) do
|
assert(weaponsByName[weaponName], "Invalid weapon name!")
|
||||||
if v.name == weaponName then
|
local weapon = Config.Weapons[weaponsByName[weaponName]]
|
||||||
for k2,v2 in ipairs(v.components) do
|
|
||||||
if v2.name == weaponComponent then
|
for _, component in ipairs(weapon.components) do
|
||||||
return v2
|
if component.name == weaponComponent then
|
||||||
end
|
return component
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user