How to get units to shoot multiple weapons
Posted: 20 Mar 2012, 18:24
I am wondering how to get a unit to shoot from a different weapon depending on what weapon is equipped. This is what I have at the moment:
The weapons are all defined in the unitdef. Right now it sometimes performs the sounds of the first weapon when it should be actually firing the second weapon, which it never does. Thank you for any help!
Code: Select all
function script.QueryWeapon1()
return flare
end
function script.AimFromWeapon1()
return flare
end
function script.AimWeapon1(heading, pitch)--(weaponID, heading, pitch)
--Spring.Echo("weapon ID is...",weaponID)
-- Function that aims the weapon
if (waterGunAllowed == true or magicWandP == true) then
Spring.Echo("heyyyyy")
--weaponID = 1
--Spring.Echo("in aim weapon!")
Signal(SIG_AIM)
SetSignalMask(SIG_AIM)
-- Each time the Signal is called, all other functions with the same SignalMask will stop running. This makes sure the tank isn't trying to fire at something, and restore the turret position, at the same time.
Turn(turret, y_axis, heading, math.rad(90))
--Turn(gun, x_axis, -pitch, math.rad(90))
--Turn(waterGunVal, x_axis, -pitch, math.rad(90))
Turn(torso, y_axis, heading, math.rad(90))
Turn(head, y_axis, heading, math.rad(90))
Turn(rHand, y_axis, heading, math.rad(90))
Turn(rFoot, y_axis, heading, math.rad(90))
Turn(lFoot, y_axis, heading, math.rad(90))
WaitForTurn(turret, y_axis)
--WaitForTurn(waterGunVal, x_axis)
--WaitForTurn(gun, x_axis)
WaitForTurn(head, y_axis)
WaitForTurn(rHand, y_axis)
WaitForTurn(rFoot, y_axis)
WaitForTurn(lFoot, y_axis)
StartThread(RestoreAfterDelay)
--Spring.Echo("in aim weapon2!")
-- else
-- -- Spring.CallCOBScript(unitID, "ChangeWeapon", 1)
-- --weaponID = 2
-- Spring.Echo("weapon ID is...",weaponID)
-- Signal(SIG_AIM)
-- SetSignalMask(SIG_AIM)
-- Move(lHand, z_axis, 15, 20)
StartThread(RestoreAfterDelay)
--else script.AimWeapon2(heading, pitch)
return true
else
return false
end
end
function script.FireWeapon1()
Spring.Echo("fire!")
end
function script.QueryWeapon2()
--if(waterGunAllowed ~= true) then
Spring.Echo("I'm querying properly")
return rHand
--end
end
function script.AimFromWeapon2()
--if(waterGunAllowed ~= true) then
Spring.Echo("aiming from proper weapon!")
return rHand
--end
end
function script.AimWeapon2(heading, pitch)
--Spring.CallCOBScript(unitID, "ChangeWeapon", 1)
Spring.Echo("aim weapon 2!")
if(waterGunAllowed ~= true) then
Spring.Echo("Fist!")
Signal(SIG_AIM)
SetSignalMask(SIG_AIM)
Move(rHand, z_axis, 15, 20)
StartThread(RestoreAfterDelay)
return true
else return false
end
end
function script.FireWeapon2()
Spring.Echo("fire2!")
end