Jump to content

setElementRotation Using Binds


Deep thinker

Recommended Posts

hello i was making a script which is depending on the rotation but i was trying to rotate it when i press a button the full script is to create a minigun and attach it to the player's body and allow him to rotate the weapon without aiming it.

function createMinigunWeapon()
    -- Create the weapon 1 meter above the player
    local x, y, z = getElementPosition(getLocalPlayer())
    local weapon = createWeapon("minigun", x, y, z + 5)
    local rotX, rotY, rotZ = getElementRotation(weapon)
    bindKey("num_6","down",
    function()
    setElementRotation(weapon,0,0,rotZ+10)
    end
    )

also i have read the wiki ,i tried to follow its instructions but i totally failed :3

notice : i have just posted the part i need in the script

Link to comment
10 minutes ago, iPrestege said:

Try this :

 


local x,y,z = getElementPosition ( localPlayer );
local weapon = createWeapon( 'minigun',x,y,z+2 );

bindKey ( 'num_6','down',
function (      )
        if not weapon then return end;
        local _,_,rotZ = getElementRotation ( weapon );
        setElementRotation ( weapon,0,0,rotZ+10 );
    end
);

 

actually it works efficiently :3 but i want to check if the player is in vehicle then attach the minigun into the car

Link to comment
34 minutes ago, Dimos7 said:

isPedInVehicle
attachElements

 

actually i tried to use 

getPedOccupiedVehicle

it worked but attaching the elements didn't work at all

addCommandHandler("bobo",
function ()   
   local position = Vector3(getElementPosition (localPlayer)) 
     local weapon = createWeapon( 'minigun',position.x, position.y, position.z + 3 );
     if ( isCar ) then
     local car = getPedOccupiedVehicle ( source )
     attachElements ( weapon, car, 0, 0, 1, 0, 90, 0 ) end

there is anther parts but i just posted what i need 

Link to comment
addCommandHandler("bobo",
function ()   
   local position = Vector3(getElementPosition (localPlayer)) 
     local weapon = createWeapon( 'minigun',position.x, position.y, position.z + 3 );
     if ( isPedInVehicle(localPlayer )) then
     local car = getPedOccupiedVehicle ( localPlayer )
     attachElements ( weapon, car, 0, 0, 1, 0, 90, 0 ) end

 

Link to comment
4 minutes ago, Dimos7 said:

addCommandHandler("bobo",
function ()   
   local position = Vector3(getElementPosition (localPlayer)) 
     local weapon = createWeapon( 'minigun',position.x, position.y, position.z + 3 );
     if ( isPedInVehicle(localPlayer )) then
     local car = getPedOccupiedVehicle ( localPlayer )
     attachElements ( weapon, car, 0, 0, 1, 0, 90, 0 ) end

 

it worked but i can't rotate now

 

1 hour ago, iPrestege said:

Try this :

 


local x,y,z = getElementPosition ( localPlayer );
local weapon = createWeapon( 'minigun',x,y,z+2 );

bindKey ( 'num_6','down',
function (      )
        if not weapon then return end;
        local _,_,rotZ = getElementRotation ( weapon );
        setElementRotation ( weapon,0,0,rotZ+10 );
    end
);

 

 

Link to comment
addCommandHandler("bobo",
function ()   
   local position = Vector3(getElementPosition (localPlayer)) 
     local weapon = createWeapon( 'minigun',position.x, position.y, position.z + 3 );
     if ( isPedInVehicle(localPlayer )) then
     local car = getPedOccupiedVehicle ( localPlayer )
     local _,_, rotZ = getElementRotation(weapon)
     setElementRotation(weapon, 0, 0 , rotZ+10)
     attachElements ( weapon, car, 0, 0, 1, 0, 90, 0 ) 
    end
end)

 

Link to comment

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...