Weapons for ped

Well i’m currently working with peds and the weapons they can use but for some reason i can’t get to work this function:

GiveWeaponToPed(ped, GetHashKey("WEAPON_BOTTLE"), 1, true, true)
GiveWeaponToPed(ped, GetHashKey("WEAPON_PISTOL"), math.random(20, 100), true, false)
SetPedAmmo(ped, GetHashKey("WEAPON_PISTOL"), math.random(20, 100))
SetCurrentPedWeapon(ped, GetHashKey("WEAPON_BOTTLE"), true)

What i want is that the ped can only use the weapon which is currently equiped so the WEAPON_BOTTLE but for some reason the ped just switch the weapon when i attack him

why hide the weapons? (true highlighted).
Also, why are you setting the ammo count for the pistol, after you’ve already randomized the ammo in the first place?

Easiest way would probably be to just use these two, remove the other ones and put it in this order:

GiveWeaponToPed(ped, GetHashKey("WEAPON_PISTOL"), math.random(20, 100), false, false)
GiveWeaponToPed(ped, GetHashKey("WEAPON_BOTTLE"), 1, false, true)

haven’t tested it but it should work.

I’m setting the ammo because after randomiez for some reason the ped still droping a weapon with infinite ammo i dont know why…

And its not working already tested with that before… the ped is spawning without the weapon but after i attack him he just switch even if i set the AI to dont switch weapons

That’s very strange, just tested it and it works fine for me. Got any scripts that could be conflicting with your setup? or perhaps using a trainer with infinite ammo?

That doesnt the problem with just that like setting again the ammo to the ped is fixed i dont really care about that… but the problem is the weapon usage of the ped

could also be another script conflicting, or you’re using it incorrectly (not sure though cause what you showed in OP looks fine) or there’s a bug with that native :confused: