LuaAPI.wiki
changeset 361 315e9db1f458
parent 360 2fcb523f0cc4
child 369 cbde2d9686a5
equal deleted inserted replaced
360:2fcb523f0cc4 361:315e9db1f458
   126 </blockquote>
   126 </blockquote>
   127 
   127 
   128 Example:
   128 Example:
   129 
   129 
   130 <code lang="lua">    function onGearDamage(gear, damage)
   130 <code lang="lua">    function onGearDamage(gear, damage)
   131         if (!GetGearType(gear) == gtHedgehog) then
   131         if (GetGearType(gear) == gtHedgehog) then
   132             -- adds a message saying, e.g. "Hoggy H took 25 points of damage"
   132             -- adds a message saying, e.g. "Hoggy H took 25 points of damage"
   133             !AddCaption(!GetHogName(gear) .. ' took ' .. damage .. ' points of damage')
   133             AddCaption(GetHogName(gear) .. ' took ' .. damage .. ' points of damage')
   134         end
   134         end
   135     end</code>
   135     end</code>
   136 === <tt>onGearResurrect(gearUid) </tt> ===
   136 === <tt>onGearResurrect(gearUid) </tt> ===
   137 
   137 
   138 <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.
   138 <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.
   260 
   260 
   261 <blockquote>This creates a new gear at position x,y (measured from top left) of kind gearType (see [GearTypes Gear Types]). The initial velocities are dx and dy. All arguments are numbers. The function returns the uid of the gear created.
   261 <blockquote>This creates a new gear at position x,y (measured from top left) of kind gearType (see [GearTypes Gear Types]). The initial velocities are dx and dy. All arguments are numbers. The function returns the uid of the gear created.
   262 </blockquote>
   262 </blockquote>
   263 Example:
   263 Example:
   264 
   264 
   265 <code lang="lua">    local gear = !AddGear(0, 0, gtTarget, 0, 0, 0, 0)
   265 <code lang="lua">    local gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
   266     !FindPlace(gear, true, 0, LAND_WIDTH)</code>
   266     FindPlace(gear, true, 0, LAND_WIDTH)</code>
   267 
   267 
   268 === <tt>!AddVisualGear(x, y, visualGearType, state, critical)</tt> ===
   268 === <tt>!AddVisualGear(x, y, visualGearType, state, critical)</tt> ===
   269 
   269 
   270 <blockquote>This creates a new visual gear at position x,y (measured from top left) of kind visualGearType (see [VisualGearTypes Visual Gear Types]).  The function returns the uid of the visual gear created.  Set critical to true if the visual gear is crucial to game play.  False if it is just an effect, and can be skipped when in fastforward (such as when joining a room).  A critical visual gear will always be created, a non-critical one may fail.  Most visual gears delete themselves. 
   270 <blockquote>This creates a new visual gear at position x,y (measured from top left) of kind visualGearType (see [VisualGearTypes Visual Gear Types]).  The function returns the uid of the visual gear created.  Set critical to true if the visual gear is crucial to game play.  False if it is just an effect, and can be skipped when in fastforward (such as when joining a room).  A critical visual gear will always be created, a non-critical one may fail.  Most visual gears delete themselves. 
   271 </blockquote>
   271 </blockquote>
   272 Example:
   272 Example:
   273 
   273 
   274 <code lang="lua">  -- adds an non-critical explosion at position 1000,1000. Returns 0 if it was not created.
   274 <code lang="lua">  -- adds an non-critical explosion at position 1000,1000. Returns 0 if it was not created.
   275     vgear = !AddVisualGear(1000, 1000, vgtExplosion, 0, false) 
   275     vgear = AddVisualGear(1000, 1000, vgtExplosion, 0, false) 
   276 </code>
   276 </code>
   277 
   277 
   278 === <tt>!SpawnHealthCrate(x, y)</tt> ===
   278 === <tt>!SpawnHealthCrate(x, y)</tt> ===
   279 
   279 
   280 <blockquote>Spawns a health crate at the specified position.
   280 <blockquote>Spawns a health crate at the specified position.
   283 
   283 
   284 <blockquote>Spawns an ammo crate at the specified position with content of ammoType (see [AmmoTypes Ammo Types]). Because by default settings the number of ammo in crates is zero it has to be increased to at least one with SetAmmo first, see the example:
   284 <blockquote>Spawns an ammo crate at the specified position with content of ammoType (see [AmmoTypes Ammo Types]). Because by default settings the number of ammo in crates is zero it has to be increased to at least one with SetAmmo first, see the example:
   285 </blockquote>
   285 </blockquote>
   286 Example:
   286 Example:
   287 
   287 
   288 <code lang="lua">    !SetAmmo(amGrenade, 0, 0, 0, 1) -- see below
   288 <code lang="lua">    SetAmmo(amGrenade, 0, 0, 0, 1) -- see below
   289     !SpawnAmmoCrate(0, 0, amGrenade) -- x=y=0 means random position on map</code>
   289     SpawnAmmoCrate(0, 0, amGrenade) -- x=y=0 means random position on map</code>
   290 === <tt>!SpawnUtilityCrate(x, y, ammoType)</tt> ===
   290 === <tt>!SpawnUtilityCrate(x, y, ammoType)</tt> ===
   291 
   291 
   292 <blockquote>Spawns an utility crate at specified position with content of ammoType.
   292 <blockquote>Spawns an utility crate at specified position with content of ammoType.
   293 </blockquote>
   293 </blockquote>
   294 Example:
   294 Example:
   295 
   295 
   296 <code lang="lua">    !SetAmmo(amLaserSight, 0, 0, 0, 1)
   296 <code lang="lua">    SetAmmo(amLaserSight, 0, 0, 0, 1)
   297     !SpawnUtilityCrate(0, 0, amLaserSight)</code>
   297     SpawnUtilityCrate(0, 0, amLaserSight)</code>
   298 === <tt>!AddTeam(teamname, color, grave, fort, voicepack, flag)</tt> ===
   298 === <tt>!AddTeam(teamname, color, grave, fort, voicepack, flag)</tt> ===
   299 
   299 
   300 <blockquote>Adds a new team. Note that this can only be done in onGameInit(), not at a later time. First argument is the team name followed by color, grave, fort, voicepack and flag settings.
   300 <blockquote>Adds a new team. Note that this can only be done in onGameInit(), not at a later time. First argument is the team name followed by color, grave, fort, voicepack and flag settings.
   301 </blockquote>
   301 </blockquote>
   302 Notice: This works only for singleplayer's training missions for now and will desync multiplayer games. Flag setting is dev only.
   302 Notice: This works only for singleplayer's training missions for now and will desync multiplayer games. Flag setting is dev only.
   303 
   303 
   304 Example:
   304 Example:
   305 
   305 
   306 <code lang="lua">    !AddTeam("team 1", 14483456, "Simple", "Island", "Default", "hedgewars")</code>
   306 <code lang="lua">    AddTeam("team 1", 14483456, "Simple", "Island", "Default", "hedgewars")</code>
   307 === <tt>!AddHog(hogname, botlevel, health, hat)</tt> ===
   307 === <tt>!AddHog(hogname, botlevel, health, hat)</tt> ===
   308 
   308 
   309 <blockquote>Adds a new hedgehog for current team (last created one), with botlevel and specified health also head.
   309 <blockquote>Adds a new hedgehog for current team (last created one), with botlevel and specified health also head.
   310 </blockquote>
   310 </blockquote>
   311 Notice: This works only for singleplayers training missions for now and will desync multiplayer games.
   311 Notice: This works only for singleplayers training missions for now and will desync multiplayer games.
   312 
   312 
   313 Example:
   313 Example:
   314 
   314 
   315 <code lang="lua">    local player = !AddHog("HH 1", 0, 100, "!NoHat") -- botlevel 0 means human player
   315 <code lang="lua">    local player = AddHog("HH 1", 0, 100, "NoHat") -- botlevel 0 means human player
   316     !SetGearPosition(player, 1500, 1000)</code>
   316     SetGearPosition(player, 1500, 1000)</code>
   317 == Functions to get gear properties ==
   317 == Functions to get gear properties ==
   318 
   318 
   319 === <tt>!GetGearType(gearUid)</tt> ===
   319 === <tt>!GetGearType(gearUid)</tt> ===
   320 
   320 
   321 <blockquote>returns one of [GearTypes Gear Types] for the specified gear
   321 <blockquote>returns one of [GearTypes Gear Types] for the specified gear
   404 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.
   404 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.
   405 Most visual gears require little to no modification of parameters.
   405 Most visual gears require little to no modification of parameters.
   406 </blockquote>
   406 </blockquote>
   407 Example:
   407 Example:
   408 
   408 
   409 <code lang="lua">    !GetVisualGearValues(vgUid) -- return visual gear values
   409 <code lang="lua">    GetVisualGearValues(vgUid) -- return visual gear values
   410 </code>
   410 </code>
   411 
   411 
   412 == Functions to modify gears ==
   412 == Functions to modify gears ==
   413 
   413 
   414 === <tt>!HideHog(gearUid)</tt> ===
   414 === <tt>!HideHog(gearUid)</tt> ===
   415 
   415 
   416 <blockquote>Removes a hedgehog from the map. The hidden hedgehog can be restored with !RestoreHog(gearUid). The current hedgehog cannot be hidden!</blockquote>
   416 <blockquote>Removes a hedgehog from the map. The hidden hedgehog can be restored with !RestoreHog(gearUid). The current hedgehog cannot be hidden!</blockquote>
   417 Example: 
   417 Example: 
   418 
   418 
   419 <code lang="lua">    gear = !AddGear(...)
   419 <code lang="lua">    gear = AddGear(...)
   420      !HideHog(gear) -- Hide the newly created gear.</code>
   420      HideHog(gear) -- Hide the newly created gear.</code>
   421 
   421 
   422 === <tt>!RestoreHog(gearUid)</tt> ===
   422 === <tt>!RestoreHog(gearUid)</tt> ===
   423 
   423 
   424 <blockquote>Restores a previously hidden hedgehog.</blockquote>
   424 <blockquote>Restores a previously hidden hedgehog.</blockquote>
   425 Example: 
   425 Example: 
   426 
   426 
   427 <code lang="lua">    gear = !AddGear(...)
   427 <code lang="lua">    gear = AddGear(...)
   428      !HideHog(gear) -- Hide the newly created gear.
   428      HideHog(gear) -- Hide the newly created gear.
   429      !RestoreHog(gear) -- Restore the newly hidden gear.</code>
   429      RestoreHog(gear) -- Restore the newly hidden gear.</code>
   430 
   430 
   431 === <tt>!DeleteGear(gearUid)</tt> ===
   431 === <tt>!DeleteGear(gearUid)</tt> ===
   432 
   432 
   433 <blockquote>Deletes a Gear</blockquote>
   433 <blockquote>Deletes a Gear</blockquote>
   434 Example:
   434 Example:
   435 
   435 
   436 <code lang="lua">    gear = !AddGear(...)
   436 <code lang="lua">    gear = AddGear(...)
   437     !DeleteGear(gear) -- Delete the newly created gear.</code>
   437     DeleteGear(gear) -- Delete the newly created gear.</code>
   438 
   438 
   439 === <tt>!DeleteVisualGear(vgUid)</tt> ===
   439 === <tt>!DeleteVisualGear(vgUid)</tt> ===
   440 
   440 
   441 <blockquote>Deletes a Visual Gear.  Note, most visual gears delete themselves.</blockquote>
   441 <blockquote>Deletes a Visual Gear.  Note, most visual gears delete themselves.</blockquote>
   442 Example:
   442 Example:
   443 
   443 
   444 <code lang="lua">    vgear = !AddVisualGear(...)
   444 <code lang="lua">    vgear = AddVisualGear(...)
   445     !DeleteVisualGear(vgear) -- Delete the newly created visual gear.</code>
   445     DeleteVisualGear(vgear) -- Delete the newly created visual gear.</code>
   446 
   446 
   447 
   447 
   448 === <tt>!SetVisualGearValues(vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)</tt> ===
   448 === <tt>!SetVisualGearValues(vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)</tt> ===
   449 
   449 
   450 <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.
   450 <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.
   451 Most visual gears require little to no modification of parameters.
   451 Most visual gears require little to no modification of parameters.
   452 </blockquote>
   452 </blockquote>
   453 Example:
   453 Example:
   454 
   454 
   455 <code lang="lua">  -- set a circle to position 1000,1000 pulsing from opacity 20 to 200 (8%-78%), radius of 50, 3px thickness, bright red.
   455 <code lang="lua">  -- set a circle to position 1000,1000 pulsing from opacity 20 to 200 (8%-78%), radius of 50, 3px thickness, bright red.
   456     !SetVisualGearValues(circleUid, 1000,1000, 20, 200, 0, 0, 100, 50, 3, 0xff0000ff)
   456     SetVisualGearValues(circleUid, 1000,1000, 20, 200, 0, 0, 100, 50, 3, 0xff0000ff)
   457 </code>
   457 </code>
   458 
   458 
   459 === <tt>!FindPlace(gearUid, fall, left, right, tryHarder) (0.9.16)</tt> ===
   459 === <tt>!FindPlace(gearUid, fall, left, right, tryHarder) (0.9.16)</tt> ===
   460 
   460 
   461 <blockquote>Finds a place for the specified gear between x=left and x=right and places it there. 0.9.16 adds an optional fifth parameter, tryHarder. Setting to true/false will determine whether the engine attempts to make additional passes, even attempting to place gears on top of each other.
   461 <blockquote>Finds a place for the specified gear between x=left and x=right and places it there. 0.9.16 adds an optional fifth parameter, tryHarder. Setting to true/false will determine whether the engine attempts to make additional passes, even attempting to place gears on top of each other.
   462 </blockquote>
   462 </blockquote>
   463 Example:
   463 Example:
   464 
   464 
   465 <code lang="lua">    gear = !AddGear(...)
   465 <code lang="lua">    gear = AddGear(...)
   466     !FindPlace(gear, true, 0, LAND_WIDTH) -- places the gear randomly between 0 and LAND_WIDTH</code>
   466     FindPlace(gear, true, 0, LAND_WIDTH) -- places the gear randomly between 0 and LAND_WIDTH</code>
   467 === <tt>!HogSay(gearUid, text, manner)</tt> ===
   467 === <tt>!HogSay(gearUid, text, manner)</tt> ===
   468 
   468 
   469 <blockquote>Makes the specified gear say, think, or shout some text in a bubble.
   469 <blockquote>Makes the specified gear say, think, or shout some text in a bubble.
   470 </blockquote>
   470 </blockquote>
   471 Example:
   471 Example:
   472 
   472 
   473 <code lang="lua">    !HogSay(!CurrentHedgehog, "I wonder what to do...", SAY_THINK) -- thought bubble with text
   473 <code lang="lua">    HogSay(CurrentHedgehog, "I wonder what to do...", SAY_THINK) -- thought bubble with text
   474     !HogSay(!CurrentHedgehog, "I'm hungry...", SAY_SAY) -- speech bubble with text
   474     HogSay(CurrentHedgehog, "I'm hungry...", SAY_SAY) -- speech bubble with text
   475     !HogSay(!CurrentHedgehog, "I smell CAKE!", SAY_SHOUT) -- exclamatory bubble with text
   475     HogSay(CurrentHedgehog, "I smell CAKE!", SAY_SHOUT) -- exclamatory bubble with text
   476 </code>
   476 </code>
   477 === <tt>!HogTurnLeft(gearUid, boolean)</tt> ===
   477 === <tt>!HogTurnLeft(gearUid, boolean)</tt> ===
   478 
   478 
   479 <blockquote>Faces the specified hog left or right.
   479 <blockquote>Faces the specified hog left or right.
   480 </blockquote>
   480 </blockquote>
   481 Example:
   481 Example:
   482 
   482 
   483 <code lang="lua">    !HogTurnLeft(!CurrentHedgehog, true) -- turns !CurrentHedgehog left 
   483 <code lang="lua">    HogTurnLeft(CurrentHedgehog, true) -- turns CurrentHedgehog left 
   484     !HogTurnLeft(!CurrentHedgehog, false) -- turns !CurrentHedgehog right</code>
   484     HogTurnLeft(CurrentHedgehog, false) -- turns CurrentHedgehog right</code>
   485 === <tt>!SetGearPosition(gearUid, x, y)</tt> ===
   485 === <tt>!SetGearPosition(gearUid, x, y)</tt> ===
   486 
   486 
   487 <blockquote>Places the specified gear exactly at the position (x,y).
   487 <blockquote>Places the specified gear exactly at the position (x,y).
   488 </blockquote>
   488 </blockquote>
   489 === <tt>!SetGearVelocity(gearUid, dx, dy)</tt> ===
   489 === <tt>!SetGearVelocity(gearUid, dx, dy)</tt> ===
   494 
   494 
   495 <blockquote>This updates the settings for a specified [AmmoTypes Ammo Type] as of count available for players, spawn probability, availability delay in turns, and the number available in crates. This is supposed to be used in the onAmmoStoreInit() event handler.
   495 <blockquote>This updates the settings for a specified [AmmoTypes Ammo Type] as of count available for players, spawn probability, availability delay in turns, and the number available in crates. This is supposed to be used in the onAmmoStoreInit() event handler.
   496 </blockquote>
   496 </blockquote>
   497 Example:
   497 Example:
   498 
   498 
   499 <code lang="lua">    !SetAmmo(amShotgun, 9, 0, 0, 0) -- unlimited amount of shotgun ammo for players
   499 <code lang="lua">    SetAmmo(amShotgun, 9, 0, 0, 0) -- unlimited amount of shotgun ammo for players
   500     !SetAmmo(amGrenade, 0, 0, 0, 3) -- crates should contain always three grenade</code>
   500     SetAmmo(amGrenade, 0, 0, 0, 3) -- crates should contain always three grenade</code>
   501 === <tt>!AddAmmo(gearUid, ammoType, ammoCount) (0.9.16) </tt> ===
   501 === <tt>!AddAmmo(gearUid, ammoType, ammoCount) (0.9.16) </tt> ===
   502 
   502 
   503 <blockquote>Adds ammoType to the specified gear. The amount added is determined by the arguments passed via !SetAmmo() in the onAmmoStoreInit() event handler. In 0.9.16 ammo can be set directly via the optional third parameter, ammoCount. A value of 0 will remove the weapon, a value of 100 will give infinite ammo.
   503 <blockquote>Adds ammoType to the specified gear. The amount added is determined by the arguments passed via !SetAmmo() in the onAmmoStoreInit() event handler. In 0.9.16 ammo can be set directly via the optional third parameter, ammoCount. A value of 0 will remove the weapon, a value of 100 will give infinite ammo.
   504 
   504 
   505 *Note:* The effectiveness of this function may be limited due to problems with gfPerHogAmmo in lua scripting.
   505 *Note:* The effectiveness of this function may be limited due to problems with gfPerHogAmmo in lua scripting.
   516   * Starting Flying Saucer (gtJetpack) with only 50% fuel.
   516   * Starting Flying Saucer (gtJetpack) with only 50% fuel.
   517   * Setting all the mines to duds.
   517   * Setting all the mines to duds.
   518   * (And more!)
   518   * (And more!)
   519 
   519 
   520 <code lang="lua">    function onGearAdd(gear)
   520 <code lang="lua">    function onGearAdd(gear)
   521        if (!GetGearType(gear) == gtRCPlaane) then
   521        if (GetGearType(gear) == gtRCPlaane) then
   522             !SetHealth(gear, 10)
   522             SetHealth(gear, 10)
   523        end
   523        end
   524        if (!GetGearType(gear) == gtJetpack) then
   524        if (GetGearType(gear) == gtJetpack) then
   525             !SetHealth(gear, 1000)
   525             SetHealth(gear, 1000)
   526        end
   526        end
   527        if (!GetGearType(gear) == gtMine) then
   527        if (GetGearType(gear) == gtMine) then
   528             !SetHealth(gear, 0)
   528             SetHealth(gear, 0)
   529        end
   529        end
   530     end</code>
   530     end</code>
   531 
   531 
   532 
   532 
   533 
   533 
   537 <blockquote>Enables (true) or disables (false) one of the effects <tt>heInvulnerable, heResurrectable, hePoisoned</tt> for the specified hedgehog gear.
   537 <blockquote>Enables (true) or disables (false) one of the effects <tt>heInvulnerable, heResurrectable, hePoisoned</tt> for the specified hedgehog gear.
   538 </blockquote>
   538 </blockquote>
   539 Example: (sets all bots poisoned)
   539 Example: (sets all bots poisoned)
   540 
   540 
   541 <code lang="lua">    function onGearAdd(gear)
   541 <code lang="lua">    function onGearAdd(gear)
   542         if (!GetGearType(gear) == gtHedgehog) and (!GetBotLevel(gear) > 0) then
   542         if (GetGearType(gear) == gtHedgehog) and (GetBotLevel(gear) > 0) then
   543             !SetEffect(gear, hePoisoned, true)
   543             SetEffect(gear, hePoisoned, true)
   544         end
   544         end
   545     end</code>
   545     end</code>
   546 
   546 
   547 === <tt>CopyPV(gearUid, gearUid)</tt> ===
   547 === <tt>CopyPV(gearUid, gearUid)</tt> ===
   548 
   548