Hi im here because i dont know what is the problem on my plugin!
Im police and when i change my skin to a model my guns disappear.
How can i solve that?
changing models means your ped gets replaced with a new ped. So that new ped doesn’t have your old ped’s weapons, you’ll need to save all weapons, attachments, tints, ammo, etc before changing skins, then restore it afterwards.
Can u teach me how to do that?
Oh that means that i need to be without guns and then change models right?
no, you need to save the weapons (checking for each weapon if the player has them, then checking all possible weapon components to see if any of them are attached to a weapon, then also save ammo and weapon tint related data) then give all those things back to the player after they’ve changed skins.
So im police and use esx_policejob in cloakroom i put one model and when i change the models i lose my guns so can u teach me how to do that?
i already said it twice, and no im not going to code it for you. It’s not hard, but it takes time to do.
ok thanks
Like it happened a long time, but … you got it fixed?
For example, code from VRP (by imagic):
local weapon_types = {
"WEAPON_KNIFE",
"WEAPON_STUNGUN",
"WEAPON_FLASHLIGHT",
"WEAPON_NIGHTSTICK",
"WEAPON_HAMMER",
"WEAPON_BAT",
"WEAPON_GOLFCLUB",
"WEAPON_CROWBAR",
"WEAPON_PISTOL",
"WEAPON_COMBATPISTOL",
"WEAPON_APPISTOL",
"WEAPON_PISTOL50",
"WEAPON_MICROSMG",
"WEAPON_SMG",
"WEAPON_ASSAULTSMG",
"WEAPON_ASSAULTRIFLE",
"WEAPON_CARBINERIFLE",
"WEAPON_ADVANCEDRIFLE",
"WEAPON_MG",
"WEAPON_COMBATMG",
"WEAPON_PUMPSHOTGUN",
"WEAPON_SAWNOFFSHOTGUN",
"WEAPON_ASSAULTSHOTGUN",
"WEAPON_BULLPUPSHOTGUN",
"WEAPON_STUNGUN",
"WEAPON_SNIPERRIFLE",
"WEAPON_HEAVYSNIPER",
"WEAPON_REMOTESNIPER",
"WEAPON_GRENADELAUNCHER",
"WEAPON_GRENADELAUNCHER_SMOKE",
"WEAPON_RPG",
"WEAPON_PASSENGER_ROCKET",
"WEAPON_AIRSTRIKE_ROCKET",
"WEAPON_STINGER",
"WEAPON_MINIGUN",
"WEAPON_GRENADE",
"WEAPON_STICKYBOMB",
"WEAPON_SMOKEGRENADE",
"WEAPON_BZGAS",
"WEAPON_MOLOTOV",
"WEAPON_FIREEXTINGUISHER",
"WEAPON_PETROLCAN",
"WEAPON_DIGISCANNER",
"WEAPON_BRIEFCASE",
"WEAPON_BRIEFCASE_02",
"WEAPON_BALL",
"WEAPON_FLARE"
}
function getWeapons()
local player = GetPlayerPed(-1)
local ammo_types = {}
local weapons = {}
for k,v in pairs(weapon_types) do
local hash = GetHashKey(v)
if HasPedGotWeapon(player,hash) then
local weapon = {}
weapons[v] = weapon
local atype = Citizen.InvokeNative(0x7FEAD38B326B9F74, player, hash)
if ammo_types[atype] == nil then
ammo_types[atype] = true
weapon.ammo = GetAmmoInPedWeapon(player,hash)
else
weapon.ammo = 0
end
end
end
return weapons
end
function giveWeapons(weapons, clear_before)
local player = GetPlayerPed(-1)
if clear_before then
RemoveAllPedWeapons(player,true)
end
for k,weapon in pairs(weapons) do
local hash = GetHashKey(k)
local ammo = weapon.ammo or 0
GiveWeaponToPed(player, hash, ammo, false)
end
end
function setArmour(amount)
SetPedArmour(GetPlayerPed(-1), amount)
end
function getArmour()
return GetPedArmour(GetPlayerPed(-1))
end
function setHealth(amount)
SetEntityHealth(GetPlayerPed(-1), math.floor(amount))
end
function getHealth()
return GetEntityHealth(GetPlayerPed(-1))
end
function LoadModel(modelhash)
Citizen.CreateThread(function()
local i = 0
while not HasModelLoaded(modelhash) and i < 10000 do
RequestModel(modelhash)
Citizen.Wait(10)
i=i+1
end
if HasModelLoaded(modelhash) and IsModelInCdimage(modelhash) and IsModelValid(modelhash) then
local weapons = getWeapons()
local armour = getArmour()
local health = getHealth()
SetPlayerModel(PlayerId(), modelhash)
giveWeapons(weapons,true)
setArmour(armour)
setHealth(health)
SetModelAsNoLongerNeeded(modelhash)
end
end)
end
Would it work for ESX?
Yes I fixed
could you tell me how? I’ve been searching for days without finding anything
Basically, use the above list and run through it with a for loop ex:
for _,weapon in pairs(weapon_types) do
if HasPedGotWeapon(PlayerPedId(), GetHashKey(weapon), false) then
-- Check ammo count/skins etc
end
end
In extended?
A week later I still can not get it, I do not know where I have to put it …
can u give it to me in vrp framework and where can i put that script
mmmm? VRP2 already have it.
i got vrp 1.0
I know this is an old thread but it’s never late to say thank you. This helped me today! <3