Jump to content

weapon to vehicles


Recommended Posts

this script use command to create weapon attach vehicle and can shot

exmple: /vehweapon 38. to create minigun...

it's still on developing

Server:

addCommandHandler("vehweapon", 
function(thePlayer, cmd, id) 
    local theVehicle = getPedOccupiedVehicle(thePlayer) 
    if (theVehicle) and (getVehicleController(theVehicle) == thePlayer) then 
        triggerClientEvent("onCreateWeaponVehicle", theVehicle, id) 
    end 
end) 
  
addEventHandler("onResourceStart", root, 
function( ) 
    for i, player in ipairs(getElementsByType("player")) do 
        bindKey(player, "vehicle_secondary_fire", "down", keyFire) 
        bindKey(player, "vehicle_secondary_fire", "up", keyStopFire) 
    end 
end) 
  
function keyFire(source) 
    local theVehicle = getPedOccupiedVehicle(source) 
    if (theVehicle) and (getVehicleController(theVehicle) == source) then 
        triggerClientEvent("onWeaponVehicleFiring", theVehicle) 
    end 
end 
  
function keyStopFire(source) 
    local theVehicle = getPedOccupiedVehicle(source) 
    if (theVehicle) and (getVehicleController(theVehicle) == source) then 
        triggerClientEvent("onWeaponVehicleReady", theVehicle) 
    end 
end 

Client:

local weapon = {sound = {}} 
  
addEvent("onCreateWeaponVehicle", true) 
addEventHandler("onCreateWeaponVehicle", root, 
function (weaponID) 
    local theVehicle = source 
    if not weaponID then weaponID= 38 end 
    if (getElementType(theVehicle) == "vehicle") and not (weapon[theVehicle]) then 
        local x, y, z = getElementPosition(theVehicle) 
        weapon[theVehicle] = createWeapon(weaponID, x, y, z) 
        attachElements(weapon[theVehicle], theVehicle, 2, 0, 0) 
        setElementData(theVehicle, "VehicleMG", weapon[theVehicle]) 
        --setWeaponClipAmmo(weapon[theVehicle], 99999)  
    end 
end) 
  
addEvent("onWeaponVehicleFiring", true) 
addEventHandler("onWeaponVehicleFiring", root, 
function( ) 
    local theVehicle = source 
    if (theVehicle) and (weapon[theVehicle]) then 
        setWeaponState(weapon[theVehicle], "firing") 
        --[[local x, y, z = getElementPosition(theVehicle) 
        local xm, ym, zm = getElementPosition(weapon[theVehicle]) 
        if not (weapon.sound[theVehicle]) then 
            weapon.sound[theVehicle] = playSound3D("minigun.wav", xm, ym, zm, true) 
            setSoundMaxDistance(weapon.sound[theVehicle], 100) 
            --setSoundEffectEnabled(weapon.sound[theVehicle], "gargle", true) 
            attachElements(weapon.sound[theVehicle], weapon[theVehicle]) 
        end]] 
    end 
end) 
  
--[[addEvent("onWeaponVehicleReady", true) 
addEventHandler("onWeaponVehicleReady", root, 
function ( ) 
    local theVehicle = source 
    if (theVehicle) and (weapon[theVehicle]) then 
        setWeaponState(weapon[theVehicle], "ready") 
        if (weapon.sound[theVehicle]) then 
            stopSound(weapon.sound[theVehicle]) 
            weapon.sound[theVehicle] = nil 
        end 
    end 
end)]] 
  
--[[bindKey("r", "up", 
function( ) 
    local theVehicle = getPedOccupiedVehicle(localPlayer) 
    if (theVehicle) and (getVehicleController(theVehicle) == thePlayer) then 
        setWeaponState(weapon[theVehicle], "reloading") 
    end 
end)]] 
  
addEventHandler("onClientWeaponFire", getRootElement(), 
function (element) 
    local theVehicle = getPedOccupiedVehicle(localPlayer) 
    if (theVehicle) and (weapon[theVehicle]) then 
        if (element == theVehicle) then 
            cancelEvent()  
        end 
    end 
end) 
  
addEventHandler("onElementDestroy", root, 
function ( ) 
    local theVehicle = source 
    if (getElementType(theVehicle) == "vehicle") and (weapon[theVehicle]) then 
         destroyElement (weapon[theVehicle]) 
         weapon[theVehicle] = nil 
         setElementData(theVehicle, "VehicleMG", false) 
    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...