Jump to content

[HELP] Fire weapon if players is in vehicle


Recommended Posts

Hi i want to shoot weapon in the vehicle, but if i bind it i got mouse1

 

Debugscript 3 says:

WARNING: fs_raindSit\client.lua:17: Bad argument @ 'setWeaponState' [Expected weapon at argument 1, got string 'mouse1]
WARNING: fs_raindSit\client.lua:23: Bad argument @ 'setWeaponState' [Expected weapon at argument 1, got string 'mouse1]

 

Client Side:

function createMinigunWeapon(myRaindanc)
    -- Create the weapon 1 meter above the player
    local pX, pY, pZ = getElementPosition(myRaindanc)
    local weapon = createWeapon("minigun", pX, pY, pZ)
    -- Give it some ammo and fire it
    setWeaponClipAmmo(weapon, 99999)
    setWeaponState(weapon, "ready")
    
    setWeaponProperty(weapon, "fire_rotation", 0, -30, 0)

    attachElements(weapon, myRaindanc, 0.9, 0.34, 0.2, 0, 30, 0 )
end
addEvent("createMinigun", true)
addEventHandler("createMinigun", resourceRoot, createMinigunWeapon)

function onPilotFireOn(weapon)
    setWeaponState(weapon, "firing")
end
bindKey("mouse1", "down", onPilotFireOn)


function onPilotFireOff(weapon)
    setWeaponState(weapon, "ready")
end
bindKey("mouse1", "up", onPilotFireOff)

 


 

Edited by SphinxDev
bad error argument
Link to comment

I assume this code is for testing purpose as it's incomplete and if you wish to use it you should be aware that you will need to do server/client side triggers to sync the weapon creation and its state.

function createMinigunWeapon(myRaindanc)
    -- Create the weapon 1 meter above the player
    local pX, pY, pZ = getElementPosition(myRaindanc)
    weapon = createWeapon("minigun", pX, pY, pZ)
    -- Give it some ammo and fire it
    setWeaponClipAmmo(weapon, 99999)
    setWeaponState(weapon, "ready")
    
    setWeaponProperty(weapon, "fire_rotation", 0, -30, 0)

    attachElements(weapon, myRaindanc, 0.9, 0.34, 0.2, 0, 30, 0 )
end
addEvent("createMinigun", true)
addEventHandler("createMinigun", resourceRoot, createMinigunWeapon)

function onPilotFireOn()
    setWeaponState(weapon, "firing")
end
bindKey("mouse1", "down", onPilotFireOn)


function onPilotFireOff()
    setWeaponState(weapon, "ready")
end
bindKey("mouse1", "up", onPilotFireOff)
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...