Jump to content

Mounted vehicle weapons


ItachiUchiha

Recommended Posts

Hi! I'm a new fag on this, I barely could build this script to make that the car have weapons mounted (like Twisted Metal cars):

local weapon = createWeapon("ak47", 0, 0, 1 ) 
local weapon2 = createWeapon("ak47", 0, 0, 1 ) 
    setElementAlpha ( weapon, 0) 
    setElementAlpha ( weapon2, 0) 
local weaponINV = createWeapon("ak47", 0, 0, 1 ) 
local weapon2INV = createWeapon("ak47", 0, 0, 1 ) 
  
function createAndFire() 
      local theVehicle = getPedOccupiedVehicle ( localPlayer ) 
      if theVehicle then 
        local x,y,z = getElementPosition ( theVehicle ) 
        local rX,rY,rZ = getElementRotation(theVehicle) 
    attachElements ( weapon, theVehicle, 1, 2, 0, 0, 0, 90 ) 
    attachElements ( weapon2, theVehicle, -1, 2, 0, 0, 0, 90 ) 
    attachElements ( weaponINV, theVehicle, 1, 2, 0, 0, 0, 95 ) 
    attachElements ( weapon2INV, theVehicle, -1, 2, 0, 0, 0, 95 ) 
        fireWeapon(weapon) 
        fireWeapon(weapon2) 
      end 
end 
bindKey("mouse2", "down", createAndFire) 
addEventHandler("onClientResourceStart", resourceRoot, createAndFire) 

This works good. But now I wanted to know how to make it works with other players. I mean, I tested it with my friend and when I shoot him he don't get damage, and he can't see my weapons on the car too, and I either.

Link to comment
addEventHandler("onPlayerLogin", root 
    function() 
        bindKey(source, "mouse2", "down", createAndFire) 
    end 
) 
addEventHandler("onResourceStart", resourceRoot, 
   function() 
       for _, v in ipairs(getElementsByType("player")) do 
           bindKey(v, "mouse2", "down", createAndFire) 
       end 
    end 
) 
  
local weapon = createWeapon("ak47", 0, 0, 1 ) 
local weapon2 = createWeapon("ak47", 0, 0, 1 ) 
    setElementAlpha ( weapon, 0) 
    setElementAlpha ( weapon2, 0) 
local weaponINV = createWeapon("ak47", 0, 0, 1 ) 
local weapon2INV = createWeapon("ak47", 0, 0, 1 ) 
  
function createAndFire(thePlayer) 
      local theVehicle = getPedOccupiedVehicle (thePlayer ) 
      if theVehicle then 
        local x,y,z = getElementPosition ( theVehicle ) 
        local rX,rY,rZ = getElementRotation(theVehicle) 
    attachElements ( weapon, theVehicle, 1, 2, 0, 0, 0, 90 ) 
    attachElements ( weapon2, theVehicle, -1, 2, 0, 0, 0, 90 ) 
    attachElements ( weaponINV, theVehicle, 1, 2, 0, 0, 0, 95 ) 
    attachElements ( weapon2INV, theVehicle, -1, 2, 0, 0, 0, 95 ) 
        fireWeapon(weapon) 
        fireWeapon(weapon2) 
      end 
end 
addEventHandler("onResourceStart", resourceRoot, createAndFire) 

Link to comment
addEventHandler("onPlayerLogin", root 
    function() 
        bindKey(source, "mouse2", "down", createAndFire) 
    end 
) 
addEventHandler("onResourceStart", resourceRoot, 
   function() 
       for _, v in ipairs(getElementsByType("player")) do 
           bindKey(v, "mouse2", "down", createAndFire) 
       end 
    end 
) 
  
local weapon = createWeapon("ak47", 0, 0, 1 ) 
local weapon2 = createWeapon("ak47", 0, 0, 1 ) 
    setElementAlpha ( weapon, 0) 
    setElementAlpha ( weapon2, 0) 
local weaponINV = createWeapon("ak47", 0, 0, 1 ) 
local weapon2INV = createWeapon("ak47", 0, 0, 1 ) 
  
function createAndFire(thePlayer) 
      local theVehicle = getPedOccupiedVehicle (thePlayer ) 
      if theVehicle then 
        local x,y,z = getElementPosition ( theVehicle ) 
        local rX,rY,rZ = getElementRotation(theVehicle) 
    attachElements ( weapon, theVehicle, 1, 2, 0, 0, 0, 90 ) 
    attachElements ( weapon2, theVehicle, -1, 2, 0, 0, 0, 90 ) 
    attachElements ( weaponINV, theVehicle, 1, 2, 0, 0, 0, 95 ) 
    attachElements ( weapon2INV, theVehicle, -1, 2, 0, 0, 0, 95 ) 
        fireWeapon(weapon) 
        fireWeapon(weapon2) 
      end 
end 
addEventHandler("onResourceStart", resourceRoot, createAndFire) 

Didn't work, using this i can't see the weapons and don't fire too

Link to comment
You should really read the MTA Wiki:

https://wiki.multitheftauto.com/wiki/CreateWeapon

or atleast use the debugscript ...

Sure, I did it. The problem is that I don't know LUA, I build that script using common sense and google, I wasted a lot of time doing that and reading old posts from this forum in order to make it works. Then if you can say me where is my exact error and you can help me with this I will really appreciate it.

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