Jump to content

helppp!!!


WASSIm.

Recommended Posts

hi guys i have problem. why just minigun1 and other dont shoting

addEventHandler("onClientVehicleEnter", root, 
    function(thePlayer, seat) 
         local theVehicle = source 
         if seat == 0 and thePlayer and getElementModel(theVehicle) == 425 then 
         local x, y, z = getElementPosition ( theVehicle ) 
         minigun1 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun2 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun3 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun4 = createWeapon ( "minigun",  x,  y,  z ) 
         setElementAlpha ( minigun1,255) 
         setElementAlpha ( minigun2,255) 
         setElementAlpha ( minigun3,255) 
         setElementAlpha ( minigun4,255) 
         attachElements ( minigun1, theVehicle, 2.15, 0.5, -1.2, 0, 0, 90 )  
         attachElements ( minigun2, theVehicle, -2.10, 0.5, -1.2, 0, 0, 90 ) 
         attachElements ( minigun3, theVehicle, 2.57, 0.5, -1.1, 0, 0, 90 )  
         attachElements ( minigun4, theVehicle, -2.52, 0.5, -1.1, 0, 0, 90 ) 
         toggleControl ( "vehicle_fire", false ) 
         toggleControl ( "vehicle_secondary_fire", false ) 
         bindKey ( "n", "down", enableFire )         
         bindKey ( "n", "up", disableFire )    
        end 
    end 
) 
  
addEventHandler("onClientVehicleExit", root, 
    function(thePlayer, seat) 
        local theVehicle = source 
        if seat == 0 and thePlayer and getElementModel(theVehicle) == 425 then 
        if minigun1 and minigun2 and minigun3 and minigun4 then 
        destroyElement (minigun1) 
        destroyElement (minigun2) 
        destroyElement (minigun3) 
        destroyElement (minigun4) 
         toggleControl ( "vehicle_fire", false ) 
         toggleControl ( "vehicle_secondary_fire", false ) 
         unbindKey ( "n", "down", enableFire )       
         unbindKey ( "n", "up", disableFire ) 
        end 
    end 
    end 
) 
  
 function enableFire() 
 if isTimer(MG1timer) and isTimer(MG2timer) and isTimer(MG3timer) and isTimer(MG4timer) then 
 if minigun1 and minigun2 and minigun3 and minigun4 then 
  killTimer(MG1timer) 
  killTimer(MG2timer) 
  killTimer(MG3timer) 
  killTimer(MG4timer) 
   else 
    MG1timer = setTimer(function() setWeaponState ( minigun1, "firing" ) end, 50, 1) 
    MG2timer = setTimer(function() setWeaponState ( minigun2, "firing" ) end, 50, 1) 
    MG3timer = setTimer(function() setWeaponState ( minigun3, "firing" ) end, 50, 1) 
    MG4timer = setTimer(function() setWeaponState ( minigun4, "firing" ) end, 50, 1) 
    MiniSound = playSound("Pro_Minigun.wav", true)  
    setSoundVolume(MiniSound, 1) 
    setSoundSpeed ( MiniSound, 1 ) 
    setSoundEffectEnabled(MiniSound,"gargle",false) 
        end 
    end 
end 
  
function disableFire() 
 if isTimer(MG1timer) and isTimer(MG2timer) and isTimer(MG3timer) and isTimer(MG4timer) then 
 if minigun1 and minigun2 and minigun3 and minigun4 then 
  killTimer(MG1timer) 
  killTimer(MG2timer) 
  killTimer(MG3timer) 
  killTimer(MG4timer) 
   else 
    MG1timer = setTimer(function() setWeaponState ( minigun1, "ready" ) end, 50, 1) 
    MG2timer = setTimer(function() setWeaponState ( minigun2, "ready" ) end, 50, 1) 
    MG3timer = setTimer(function() setWeaponState ( minigun3, "ready" ) end, 50, 1) 
    MG4timer = setTimer(function() setWeaponState ( minigun4, "ready" ) end, 50, 1) 
      stopSound ( MiniSound ) 
        end 
    end 
end 
  

Edited by Guest
Link to comment
  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

Try this:

local miniguns = {} 
local miniTimers = {} 
local miniSound 
addEventHandler("onClientVehicleEnter", root,function(_, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    local x, y, z = getElementPosition ( source ) 
    miniguns[0] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[1] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[2] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[3] = createWeapon ( "minigun",  x,  y,  z ) 
    for _,v in ipairs(miniguns)do 
        setElementAlpha(v,255) 
    end 
    attachElements ( miniguns[0], source, 2.15, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[1], source, -2.10, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[2], source, 2.57, 0.5, -1.1, 0, 0, 90 ) 
    attachElements ( miniguns[3], source, -2.52, 0.5, -1.1, 0, 0, 90 ) 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    bindKey ( "n", "down", fire ) 
    bindKey ( "n", "up", fire ) 
end) 
addEventHandler("onClientVehicleExit",root,function(_, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    for _,v in ipairs(miniguns)do 
        if not v then return end 
        destroyElement(v) 
    end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    unbindKey ( "n", "down", fire )       
    unbindKey ( "n", "up", fire ) 
end) 
  
function fire(_,kState) 
    if kState=="down" then 
        for _,v in ipairs(miniTimers)do 
            if not isTimer(v) then return end 
            for _,i in ipairs(miniguns)do 
                if i then 
                    killTimer(v) 
                else 
                    setTimer(setWeaponState,50,1,i,"firing") 
                    miniSound = playSound("Pro_Minigun.wav", true) 
                    setSoundVolume(miniSound, 1) 
                    setSoundSpeed ( miniSound, 1 ) 
                    setSoundEffectEnabled(miniSound,"gargle",false) 
                end 
            end 
        end 
    elseif kState=="up" then 
        for _,v in ipairs(miniTimers)do 
            if not isTimer(v) then return end 
            for _,i in ipairs(miniguns)do 
                if i then 
                    killTimer(v) 
                else 
                    setTimer(setWeaponState,50,1,i,"ready") 
                    stopSound(miniSound) 
                end 
            end 
        end 
    end 
end 

Link to comment

try this:

local miniguns = {} 
local miniTimers = {} 
local miniSound 
addEventHandler("onClientVehicleEnter", root,function(_, seat) 
    if seat~=0 and getElementModel(source)~=425 then return end 
    local x, y, z = getElementPosition (source) 
    miniguns[0] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[1] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[2] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[3] = createWeapon ( "minigun",  x,  y,  z ) 
    for _,minigun in ipairs(miniguns)do 
        setElementAlpha(minigun,255) 
    end 
    attachElements ( miniguns[0], source, 2.15, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[1], source, -2.10, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[2], source, 2.57, 0.5, -1.1, 0, 0, 90 ) 
    attachElements ( miniguns[3], source, -2.52, 0.5, -1.1, 0, 0, 90 ) 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    bindKey ( "n", "down", fire ) 
    bindKey ( "n", "up", fire ) 
end) 
addEventHandler("onClientVehicleExit",root,function(_, seat) 
    if seat~=0 and getElementModel(source)~=425 then return end 
    for _,minigun in ipairs(miniguns)do 
        if not isElement(minigun) then return end 
        destroyElement(minigun) 
    end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    unbindKey ( "n", "down", fire )       
    unbindKey ( "n", "up", fire ) 
end) 
  
function fire(_,kState) 
    if kState=="down" then 
        for _,timer in ipairs(miniTimers)do 
            if not isTimer(timer) then return end 
            for _,minigun in ipairs(miniguns)do 
                if isElement(minigun) then 
                    killTimer(timer) 
                else 
                    setTimer(setWeaponState,50,1,minigun,"firing") 
                    -miniSound = playSound("Pro_Minigun.wav", true) or false 
                    setSoundVolume(miniSound, 1) 
                    setSoundSpeed ( miniSound, 1 ) 
                    setSoundEffectEnabled(miniSound,"gargle",false) 
                end 
            end 
        end 
    elseif kState=="up" then 
        for _,timer in ipairs(miniTimers)do 
            if not isTimer(timer) then return end 
            for _,minigun in ipairs(miniguns)do 
                if isElement(minigun) then 
                    killTimer(timer) 
                else 
                    setTimer(setWeaponState,50,1,minigun,"ready") 
                    stopSound(miniSound) 
                end 
            end 
        end 
    end 
end 

Link to comment

Ok, I've edited it my self and found out what the problem was...

The minigun was going through the helicopter's wing and artillery things and it automatically blocks the minigun/weapon from shooting...

try this:

local miniguns = {} 
local miniSound 
addEventHandler("onClientVehicleEnter", root,function(_, seat) 
    if seat~=0 and getElementModel(source)~=425 then return end 
    local x, y, z = getElementPosition (source) 
    miniguns[1] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[2] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[3] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[4] = createWeapon ( "minigun",  x,  y,  z ) 
    for _,minigun in ipairs(miniguns)do 
        setElementAlpha(minigun,255) 
    end 
    attachElements ( miniguns[1], source, 2.15, 0.5, -1.2, 45, 0, 90 ) 
    attachElements ( miniguns[2], source, -2.10, 0.5, -1.2, 45, 0, 90 ) 
    attachElements ( miniguns[3], source, 2.57, 0.5, -1.1, 45, 0, 90 ) 
    attachElements ( miniguns[4], source, -2.52, 0.5, -1.1, 45, 0, 90 ) 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    addEventHandler("onClientPreRender",root,fire) 
end) 
addEventHandler("onClientVehicleExit",root,function(_, seat) 
    if seat~=0 and getElementModel(source)~=425 then return end 
    for _,minigun in ipairs(miniguns)do 
        destroyElement(minigun) 
    end 
    toggleControl ( "vehicle_fire", true ) 
    toggleControl ( "vehicle_secondary_fire", true ) 
    removeEventHandler("onClientRender",root,fire) 
end) 
function fire() 
    if getKeyState("n")then 
        for _,minigun in ipairs(miniguns)do 
            if not isElement(minigun) then return end 
            fireWeapon(minigun) 
        end 
        miniSound = playSound("Pro_Minigun.wav", true) or false 
        setSoundVolume(miniSound, 1) 
        setSoundSpeed ( miniSound, 1 ) 
        setSoundEffectEnabled(miniSound,"gargle",false) 
    else 
        stopSound(miniSound) 
    end 
end 

Link to comment

i get history file before bug. its working now but i have problem to sound

addEventHandler("onClientVehicleEnter", root, 
    function(thePlayer, seat) 
        theVehicle = source 
        if seat == 0 and thePlayer == localPlayer and  getElementModel(theVehicle) == 425 then 
         x, y, z = getElementPosition ( theVehicle ) 
         rx, ry, rz = getElementRotation ( theVehicle ) 
         minigun1 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun2 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun3 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun4 = createWeapon ("minigun",  x,  y,  z ) 
         setElementAlpha ( minigun1,0) 
         setElementAlpha ( minigun2,0) 
         setElementAlpha ( minigun3,0) 
         setElementAlpha ( minigun4,0) 
         attachElements ( minigun1, theVehicle, 2.15, 0.5, -1.2, 0, 0, 90 )  
         attachElements ( minigun2, theVehicle, -2.10, 0.5, -1.2, 0, 0, 90 ) 
         attachElements ( minigun3, theVehicle, 2.57, 0.5, -1.1, 0, 0, 90 )  
         attachElements ( minigun4, theVehicle, -2.52, 0.5, -1.1, 0, 0, 90 ) 
        toggleControl ( "vehicle_fire", false ) 
        toggleControl ( "vehicle_secondary_fire", false ) 
         bindKey ( "vehicle_fire", "down", enableFire )         
         bindKey ( "vehicle_fire", "up", disableFire )    
        end 
    end 
) 
addEventHandler("onClientVehicleExit", root, 
    function(thePlayer, seat) 
        local theVehicle = source 
        if seat == 0 and thePlayer == localPlayer and getElementModel(theVehicle) == 425 then 
        if minigun1 and minigun2 and minigun3 and minigun4 then 
        destroyElement (minigun1) 
        destroyElement (minigun2) 
        destroyElement (minigun3) 
        destroyElement (minigun4) 
        toggleControl ( "vehicle_fire", false ) 
        toggleControl ( "vehicle_secondary_fire", false ) 
         unbindKey ( "vehicle_fire", "down", enableFire )       
         unbindKey ( "vehicle_fire", "up", disableFire ) 
        end 
    end 
    end 
) 
 function enableFire() 
 if isTimer(MGtimer) and isTimer(MG2timer) and isTimer(MG3timer) and isTimer(MG4timer) and minigun1 and minigun2 and minigun3 and minigun4 then 
  killTimer(MGtimer) 
  killTimer(MG2timer) 
  killTimer(MG3timer) 
  killTimer(MG4timer) 
   else 
    MGtimer = setTimer(function() setWeaponState ( minigun1, "firing" ) end, 50, 1) 
    MG2timer = setTimer(function() setWeaponState ( minigun2, "firing" ) end, 50, 1) 
    MG3timer = setTimer(function() setWeaponState ( minigun3, "firing" ) end, 50, 1) 
    MG4timer = setTimer(function() setWeaponState ( minigun4, "firing" ) end, 50, 1) 
    MiniSound = playSound3D("test.wav", x, y, z,true)  
    setSoundMaxDistance(MiniSound, 140) 
    setSoundEffectEnabled(MiniSound,"gargle",true) 
        end 
    end 
  
function disableFire() 
 if isTimer(MGtimer) and isTimer(MG2timer) and isTimer(MG3timer) and isTimer(MG4timer) and minigun1 and minigun2 and minigun3 and minigun4 then 
  killTimer(MGtimer) 
  killTimer(MG2timer) 
  killTimer(MG3timer) 
  killTimer(MG4timer) 
   else 
    MGtimer = setTimer(function() setWeaponState ( minigun1, "ready" ) end, 50, 1) 
    MG2timer = setTimer(function() setWeaponState ( minigun2, "ready" ) end, 50, 1) 
    MG3timer = setTimer(function() setWeaponState ( minigun3, "ready" ) end, 50, 1) 
    MG4timer = setTimer(function() setWeaponState ( minigun4, "ready" ) end, 50, 1) 
              stopSound(MiniSound) 
        end 
    end 

Link to comment

Oh yes thx :D

but now i can't kill player with minigun and player can't minigun :/

addEventHandler("onClientVehicleEnter", root, 
    function(thePlayer, seat) 
        theVehicle = source 
        if seat == 0 and thePlayer == localPlayer and  getElementModel(theVehicle) == 425 then 
         x, y, z = getElementPosition ( theVehicle ) 
         rx, ry, rz = getElementRotation ( theVehicle ) 
         minigun1 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun2 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun3 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun4 = createWeapon ("minigun",  x,  y,  z ) 
         setWeaponOwner ( minigun1, thePlayer) 
         setWeaponOwner ( minigun2, thePlayer) 
         setWeaponOwner ( minigun3, thePlayer) 
         setWeaponOwner ( minigun4, thePlayer) 
         setElementAlpha ( minigun1,0) 
         setElementAlpha ( minigun2,0) 
         setElementAlpha ( minigun3,0) 
         setElementAlpha ( minigun4,0) 
         attachElements ( minigun1, theVehicle, 2.15, 0.5, -1.2, 0, 0, 90 )  
         attachElements ( minigun2, theVehicle, -2.10, 0.5, -1.2, 0, 0, 90 ) 
         attachElements ( minigun3, theVehicle, 2.57, 0.5, -1.1, 0, 0, 90 )  
         attachElements ( minigun4, theVehicle, -2.52, 0.5, -1.1, 0, 0, 90 ) 
        toggleControl ( "vehicle_fire", false ) 
        toggleControl ( "vehicle_secondary_fire", false ) 
         bindKey ( "vehicle_fire", "down", enableFire )         
         bindKey ( "vehicle_fire", "up", disableFire )    
        end 
    end 
) 
  
addEventHandler("onClientVehicleExit", root, 
    function(thePlayer, seat) 
        local theVehicle = source 
        if seat == 0 and thePlayer == localPlayer and getElementModel(theVehicle) == 425 then 
        if minigun1 and minigun2 and minigun3 and minigun4 then 
        destroyElement (minigun1) 
        destroyElement (minigun2) 
        destroyElement (minigun3) 
        destroyElement (minigun4) 
        toggleControl ( "vehicle_fire", false ) 
        toggleControl ( "vehicle_secondary_fire", false ) 
         unbindKey ( "vehicle_fire", "down", enableFire )       
         unbindKey ( "vehicle_fire", "up", disableFire ) 
        end 
    end 
 end 
) 
  
 function enableFire() 
 if minigun1 and minigun2 and minigun3 and minigun4 then 
    setWeaponState ( minigun1, "firing" )  
    setWeaponState ( minigun2, "firing" )  
    setWeaponState ( minigun3, "firing" )  
    setWeaponState ( minigun4, "firing" )  
    addEventHandler ( "onClientRender", root, move) 
        end 
    end 
  
function disableFire() 
 if minigun1 and minigun2 and minigun3 and minigun4 then 
    setWeaponState ( minigun1, "ready" )  
    setWeaponState ( minigun2, "ready" )  
    setWeaponState ( minigun3, "ready" )  
    setWeaponState ( minigun4, "ready" )  
    removeEventHandler ( "onClientRender", root, move) 
        end 
    end 
  
function move () 
 if minigun1 and minigun2 and minigun3 and minigun4 then 
    MiniSound = playSound3D("test.wav", x, y, z,false)  
    setSoundMaxDistance(MiniSound, 140) 
    setSoundEffectEnabled(MiniSound,"gargle",true) 
    attachElements ( MiniSound, theVehicle, 0, 0.5, -1.1, 0, 0, 90 ) 
         end 
    end 
     

Link to comment
You're ignoring my post in first page.

sry i dont see first

Try using triggerClientEvent in a server-side script.

BUG

sanstitrexdi.png

SERVER

addEventHandler ("onVehicleEnter", root, 
    function ( ) 
        triggerClientEvent ( "onEnter", thePlayer )    
        end 
) 
  
addEventHandler("onVehicleExit", root, 
    function ( ) 
        triggerClientEvent ( "onExit", thePlayer )    
        end 
) 
  
    function ( ) 
        triggerClientEvent ( "onEnableFire", thePlayer )    
        end 
  
  
    function ( ) 
        triggerClientEvent ( "onDisableFire", thePlayer )    
        end 
  
  
    function ( ) 
        triggerClientEvent ( "onMove", thePlayer )    
        end 
  

CLIENT

  
addEvent( "onEnter", true ) 
addEventHandler( "onEntre", getRootElement(), 
    function(thePlayer, seat) 
        theVehicle = source 
        if seat == 0 and thePlayer == localPlayer and  getElementModel(theVehicle) == 425 then 
         x, y, z = getElementPosition ( theVehicle ) 
         rx, ry, rz = getElementRotation ( theVehicle ) 
         minigun1 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun2 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun3 = createWeapon ( "minigun",  x,  y,  z ) 
         minigun4 = createWeapon ("minigun",  x,  y,  z ) 
         setWeaponOwner ( minigun1, thePlayer) 
         setWeaponOwner ( minigun2, thePlayer) 
         setWeaponOwner ( minigun3, thePlayer) 
         setWeaponOwner ( minigun4, thePlayer) 
         setElementAlpha ( minigun1,0) 
         setElementAlpha ( minigun2,0) 
         setElementAlpha ( minigun3,0) 
         setElementAlpha ( minigun4,0) 
         attachElements ( minigun1, theVehicle, 2.15, 0.5, -1.2, 0, 0, 90 ) 
         attachElements ( minigun2, theVehicle, -2.10, 0.5, -1.2, 0, 0, 90 ) 
         attachElements ( minigun3, theVehicle, 2.57, 0.5, -1.1, 0, 0, 90 ) 
         attachElements ( minigun4, theVehicle, -2.52, 0.5, -1.1, 0, 0, 90 ) 
        toggleControl ( "vehicle_fire", false ) 
        toggleControl ( "vehicle_secondary_fire", false ) 
         bindKey ( "vehicle_fire", "down", enableFire )         
         bindKey ( "vehicle_fire", "up", disableFire )   
        end 
    end 
) 
  
addEvent( "onExit", true ) 
addEventHandler( "onEntre", getRootElement(), 
    function(thePlayer, seat) 
        local theVehicle = source 
        if seat == 0 and thePlayer == localPlayer and getElementModel(theVehicle) == 425 then 
        if minigun1 and minigun2 and minigun3 and minigun4 then 
        destroyElement (minigun1) 
        destroyElement (minigun2) 
        destroyElement (minigun3) 
        destroyElement (minigun4) 
        toggleControl ( "vehicle_fire", false ) 
        toggleControl ( "vehicle_secondary_fire", false ) 
         unbindKey ( "vehicle_fire", "down", enableFire )       
         unbindKey ( "vehicle_fire", "up", disableFire ) 
        end 
    end 
 end 
) 
  
addEvent( "onEnableFire", true ) 
addEventHandler( "onEnableFire", getRootElement(), 
 if minigun1 and minigun2 and minigun3 and minigun4 then 
    setWeaponState ( minigun1, "firing" ) 
    setWeaponState ( minigun2, "firing" ) 
    setWeaponState ( minigun3, "firing" ) 
    setWeaponState ( minigun4, "firing" ) 
    addEventHandler ( "onClientRender", root, move) 
        end 
    end 
  
addEvent( "onDisableFire", true ) 
addEventHandler( "onDisableFire", getRootElement(), 
function disableFire() 
 if minigun1 and minigun2 and minigun3 and minigun4 then 
    setWeaponState ( minigun1, "ready" ) 
    setWeaponState ( minigun2, "ready" ) 
    setWeaponState ( minigun3, "ready" ) 
    setWeaponState ( minigun4, "ready" ) 
    removeEventHandler ( "onClientRender", root, move) 
        end 
    end 
  
addEvent( "onMove", true ) 
addEventHandler( "onMove", getRootElement(), 
function move () 
 if minigun1 and minigun2 and minigun3 and minigun4 then 
    MiniSound = playSound3D("test.wav", x, y, z,false) 
    setSoundMaxDistance(MiniSound, 140) 
    setSoundEffectEnabled(MiniSound,"gargle",true) 
    attachElements ( MiniSound, theVehicle, 0, 0.5, -1.1, 0, 0, 90 ) 
         end 
    end 
    

Link to comment

Fine, try this:

server:

addEventHandler ("onVehicleEnter", root,function(player,seat) 
    triggerClientEvent("onEnter",source,player,seat)   
end) 
  
addEventHandler("onVehicleExit", root,function(player,seat) 
    triggerClientEvent ( "onExit",source,player,seat)  
end) 
addEvent("fire",false) 
addEventHandler("fire",root,function(state) 
    if state=="down"then 
        triggerClientEvent("onEnableFire",client) 
    elseif state=="up"then 
        triggerClientEvent ("onDisableFire",client) 
    end 
end) 

Client:

local miniguns = {} 
  
addEvent( "onEnter", true ) 
addEventHandler( "onEnter",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    miniguns[thePlayer] = {} 
    local x, y, z = getElementPosition ( source ) 
    local rx, ry, rz = getElementRotation ( source ) 
    miniguns[thePlayer][1] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][2] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][3] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][4] = createWeapon ("minigun",  x,  y,  z ) 
    for _,minigun in ipairs(miniguns[thePlayer])do 
        setWeaponOwner ( minigun, thePlayer) 
        setElementAlpha ( minigun,0) 
    end 
    attachElements ( miniguns[thePlayer][1], source, 2.15, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][2], source, -2.10, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][3], source, 2.57, 0.5, -1.1, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][4], source, -2.52, 0.5, -1.1, 0, 0, 90 ) 
    if thePlayer~=localPlayer then return end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    for _,key in ipairs(getBoundKeys("vehicle_fire"))do 
        bindKey ( key, "down",fire )         
        bindKey ( key, "up",fire ) 
    end 
end) 
  
addEvent( "onExit", true ) 
addEventHandler( "onExit",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    for _,minigun in ipairs(miniguns[thePlayer])do 
        destroyElement (minigun) 
    end 
    miniguns[thePlayer] = nil 
    if thePlayer~=localPlayer then return end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    for _,key in ipairs(getBoundKeys("vehicle_fire"))do 
        unbindKey ( key, "down",fire )         
        unbindKey ( key, "up",fire ) 
    end 
end) 
function fire(_,state) 
    triggerServerEvent("fire",localPlayer,state) 
end 
  
function move(source) 
    local MiniSound = playSound3D("test.wav", x, y, z,false) 
    setSoundMaxDistance(MiniSound, 140) 
    setSoundEffectEnabled(MiniSound,"gargle",true) 
    attachElements ( MiniSound, getPedOccupiedVehicle(source), 0, 0.5, -1.1, 0, 0, 90 ) 
end 
addEvent( "onEnableFire", true ) 
addEventHandler( "onEnableFire",root,function() 
    for _,minigun in ipairs(miniguns[source])do 
        setWeaponState ( minigun, "firing") 
    end 
    move(source) 
end) 
addEvent( "onDisableFire", true ) 
addEventHandler( "onDisableFire",root,function() 
    for _,minigun in ipairs(miniguns[source])do 
        setWeaponState ( minigun, "ready") 
    end 
    move(source) 
end) 

Edited by Guest
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...