Jump to content

How to turn Secondary Weapon off


Bonsai

Recommended Posts

Posted

Hey Guys,

I tried to disable the secondary Weapon in Hunter {Minigun), but it doesnt work.

It shall disable secondary Weapon, when the Player hits a Hunter Pickup.

I got this code from wiki, but its not made for Race Mode.

function disableFireForHunter ( theVehicle, seat )
if ( getElementModel ( theVehicle ) == 425 ) then -- if they entered a hunter
toggleControl ( "vehicle_secondary_fire", false ) -- disable their fire key
else -- if they entered another vehicle
toggleControl ( "vehicle_secondary_fire", true ) -- enable their fire key
end
end
addEventHandler ( "onClientPlayerEnterVehicle", getLocalPlayer(), disableFireForHunter)

I changed it so that it should actually work, when the Player hits Vehicle Change Pickup.

function disableFireForHunter ( theVehicle, seat )
if ( getElementModel ( theVehicle ) == 425 ) then -- if they entered a hunter
toggleControl ( "vehicle_secondary_fire", false ) -- disable their fire key
else -- if they entered another vehicle
toggleControl ( "vehicle_secondary_fire", true ) -- enable their fire key
end
setTimer(disableFireForHunter, 1000, 0)
end
addEventHandler ( "onClientResourceStart", getLocalPlayer(), disableFireForHunter )

Maybe someone knows a solution for this problem.

Posted

1st of all: You placed setTimer inside "himself". Your script starts a new timer every second. And also, how is this func get the player's vehicle?

try smth like that:

setTimer(disableFireForHunter, 1000, -1)
function disableFireForHunter ()
local theVehicle = getPedOccupiedVehicle(getLocalPlayer());
if ( getElementModel ( theVehicle ) == 425 ) then -- if they entered a hunter
toggleControl ( "vehicle_secondary_fire", false ) -- disable their fire key
else -- if they entered another vehicle
toggleControl ( "vehicle_secondary_fire", true ) -- enable their fire key
end
end

Posted

Yeah, I did that because there is no "OnClientVehicleChange".

And I want the function to check that always, and not just at map start.

EDIT: Whats -1? :shock:

Posted

oh, yeap, just a small error >_<. "setTimer" must be after his function, like this:

function disableFireForHunter ()
outputChatBox("test");
local theVehicle = getPedOccupiedVehicle(getLocalPlayer());
if getElementModel ( theVehicle ) == 425  then
toggleControl ( "vehicle_secondary_fire", false )
else
toggleControl ( "vehicle_secondary_fire", true )
end     
end
setTimer(disableFireForHunter, 1000, -1)

P.S - just tested it, it works!

P.P.S - remove the outputChatBox("test"); =3

Posted

WTF? leave these timers alone!! :/

function disableFireForHunter ( theVehicle, seat )
if ( getElementModel ( theVehicle ) == 425 ) then -- if they entered a hunter
toggleControl ( "vehicle_secondary_fire", false ) -- disable their fire key
else -- if they entered another vehicle
toggleControl ( "vehicle_secondary_fire", true ) -- enable their fire key
end
end
addEventHandler ( "onClientPlayerVehicleEnter", getLocalPlayer(), disableFireForHunter)

the only problem is that onClientPlayerEnterVehicle event not exist, it's onClientPlayerVehicleEnter

there was bug in wiki, and i fixed it

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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