From baa9ca3afc109ec9f34bcfd997810fbebc8ad5e3 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Tue, 11 Feb 2020 21:11:54 +0100 Subject: [PATCH] Implemented weapon tint support (desc), closes #477 - Implemented two new xPlayer functions: - .getWeaponTint(weaponName) - .setWeaponTint(weaponName, weaponTintIndex) Thanks to @profex1999 for co authoring this! Co-Authored-By: Andrea Passarini --- client/main.lua | 35 +++++++++++------- config.weapons.lua | 74 ++++++++++++++++++++++++++++++--------- locales/br.lua | 10 ++++++ locales/cs.lua | 10 ++++++ locales/de.lua | 10 ++++++ locales/en.lua | 10 ++++++ locales/fi.lua | 10 ++++++ locales/fr.lua | 10 ++++++ locales/pl.lua | 10 ++++++ locales/sv.lua | 12 ++++++- server/classes/player.lua | 27 +++++++++++++- server/functions.lua | 5 +-- server/main.lua | 8 ++--- 13 files changed, 194 insertions(+), 37 deletions(-) diff --git a/client/main.lua b/client/main.lua index d99ef51f..7e74d212 100644 --- a/client/main.lua +++ b/client/main.lua @@ -85,6 +85,8 @@ AddEventHandler('esx:restoreLoadout', function() local weaponHash = GetHashKey(weaponName) GiveWeaponToPed(playerPed, weaponHash, 0, false, false) + SetPedWeaponTintIndex(playerPed, weaponHash, v.tintIndex) + local ammoType = GetPedAmmoTypeFromWeapon(playerPed, weaponHash) for k2,v2 in ipairs(v.components) do @@ -168,7 +170,7 @@ end) RegisterNetEvent('esx:addWeapon') AddEventHandler('esx:addWeapon', function(weaponName, ammo) - local playerPed = PlayerPedId() + local playerPed = PlayerPedId() local weaponHash = GetHashKey(weaponName) GiveWeaponToPed(playerPed, weaponHash, ammo, false, false) @@ -176,7 +178,7 @@ end) RegisterNetEvent('esx:addWeaponComponent') AddEventHandler('esx:addWeaponComponent', function(weaponName, weaponComponent) - local playerPed = PlayerPedId() + local playerPed = PlayerPedId() local weaponHash = GetHashKey(weaponName) local componentHash = ESX.GetWeaponComponent(weaponName, weaponComponent).hash @@ -185,15 +187,23 @@ end) RegisterNetEvent('esx:setWeaponAmmo') AddEventHandler('esx:setWeaponAmmo', function(weaponName, weaponAmmo) - local playerPed = PlayerPedId() + local playerPed = PlayerPedId() local weaponHash = GetHashKey(weaponName) SetPedAmmo(playerPed, weaponHash, weaponAmmo) end) +RegisterNetEvent('esx:setWeaponTint') +AddEventHandler('esx:setWeaponTint', function(weaponName, weaponTintIndex) + local playerPed = PlayerPedId() + local weaponHash = GetHashKey(weaponName) + + SetPedWeaponTintIndex(playerPed, weaponHash, weaponTintIndex) +end) + RegisterNetEvent('esx:removeWeapon') AddEventHandler('esx:removeWeapon', function(weaponName, ammo) - local playerPed = PlayerPedId() + local playerPed = PlayerPedId() local weaponHash = GetHashKey(weaponName) RemoveWeaponFromPed(playerPed, weaponHash) @@ -209,7 +219,7 @@ end) RegisterNetEvent('esx:removeWeaponComponent') AddEventHandler('esx:removeWeaponComponent', function(weaponName, weaponComponent) - local playerPed = PlayerPedId() + local playerPed = PlayerPedId() local weaponHash = GetHashKey(weaponName) local componentHash = ESX.GetWeaponComponent(weaponName, weaponComponent).hash @@ -243,9 +253,8 @@ AddEventHandler('esx:spawnVehicle', function(vehicle) local model = (type(vehicle) == 'number' and vehicle or GetHashKey(vehicle)) if IsModelInCdimage(model) then - local playerPed = PlayerPedId() - local coords = GetEntityCoords(playerPed) - local playerHeading = GetEntityHeading(playerPed) + local playerPed = PlayerPedId() + local playerCoords, playerHeading = GetEntityCoords(playerPed), GetEntityHeading(playerPed) ESX.Game.SpawnVehicle(model, coords, playerHeading, function(vehicle) TaskWarpPedIntoVehicle(playerPed, vehicle, -1) @@ -256,7 +265,7 @@ AddEventHandler('esx:spawnVehicle', function(vehicle) end) RegisterNetEvent('esx:createPickup') -AddEventHandler('esx:createPickup', function(pickupId, label, playerId, type, name, components) +AddEventHandler('esx:createPickup', function(pickupId, label, playerId, type, name, components, tintIndex) local playerPed = GetPlayerPed(GetPlayerFromServerId(playerId)) local entityCoords, forward, pickupObject = GetEntityCoords(playerPed), GetEntityForwardVector(playerPed) local objectCoords = (entityCoords + forward * 1.0) @@ -264,6 +273,7 @@ AddEventHandler('esx:createPickup', function(pickupId, label, playerId, type, na if type == 'item_weapon' then ESX.Streaming.RequestWeaponAsset(GetHashKey(name)) pickupObject = CreateWeaponObject(GetHashKey(name), 50, objectCoords, true, 1.0, 0) + SetWeaponObjectTintIndex(pickupObject, tintIndex) for k,v in ipairs(components) do local component = ESX.GetWeaponComponent(name, v) @@ -300,6 +310,7 @@ AddEventHandler('esx:createMissingPickups', function(missingPickups) if pickup.type == 'item_weapon' then ESX.Streaming.RequestWeaponAsset(GetHashKey(pickup.name)) pickupObject = CreateWeaponObject(GetHashKey(pickup.name), 50, pickup.coords.x, pickup.coords.y, pickup.coords.z, true, 1.0, 0) + SetWeaponObjectTintIndex(pickupObject, pickup.tintIndex) for k,componentName in ipairs(pickup.components) do local component = ESX.GetWeaponComponent(pickup.name, componentName) @@ -405,10 +416,9 @@ Citizen.CreateThread(function() for k,v in ipairs(Config.Weapons) do local weaponName = v.name local weaponHash = GetHashKey(weaponName) - local weaponComponents = {} if HasPedGotWeapon(playerPed, weaponHash, false) then - local ammo = GetAmmoInPedWeapon(playerPed, weaponHash) + local ammo, tintIndex, weaponComponents = GetAmmoInPedWeapon(playerPed, weaponHash), GetPedWeaponTintIndex(playerPed, weaponHash), {} for k2,v2 in ipairs(v.components) do if HasPedGotWeaponComponent(playerPed, weaponHash, v2.hash) then @@ -426,7 +436,8 @@ Citizen.CreateThread(function() name = weaponName, ammo = ammo, label = v.label, - components = weaponComponents + components = weaponComponents, + tintIndex = tintIndex }) else if lastLoadout[weaponName] then diff --git a/config.weapons.lua b/config.weapons.lua index 037062fc..6c08d1a7 100644 --- a/config.weapons.lua +++ b/config.weapons.lua @@ -1,8 +1,20 @@ +Config.DefaultWeaponTints = { + [0] = _U('tint_default'), + [1] = _U('tint_green'), + [2] = _U('tint_gold'), + [3] = _U('tint_pink'), + [4] = _U('tint_army'), + [5] = _U('tint_lspd'), + [6] = _U('tint_orange'), + [7] = _U('tint_platinum') +} + Config.Weapons = { { name = 'WEAPON_PISTOL', label = _U('weapon_pistol'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_PISTOL_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_PISTOL_CLIP_02')}, @@ -16,6 +28,7 @@ Config.Weapons = { name = 'WEAPON_COMBATPISTOL', label = _U('weapon_combatpistol'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_COMBATPISTOL_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_COMBATPISTOL_CLIP_02')}, @@ -29,6 +42,7 @@ Config.Weapons = { name = 'WEAPON_APPISTOL', label = _U('weapon_appistol'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_APPISTOL_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_APPISTOL_CLIP_02')}, @@ -42,6 +56,7 @@ Config.Weapons = { name = 'WEAPON_PISTOL50', label = _U('weapon_pistol50'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_PISTOL50_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_PISTOL50_CLIP_02')}, @@ -55,6 +70,7 @@ Config.Weapons = { name = 'WEAPON_SNSPISTOL', label = _U('weapon_snspistol'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_SNSPISTOL_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_SNSPISTOL_CLIP_02')}, @@ -66,6 +82,7 @@ Config.Weapons = { name = 'WEAPON_HEAVYPISTOL', label = _U('weapon_heavypistol'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_HEAVYPISTOL_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_HEAVYPISTOL_CLIP_02')}, @@ -79,6 +96,7 @@ Config.Weapons = { name = 'WEAPON_VINTAGEPISTOL', label = _U('weapon_vintagepistol'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_VINTAGEPISTOL_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_VINTAGEPISTOL_CLIP_02')}, @@ -90,6 +108,7 @@ Config.Weapons = { name = 'WEAPON_MACHINEPISTOL', label = _U('weapon_machinepistol'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_MACHINEPISTOL_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_MACHINEPISTOL_CLIP_02')}, @@ -98,14 +117,15 @@ Config.Weapons = { } }, - {name = 'WEAPON_REVOLVER', label = _U('weapon_revolver'), components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}}, - {name = 'WEAPON_MARKSMANPISTOL', label = _U('weapon_marksmanpistol'), components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}}, + {name = 'WEAPON_REVOLVER', label = _U('weapon_revolver'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}}, + {name = 'WEAPON_MARKSMANPISTOL', label = _U('weapon_marksmanpistol'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}}, {name = 'WEAPON_DOUBLEACTION', label = _U('weapon_doubleaction'), components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_PISTOL')}}, { name = 'WEAPON_SMG', label = _U('weapon_smg'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_SMG')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_SMG_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_SMG_CLIP_02')}, @@ -121,6 +141,7 @@ Config.Weapons = { name = 'WEAPON_ASSAULTSMG', label = _U('weapon_assaultsmg'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_SMG')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_ASSAULTSMG_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_ASSAULTSMG_CLIP_02')}, @@ -135,6 +156,7 @@ Config.Weapons = { name = 'WEAPON_MICROSMG', label = _U('weapon_microsmg'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_SMG')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_MICROSMG_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_MICROSMG_CLIP_02')}, @@ -149,6 +171,7 @@ Config.Weapons = { name = 'WEAPON_MINISMG', label = _U('weapon_minismg'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_SMG')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_MINISMG_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_MINISMG_CLIP_02')} @@ -159,6 +182,7 @@ Config.Weapons = { name = 'WEAPON_COMBATPDW', label = _U('weapon_combatpdw'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_SMG')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_COMBATPDW_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_COMBATPDW_CLIP_02')}, @@ -173,6 +197,7 @@ Config.Weapons = { name = 'WEAPON_PUMPSHOTGUN', label = _U('weapon_pumpshotgun'), ammo = {label = _U('ammo_shells'), hash = GetHashKey('AMMO_SHOTGUN')}, + tints = Config.DefaultWeaponTints, components = { {name = 'flashlight', label = _U('component_flashlight'), hash = GetHashKey('COMPONENT_AT_AR_FLSH')}, {name = 'suppressor', label = _U('component_suppressor'), hash = GetHashKey('COMPONENT_AT_SR_SUPP')}, @@ -184,6 +209,7 @@ Config.Weapons = { name = 'WEAPON_SAWNOFFSHOTGUN', label = _U('weapon_sawnoffshotgun'), ammo = {label = _U('ammo_shells'), hash = GetHashKey('AMMO_SHOTGUN')}, + tints = Config.DefaultWeaponTints, components = { {name = 'luxary_finish', label = _U('component_luxary_finish'), hash = GetHashKey('COMPONENT_SAWNOFFSHOTGUN_VARMOD_LUXE')} } @@ -193,6 +219,7 @@ Config.Weapons = { name = 'WEAPON_ASSAULTSHOTGUN', label = _U('weapon_assaultshotgun'), ammo = {label = _U('ammo_shells'), hash = GetHashKey('AMMO_SHOTGUN')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_ASSAULTSHOTGUN_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_ASSAULTSHOTGUN_CLIP_02')}, @@ -206,6 +233,7 @@ Config.Weapons = { name = 'WEAPON_BULLPUPSHOTGUN', label = _U('weapon_bullpupshotgun'), ammo = {label = _U('ammo_shells'), hash = GetHashKey('AMMO_SHOTGUN')}, + tints = Config.DefaultWeaponTints, components = { {name = 'flashlight', label = _U('component_flashlight'), hash = GetHashKey('COMPONENT_AT_AR_FLSH')}, {name = 'suppressor', label = _U('component_suppressor'), hash = GetHashKey('COMPONENT_AT_AR_SUPP_02')}, @@ -217,6 +245,7 @@ Config.Weapons = { name = 'WEAPON_HEAVYSHOTGUN', label = _U('weapon_heavyshotgun'), ammo = {label = _U('ammo_shells'), hash = GetHashKey('AMMO_SHOTGUN')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_HEAVYSHOTGUN_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_HEAVYSHOTGUN_CLIP_02')}, @@ -227,14 +256,15 @@ Config.Weapons = { } }, - {name = 'WEAPON_DBSHOTGUN', label = _U('weapon_dbshotgun'), components = {}, ammo = {label = _U('ammo_shells'), hash = GetHashKey('AMMO_SHOTGUN')}}, - {name = 'WEAPON_AUTOSHOTGUN', label = _U('weapon_autoshotgun'), components = {}, ammo = {label = _U('ammo_shells'), hash = GetHashKey('AMMO_SHOTGUN')}}, - {name = 'WEAPON_MUSKET', label = _U('weapon_musket'), components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_SHOTGUN')}}, + {name = 'WEAPON_DBSHOTGUN', label = _U('weapon_dbshotgun'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_shells'), hash = GetHashKey('AMMO_SHOTGUN')}}, + {name = 'WEAPON_AUTOSHOTGUN', label = _U('weapon_autoshotgun'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_shells'), hash = GetHashKey('AMMO_SHOTGUN')}}, + {name = 'WEAPON_MUSKET', label = _U('weapon_musket'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_SHOTGUN')}}, { name = 'WEAPON_ASSAULTRIFLE', label = _U('weapon_assaultrifle'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_RIFLE')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_ASSAULTRIFLE_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_ASSAULTRIFLE_CLIP_02')}, @@ -251,6 +281,7 @@ Config.Weapons = { name = 'WEAPON_CARBINERIFLE', label = _U('weapon_carbinerifle'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_RIFLE')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_CARBINERIFLE_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_CARBINERIFLE_CLIP_02')}, @@ -267,6 +298,7 @@ Config.Weapons = { name = 'WEAPON_ADVANCEDRIFLE', label = _U('weapon_advancedrifle'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_RIFLE')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_ADVANCEDRIFLE_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_ADVANCEDRIFLE_CLIP_02')}, @@ -281,6 +313,7 @@ Config.Weapons = { name = 'WEAPON_SPECIALCARBINE', label = _U('weapon_specialcarbine'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_RIFLE')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_SPECIALCARBINE_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_SPECIALCARBINE_CLIP_02')}, @@ -297,6 +330,7 @@ Config.Weapons = { name = 'WEAPON_BULLPUPRIFLE', label = _U('weapon_bullpuprifle'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_RIFLE')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_BULLPUPRIFLE_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_BULLPUPRIFLE_CLIP_02')}, @@ -312,6 +346,7 @@ Config.Weapons = { name = 'WEAPON_COMPACTRIFLE', label = _U('weapon_compactrifle'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_RIFLE')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_COMPACTRIFLE_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_COMPACTRIFLE_CLIP_02')}, @@ -323,6 +358,7 @@ Config.Weapons = { name = 'WEAPON_MG', label = _U('weapon_mg'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_MG')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_MG_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_MG_CLIP_02')}, @@ -335,6 +371,7 @@ Config.Weapons = { name = 'WEAPON_COMBATMG', label = _U('weapon_combatmg'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_MG')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_COMBATMG_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_COMBATMG_CLIP_02')}, @@ -348,6 +385,7 @@ Config.Weapons = { name = 'WEAPON_GUSENBERG', label = _U('weapon_gusenberg'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_MG')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_GUSENBERG_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_GUSENBERG_CLIP_02')}, @@ -358,6 +396,7 @@ Config.Weapons = { name = 'WEAPON_SNIPERRIFLE', label = _U('weapon_sniperrifle'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_SNIPER')}, + tints = Config.DefaultWeaponTints, components = { {name = 'scope', label = _U('component_scope'), hash = GetHashKey('COMPONENT_AT_SCOPE_LARGE')}, {name = 'scope_advanced', label = _U('component_scope_advanced'), hash = GetHashKey('COMPONENT_AT_SCOPE_MAX')}, @@ -370,6 +409,7 @@ Config.Weapons = { name = 'WEAPON_HEAVYSNIPER', label = _U('weapon_heavysniper'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_SNIPER')}, + tints = Config.DefaultWeaponTints, components = { {name = 'scope', label = _U('component_scope'), hash = GetHashKey('COMPONENT_AT_SCOPE_LARGE')}, {name = 'scope_advanced', label = _U('component_scope_advanced'), hash = GetHashKey('COMPONENT_AT_SCOPE_MAX')} @@ -380,6 +420,7 @@ Config.Weapons = { name = 'WEAPON_MARKSMANRIFLE', label = _U('weapon_marksmanrifle'), ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_SNIPER')}, + tints = Config.DefaultWeaponTints, components = { {name = 'clip_default', label = _U('component_clip_default'), hash = GetHashKey('COMPONENT_MARKSMANRIFLE_CLIP_01')}, {name = 'clip_extended', label = _U('component_clip_extended'), hash = GetHashKey('COMPONENT_MARKSMANRIFLE_CLIP_02')}, @@ -391,19 +432,19 @@ Config.Weapons = { } }, + {name = 'WEAPON_MINIGUN', label = _U('weapon_minigun'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_MINIGUN')}}, + {name = 'WEAPON_RAILGUN', label = _U('weapon_railgun'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_RAILGUN')}}, + {name = 'WEAPON_STUNGUN', label = _U('weapon_stungun'), tints = Config.DefaultWeaponTints, components = {}}, + {name = 'WEAPON_RPG', label = _U('weapon_rpg'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_rockets'), hash = GetHashKey('AMMO_RPG')}}, + {name = 'WEAPON_HOMINGLAUNCHER', label = _U('weapon_hominglauncher'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_rockets'), hash = GetHashKey('AMMO_HOMINGLAUNCHER')}}, + {name = 'WEAPON_GRENADELAUNCHER', label = _U('weapon_grenadelauncher'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_grenadelauncher'), hash = GetHashKey('AMMO_GRENADELAUNCHER')}}, + {name = 'WEAPON_COMPACTLAUNCHER', label = _U('weapon_compactlauncher'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_grenadelauncher'), hash = GetHashKey('AMMO_GRENADELAUNCHER')}}, + {name = 'WEAPON_FLAREGUN', label = _U('weapon_flaregun'), tints = Config.DefaultWeaponTints, components = {}, ammo = {label = _U('ammo_flaregun'), hash = GetHashKey('AMMO_FLAREGUN')}}, {name = 'WEAPON_FIREEXTINGUISHER', label = _U('weapon_fireextinguisher'), components = {}, ammo = {label = _U('ammo_charge'), hash = GetHashKey('AMMO_FIREEXTINGUISHER')}}, {name = 'WEAPON_PETROLCAN', label = _U('weapon_petrolcan'), components = {}, ammo = {label = _U('ammo_petrol'), hash = GetHashKey('AMMO_PETROLCAN')}}, - {name = 'WEAPON_MINIGUN', label = _U('weapon_minigun'), components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_MINIGUN')}}, - {name = 'WEAPON_RAILGUN', label = _U('weapon_railgun'), components = {}, ammo = {label = _U('ammo_rounds'), hash = GetHashKey('AMMO_RAILGUN')}}, - {name = 'WEAPON_STUNGUN', label = _U('weapon_stungun'), components = {}}, {name = 'WEAPON_FIREWORK', label = _U('weapon_firework'), components = {}, ammo = {label = _U('ammo_firework'), hash = GetHashKey('AMMO_FIREWORK')}}, - {name = 'WEAPON_RPG', label = _U('weapon_rpg'), components = {}, ammo = {label = _U('ammo_rockets'), hash = GetHashKey('AMMO_RPG')}}, - {name = 'WEAPON_HOMINGLAUNCHER', label = _U('weapon_hominglauncher'), components = {}, ammo = {label = _U('ammo_rockets'), hash = GetHashKey('AMMO_HOMINGLAUNCHER')}}, - {name = 'WEAPON_GRENADELAUNCHER', label = _U('weapon_grenadelauncher'), components = {}, ammo = {label = _U('ammo_grenadelauncher'), hash = GetHashKey('AMMO_GRENADELAUNCHER')}}, - {name = 'WEAPON_COMPACTLAUNCHER', label = _U('weapon_compactlauncher'), components = {}, ammo = {label = _U('ammo_grenadelauncher'), hash = GetHashKey('AMMO_GRENADELAUNCHER')}}, {name = 'WEAPON_FLASHLIGHT', label = _U('weapon_flashlight'), components = {}}, {name = 'GADGET_PARACHUTE', label = _U('gadget_parachute'), components = {}}, - {name = 'WEAPON_KNUCKLE', label = _U('weapon_knuckle'), components = {}}, {name = 'WEAPON_HATCHET', label = _U('weapon_hatchet'), components = {}}, {name = 'WEAPON_MACHETE', label = _U('weapon_machete'), components = {}}, @@ -421,14 +462,13 @@ Config.Weapons = { {name = 'WEAPON_CROWBAR', label = _U('weapon_crowbar'), components = {}}, {name = 'WEAPON_GRENADE', label = _U('weapon_grenade'), components = {}, ammo = {label = _U('ammo_grenade'), hash = GetHashKey('AMMO_GRENADE')}}, + {name = 'WEAPON_SMOKEGRENADE', label = _U('weapon_smokegrenade'), components = {}, ammo = {label = _U('ammo_smokebomb'), hash = GetHashKey('AMMO_SMOKEGRENADE')}}, {name = 'WEAPON_STICKYBOMB', label = _U('weapon_stickybomb'), components = {}, ammo = {label = _U('ammo_stickybomb'), hash = GetHashKey('AMMO_STICKYBOMB')}}, {name = 'WEAPON_PIPEBOMB', label = _U('weapon_pipebomb'), components = {}, ammo = {label = _U('ammo_pipebomb'), hash = GetHashKey('AMMO_PIPEBOMB')}}, - {name = 'WEAPON_SMOKEGRENADE', label = _U('weapon_smokegrenade'), components = {}, ammo = {label = _U('ammo_smokebomb'), hash = GetHashKey('AMMO_SMOKEGRENADE')}}, {name = 'WEAPON_BZGAS', label = _U('weapon_bzgas'), components = {}, ammo = {label = _U('ammo_bzgas'), hash = GetHashKey('AMMO_BZGAS')}}, {name = 'WEAPON_MOLOTOV', label = _U('weapon_molotov'), components = {}, ammo = {label = _U('ammo_molotov'), hash = GetHashKey('AMMO_MOLOTOV')}}, {name = 'WEAPON_PROXMINE', label = _U('weapon_proxmine'), components = {}, ammo = {label = _U('ammo_proxmine'), hash = GetHashKey('AMMO_PROXMINE')}}, - {name = 'WEAPON_BALL', label = _U('weapon_ball'), components = {}, ammo = {label = _U('ammo_ball'), hash = GetHashKey('AMMO_BALL')}}, {name = 'WEAPON_SNOWBALL', label = _U('weapon_snowball'), components = {}, ammo = {label = _U('ammo_snowball'), hash = GetHashKey('AMMO_SNOWBALL')}}, - {name = 'WEAPON_FLARE', label = _U('weapon_flare'), components = {}, ammo = {label = _U('ammo_flare'), hash = GetHashKey('AMMO_FLARE')}}, - {name = 'WEAPON_FLAREGUN', label = _U('weapon_flaregun'), components = {}, ammo = {label = _U('ammo_flaregun'), hash = GetHashKey('AMMO_FLAREGUN')}} + {name = 'WEAPON_BALL', label = _U('weapon_ball'), components = {}, ammo = {label = _U('ammo_ball'), hash = GetHashKey('AMMO_BALL')}}, + {name = 'WEAPON_FLARE', label = _U('weapon_flare'), components = {}, ammo = {label = _U('ammo_flare'), hash = GetHashKey('AMMO_FLARE')}} } diff --git a/locales/br.lua b/locales/br.lua index b3db1ee3..a7b54c8f 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -190,4 +190,14 @@ Locales['br'] = { ['ammo_snowball'] = 'snowball(s)', ['ammo_flare'] = 'flare(s)', ['ammo_flaregun'] = 'flare(s)', + + -- Weapon Tints + ['tint_default'] = 'default skin', + ['tint_green'] = 'green skin', + ['tint_gold'] = 'gold skin', + ['tint_pink'] = 'pink skin', + ['tint_army'] = 'army skin', + ['tint_lspd'] = 'blue skin', + ['tint_orange'] = 'orange skin', + ['tint_platinum'] = 'platinum skin', } diff --git a/locales/cs.lua b/locales/cs.lua index b980fc6a..72b398de 100644 --- a/locales/cs.lua +++ b/locales/cs.lua @@ -190,4 +190,14 @@ Locales['cs'] = { ['ammo_snowball'] = 'snowball(s)', ['ammo_flare'] = 'flare(s)', ['ammo_flaregun'] = 'flare(s)', + + -- Weapon Tints + ['tint_default'] = 'default skin', + ['tint_green'] = 'green skin', + ['tint_gold'] = 'gold skin', + ['tint_pink'] = 'pink skin', + ['tint_army'] = 'army skin', + ['tint_lspd'] = 'blue skin', + ['tint_orange'] = 'orange skin', + ['tint_platinum'] = 'platinum skin', } diff --git a/locales/de.lua b/locales/de.lua index 0068ed65..37beefe7 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -189,4 +189,14 @@ Locales['de'] = { ['ammo_snowball'] = 'snowball(s)', ['ammo_flare'] = 'flare(s)', ['ammo_flaregun'] = 'flare(s)', + + -- Weapon Tints + ['tint_default'] = 'default skin', + ['tint_green'] = 'green skin', + ['tint_gold'] = 'gold skin', + ['tint_pink'] = 'pink skin', + ['tint_army'] = 'army skin', + ['tint_lspd'] = 'blue skin', + ['tint_orange'] = 'orange skin', + ['tint_platinum'] = 'platinum skin', } diff --git a/locales/en.lua b/locales/en.lua index babcb272..e8ed9a67 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -189,4 +189,14 @@ Locales['en'] = { ['ammo_snowball'] = 'snowball(s)', ['ammo_flare'] = 'flare(s)', ['ammo_flaregun'] = 'flare(s)', + + -- Weapon Tints + ['tint_default'] = 'default skin', + ['tint_green'] = 'green skin', + ['tint_gold'] = 'gold skin', + ['tint_pink'] = 'pink skin', + ['tint_army'] = 'army skin', + ['tint_lspd'] = 'blue skin', + ['tint_orange'] = 'orange skin', + ['tint_platinum'] = 'platinum skin', } diff --git a/locales/fi.lua b/locales/fi.lua index 2dd566c4..5e987651 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -189,4 +189,14 @@ Locales['fi'] = { ['ammo_snowball'] = 'snowball(s)', ['ammo_flare'] = 'flare(s)', ['ammo_flaregun'] = 'flare(s)', + + -- Weapon Tints + ['tint_default'] = 'default skin', + ['tint_green'] = 'green skin', + ['tint_gold'] = 'gold skin', + ['tint_pink'] = 'pink skin', + ['tint_army'] = 'army skin', + ['tint_lspd'] = 'blue skin', + ['tint_orange'] = 'orange skin', + ['tint_platinum'] = 'platinum skin', } diff --git a/locales/fr.lua b/locales/fr.lua index 55d849d6..4d83dd0e 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -189,4 +189,14 @@ Locales['fr'] = { ['ammo_snowball'] = 'boule(s) de neige', ['ammo_flare'] = 'fusée(s) éclairante(s)', ['ammo_flaregun'] = 'fusée(s)', + + -- Weapon Tints + ['tint_default'] = 'default skin', + ['tint_green'] = 'green skin', + ['tint_gold'] = 'gold skin', + ['tint_pink'] = 'pink skin', + ['tint_army'] = 'army skin', + ['tint_lspd'] = 'blue skin', + ['tint_orange'] = 'orange skin', + ['tint_platinum'] = 'platinum skin', } diff --git a/locales/pl.lua b/locales/pl.lua index 9ad79c2e..2c9d3bdc 100644 --- a/locales/pl.lua +++ b/locales/pl.lua @@ -189,4 +189,14 @@ Locales['pl'] = { ['ammo_snowball'] = 'snowball(s)', ['ammo_flare'] = 'flare(s)', ['ammo_flaregun'] = 'flare(s)', + + -- Weapon Tints + ['tint_default'] = 'default skin', + ['tint_green'] = 'green skin', + ['tint_gold'] = 'gold skin', + ['tint_pink'] = 'pink skin', + ['tint_army'] = 'army skin', + ['tint_lspd'] = 'blue skin', + ['tint_orange'] = 'orange skin', + ['tint_platinum'] = 'platinum skin', } diff --git a/locales/sv.lua b/locales/sv.lua index d1e41405..66060f6f 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -152,7 +152,7 @@ Locales['sv'] = { ['weapon_minismg'] = 'mini smg', ['weapon_pipebomb'] = 'pipe bomb', ['weapon_poolcue'] = 'biljardkö', - ['weapon_wrench'] = 'rörtång', + ['weapon_wrench'] = 'skiftnyckel', ['weapon_flashlight'] = 'ficklampa', ['gadget_parachute'] = 'fallskärm', ['weapon_flare'] = 'signalpistol', @@ -189,4 +189,14 @@ Locales['sv'] = { ['ammo_snowball'] = 'snöboll(ar)', ['ammo_flare'] = 'lysraket(er)', ['ammo_flaregun'] = 'lysraket(er)', + + -- Weapon Tints + ['tint_default'] = 'standardutseende', + ['tint_green'] = 'grönskinn', + ['tint_gold'] = 'guldskinn', + ['tint_pink'] = 'råsaskinn', + ['tint_army'] = 'arméskinn', + ['tint_lspd'] = 'blåskinn', + ['tint_orange'] = 'orangeskinn', + ['tint_platinum'] = 'platinaskinn', } diff --git a/server/classes/player.lua b/server/classes/player.lua index 3b931af8..0f5bf295 100644 --- a/server/classes/player.lua +++ b/server/classes/player.lua @@ -375,7 +375,8 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c name = weaponName, ammo = ammo, label = weaponLabel, - components = {} + components = {}, + tintIndex = 0 }) self.triggerEvent('esx:addWeapon', weaponName, ammo) @@ -408,6 +409,30 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c end end + self.setWeaponTint = function(weaponName, weaponTintIndex) + local loadoutNum, weapon = self.getWeapon(weaponName) + + if weapon then + local weaponNum, weaponObject = ESX.GetWeapon(weaponName) + + if weaponObject.tints and weaponObject.tints[weaponTintIndex] then + self.loadout[loadoutNum].tintIndex = weaponTintIndex + self.triggerEvent('esx:setWeaponTint', weaponName, weaponTintIndex) + self.triggerEvent('esx:addInventoryItem', weaponObject.tints[weaponTintIndex], false, true) + end + end + end + + self.getWeaponTint = function(weaponName) + local loadoutNum, weapon = self.getWeapon(weaponName) + + if weapon then + return weapon.tintIndex + end + + return 0 + end + self.removeWeapon = function(weaponName, ammo) local weaponLabel diff --git a/server/functions.lua b/server/functions.lua index 2a20eeea..b9cc7b87 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -159,7 +159,7 @@ ESX.GetItemLabel = function(item) end end -ESX.CreatePickup = function(type, name, count, label, playerId, components) +ESX.CreatePickup = function(type, name, count, label, playerId, components, tintIndex) local pickupId = (ESX.PickupId == 65635 and 0 or ESX.PickupId + 1) local xPlayer = ESX.GetPlayerFromId(playerId) @@ -173,9 +173,10 @@ ESX.CreatePickup = function(type, name, count, label, playerId, components) if type == 'item_weapon' then ESX.Pickups[pickupId].components = components + ESX.Pickups[pickupId].tintIndex = tintIndex end - TriggerClientEvent('esx:createPickup', -1, pickupId, label, playerId, type, name, components) + TriggerClientEvent('esx:createPickup', -1, pickupId, label, playerId, type, name, components, tintIndex) ESX.PickupId = pickupId end diff --git a/server/main.lua b/server/main.lua index ae630198..6e59e989 100644 --- a/server/main.lua +++ b/server/main.lua @@ -159,9 +159,8 @@ AddEventHandler('es:playerLoaded', function(playerId, player) -- Compatibility with old loadouts prior to components update for k,v in ipairs(userData.loadout) do - if v.components == nil then - v.components = {} - end + if not v.components then v.components = {} end + if not v.tintIndex then v.tintIndex = 0 end end end @@ -404,7 +403,7 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount) xPlayer.showNotification(_U('threw_weapon', weapon.label)) end - ESX.CreatePickup('item_weapon', itemName, weapon.ammo, pickupLabel, playerId, weapon.components) + ESX.CreatePickup('item_weapon', itemName, weapon.ammo, pickupLabel, playerId, weapon.components, weapon.tintIndex) end end end) @@ -445,6 +444,7 @@ AddEventHandler('esx:onPickup', function(id) else success = true xPlayer.addWeapon(pickup.name, pickup.count) + xPlayer.setWeaponTint(pickup.name, pickup.tintIndex) for k,v in ipairs(pickup.components) do xPlayer.addWeaponComponent(pickup.name, v)