Thanks for the help. I have been trying to implement it without creating a gadget. Here is the code I have for that portion:
Code: Select all
local function RestoreAfterDelay(unitID)
-- Defines a local funtion to wait a bit, then move the turret back to how it was originally.
Sleep(RESTORE_DELAY)
if(waterGunAllowed == true) then
Turn(turret, y_axis, 0, math.rad(90))
--Turn(gun, x_axis, 0, math.rad(90))
--rn(waterGunVal, x_axis, 0, math.rad(90))
Turn(torso, y_axis, 0, math.rad(90))
Turn(head, y_axis, 0, math.rad(90))
Turn(rHand, y_axis, 0, math.rad(90))
Turn(rFoot, y_axis, 0, math.rad(90))
Turn(lFoot, y_axis, 0, math.rad(90))
else
Move(lHand, z_axis, 0, 20)
end
end
function script.QueryWeapon2()
--if(waterGunAllowed ~= true) then
--Spring.Echo("I'm querying properly")
--Spring.Echo("querying le 2")
return rHand
--end
end
function script.AimFromWeapon2()
--if(waterGunAllowed ~= true) then
--Spring.Echo("aiming from proper weapon!")
--Spring.Echo("aiming from le 2")
return rHand
--end
end
function script.AimWeapon2(heading, pitch)
--Spring.CallCOBScript(unitID, "ChangeWeapon", 1)
Spring.Echo("aim weapon 2!")
Signal(SIG_AIM)
SetSignalMask(SIG_AIM)
--if(waterGunAllowed ~= true) then
Spring.Echo("I am fist!")
while(weaponChosen ~= 1) do
Sleep (100)
end
Spring.Echo("Fist!")
Move(rHand, z_axis, 15, 20)
StartThread(RestoreAfterDelay)
return true
-- else return false
-- end
end
function script.FireWeapon2()
Spring.Echo("fire2!")
end
function script.QueryWeapon1()
-- The piece that the bullet/laser/whatever comes out of. FLARE
--if (waterGunAllowed == true or magicWandP == true) then
return flare
-- else
-- return lHand
--else script.QueryWeapon2()
--end
end
function script.AimFromWeapon1()
-- The unit looks from this piece down the QueryWeapon piece, to see whether it's aiming at anything. FLARE
--if (waterGunAllowed == true or magicWandP == true) then
return flare
-- else
-- return lHand
--end
--else script.AimFromWeapon2()
--end
end
function SwitchWeapon()
if (waterGunP == true) then
weaponChosen = 0
elseif (magicWandP == true) then
weaponChosen = 2
else
weaponChosen = 1
end
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_2)
SetSignalMask(SIG_AIM_2)
--while(!bCanAim || weaponchosen != 0)
while(weaponChosen ~=0) do
Sleep(100)
end
Spring.Echo("aiming when I shouldn't")
-- 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
--ename1 = UnitDefs[enemyID1].name
function script.HitByWeapon(x, z, weaponDefID, damage)
wname = WeaponDefs[weaponDefID].name
i, j = string.find(wname, "fist")
if(hulaHoopP == true) then
--if(i ~= nil) then
newDamage = damage - (0.75*damage)
return newDamage
--end
end
end
-- Mentioned in section 4.3.1.2 of MTDF v0
function script.StartMoving()
StartThread(walk)
end
-- Mentioned in section 4.3.1.3 of MTDF v0
function script.StopMoving()
Signal(SIG_WALK)
legs_down()
end
-- function script.BeginTransport(passengerID)
-- end
-- function script.QueryTransport(passengerID)
-- return -1
-- end
function script.TransportDrop(passengerID)
end
--wname = WeaponDefs[weaponDefID].name
function script.TransportPickup (passengerID)
Spring.UnitScript.AttachUnit(turret, passengerID)
local unitDefID = Spring.GetUnitDefID(passengerID)
wID = passengerID
local name = UnitDefs[unitDefID].name
--Spring.Echo("carrying a ", name)
if (name == "wwatergun") then
waterGunAllowed = true
Equip()
waterGunP = true
Spring.SetUnitRulesParam(unitID, "waterGun", 1, {public = true})
--waterGunVal = passengerID
--wname = WeaponDefs[1].name
--wname2 = WeaponDefs[2].name
end
if(name == "whulahoop") then
hulaHoopP = true
-- CHANGE THE UNIT'S HEALTH --
local _, currentMaxHealth, _, _, _= Spring.GetUnitHealth(unitID)
currentMaxHealth = currentMaxHealth+20
Spring.SetUnitMaxHealth(unitID, currentMaxHealth)
Spring.SetUnitHealth(unitID, currentMaxHealth)
Spring.SetUnitRulesParam(unitID, "hulaHoop", 1, {public = true})
end
if(name == "wbbglove") then
bbGloveP = true
Spring.SetUnitRulesParam(unitID, "bbGlove", 1, {public = true})
Spring.UnitScript.SetPieceVisibility(rHand, false)
end
if(name == "wmagicwand") then
magicWandP = true
Spring.SetUnitRulesParam(unitID, "magicWand", 1, {public = true})
end
if(name == "wcape") then
capeP = true
Spring.SetUnitRulesParam(unitID, "cape", 1, {public = true})
end
if(name == "wswimTrunks") then
swimTrunksP = true
Spring.SetUnitRulesParam(unitID, "swimTrunks", 1, {public = true})
end
if(name == "wrunningShoes") then
runningShoesP = true
Spring.SetUnitRulesParam(unitID, "runningShoes", 1, {public = true})
end
SwitchWeapon()
Spring.Echo("chosen weapon is", weaponChosen)
end
Right now it is firing a weapon, but not the correct one and I'm not really even sure what one is firing. I've checked and it knows that the correct weapon is the second weapon. It prints the "heyyy" message showing it is going into AimWeapon1. Though it does not aim it. It never enters AimWeapon2 but does query it and know where to aim from for it. Is this because I do not have a gadget or am I doing something else wrong?