Xwad

getAttachedElements

Recommended Posts

Hello. As you can see, in my script i attached 2 weapons to a vehicle. I set a bind for shooting one of the gun. My problem is that when i start the function called "fire_gun_c" then both of the weapons will be fired. So my question is how can i only shoot the weapon "gun1" by using getAttachedElements? 

 

 

client

function attach()
local gun1 = createWeapon(31, 0,0,0)
local gun2 = createWeapon(31, 0,0,0)

attachElements ( gun1, veh, 0, 1, 0)
attachElements ( gun1, veh, 0, -1, 0)
end



function fire_gun_c(veh)
local attachedElements = getAttachedElements(veh)
for ElementKey, ElementValue in ipairs ( attachedElements ) do
  
fireWeapon ( ElementValue ) -- it fires both of the guns because it gets all the data with getAttachedElements 
end
end
addEvent("fire_gun_c", true)
addEventHandler ( "fire_gun_c", resourceRoot, fire_gun_c)

 

Share this post


Link to post
local attachedElements = getAttachedElements(veh)
if attachedElements[1] then
	fireWeapon ( attachedElements[1] )
end

 

P.s. you are not attaching gun2 in your code. There is a typo.

Share this post


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.