Sign in to follow this  
Xwad

rotating attached object not working

Recommended Posts

Everythink is working in the code, only the rotating not. When i press mouse1 then the weapons and the object will be created but its not rotating. This rotating function makes possible to rotate the object called "object3" to that direction where the "misc_a" (vehicle component) and the "misc_c" (vehicle component) is rotating at. The problem is that its not rotating the object. I hope you can help me again. Thanks in advance!

 

client

object3 = {};
mg1 = {};
mg2 = {};

addEvent ( 'fire_mg',true );
addEventHandler ( 'fire_mg',root,
  function ( aVehicle,aX,aY,aZ )
      if aVehicle and aX and aY and aZ then
	    object3 [ aVehicle ] = createObject ( 357, aX,aY,aZ)
        attachElements ( object3 [ aVehicle ], aVehicle, -0.05,10,3, 0,0,90 )
	    mg1 [ aVehicle ] = createWeapon("m4", aX,aY,aZ)
	    mg2 [ aVehicle ] = createWeapon("m4", aX,aY,aZ)
     	setWeaponFiringRate(mg1 [ aVehicle ], 20)
	    setWeaponFiringRate(mg2 [ aVehicle ], 20)
        setWeaponState(mg1 [ aVehicle ], "firing")
        setWeaponState(mg2 [ aVehicle ], "firing")
	    attachElements(mg1 [ aVehicle ], object3 [ aVehicle ], 0.2, 0.2, 0, 0, 0, 0)
	    attachElements(mg2 [ aVehicle ], object3 [ aVehicle ], 0.2, -0.3, 0, 0, 0, 0)			
	  
        setElementData ( aVehicle,'mgFireOn',true );
        
		local veh = getPedOccupiedVehicle(localPlayer)
		setElementData ( aVehicle,'object3',object3 [ aVehicle ] );
		
		addEventHandler("onClientRender",root,rotate_object)
    end
end
);

function rotate_object()
local veh = getPedOccupiedVehicle(localPlayer)
local _,_,rz = getVehicleComponentRotation(veh, "misc_a")
local rx,_,_ = getVehicleComponentRotation(veh, "misc_c")
triggerServerEvent("rotateWeapon", localPlayer, rx,rz)
end 

server

function rotateWeapon(rx,rz)
outputChatBox("rotate_s")
local object3 = getElementData ( aVehicle, "object3" )
rx = (-rx)
setElementAttachedOffsets ( object3, 0, 5.25, 2.45, 0, rx+7, rz+96)
end
addEvent("rotateWeapon", true)
addEventHandler("rotateWeapon", root, rotateWeapon)


function fire ( aPlayer )
    if aPlayer and getElementType ( aPlayer ) == 'player' then
      if isPedInVehicle ( aPlayer ) then
        local aVehicle = getPedOccupiedVehicle( aPlayer );
        if aVehicle and getElementModel ( aVehicle ) == 592 then
          local aX,aY,aZ = getElementPosition ( aVehicle );
          triggerClientEvent ( root,'fire_mg',root,aVehicle,aX,aY,aZ );
      end
    end
  end
end


function bind_start()
for _,aPlayers in ipairs ( getElementsByType ( 'player' ) ) do
bindKey ( aPlayers,'mouse1','down',fire );
end
end
addEventHandler ( 'onResourceStart',resourceRoot,bind_start)

function bind_join()
bindKey ( aPlayers,'mouse1','down',fire );
end
addEventHandler ( 'onPlayerJoin',root,bind_join )

 

Share this post


Link to post

You are changing the offsets and not the rotation itself. Use setElementRotation instead of setElementAttachedOffsets.

Also using triggerServerEvent in onClientRender isn't really wise. There's no need to change the rotation server sided since you're using vehicle component rotations, so it could be done client sided and every player would see the same thing.

Edited by MIKI785

Share this post


Link to post
Quote

You are changing the offsets and not the rotation itself. Use setElementRotation instead of setElementAttachedOffsets.

the wiki says:  "This function updates the offsets of an element that has been attached to another element using attachElements."

thats why i am using  setElementAttachedOffsets and not setElementRotation.

 

Quote

Also using triggerServerEvent in onClientRender isn't really wise. There's no need to change the rotation server sided since you're using vehicle component rotations, so it could be done client sided and every player would see the same thing.

Thats true, i gonna try it:D

Share this post


Link to post

Rotation offset is not the same as rotation. Offset specifies the X, Y, and Z points that the element should rotate around (like the center of the element).

Did you even try using setElementRotation?

Share this post


Link to post

Now i test it and i am sure that the problem is not with the element rotation. The problem is with the setElementData.. it dosent get the element data of the object called "object3", and thats why it cant rotate it

Share this post


Link to post

The object was created client side, so it doesn't exist on the server. Do it all client-sided as I told you before.

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.