Xwad Posted January 31, 2016 Share Posted January 31, 2016 Hi i made a script where i attach an m4 gun to a car. Its working ,the only problem is that i cant rotate the weapon when its attached to the vehicle:/ Maybe the setElementRotation is not good for that? function attach(theElement) local x,y,z = getElementPosition ( vehicle ) local x,y,z = getElementPosition(localPlayer) local vehicle = getPedOccupiedVehicle (localPlayer) local rotX, rotY, rotZ = getElementRotation(weapon) if vehicle then weapon = createWeapon("m4", x, y, z+10) setElementRotation(weapon,rotX,rotY+4,rotZ+43) setWeaponState(weapon, "ready") attachElements ( weapon, vehicle, -0.4, 0.5, 1.5 ) outputChatBox ( "Machinegun attached!" ) end end addEvent( "attach", true ) addEventHandler( "attach", localPlayer, attach ) Link to comment
Dealman Posted January 31, 2016 Share Posted January 31, 2016 No, you can not use setElementRotation on attached objects. See these 2 functions instead; getElementAttachedOffsets setElementAttachedOffsets Link to comment
Xwad Posted January 31, 2016 Author Share Posted January 31, 2016 i tried to rotate it but its not working:/ Whats the problem? -- Offsets local x,y,z,rx,ry,rz= 0,0.2,1.5,0,0,90 function createArmedBobcat(cmd, commandName) local lx, ly, lz = getElementPosition(localPlayer) -- get the position of the player lx = lx + 5 -- add 5 units to the x position base = createWeapon("m4", x, y, z) veh = createVehicle( 470, lx, ly, lz) -- create a bobcat setElementCollisionsEnabled ( base, false ) -- the minigun_base damages the car -- you could alternatively load an empty col file for the minigun object attachElements ( base, veh, x,y,z,rx,ry,rz) -- attach the base to the bobcat end function rotateIt(cmd, addZ) if(addZ) then local x, y, z, rx, ry, rz = getElementAttachedOffsets (base) -- get the offsets rz = rz + addZ setElementAttachedOffsets (base, x, y, z, rx+10, ry, rz+5) -- update offsets end end addCommandHandler("car", createArmedBobcat) addCommandHandler("rotate", rotateIt) Link to comment
Xwad Posted February 7, 2016 Author Share Posted February 7, 2016 can i also rotate player with setElementAttachedOffsets? becaouse i tryed it and its not working with player only with objects function attach() setPedAnimation ( source, "SILENCED", "SilenceCrouchfire", 1, false, false, false, true ) attachElements ( source, weapon, 0, 0.06, 0, 10, 20, 30 ) toggleControl (source,"fire", false) local x, y, z, xr, yr, yz = getElementAttachedOffsets(source) setElementAttachedOffsets(source, 3, 4, 4, 25, 50, 30) <-- look here. The player rotation is not changing.. end addEvent("attachPlayerToMinigun", true) addEventHandler("attachPlayerToMinigun",getRootElement(), attach) 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