[Release] [ESX] Easy Weapon Accessories (Add and remove attachments)

Ah, I’m not sure I just use Inventory hud, drag the item onto use and it’s all good from there

ahh yeah, i think its cause im still on esx inventory system :slight_smile:

Either way, Nice work :slight_smile:

This is not very related, but how do I make this line work with mythic_notification?
Answer: check 2 posts below

ESX.ShowNotification(string.format(’%s %s’, "You’ve equipped your ", type))

Also how do you ‘unequipped’ the items (suppressor, grip etc)?
Answer: ARROWUP key

Just change where the notification is to work with Mythics, no idea how but… it shouldn’t be too hard, let me know if you find out, it’d also be good to add mythics progress bar too it.

I know you edited it but the answer to the removal is in the description :stuck_out_tongue:

If you find out how to do anything mythic ui wise let me know and i’ll push it as a pull request on the github :slight_smile:

And here is how to make it work with mythic_progbar. Feel free to use it @Gregamite

-- Use item mythic_progbar
RegisterNetEvent('eden_accesories:use')
AddEventHandler('eden_accesories:use', function( type )
	TriggerEvent("mythic_progbar:client:progress", {
			name = "weapon_attachment",
			duration = 10000,
			label = "Applying Weapon attachment",
			useWhileDead = false,
			canCancel = true,
			controlDisables = {
					disableMovement = false,
					disableCarMovement = false,
					disableMouse = false,
					disableCombat = true,
			},
			animation = {
					animDict = "missheistdockssetup1clipboard@idle_a",
					anim = "idle_a",
					flags = 49,
			},
			prop = {
					model = "prop_ld_ammo_pack_02",
			}
		}, function(status)
			if not status then
				if weapons[GetSelectedPedWeapon(PlayerPedId())] and weapons[GetSelectedPedWeapon(PlayerPedId())][type] then
					if not HasPedGotWeaponComponent(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), weapons[GetSelectedPedWeapon(PlayerPedId())][type]) then
						GiveWeaponComponentToPed(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), weapons[GetSelectedPedWeapon(PlayerPedId())][type])  
						exports['mythic_notify']:DoHudText('inform', 'You\'ve equiped your weapon attachment')
						--ESX.ShowNotification(string.format('%s %s', "You've equiped your ", type))
					else
						RemoveWeaponComponentFromPed(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), weapons[GetSelectedPedWeapon(PlayerPedId())][type])  
						exports['mythic_notify']:DoHudText('inform', 'You\'ve removed the weapon attachment')
						--ESX.ShowNotification(string.format('%s %s', "You've removed your ", type))
					end
				else
					exports['mythic_notify']:DoHudText('error', 'The attachment doesn\'t fit with your weapon')
					--ESX.ShowNotification(string.format('%s %s %s', 'The ', type, " doesn't fit on your weapon.."))
				end
			end
			
		end)
	end)

I am too lazy to make another one for mythic_progbar so I quickly did the ‘taking off attachment’ with Progress Bars 1.0 [Stand Alone] with the below script. Not the best way, but it works.

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		if IsControlJustPressed(0, 172) then
			if weapons[GetSelectedPedWeapon(PlayerPedId())] then
				for k,v in pairs(weapons) do
					if GetSelectedPedWeapon(PlayerPedId()) == k then
						if HasPedGotWeaponComponent(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), v.suppressor) then
							exports['progressBars']:startUI(3500, "Taking Off Suppressor")
							Citizen.Wait(3500)
							TriggerServerEvent('eden_accesories:giveBack', 'suppressor')
							exports['mythic_notify']:DoHudText('inform', 'You\'ve removed your weapon suppressor')
							--ESX.ShowNotification("You've removed your weapon suppressor")
							RemoveWeaponComponentFromPed(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), v.suppressor)
						elseif HasPedGotWeaponComponent(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), v.flashlight) then
							exports['progressBars']:startUI(3500, "Taking Off Flashlight")
							Citizen.Wait(3500)
							TriggerServerEvent('eden_accesories:giveBack', 'flashlight')
							exports['mythic_notify']:DoHudText('inform', 'You\'ve removed your weapon flashlight')
							--ESX.ShowNotification("You've removed your weapon flashlight")
							RemoveWeaponComponentFromPed(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), v.flashlight)
						elseif HasPedGotWeaponComponent(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), v.skin) then
							exports['progressBars']:startUI(3500, "Taking Off Weapon Skin")
							Citizen.Wait(3500)
							TriggerServerEvent('eden_accesories:giveBack', 'yusuf')
							exports['mythic_notify']:DoHudText('inform', 'You\'ve removed your weapon skin')
							--ESX.ShowNotification("You've removed your weapon skin")
							RemoveWeaponComponentFromPed(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), v.skin)
						elseif HasPedGotWeaponComponent(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), v.grip) then
							exports['progressBars']:startUI(3500, "Taking Off Weapon Grip")
							Citizen.Wait(3500)
							TriggerServerEvent('eden_accesories:giveBack', 'grip')
							exports['mythic_notify']:DoHudText('inform', 'You\'ve removed your weapon grip')
							--ESX.ShowNotification("You've removed your weapon grip")
							RemoveWeaponComponentFromPed(GetPlayerPed(-1), GetSelectedPedWeapon(PlayerPedId()), v.grip)
						end
					end
				end
			end
		end
	end
end)
1 Like

If you use one of the items and you don’t have the correct weapon it gives the notification: That there is no weapon to use it. but instead of just giving the notification it also removes the item

Fix it then :wink: Haha and if you do post it here and i’ll push the change

pretty sure they all work with most guns, i added 20 random guns and everything works on them, are you sure you are not pressing escape after using the item? press right click instead and it wont remove the attachment.

Can you make it so that when you press 1,2,3,4 or 5 that the attachments are removed and put back in the inventory?

Why do i asked this? Because im using a inv HUD -> [Deprecated] [ESX] Disc-InventoryHUD

And the attachments are removed when i press 1 till 5.

No.

It’s setup how it is setup, make the changes you need for you, yourself.

The item dosent remove from my inventory when i attach it, and when i remove the item, it just duplicate the inventory with a new one. Is this something you can fix?

Works fine for me and others, please post logs etc maybe get a video too

I’m slowly working on adding a lot of components missing (Extended Clip, Muzzle Break, Compensator, Scopes, etc), as well as MK2 weapons (You need to make sure the MK2 weapons and components are added to es_extended)

I’m not adding it all because I feel like there should be a way to index the components in a table when its just the number at the end that changes, especially skins, since most of them go:

COMPONENT_REVOLVER_MK2_CAMO_02
to
COMPONENT_REVOLVER_MK2_CAMO_07, etc,etc (Usually from 02 to 10)

I’m still learning Code so bear with me while I figure out how to do this kind of stuff.
Because there are many muzzle breaks and shit too…
And barrels…
And tints…

Tints I haven’t touched yet, but I will… again, need a way to easily have a table of tints and only call the number after it, or else you would need to add like 20 lines PER MK2 weapon… seems like a lot of repetitive code…

I will send a pull or merge or whatever once I’m done! Save you guys some work.

For references on tints, I’ve been looking at this: xnWeapons v1.0.1 - A beautiful and intuitive weapon shop resource. **NOT FOR RP SERVERS**

But seems like it wouldn’t be too complicated… check weapon, check tint, get number of tint, apply to weapon.

The tricky part is going to be altering the weapon tables everywhere (property inventories, trunks, trading items) to add components and not fuck up the old data? (Maybe? Still a Trial Dev here LOL…)

3 Likes

As someone who’s literally just done this, don’t do what I did and make your own storage system. Piggyback off of ESX’s weapons.config.lua and change the way weapons are stored and loaded. (you will need to edit es_extended) then add your own xPlayer functions to add/remove weapons but with more info about tints and components and such.

That would be pretty awesome, liking the sound of it, take your time man! Look forward to the merge from you

My players have informed me of a bug. And its strange lol. The weapons today, for some reason, lose their attachments on logout

Checking in the db the weapons have no components under loadout.

Anyone else run into this?

:stuck_out_tongue: Not a bug

> Loadout updates happen automatically through es_extended
*> *
> The other scope/attachment script floating around had no DB calls? Yet still saved your gun when logging in and out… I’m looking into it…

Nevermind everything I said above. I believe vMenu was helping with the loadout. Old script does not work either. Sorry about that.

Excellent work strongly the weapon accessories back up in the DB

Hi, were u working with saving these components to DB yet? It’s the only one thing that I want implement to this script for my server, because when somone is crashed with the accessory he lose it ;/

1 Like