Jump to content

RearmPlayerWeapon


Recommended Posts

I'm want to make the function run with a loop for 3 possible weapons and only give/ take away 1 weapon at a time.

but it removes primary weapon from back when i equip secondary or vise versa 

also only equips secondary when equiping any weapon.

 

function rearmPlayerWeapon(weaponName,slot,slot1,slot2,slot3)
	takeAllWeapons(source)
	setElementData(source,"currentweapon_"..slot,weaponName)
	 weapon = getElementData(source,"currentweapon_1")
	if weapon then
	  for id,item in pairs(weaponTable)do
		if weapon == item[1] and getElementData(source,item[1])>= 1 and getElementData(source,item[2])>= 1 and item[5] == 1 then
		  	ammoData,weapID = getWeaponAmmoType(weapon)
		  	removeWeaponBack()
		  	giveWeapon(source,weapID,getElementData(source,ammoData),slot1)
		end
	  end
	end
	 weapon2 = getElementData(source,"currentweapon_2")
	if weapon2 then
	  for id,item in pairs(weaponTable)do
		if weapon2 == item[1] and getElementData(source,item[1])>= 1 and ((getElementData(source,item[2]) and getElementData(source,item[2])>= 1) or item[2] == "others") and item[5] == 2 then
			ammoData2,weapID2 = getWeaponAmmoType(weapon2)
			removeWeaponBackSec()
		  	giveWeapon(source,weapID2,getElementData(source,ammoData2),slot2)
		end
	  end
	end
	weapon3 = getElementData(source,"currentweapon_3")
	if weapon3 then
	  for id,item in pairs(weaponTable)do
		if weapon3 == item[1] and getElementData(source,item[1])>= 1 and item[5] == 3 then
			ammoData3,weapID3 = getWeaponAmmoType(weapon3)
			removeWeaponBackSpe()
		  	giveWeapon(source,weapID3,getElementData(source,ammoData3),slot3)
		end
	  end
	end
	triggerClientEvent(source,"refreshInventoryManual",source)
  end
  addEvent("onPlayerRearmWeapon",true)
  addEventHandler("onPlayerRearmWeapon",getRootElement(),rearmPlayerWeapon)

 

Link to post
  • Other Languages Moderators

You need to write in Portuguese if you want to post on the Portuguese Section.

Topic moved to international section.

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...