LuaAPI.wiki
changeset 76 0cdebc52edad
parent 75 2ef49675d837
child 77 588f5dc682e2
equal deleted inserted replaced
75:2ef49675d837 76:0cdebc52edad
    55 === <tt>onGameTick()</tt> ===
    55 === <tt>onGameTick()</tt> ===
    56 
    56 
    57 <blockquote>This function is called on every game tick, i.e. 1000 times a second.
    57 <blockquote>This function is called on every game tick, i.e. 1000 times a second.
    58 </blockquote>
    58 </blockquote>
    59 
    59 
    60 === <tt>onNewTurn()</tt> (dev) ===
    60 === <tt>onNewTurn()</tt> (0.9.15) ===
    61 
    61 
    62 <blockquote>This function calls at the start of every turn.
    62 <blockquote>This function calls at the start of every turn.
    63 </blockquote>
    63 </blockquote>
    64 === <tt>onGearAdd(gearUid)</tt> ===
    64 === <tt>onGearAdd(gearUid)</tt> ===
    65 
    65 
    69 === <tt>onGearDelete(gearUid)</tt> ===
    69 === <tt>onGearDelete(gearUid)</tt> ===
    70 
    70 
    71 <blockquote>This function is called when a new gear is deleted. Useful in
    71 <blockquote>This function is called when a new gear is deleted. Useful in
    72 combination with <tt>!GetGearType(gearUid)</tt>.
    72 combination with <tt>!GetGearType(gearUid)</tt>.
    73 </blockquote>
    73 </blockquote>
    74 === <tt>onGearDamage(gearUid, damage)</tt> (dev) ===
    74 === <tt>onGearDamage(gearUid, damage)</tt> (0.9.15) ===
    75 
    75 
    76 <blockquote>This function is called when a gear is damaged.
    76 <blockquote>This function is called when a gear is damaged.
    77 </blockquote>
    77 </blockquote>
    78 
    78 
    79 Example:
    79 Example:
    82         if (!GetGearType(gear) == gtHedgehog) then
    82         if (!GetGearType(gear) == gtHedgehog) then
    83             -- adds a message saying, e.g. "Hoggy H took 25 points of damage"
    83             -- adds a message saying, e.g. "Hoggy H took 25 points of damage"
    84             !AddCaption(!GetHogName(gear) .. ' took ' .. damage .. ' points of damage')
    84             !AddCaption(!GetHogName(gear) .. ' took ' .. damage .. ' points of damage')
    85         end
    85         end
    86     end</code>
    86     end</code>
    87 === <tt>onGearResurrect(gearUid) (dev)</tt> ===
    87 === <tt>onGearResurrect(gearUid) (0.9.14)</tt> ===
    88 
    88 
    89 <blockquote>This function is called when a gear is resurrected. CPU Hogs will resurrect if gfAISurvival is included in !GameFlags. Alternatively, specific gears can have heResurrectable set to true via !SetEffect.
    89 <blockquote>This function is called when a gear is resurrected. CPU Hogs will resurrect if gfAISurvival is included in !GameFlags. Alternatively, specific gears can have heResurrectable set to true via !SetEffect.
    90 </blockquote>
    90 </blockquote>
    91 === <tt>onAmmoStoreInit()</tt> ===
    91 === <tt>onAmmoStoreInit()</tt> ===
    92 
    92 
   209 === <tt>!GetBotLevel(gearUid)</tt> (0.9.14) ===
   209 === <tt>!GetBotLevel(gearUid)</tt> (0.9.14) ===
   210 
   210 
   211 <blockquote>returns the bot level from 0 to 5. 0 means human player.
   211 <blockquote>returns the bot level from 0 to 5. 0 means human player.
   212 </blockquote>
   212 </blockquote>
   213 
   213 
   214 === <tt>!GetVisualGearValues(vgUid)</tt> (dev) ===
   214 === <tt>!GetVisualGearValues(vgUid)</tt> (0.9.15) ===
   215 
   215 
   216 <blockquote>This returns the typically set visual gear values, useful if manipulating things like smoke or bubbles or circles.  It returns the following values:
   216 <blockquote>This returns the typically set visual gear values, useful if manipulating things like smoke or bubbles or circles.  It returns the following values:
   217 X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint 
   217 X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint 
   218 X, Y typically position, dX, dY typically speed, Angle is usually the rotation angle, Frame is typically the animation frame, FrameTicks is usually an animation counter.  State can have a variety of values, but is typically bit packed, Timer is usually the gear lifetime and Tint is the colour.
   218 X, Y typically position, dX, dY typically speed, Angle is usually the rotation angle, Frame is typically the animation frame, FrameTicks is usually an animation counter.  State can have a variety of values, but is typically bit packed, Timer is usually the gear lifetime and Tint is the colour.
   219 Most visual gears require little to no modification of parameters.
   219 Most visual gears require little to no modification of parameters.
   231 Example:
   231 Example:
   232 
   232 
   233 <code lang="lua">    gear = !AddGear(…)
   233 <code lang="lua">    gear = !AddGear(…)
   234     !DeleteGear(gear) -- Delete the newly created gear.</code>
   234     !DeleteGear(gear) -- Delete the newly created gear.</code>
   235 
   235 
   236 === <tt>!DeleteVisualGear(vgUid)</tt> (dev) ===
   236 === <tt>!DeleteVisualGear(vgUid)</tt> (0.9.15) ===
   237 
   237 
   238 <blockquote>Deletes a Visual Gear.  Note, most visual gears delete themselves.</blockquote>
   238 <blockquote>Deletes a Visual Gear.  Note, most visual gears delete themselves.</blockquote>
   239 Example:
   239 Example:
   240 
   240 
   241 <code lang="lua">    vgear = !AddVisualGear(…)
   241 <code lang="lua">    vgear = !AddVisualGear(…)
   242     !DeleteVisualGear(vgear) -- Delete the newly created visual gear.</code>
   242     !DeleteVisualGear(vgear) -- Delete the newly created visual gear.</code>
   243 
   243 
   244 
   244 
   245 === <tt>!SetVisualGearValues(vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)</tt> (dev) ===
   245 === <tt>!SetVisualGearValues(vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)</tt> (0.9.15) ===
   246 
   246 
   247 <blockquote>This allows manipulation of many of the visual gear values.  Calling GetVisualGearValues first is recommended on most visual gears unless you are controlling all the key values.  In the case of vgtCircle, the visual gear values are mapped as follows.  X, Y: position.  State: radius. Timer: Thickness.  FrameTicks: pulsation speed (0 to disable).  dX, dY: min/max pulsation opacity (0-255). Tint: colour, RGBA.
   247 <blockquote>This allows manipulation of many of the visual gear values.  Calling GetVisualGearValues first is recommended on most visual gears unless you are controlling all the key values.  In the case of vgtCircle, the visual gear values are mapped as follows.  X, Y: position.  State: radius. Timer: Thickness.  FrameTicks: pulsation speed (0 to disable).  dX, dY: min/max pulsation opacity (0-255). Tint: colour, RGBA.
   248 Most visual gears require little to no modification of parameters.
   248 Most visual gears require little to no modification of parameters.
   249 </blockquote>
   249 </blockquote>
   250 Example:
   250 Example:
   281     !HogTurnLeft(!CurrentHedgehog, false) -- turns !CurrentHedgehog right</code>
   281     !HogTurnLeft(!CurrentHedgehog, false) -- turns !CurrentHedgehog right</code>
   282 === <tt>!SetGearPosition(gearUid, x, y)</tt> ===
   282 === <tt>!SetGearPosition(gearUid, x, y)</tt> ===
   283 
   283 
   284 <blockquote>Places the specified gear exactly at the position (x,y).
   284 <blockquote>Places the specified gear exactly at the position (x,y).
   285 </blockquote>
   285 </blockquote>
   286 === <tt>!SetGearVelocity(gearUid, dx, dy)</tt> (dev) ===
   286 === <tt>!SetGearVelocity(gearUid, dx, dy)</tt> (0.9.15) ===
   287 
   287 
   288 <blockquote>Gives the specified gear the velocity of dx, dy.
   288 <blockquote>Gives the specified gear the velocity of dx, dy.
   289 </blockquote>
   289 </blockquote>
   290 === <tt>!SetAmmo(ammoType, count, probability, delay, numberInCrate)</tt> ===
   290 === <tt>!SetAmmo(ammoType, count, probability, delay, numberInCrate)</tt> ===
   291 
   291 
   374 === <tt>!PlaySound(soundId)</tt> ===
   374 === <tt>!PlaySound(soundId)</tt> ===
   375 
   375 
   376 <blockquote>Plays the specified sound.
   376 <blockquote>Plays the specified sound.
   377 </blockquote>
   377 </blockquote>
   378 
   378 
   379 === <tt>!PlaySound(soundId, gearUid)</tt> (dev) ===
   379 === <tt>!PlaySound(soundId, gearUid)</tt> (0.9.15) ===
   380 
   380 
   381 <blockquote>Plays the specified sound for the chosen hedgehog's team.
   381 <blockquote>Plays the specified sound for the chosen hedgehog's team.
   382 </blockquote>
   382 </blockquote>
   383 
   383 
   384 === <tt>!SetZoom(zoomLevel)</tt> (0.9.14) ===
   384 === <tt>!SetZoom(zoomLevel)</tt> (0.9.14) ===
   394 === <tt>!GetRandom(number)</tt> (0.9.14) ===
   394 === <tt>!GetRandom(number)</tt> (0.9.14) ===
   395 
   395 
   396 <blockquote>Returns a randomly generated number in the range of 0 to number - 1.  This random number uses the game seed, so is synchronised, and thus safe for multiplayer and saved games.  Use GetRandom for anything that could impact the engine state.  For example, a visual gear can use the Lua random, but adding a regular gear should use GetRandom.
   396 <blockquote>Returns a randomly generated number in the range of 0 to number - 1.  This random number uses the game seed, so is synchronised, and thus safe for multiplayer and saved games.  Use GetRandom for anything that could impact the engine state.  For example, a visual gear can use the Lua random, but adding a regular gear should use GetRandom.
   397 </blockquote>
   397 </blockquote>
   398 
   398 
   399 === <tt>!SetWind(windSpeed)</tt> (dev) ===
   399 === <tt>!SetWind(windSpeed)</tt> (0.9.15) ===
   400 
   400 
   401 <blockquote>Sets the current wind in the range of -100 to 100. Use together with gfDisableWind for full control.
   401 <blockquote>Sets the current wind in the range of -100 to 100. Use together with gfDisableWind for full control.
   402 </blockquote>
   402 </blockquote>
   403 
   403 
   404 === <tt>!GetDataPath()</tt> (dev) ===
   404 === <tt>!GetDataPath()</tt> (dev) ===
   405 
   405 
   406 <blockquote>Returns the path to the data directory, used when adding libraries.
   406 <blockquote>Returns the path to the data directory, used when adding libraries.
   407 </blockquote>
   407 </blockquote>
   408 
   408 
   409 === <tt>!GetClanColor(clan)<tt> (dev) ===
   409 === <tt>!GetClanColor(clan)<tt> (0.9.15) ===
   410 
   410 
   411 <blockquote>Returns the colour of the chosen clan by its number.
   411 <blockquote>Returns the colour of the chosen clan by its number.
   412 </blockquote>
   412 </blockquote>
   413 
   413 
   414 == Debugging Functions ==
   414 == Debugging Functions ==