Animation:LuaExamples: Difference between revisions
m tweak for 97+ |
m →Factory: should really call YARD_OPEN, too |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 6: | Line 6: | ||
== Script Scaffolds == | == Script Scaffolds == | ||
=== Air Transport === | |||
<syntaxhighlight lang="lua"> | |||
-- FIXME: This should be whatever piece name you want to attach to in your model | |||
local attachPiece = piece "attach" | |||
-- called for each unit loaded, returns the attaching piece | |||
function script.QueryTransport(passengerID) | |||
return attachPiece | |||
end | |||
-- called for each unit loaded to animate the load process | |||
function script.BeginTransport(passengerID) | |||
-- TODO: any loading animations here | |||
end | |||
--how this is called depends on https://springrts.com/wiki/Gamedev:UnitDefs#transportUnloadMethod | |||
-- 0 (Default) called once on the last unit dropped | |||
-- 1 called for each unit dropped in mid-air | |||
-- 2 called for the last unit dropped | |||
function script.EndTransport(passengerID) | |||
-- TODO: relevant end of transport sequence animations | |||
end | |||
-- Only called if transportUnloadMethod = 2 | |||
function script.TransportDrop(passengerID, x,y,z) | |||
-- TODO: animation to unload each individual passenger on the ground | |||
end | |||
</syntaxhighlight> | |||
=== Builder === | === Builder === | ||
< | <syntaxhighlight lang="lua"> | ||
local nanoPieces = {} | local nanoPieces = {} | ||
-- FIXME: this example has 2 nano pieces to alternate between | -- FIXME: this example has 2 nano pieces to alternate between | ||
| Line 24: | Line 54: | ||
SetUnitValue(COB.INBUILDSTANCE, false) | SetUnitValue(COB.INBUILDSTANCE, false) | ||
end | end | ||
</ | </syntaxhighlight> | ||
=== Factory === | === Factory === | ||
< | <syntaxhighlight lang="lua"> | ||
local nanoPieces = {} | local nanoPieces = {} | ||
-- FIXME: this example has 2 nano pieces to alternate between | -- FIXME: this example has 2 nano pieces to alternate between | ||
| Line 49: | Line 79: | ||
-- TODO: This is where you would add your closing up anim | -- TODO: This is where you would add your closing up anim | ||
end | end | ||
SetUnitValue(COB.YARD_OPEN, open) | |||
SetUnitValue(COB.BUGGER_OFF, open) | |||
SetUnitValue(COB.INBUILDSTANCE, open) | SetUnitValue(COB.INBUILDSTANCE, open) | ||
end | end | ||
| Line 72: | Line 103: | ||
-- TODO: You can run any animation that signifies the end of the build process here | -- TODO: You can run any animation that signifies the end of the build process here | ||
end | end | ||
</ | </syntaxhighlight> | ||
=== Wind Generator === | === Wind Generator === | ||
< | <syntaxhighlight lang="lua"> | ||
-- FIXME: Assumes model has pieces named 'tower' and 'blades' | -- FIXME: Assumes model has pieces named 'tower' and 'blades' | ||
local tower, blades = piece("tower", "blades") | local tower, blades = piece("tower", "blades") | ||
| Line 86: | Line 117: | ||
Spin(blades, z_axis, strength * 0.5) | Spin(blades, z_axis, strength * 0.5) | ||
end | end | ||
</ | </syntaxhighlight> | ||
[[Category:Animation]] | |||
Latest revision as of 16:38, 9 June 2020
LUS Script Examples
How to use
FIXME- Indicates a section of code you will need to tweak to suit your own unit / modelTODO- Indicates an optional section of code is missing that you may wish to pad out e.g. with an animation
Script Scaffolds
Air Transport
<syntaxhighlight lang="lua"> -- FIXME: This should be whatever piece name you want to attach to in your model local attachPiece = piece "attach"
-- called for each unit loaded, returns the attaching piece function script.QueryTransport(passengerID)
return attachPiece
end
-- called for each unit loaded to animate the load process function script.BeginTransport(passengerID)
-- TODO: any loading animations here
end
--how this is called depends on https://springrts.com/wiki/Gamedev:UnitDefs#transportUnloadMethod -- 0 (Default) called once on the last unit dropped -- 1 called for each unit dropped in mid-air -- 2 called for the last unit dropped function script.EndTransport(passengerID)
-- TODO: relevant end of transport sequence animations
end
-- Only called if transportUnloadMethod = 2
function script.TransportDrop(passengerID, x,y,z)
-- TODO: animation to unload each individual passenger on the ground
end </syntaxhighlight>
Builder
<syntaxhighlight lang="lua"> local nanoPieces = {} -- FIXME: this example has 2 nano pieces to alternate between for i = 1, 2 do
-- FIXME: the pieces are named nanoPiece1 and nanoPiece2 in the model
nanoPieces[i] = piece("nanoPiece" .. i)
end Spring.SetUnitNanoPieces(unitID, nanoPieces)
function script.StartBuilding(heading, pitch)
-- TODO: This is where you would add your unpack / point towards animation SetUnitValue(COB.INBUILDSTANCE, true)
end function script.StopBuilding()
-- TODO: This is where you would add your pack-up animation SetUnitValue(COB.INBUILDSTANCE, false)
end </syntaxhighlight>
Factory
<syntaxhighlight lang="lua"> local nanoPieces = {} -- FIXME: this example has 2 nano pieces to alternate between for i = 1, 2 do
-- FIXME: the pieces are named nanoPiece1 and nanoPiece2 in the model
nanoPieces[i] = piece("nanoPiece" .. i)
end Spring.SetUnitNanoPieces(unitID, nanoPieces)
function script.QueryBuildInfo()
-- FIXME: the pad piece is named buildPad in the model
return piece("buildPad")
end
local function OpenCloseAnim(open)
Signal(1) -- Kill any other copies of this thread
SetSignalMask(1) -- Allow this thread to be killed by fresh copies
if open then
-- TODO: This is where you would add your opening up anim
else
-- TODO: This is where you would add your closing up anim
end
SetUnitValue(COB.YARD_OPEN, open)
SetUnitValue(COB.BUGGER_OFF, open)
SetUnitValue(COB.INBUILDSTANCE, open)
end
-- Called when factory yard opens function script.Activate()
-- OpenCloseAnim must be threaded to call Sleep() or WaitFor functions StartThread(OpenCloseAnim, true)
end
-- Called when factory yard closes function script.Deactivate()
-- OpenCloseAnim must be threaded to call Sleep() or WaitFor functions StartThread(OpenCloseAnim, false)
end
function script.StartBuilding()
-- TODO: You can run any animation that continues throughout the build process here e.g. spin pad
end
function script.StopBuilding()
-- TODO: You can run any animation that signifies the end of the build process here
end </syntaxhighlight>
Wind Generator
<syntaxhighlight lang="lua"> -- FIXME: Assumes model has pieces named 'tower' and 'blades' local tower, blades = piece("tower", "blades")
function script.WindChanged (number heading, number strength)
-- Turn the tower to face the wind at 30deg/s Turn(tower, y_axis, heading, math.rad(30)) -- Spin the turbine blades relative to wind strength -- FIXME: Here I set rotational speed to half of strength Spin(blades, z_axis, strength * 0.5)
end </syntaxhighlight>