So about a week ago I made a huge breakthrough with my project and learned how to make my units shoot multiple weapons using Lua. Hooray.
Part of that process, though, was taking the Signal and SetSignalMask parts out of the AimWeapon thread in the animation script. I was able to get all weapons to fire at once, but noticed spastic behavior, like continually returning to default orientation and then re-aiming between each shot. I didn't know what the Signals and all that meant till a few days ago, and I thought armed with that new knowledge I could fix this bug, because I figured the Signals were important just not absolutely crucial to the core function of firing. Apparently my knowledge wasn't enough, as the units still won't fire all weapons with Signals included.
So, my two big questions are, does the number assigned to a Signal mask matter?
And, how do I set up my multiple weapons firing with these signals?
Just to specify, my understanding of signals is that SetSignalMask sort of labels a function as such and such, and you use Signal to make that function stop. I've tried assigning a different number to the second weapon, but that didn't work either.
And to complete the ensemble, here is an example of how I currently have my multiple weapons script.
Code: Select all
-- by KR
--pieces
local waist = piece "waist"
local rightthigh = piece "rightthigh"
local rightshin = piece "rightshin"
local rightfoot = piece "rightfoot"
local leftthigh = piece "leftthigh"
local leftshin = piece "leftshin"
local leftfoot = piece "leftfoot"
local body = piece "body"
local head = piece "head"
local rightarm = piece "rightarm"
local rightgun = piece "rightgun"
local flare2 = piece "flare2"
local leftarm = piece "leftarm"
local leftgun = piece "leftgun"
local flare1 = piece "flare1"
--signals
local SIG_AIM = 2
local SIG_AIM_SEC = 3
local walk_go = 4
local walk_stop = 5
function script.Create()
end
local function walk()
SetSignalMask(walk_go)
while (true) do
Turn( leftshin, x_axis, -1, 2 )
Turn( leftthigh, x_axis, 1, 2 )
Turn( rightshin, x_axis, 1, 2 )
Turn( rightthigh, x_axis, -1, 2 )
WaitForTurn( leftshin, x_axis )
WaitForTurn( leftthigh, x_axis )
WaitForTurn( rightshin, x_axis )
WaitForTurn( rightthigh, x_axis )
Sleep(1)
Turn( leftshin, x_axis, 1, 2 )
Turn( leftthigh, x_axis, -1, 2 )
Turn( rightshin, x_axis, -1, 2 )
Turn( rightthigh, x_axis, 1, 2 )
WaitForTurn( leftshin, x_axis )
WaitForTurn( leftthigh, x_axis )
WaitForTurn( rightshin, x_axis )
WaitForTurn( rightthigh, x_axis )
Sleep(1)
end
end
local function stop_walk()
Signal(walk_go)
Turn( leftshin, x_axis, 0, 2 )
Turn( leftthigh, x_axis, 0, 2 )
Turn( rightshin, x_axis, 0, 2 )
Turn( rightthigh, x_axis, 0, 2 )
end
function script.StartMoving()
StartThread(walk)
end
function script.StopMoving()
StartThread(stop_walk)
end
local function RestoreAfterDelay(unitID)
Sleep(2500)
Turn(body, y_axis, 0, math.rad(90))
Turn(leftarm, x_axis, 0, math.rad(50))
Turn(leftgun, x_axis, 0, math.rad(50))
Turn(rightarm, x_axis, 0, math.rad(50))
Turn(rightgun, x_axis, 0, math.rad(50))
end
function script.QueryWeapon1() return flare1 end
function script.QueryWeapon2() return flare2 end
function script.AimFromWeapon1() return body end
function script.AimFromWeapon2() return body end
function script.AimWeapon1( heading, pitch )
Signal(SIG_AIM)
SetSignalMask(SIG_AIM)
Turn(body, y_axis, heading, math.rad(90))
Turn(leftarm, x_axis, -0.75, math.rad(60))
Turn(leftgun, x_axis, -0.85, math.rad(60))
WaitForTurn(body, y_axis)
WaitForTurn(leftarm, x_axis)
WaitForTurn(leftgun, x_axis)
StartThread(RestoreAfterDelay)
return true
end
function script.AimWeapon2( heading, pitch )
Signal(SIG_AIM_SEC)
SetSignalMask(SIG_AIM_SEC)
Turn(body, y_axis, heading, math.rad(90))
Turn(rightarm, x_axis, -0.75, math.rad(60))
Turn(rightgun, x_axis, -0.85, math.rad(60))
WaitForTurn(body, y_axis)
WaitForTurn(rightarm, x_axis)
WaitForTurn(rightgun, x_axis)
StartThread(RestoreAfterDelay)
return true
end
function script.FireWeapon1()
Sleep(30)
end
function script.FireWeapon2()
Sleep(30)
end
function script.Killed(recentDamage, maxHealth)
Sleep(30)
end