LuaCallinReturn: Difference between revisions

From Spring
Jump to navigationJump to search
Knorke (talk | contribs)
Knorke (talk | contribs)
various small edits
Line 1: Line 1:
[[Engine_Development|Development]] < [[Lua_Scripting|Lua Scripting]] < {{FULLPAGENAME}}
[[Engine_Development|Development]] < [[Lua_Scripting|Lua Scripting]] < {{FULLPAGENAME}}


===Lua Call-Ins, with parameters===
==What is a callin anyway?==
<font style="font-size:90%">
Call-ins are calls from the engine, into the gadget or widget script. In other words, these functions are called when a particular “event” happens.
''Here are the known reserved parameter values for all Lua Call-Ins.  If you add new Call-Ins to Spring, please document them here.''
Some call-in functions can return values to the engine.
===Blocking events with return values===
The call-in functions named '''''Allow'''''XXX can block their event by returning ''false''.<br>
For example ''AllowUnitTransfer()''<br>
<code>return true</code> = allow transfer <br>
<code>return false</code> = deny transfer
 
 


==Commands, general-purpose:==
==Commands, general-purpose:==
Line 21: Line 28:


<font color=#55ee99>KeyRelease()</font> --> "key"
<font color=#55ee99>KeyRelease()</font> --> "key"
<font color=#55ee99>MapDrawCmd()</font> --> "playerID, cmdType, px, py, pz, label"


<font color=#55ee99>MouseMove()</font> --> "x, y, dx, dy, button"
<font color=#55ee99>MouseMove()</font> --> "x, y, dx, dy, button"
Line 67: Line 72:
<font color=#55ee99>UnitPreDamaged()</font> --> "unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam"
<font color=#55ee99>UnitPreDamaged()</font> --> "unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam"


<font color=#55ee99>UnitDamaged()</font> --> "unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam"
<font color=#55ee99>UnitDamaged()</font> --> "unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam"<br>
can overwrite the taken damage by returning a new number value


<font color=#55ee99>UnitCreated()</font> --> "unitID, unitDefID, teamID, builderID"
<font color=#55ee99>UnitCreated()</font> --> "unitID, unitDefID, teamID, builderID"
Line 124: Line 130:


<font color=#55ee99>UnitCmdDone()</font> --> "unitID, unitDefID, unitTeam, cmdID, cmdTag"
<font color=#55ee99>UnitCmdDone()</font> --> "unitID, unitDefID, unitTeam, cmdID, cmdTag"




==Drawing:==
==Drawing:==
Inside these functions, you can use the [[Lua_OpenGL_Api | Lua OpenGL Api]] to draw graphics.


* <font color=#55ee99>DrawGenesis()</font> --> none.  Don't render here.
* <font color=#55ee99>DrawGenesis()</font> --> none.  Don't render here.


* Spring draws the sky, the map, some water types, and unit selection.
Spring draws the sky, the map, some water types, and unit selection.


* <font color=#55ee99>DrawWorldPreUnit()</font> --> none.
* <font color=#55ee99>DrawWorldPreUnit()</font> --> none.


* Spring draws units, features, some water types, cloaked units, and the sun.
Spring draws units, features, some water types, cloaked units, and the sun.


* <font color=#55ee99>DrawWorld()</font> --> none.
* <font color=#55ee99>DrawWorld()</font> --> none.


* Spring draws command queues, 'map stuff', and map marks.
Spring draws command queues, 'map stuff', and map marks.


Each unit might also have a DrawUnit call, [[Lua_UnitRendering|enabled here.]]
Each unit might also have a DrawUnit call, [[Lua_UnitRendering|enabled here.]]
Line 196: Line 202:


<font color=#55ee99>ProjectileDestroyed()</font> --> "proID"
<font color=#55ee99>ProjectileDestroyed()</font> --> "proID"
==What is a callin anyway?==
Call-ins are calls from the engine, into the gadget or widget script. In other words, these functions are called when a particular “event” happens.
Some call-in functions can return values to the engine.


[[category: Lua]]
[[category: Lua]]
==Blocking events with return values:==
The call-in functions named '''''Allow'''''XXX can block their event by returning false.<br>
For example ''AllowUnitTransfer()''<br>
<code>return true</code> = allow transfer <br>
<code>return false</code> = deny transfer

Revision as of 17:42, 3 July 2011

Development < Lua Scripting < LuaCallinReturn

What is a callin anyway?

Call-ins are calls from the engine, into the gadget or widget script. In other words, these functions are called when a particular “event” happens. Some call-in functions can return values to the engine.

Blocking events with return values

The call-in functions named AllowXXX can block their event by returning false.
For example AllowUnitTransfer()
return true = allow transfer
return false = deny transfer


Commands, general-purpose:

Initialize() --> none.
called when widget/gadget gets (re-)loaded.

Shutdown() --> none.

LayoutButtons() --> unknown, please document.

ConfigureLayout() --> "command".

CommandNotify() --> "id, params, options", where id = the CommandID

KeyPress() --> "key, mods, isRepeat", where key = keymap, mods = SHIFT, etc.

KeyRelease() --> "key"

MouseMove() --> "x, y, dx, dy, button"

MousePress() --> "x, y, button"
button parameter values: left - 1, middle - 2, right - 3

MouseRelease() --> "x, y, button"
Please note that in order to have Spring call MouseRelease, you need to have a MousePress call-in in the same widget that returns true.

IsAbove() --> "x, y" where x,y = screen coordinates.

GetTooltip() --> "x, y" where x,y = screen coordinates. Returns WorldTooltip.

AddConsoleLine() --> "msg, priority"

MapDrawCmd() --> "playerID, cmdType, px, py, pz, labeltext"

AllowCommand() --> "unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced"

CommandFallback() --> "unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag"

CommandsChanged() --> unknown (none?)

AllowUnitCreation() --> "unitDefID, builderID, builderTeam, x, y, z"

AllowUnitTransfer() --> "unitID, unitDefID, oldTeam, newTeam, capture"

AllowUnitBuildStep() --> "builderID, builderTeam, unitID, unitDefID, part"

AllowFeatureCreation() --> "featureDefID, teamID, x, y, z"

AllowFeatureBuildStep() --> unknown, please document.

AllowResourceLevel() --> "teamID, res, level"

AllowResourceTransfer() --> "teamID, res, level"

Update() --> "dt"
gets called very often, even if the game is paused. dt is the time since the function was last called (???)

Unit-Specific:

UnitPreDamaged() --> "unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam"

UnitDamaged() --> "unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam"
can overwrite the taken damage by returning a new number value

UnitCreated() --> "unitID, unitDefID, teamID, builderID"

UnitFinished() --> "unitID, unitDefID, teamID"

UnitFromFactory() --> "unitID, unitDefID, unitTeam, factID, factDefID, userOrders"

UnitDestroyed() --> "unitID, unitDefID, teamID, attackerID?"

UnitTaken() --> "unitID, unitDefID, unitTeam, newTeam"

UnitGiven() --> "unitID, unitDefID, unitTeam, oldTeam"

UnitIdle() --> "unitID, unitDefID, teamID"

UnitCommand() --> "unitID, unitDefID, unitTeam, cmdID, cmdOpts, cmdParams"

UnitSeismicPing() --> "x, y, z, strength"

UnitEnteredRadar() --> "unitID, unitTeam"

UnitEnteredLos() --> "unitID, teamID"

UnitLeftRadar() --> "unitID, unitTeam"

UnitLeftLos() --> "unitID, unitDefID, teamID"

UnitLoaded() --> "unitID, unitDefID, unitTeam, transportID, transportTeam"

UnitUnloaded() --> "unitID, unitDefID, teamID, transportID"

UnitCloaked() --> "unitID, unitDefID, teamID"

UnitDecloaked)--> "unitID, unitDefID, teamID"

UnitMoveFailed() --> "unitID, unitDefID, unitTeam"

StockpileChanged() --> "unitID, unitDefID, unitTeam, weaponNum, oldCount, newCount"

UnitEnteredWater() --> "unitID, unitDefID, teamID"

UnitEnteredAir() --> "unitID, unitDefID, teamID"

UnitLeftWater() --> "unitID, unitDefID, teamID"

UnitLeftAir() --> "unitID, unitDefID, teamID"

Feature-Specific:

FeatureCreated() --> "featureID, allyTeam"

FeatureDestroyed() --> "featureID, allyTeam"

TerraformComplete() --> "unitID, unitDefID, unitTeam, buildUnitID, buildUnitDefID, buildUnitTeam"

UnitCmdDone() --> "unitID, unitDefID, unitTeam, cmdID, cmdTag"


Drawing:

Inside these functions, you can use the Lua OpenGL Api to draw graphics.

  • DrawGenesis() --> none. Don't render here.
Spring draws the sky, the map, some water types, and unit selection.
  • DrawWorldPreUnit() --> none.
Spring draws units, features, some water types, cloaked units, and the sun.
  • DrawWorld() --> none.
Spring draws command queues, 'map stuff', and map marks.

Each unit might also have a DrawUnit call, enabled here.

DrawUnit(unitID,DrawMode)
With enum DrawMode {
notDrawing = 0,
normalDraw = 1,
shadowDraw = 2,
reflectionDraw = 3,
refractionDraw = 4
};

DrawScreenEffects() --> "vsx, vsy" where vsx, vsy are screen coords.

DrawScreen() --> none.

DrawInMiniMap() --> "sx, sy" where sx,sy are values relative to the minimap's position and scale.

DrawWorldShadow() --> none.

DrawWorldReflection() --> none.

DrawWorldRefraction() --> none.

Game Events:

Explosion() --> "weaponID, px, py, pz, ownerID"

ShockFront() --> "power, dx, dy, dz"

GameFrame() --> "frameNum"

CobCallback() --> unknown, marked FIXME.

GroupChanged() --> "groupID" where groupID is the value of Group whose table value changed.

WorldTooltip() --> "ttType, data1, data2, data3" special, should be documented in detail.

GamePreload() --> none.

GameStart() --> none.

GameProgress() --> "serverFrameNum" ( called every 60 frames, calculating delta between GameFrame and GameProgress can give an ETA about catching up with simulation ) New in 0.83.x

GameOver() --> "[ [1] = allyTeamID1, [2] = allyTeamID2, ... ]", a list of winning allyteams, if empty the game result was undecided ( like when dropping from an host ) Will return nil in pre 0.83.x

TeamDied() --> "TeamID" where TeamID = the team that has been eliminated.

AllowStartPosition() --> nobody cares
returns nobody cares

Projectiles:

ProjectileCreated() --> "proID, proOwnerID"

ProjectileDestroyed() --> "proID"