Jump to content

Vehicle weapon


Xwad

Recommended Posts

  
I made this but it does not work and i think i must give a bind for mouse 1 no? 
  
  
  
function attach ( source, commandName ) 
      local vehicle = getElementPosition ( source ) --Get the vehicle position 
      attachElements ( minigun, source, 0, 0, 5 ) --Attach the weapon to the vehicle. 
      local weapon = createWeapon("minigun", x, y, z + 1) --Create a Weapon 
      setWeaponClipAmmo(weapon, 99999) 
      setWeaponState(weapon, "firing") 
      setWeaponProperty(weapon, "fire_rotation", 0, -30, 0) -- Optionally adjust for model rotation (this value will be different for other weapons) 
end 
addCommandHandler ( "attach", attach ) 
  

Link to comment

There was so much errors in your code , try this should work but i didn't tested it

function attach ( ) 
      local theVehicle = getPedOccupiedVehicle ( localPlayer ) 
      if theVehicle then 
      local x,y,z = getElementPosition ( theVehicle )  
      local weapon = createWeapon("minigun", x, y, z + 1)  
      attachElements ( minigun, theVehicle, 0, 0, 5 )  
      setWeaponClipAmmo(weapon, 99999) 
      setWeaponState(weapon, "firing") 
      setWeaponProperty(weapon, "fire_rotation", 0, -30, 0)  
end 
end 
addCommandHandler ( "attach", attach ) 

Link to comment

You need a lot more than just that, you can set it up to fire in a variety of ways. For one, you can use getKeyState inside a render event. Or you can just bind a key using bindKey.

As looking around with it, I was working on something like this before, got pretty close to release - but as always I keep jumping between projects of mine.

Here's a little snippet of what I used to look around with my weapons(with restrictions and sensitivity);

local aimSensitivity = 30; 
  
function rotateGun_Handler(cX, cY, aX, aY, wX, wY, wZ) 
    local oX, oY, oZ, oRX, oRY, oRZ = getElementAttachedOffsets(theWeapon); 
    if (oRX-((cY-0.5)*aimSensitivity) > 345 or oRX-((cY-0.5)*aimSensitivity) < 30) then -- Pitch Restriction 
            oRX = oRX-((cY-0.5)*aimSensitivity); 
    end 
    if (oRZ-((cX-0.5)*aimSensitivity) > 330 or oRZ-((cX-0.5)*aimSensitivity) < 50) then -- Yaw Restriction 
            oRZ = oRZ-((cX-0.5)*aimSensitivity); 
    end 
    setElementAttachedOffsets(theWeapon, oX, oY, oZ, oRX, oRY, oRZ); 
    setCursorPosition(screenW/2, screenH/2); 
end 

I updated these with onClientCursorMove.

Link to comment

i think that i did something wrong

  
  
function attach ( ) 
      local theVehicle = getPedOccupiedVehicle ( localPlayer ) 
      if theVehicle then 
      local x,y,z = getElementPosition ( theVehicle ) 
      local weapon = createWeapon("minigun", x, y, z + 1) 
      attachElements ( minigun, theVehicle, 0, 0, 5 ) 
      setWeaponClipAmmo(weapon, 99999) 
      setWeaponState(weapon, "firing") 
      setWeaponProperty(weapon, "fire_rotation", 0, -30, 0) 
end 
end 
addCommandHandler ( "attach", attach ) 
  
local aimSensitivity = 30; 
  
function rotateGun_Handler(cX, cY, aX, aY, wX, wY, wZ) 
    local oX, oY, oZ, oRX, oRY, oRZ = getElementAttachedOffsets(theWeapon); 
    if (oRX-((cY-0.5)*aimSensitivity) > 345 or oRX-((cY-0.5)*aimSensitivity) < 30) then -- Pitch Restriction 
            oRX = oRX-((cY-0.5)*aimSensitivity); 
    end 
    if (oRZ-((cX-0.5)*aimSensitivity) > 330 or oRZ-((cX-0.5)*aimSensitivity) < 50) then -- Yaw Restriction 
            oRZ = oRZ-((cX-0.5)*aimSensitivity); 
    end 
    setElementAttachedOffsets(theWeapon, oX, oY, oZ, oRX, oRY, oRZ); 
    setCursorPosition(screenW/2, screenH/2); 
end 
  
function consoleSetPlayerPosition ( source, commandName, posX, posY, posZ ) 
    setElementPosition ( source, posX, posY, posZ ) 
end 
addCommandHandler ( "setpos", consoleSetPlayerPosition  ) 
  

Link to comment

Not sure

local screenW,screenH = guiGetScreenSize() 
local weapon 
function attach ( ) 
      local theVehicle = getPedOccupiedVehicle ( localPlayer ) 
      if theVehicle then 
      local x,y,z = getElementPosition ( theVehicle ) 
      weapon = createWeapon("minigun", x, y, z + 1) 
      attachElements ( weapon, theVehicle, 0, 0, 1 ) 
      setWeaponClipAmmo(weapon, 99999) 
      setWeaponState(weapon, "firing") 
      setWeaponProperty(weapon, "fire_rotation", 0, -30, 0) 
end 
end 
addCommandHandler ( "attach", attach ) 
local aimSensitivity = 30; 
  
function rotateGun_Handler(cX, cY, aX, aY, wX, wY, wZ) 
    local oX, oY, oZ, oRX, oRY, oRZ = getElementAttachedOffsets(weapon); 
    if (oRX-((cY-0.5)*aimSensitivity) > 345 or oRX-((cY-0.5)*aimSensitivity) < 30) then -- Pitch Restriction 
            oRX = oRX-((cY-0.5)*aimSensitivity); 
    end 
    if (oRZ-((cX-0.5)*aimSensitivity) > 330 or oRZ-((cX-0.5)*aimSensitivity) < 50) then -- Yaw Restriction 
            oRZ = oRZ-((cX-0.5)*aimSensitivity); 
    end 
    --setCameraTarget(localPlayer,weapon) 
    setCameraTarget(weapon) 
    --setCameraMatrix(wX,wY,wZ) 
    setElementAttachedOffsets(weapon, oX, oY, oZ, oRX, oRY, oRZ); 
    setCursorPosition(screenW/2, screenH/2); 
end 
addEventHandler( "onClientCursorMove", getRootElement( ), rotateGun_Handler) 

Link to comment

Do you even read the code?

When you create the minigun, you have this line of code;

setWeaponState(weapon, "firing") 

Of course it will always be firing when you set its weapon state to firing :P

Edit:

To "enter" the minigun, you're best off using collision spheres, attach it to the minigun and trigger an event whenever a client enters it. So whenever a player is inside that sphere, and he press for example E, he will be attached to the minigun.

Link to comment
Thanks! And what function need i use to enter the minigun?
To "enter" the minigun, you're best off using collision spheres, attach it to the minigun and trigger an event whenever a client enters it. So whenever a player is inside that sphere, and he press for example E, he will be attached to the minigun.
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...