Xwad Posted November 23, 2017 Share Posted November 23, 2017 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) Link to comment
Moderators IIYAMA Posted November 23, 2017 Moderators Share Posted November 23, 2017 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. Link to comment
Xwad Posted November 23, 2017 Author Share Posted November 23, 2017 Wow exatcly!! Thanks for your help again <3 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now