There are tons of things that comprise a "complete" script. You are asking for a very specific thing but have yet to set down requirements.
Code: Select all
-------------------------------------------------------
-- License: Public Domain
-- Author: Steve (Smoth) Smith
-- Date: 4/19/2014
-------------------------------------------------------
-- Piece names
head = piece 'torso'
base = piece 'torso'
l_arm = piece 'luparm'
l_forearm = piece 'biggun'
r_arm = piece 'ruparm'
r_forearm = piece 'rloarm'
lflare = piece 'lflare'
nano = piece 'nano'
laserflare = piece 'laserflare'
cod = piece 'pelvis'
right_l = piece 'rthigh'
left_l = piece 'lthigh'
shin_l = piece 'lleg'
shin_r = piece 'rleg'
foot_r = piece 'rfoot'
foot_l = piece 'lfoot'
dish = piece 'dish'
-- State variables
isMoving, isAiming, isBuilding = "derpy spring", "derpy spring", "derpy spring"
-- used to restore build aiming
buildY, buildX = 0, 0
firedWeapon = false
-- Unit Speed
speedMult = 2.4
-- Unit animation preferences
leftArm = true;
rightArm = true;
heavy = true;
-- Signal definitions
local SIG_AIM = 2
local SIG_WALK = 4
-- effects for emitters
local effectA = 1024
local effectB = 1025
--local SMOKEPIECE1 = base
local inStance = false
function walk()
Signal(SIG_WALK)
SetSignalMask(SIG_WALK)
Turn(right_l, z_axis, 0, math.rad(135))
Turn(left_l, z_axis, 0, math.rad(130))
Turn(foot_l, y_axis, 0, math.rad(130))
Turn(foot_r, y_axis, 0, math.rad(130))
Turn(foot_l, x_axis, 0, math.rad(130))
Turn(foot_r, x_axis, 0, math.rad(130))
Turn(foot_l, z_axis, 0, math.rad(130))
Turn(foot_r, z_axis, 0, math.rad(130))
Turn(right_l, y_axis, 0, math.rad(135))
Turn(left_l, y_axis, 0, math.rad(130))
while true do
if (isAiming == false) then
if (leftArm == true ) then
Turn(l_arm, x_axis, math.rad(-25), math.rad(35 * speedMult))
end
if (rightArm == true ) then
Turn(r_arm, x_axis, math.rad(25), math.rad(45 * speedMult))
end
Turn(base, y_axis, math.rad(-5), math.rad(25 * speedMult))
Turn(base, z_axis, math.rad(2), math.rad(2 * speedMult))
end
Turn(shin_r, x_axis, math.rad(85), math.rad(137.5 * speedMult))
Turn(right_l, x_axis, math.rad(-60), math.rad(70 * speedMult))
Turn(left_l, x_axis, math.rad(30), math.rad(70 * speedMult))
Sleep(600/speedMult)
Move(cod, y_axis, 0.8, 40)
Sleep(500/speedMult)
Turn(shin_r, x_axis, math.rad(10), math.rad(185 * speedMult))
Move(cod, y_axis, -3, 20)
if (isAiming == false) then
if (rightArm == true ) then
Turn(r_arm, x_axis, math.rad(-25), math.rad(35 * speedMult))
end
if (leftArm == true ) then
Turn(l_arm, x_axis, math.rad(25), math.rad(45 * speedMult))
end
Turn(base, y_axis, math.rad(5), math.rad(25 * speedMult))
Turn(base, z_axis, math.rad(-2), math.rad(2 * speedMult))
end
Turn(shin_l, x_axis, math.rad(85), math.rad(137.5 * speedMult))
Turn(left_l, x_axis, math.rad(-60), math.rad(70 * speedMult))
Turn(right_l, x_axis, math.rad(30), math.rad(70 * speedMult))
Sleep(658/speedMult)
Move(cod, y_axis, 0.8, 40)
Sleep(500/speedMult)
Turn(shin_l, x_axis, math.rad(10), math.rad(185 * speedMult))
Move(cod, y_axis, -3, 20)
end
end
function poser()
Signal(SIG_WALK)
SetSignalMask(SIG_WALK)
if(heavy == true ) then
SquatStance()
else
StandStance()
end
end
function StandStance()
Sleep(200)
Move(cod, y_axis, 0, now)
Turn(base, z_axis, 0, now)
Signal(SIG_WALK)
SetSignalMask(SIG_WALK)
Move(cod, y_axis, math.rad(-0.5), math.rad(8000))
Turn(base, x_axis, math.rad(-2), math.rad(395))
if (isAiming == false) then
if (leftArm == true ) then
Turn(l_arm, x_axis, math.rad(10), math.rad(395))
Turn(l_arm, y_axis, math.rad(5), math.rad(395))
Turn(l_arm, z_axis, math.rad(9), math.rad(395))
Turn(l_forearm, x_axis, math.rad(-38), math.rad(395))
end
if (rightArm == true ) then
Turn(r_arm, x_axis, math.rad(10), math.rad(395))
Turn(r_arm, y_axis, math.rad(-5), math.rad(395))
Turn(r_arm, z_axis, math.rad(-9), math.rad(395))
Turn(r_forearm, x_axis, math.rad(-38), math.rad(395))
end
end
Turn(right_l, x_axis, 0, math.rad(235))
Turn(right_l, y_axis, math.rad(-18), math.rad(135))
Turn(right_l, z_axis, math.rad(-15), math.rad(135))
Turn(left_l, x_axis, 0, math.rad(235))
Turn(left_l, y_axis, math.rad(18), math.rad(135))
Turn(left_l, z_axis, math.rad(15), math.rad(135))
Turn(shin_l, x_axis, 0, math.rad(235))
Turn(shin_r, x_axis, 0, math.rad(230))
Turn(foot_l, x_axis, math.rad(1), math.rad(395))
Turn(foot_l, y_axis, math.rad(5), math.rad(130))
Turn(foot_l, z_axis, math.rad(-15), math.rad(130))
Turn(foot_r, x_axis, math.rad(1), math.rad(395))
Turn(foot_r, y_axis, math.rad(-5), math.rad(130))
Turn(foot_r, z_axis, math.rad(15), math.rad(130))
Sleep(0)
end
function SquatStance ()
Sleep(200)
Signal(SIG_WALK)
SetSignalMask(SIG_WALK)
Move(cod, y_axis, -3, now)
Turn(base, z_axis, 0, now)
Turn(base, x_axis, math.rad(5), math.rad(395))
Turn(cod, x_axis, math.rad(-5), math.rad(395))
if (isAiming == false) then
if (leftArm == true ) then
Turn(l_arm, x_axis, math.rad(15), math.rad(395))
Turn(l_arm, y_axis, math.rad(5), math.rad(395))
Turn(l_arm, z_axis, math.rad(10), math.rad(395))
Turn(l_forearm, x_axis, math.rad(-50), math.rad(395))
end
if (rightArm == true ) then
Turn(r_arm, x_axis, math.rad(15), math.rad(395))
Turn(r_arm, y_axis, math.rad(-5), math.rad(395))
Turn(r_arm, z_axis, math.rad(-10), math.rad(395))
Turn(r_forearm, x_axis, math.rad(-50), math.rad(395))
end
end
Turn(right_l, x_axis, math.rad(-24), math.rad(235))
Turn(right_l, y_axis, math.rad(-10), math.rad(135))
Turn(right_l, z_axis, math.rad(-20), math.rad(135))
Turn(left_l, x_axis, math.rad(-24), math.rad(235))
Turn(left_l, y_axis, math.rad(10), math.rad(135))
Turn(left_l, z_axis, math.rad(20), math.rad(135))
Turn(shin_l, x_axis, math.rad(45), math.rad(235))
Turn(shin_r, x_axis, math.rad(45), math.rad(230))
Turn(foot_l, x_axis, math.rad(-11), math.rad(395))
Turn(foot_l, y_axis, math.rad(10), math.rad(130))
Turn(foot_l, z_axis, math.rad(-20), math.rad(130))
Turn(foot_r, x_axis, math.rad(-11), math.rad(395))
Turn(foot_r, y_axis, math.rad(-10), math.rad(130))
Turn(foot_r, z_axis, math.rad(20), math.rad(130))
LookAround()
Sleep(0)
end
function FixArms(leftflag, rightflag)
Turn(l_arm, z_axis, 0, math.rad(395))
Turn(r_arm, z_axis, 0, math.rad(395))
if (leftflag == true ) then
Turn(l_arm, x_axis, 0, math.rad(395))
Turn(l_arm, y_axis, 0, math.rad(395))
Turn(l_forearm, x_axis, 0, math.rad(395))
end
if (rightflag == true ) then
Turn(r_arm, x_axis, 0, math.rad(395))
Turn(r_arm, y_axis, 0, math.rad(395))
Turn(r_forearm, x_axis, 0, math.rad(395))
end
end
function Dash(leftflag, rightflag)
Turn(head, x_axis, math.rad(-20), math.rad(395))
Turn(cod, x_axis, math.rad(20), math.rad(395))
if (isAiming == false) then
Turn(l_arm, x_axis, math.rad(30), math.rad(395))
Turn(l_arm, y_axis, math.rad(10), math.rad(395))
Turn(l_forearm, x_axis, math.rad(-45), math.rad(395))
Turn(r_arm, x_axis, math.rad(30), math.rad(395))
Turn(r_arm, y_axis, math.rad(-10), math.rad(395))
Turn(r_forearm, x_axis, math.rad(-45), math.rad(395))
end
Turn(right_l, x_axis, math.rad(-50), math.rad(235))
Turn(left_l, x_axis, math.rad(40), math.rad(235))
Turn(shin_l, x_axis, 0, math.rad(235))
Turn(shin_r, x_axis, math.rad(90), math.rad(230))
Turn(foot_l, x_axis, math.rad(20), math.rad(395))
Turn(foot_r, x_axis, math.rad(20), math.rad(395))
Sleep(50)
end
function AmIBored()
return isAiming == false and isBuilding == false and isMoving == false
end
function LookAround()
while true do
if AmIBored() then
Turn(base, y_axis, 0, 5)
local randomRotDegrees = math.random(10, 50)
local randomRotRadians = math.rad(randomRotDegrees)
randomAnim = math.random(1, 3)
if randomAnim >= 2 and AmIBored() then
Turn(base, y_axis, randomRotRadians, 0.34*randomAnim)
Turn(head, y_axis, randomRotRadians/2, 0.18*randomAnim)
Sleep(400)
end
if randomAnim == 2 and AmIBored() then
if (isAiming == false and isMoving == false) then
Turn(r_arm, x_axis, -1.1, randomRotDegrees/10)
Turn(l_arm, x_axis, 0.1, 2)
Sleep(400)
end
else
Turn(r_arm, x_axis, -0.15, 0.18)
Turn(l_arm, x_axis, 0.1, 2)
Sleep(400)
end
if randomAnim <= 2 and AmIBored() then
Turn(base, y_axis, -randomRotRadians, 0.34*randomAnim)
Turn(head, y_axis, -randomRotRadians/2, 0.18*randomAnim)
Sleep(400)
end
if AmIBored() then
Sleep(500)
end
if randomAnim == 1 and AmIBored() then
Turn(r_arm, x_axis, 0.1, 2)
Turn(l_arm, x_axis, -randomRotDegrees/95, randomRotDegrees/20)
Sleep(400)
else
if randomAnim == 2 then
Turn(r_arm, x_axis, 0.1, 0.1)
else
Turn(r_arm, x_axis, 0.1, 0.5)
end
Turn(l_arm, x_axis, -0.15, 0.18)
Sleep(500)
end
Sleep(600)
else-- not aiming, not building oh lawd!
Sleep(600)
end
end
end
function MotionControl()
idleTimer = 0
while (1) do
if ( isMoving and isMoving == true ) then
inStance = false
--StartThread(walk)
else
-- we only want to run the standing animation once
end
Sleep(50)
end
end
function script.StartMoving()
isMoving = true
StartThread(walk)
end
function script.StopMoving()
isMoving = false
StartThread(poser)
end
--------------------------------------------------------
--start ups :)
--------------------------------------------------------
function script.Create()
-- Initial State
Turn(r_forearm, x_axis, math.rad(-15),math.rad(130))
Turn(lflare, x_axis,math.rad(90))
Turn(nano, x_axis,math.rad(90))
Turn(laserflare, x_axis,math.rad(90))
Spin(dish, y_axis, 2.5)
-- because DERP
isAiming = false
isBuilding = false
isMoving = false
if(heavy == true ) then
SquatStance()
else
StandStance()
end
-- should do this instead of query nano piece
--Spring.SetUnitNanoPieces( unitID, {nano} )
end
-----------------------------------------------------------------------
--function to restore the aim if construction was interupted by combat
-----------------------------------------------------------------------
function ResumeBuilding()
sleep(400)
if isBuilding and firedWeapon then
Turn(base, y_axis, buildY, 2.618)
Turn(r_arm, x_axis, 0.5235 - buildx, 2.618 )
end
end
-----------------------------------------------------------------------
--gun functions;
-----------------------------------------------------------------------
function script.AimFromWeapon(weaponID)
if weaponID == 3 then
return l_arm
else
return r_arm
end
end
function script.QueryWeapon(weaponID)
if weaponID == 3 then
return lflare
else
return laserflare
end
end
-----------------------------------------------------------------------
-- This coroutine is restarted with each time a unit reaims,
-- not the most efficient and should be optimized. Possible
-- augmentation needed to lus.
-----------------------------------------------------------------------
local function RestoreAfterDelayLeft()
Sleep(1000)
Turn(base, y_axis, 0, math.rad(105))
Turn(l_forearm, x_axis, math.rad(-38), math.rad(95))
Turn(l_arm, x_axis, math.rad(15), math.rad(95))
isAiming = false
end
local function RestoreAfterDelayRight()
Sleep(1000)
Turn(base, y_axis, 0, math.rad(105))
Turn(r_forearm, x_axis, math.rad(-38), math.rad(95))
Turn(r_arm, x_axis, math.rad(15), math.rad(95))
isAiming = false
end
function script.AimWeapon(weaponID, heading, pitch)
-- weapon2 is supposed to only fire underwater, check for it.
if weaponID == 2 then
local _, basepos, _ = Spring.GetUnitPosition(unitID)
if basepos > -16 then
return false
end
end
--Spring.Echo("AimWeapon " .. weaponID)
Signal(SIG_AIM)
SetSignalMask(SIG_AIM)
isAiming = true
if weaponID == 1 or weaponID == 2 then
FixArms(false, true)
Turn(base, y_axis, heading, math.rad(105))
Turn(r_forearm, x_axis, math.rad(-55), math.rad(390))
Turn(r_arm, x_axis, math.rad(-45) - pitch, math.rad(390))
Sleep(200)
WaitForTurn(base, y_axis)
WaitForTurn(r_arm, x_axis)
WaitForTurn(r_forearm, x_axis)
--Spring.Echo("AimWeapon " .. weaponID .. " done turning")
StartThread(RestoreAfterDelayRight)
firedWeapon = false
-- if I was buidling restore my arm position
if (isBuilding == true) then
-- ResumeBuilding();
end
--Spring.Echo("AimWeapon " .. weaponID .. " end")
return true
elseif weaponID == 3 then
FixArms(true, false)
Turn(base, y_axis, heading, math.rad(105))
Turn(l_forearm, x_axis, math.rad(-85), math.rad(390))
Turn(l_arm, x_axis, math.rad(-5) - pitch, math.rad(390))
Sleep(200)
WaitForTurn(base, y_axis)
WaitForTurn(l_arm, x_axis)
WaitForTurn(l_forearm, x_axis)
--Spring.Echo("AimWeapon done turning")
StartThread(RestoreAfterDelayLeft)
firedWeapon = false
-- if I was buidling restore my arm position
if (isBuilding == true) then
-- ResumeBuilding();
end
--Spring.Echo("AimWeapon end")
return true
else
return false
end
end
function script.FireWeapon(weaponID)
Sleep(500)
firedWeapon = true
end
-----------------------------------------------------------------------
-- I dunno, a bunch of stuff I hastily ported to lua.
-----------------------------------------------------------------------
function script.QueryNanoPiece()
return nano
end
function script.StartBuilding(heading, pitch)
-- Spring.Echo("StartBuilding")
IsFiringDgun = 0;
isBuilding = true;
buildY, buildX = heading, pitch
Turn(base, y_axis, heading, math.rad(105))
Turn(r_forearm, x_axis, math.rad(-55), math.rad(390))
Turn(r_arm, x_axis, math.rad(-55) - pitch, math.rad(390))
WaitForTurn(r_arm, x_axis)
SetUnitValue(COB.INBUILDSTANCE, 1)
end
function script.StopBuilding()
Sleep(200)
isBuilding = false;
SetUnitValue(COB.INBUILDSTANCE, 0)
-- Spring.Echo("Stop Building", isAiming, isBuilding, isMoving)
end
-----------------------------------------------------------------------
-- death stuffs
-----------------------------------------------------------------------
function script.Killed(recentDamage, maxHealth)
-- fall over
Turn(cod, x_axis, math.rad(270), 5)
-- reset parts
Turn(base, y_axis, 0, 8)
Turn(r_arm, z_axis, 4, 3)
Turn(l_arm, z_axis, -4, 3)
-- fall
Move(cod, y_axis, -30, 100)
Turn(base, x_axis, 0.5, 8)
Turn(right_l, x_axis, -0.5, 8)
Turn(left_l, x_axis, -0.5, 8)
WaitForMove(cod, y_axis)
-- land
Turn(r_forearm, x_axis, 0, 5)
Turn(l_forearm, x_axis, 0, 5)
Move(cod, y_axis, -35, 200)
Turn(base, x_axis, 0, 10)
Turn(right_l, x_axis, 0, 10)
Turn(left_l, x_axis, 0, 10)
WaitForMove(cod, y_axis)
local severity = recentDamage/maxHealth
if (severity <= 99) then
Explode(l_arm, SFX.FALL)
Explode(r_arm, SFX.FALL)
Explode(l_arm, SFX.FALL)
Explode(l_forearm, SFX.FALL)
Explode(r_arm, SFX.FALL)
Explode(r_forearm, SFX.FALL)
return 3
else
return 0
end
end
All I had to do was paste the include into the script. If this is too complicated, well you wanted a full script.
this stuff is not hard.