Jump to content

I need the hunter to shoot automatically


AhmadRS

Recommended Posts

Hello and welcome to the Forums!

If you want the ped to shoot with a weapon (if this is what you want) you should use the control named "fire" instead of "Vehicle_fire".

Edit: Nevermind... didn't read the whole script. Sorry!

Edited by SpecT
Link to comment
3 minutes ago, SpecT said:

Hello and welcome to the Forums!

If you want the ped to shoot with a weapon (if this is what you want) you should use the control named "fire" instead of "Vehicle_fire".

No bro I want the ped to shoot from the the hunter (missiles). Not from his own weapon 

Edited by AhmadRS
Link to comment
3 hours ago, AhmadRS said:

I tried to do it but it doesn't shoot


local hunter = createVehicle(425,x,y,z)
local ped = createPed(0,x,y,z)
warpPedIntoVehicle(ped, hunter) 
setPedAnalogControlState(ped, "Vehicle_fire") 

 

try use vehicle_fire instead of Vehicle_fire

Link to comment

setPedAnalogControlState takes a third argument, which is a number between 0 (no effect) to 1 (full effect). For the control to take full effect, it should be like this:

setPedAnalogControlState(ped, "vehicle_fire", 1)

But I don't know if it's even valid to use analog control state for vehicle_fire, because you can either be shooting or not, there's no "in-between". For this reason, maybe it makes more sense to use setPedControlState:

setPedControlState(ped, "vehicle_fire", true)

 

Link to comment
18 minutes ago, CrystalMV said:

setPedAnalogControlState takes a third argument, which is a number between 0 (no effect) to 1 (full effect). For the control to take full effect, it should be like this:


setPedAnalogControlState(ped, "vehicle_fire", 1)

But I don't know if it's even valid to use analog control state for vehicle_fire, because you can either be shooting or not, there's no "in-between". For this reason, maybe it makes more sense to use setPedControlState:


setPedControlState(ped, "vehicle_fire", true)

 

yep , i fixed the 3rd argument.. but it doesn't work as well.

Besides, 

setPedControlState(ped, "vehicle_fire", true)

only works for the player, not for ped.. That's what i have read on the wiki

Link to comment
30 minutes ago, AhmadRS said:

Besides, 


setPedControlState(ped, "vehicle_fire", true)

only works for the player, not for ped.. That's what i have read on the wiki

No, the wiki says setPedControlState was made to work for the local player as well (in addition to peds, because previously it only worked for peds). It was setControlState that only worked for players, and because setPedControlState now works for both player and peds, setControlState has been deprecated on the client side.

Anyway, if that still doesn't work, I guess the ped has not been streamed in yet when the function gets called. Another thing I just realized that needs to be taken into account is that when you hold the fire control, you only shoot missiles once. Not repeatedly. In order to keep shooting repeatedly, you need to press it repeatedly. The same holds true for peds, you need to keep switching the control state between true and false. A timer can do this:

local hunter = createVehicle(425,x,y,z)
local ped = createPed(0,x,y,z)
warpPedIntoVehicle(ped, hunter)

local function toggleFireControl()
  	local old_state = getPedControlState(ped, "vehicle_fire")
	setPedControlState(ped, "vehicle_fire", not old_state)
end
setTimer(toggleFireControl, 100, 0)

 

Edited by CrystalMV
Link to comment
2 hours ago, CrystalMV said:

No, the wiki says setPedControlState was made to work for the local player as well (in addition to peds, because previously it only worked for peds). It was setControlState that only worked for players, and because setPedControlState now works for both player and peds, setControlState has been deprecated on the client side.

Anyway, if that still doesn't work, I guess the ped has not been streamed in yet when the function gets called. Another thing I just realized that needs to be taken into account is that when you hold the fire control, you only shoot missiles once. Not repeatedly. In order to keep shooting repeatedly, you need to press it repeatedly. The same holds true for peds, you need to keep switching the control state between true and false. A timer can do this:


local hunter = createVehicle(425,x,y,z)
local ped = createPed(0,x,y,z)
warpPedIntoVehicle(ped, hunter)

local function toggleFireControl()
  	local old_state = getPedControlState(ped, "vehicle_fire")
	setPedControlState(ped, "vehicle_fire", not old_state)
end
setTimer(toggleFireControl, 100, 0)

 

Well, thank you for the amazing explanation.. I think that shooting missiles is not possible using peds because i have tried your code and it did not work for ped, but i replaced the ped with the local player and it worked. Also , i have tried another controls like acceleration and it worked for ped. While vehicle_fire did not work. Anyway , thank you so much for helping me to realize that.

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