LuaAPI.wiki
changeset 12 74ead59b6c64
child 13 2074f03075c6
equal deleted inserted replaced
11:812b13502f05 12:74ead59b6c64
       
     1 <wiki:toc max_depth="3" />
       
     2 
       
     3 == Global available Constants ==
       
     4 
       
     5 <blockquote><tt>LAND_WIDTH</tt>, <tt>LAND_HEIGHT</tt>
       
     6 </blockquote>
       
     7 Game flags:
       
     8 
       
     9 <blockquote><tt>gfForts, gfMultiWeapon, gfSolidLand, gfDivideTeams, gfLowGravity, gfLaserSight, gfInvulnerable, gfMines, gfVampiric, gfKarma, gfArtillery, gfOneClanMode, gfRandomOrder, gfKing, gfPlaceHog, gfSharedAmmo, gfDisableGirders, gfExplosives, gfDisableLandObjects, gfAISurvival</tt>
       
    10 </blockquote>
       
    11 More constants at [GearTypes, Gear Types] , [AmmoTypes Ammo Types], [Sounds], [States]
       
    12 
       
    13 Additional global changing variables accessible:
       
    14 
       
    15  * <tt>!TurnTimeLeft</tt> - number of game ticks left until the current turn ends
       
    16  * <tt>!ClansCount</tt> - number of clans in the game, i.e. number of players
       
    17 
       
    18 == Event Handlers ==
       
    19 
       
    20 === <tt>onGameInit()</tt> ===
       
    21 
       
    22 <blockquote>This function is called before the game loads its resources. One can modify various game variables here:
       
    23 </blockquote>
       
    24  * <tt>Seed = 0</tt> - sets the seed of the random number generator
       
    25  * <tt>!GameFlags = gfSolidLand + gfArtillery + …</tt> - sets the gameflags, see above for the available flags
       
    26  * <tt>!TurnTime = 60000</tt> - set the turntime in ms
       
    27  * <tt>!CaseFreq = 0</tt> - frequency of crate drops
       
    28  * <tt>!LandAdds = 0</tt> - number of mines being placed
       
    29  * <tt>Explosives = 0</tt> - number of explosives being placed
       
    30  * <tt>Delay = 0</tt> - delay between each round
       
    31  * <tt>!SuddenDeathTurns = 30</tt> - turns until sudden death begins
       
    32  * <tt>Map = "Bamboo"</tt> - the map being played
       
    33  * <tt>Theme = "Bamboo"</tt> - the theme to be used
       
    34 
       
    35 If you want to add teams or hogs manually you have to do it here.
       
    36 
       
    37 === <tt>onGameStart()</tt> ===
       
    38 
       
    39 <blockquote>This function is called when the first round starts.
       
    40 </blockquote>
       
    41 Can be used to show the mission and for more setup, for example initial target spawning.
       
    42 
       
    43 === <tt>onGameTick()</tt> ===
       
    44 
       
    45 <blockquote>This function is called on every game tick, i.e. 1000 times a second.
       
    46 </blockquote>
       
    47 === <tt>onGearAdd(gearUid)</tt> ===
       
    48 
       
    49 <blockquote>This function is called when a new gear is added. Useful in
       
    50 combination with <tt>!GetGearType(gearUid)</tt>.
       
    51 </blockquote>
       
    52 === <tt>onGearDelete(gearUid)</tt> ===
       
    53 
       
    54 <blockquote>This function is called when a new gear is deleted. Useful in
       
    55 combination with <tt>!GetGearType(gearUid)</tt>.
       
    56 </blockquote>
       
    57 === <tt>onAmmoStoreInit()</tt> ===
       
    58 
       
    59 <blockquote>This function is called when the game is initialized to request the available ammo and ammo probabilities. Use SetAmmo here.
       
    60 </blockquote>
       
    61 == Functions for creating gears ==
       
    62 
       
    63 === <tt>!AddGear(x, y, gearType, state, dx, dy, timer)</tt> ===
       
    64 
       
    65 <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.
       
    66 </blockquote>
       
    67 Example:
       
    68 
       
    69 <code lang="lua">    local gear = !AddGear(0, 0, gtTarget, 0, 0, 0, 0)
       
    70     !FindPlace(gear, true, 0, LAND_WIDTH)</code>
       
    71 === <tt>!SpawnHealthCrate(x, y)</tt> (0.9.14) ===
       
    72 
       
    73 <blockquote>Spawns a health crate at the specified position.
       
    74 </blockquote>
       
    75 === <tt>!SpawnAmmoCrate(x, y, ammoType)</tt> (0.9.14) ===
       
    76 
       
    77 <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:
       
    78 </blockquote>
       
    79 Example:
       
    80 
       
    81 <code lang="lua">    !SetAmmo(amGrenade, 0, 0, 0, 1) -- see below
       
    82     !SpawnAmmoCrate(0, 0, amGrenade) -- x=y=0 means random position on map</code>
       
    83 === <tt>!SpawnUtilityCrate(x, y, ammoType)</tt> (0.9.14) ===
       
    84 
       
    85 <blockquote>Spawns an utility crate at specified position with content of ammoType.
       
    86 </blockquote>
       
    87 Example:
       
    88 
       
    89 <code lang="lua">    !SetAmmo(amLaserSight, 0, 0, 0, 1)
       
    90     !SpawnUtilityCrate(0, 0, amLaserSight)</code>
       
    91 === <tt>!AddTeam(teamname, color, grave, fort, voicepack)</tt> ===
       
    92 
       
    93 <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 and voicepack settings.
       
    94 </blockquote>
       
    95 Notice: This works only for singleplayers training missions for now and will desync multiplayer games.
       
    96 
       
    97 Example:
       
    98 
       
    99 <code lang="lua">    !AddTeam("team 1", 14483456, "Simple", "Island", "Default")</code>
       
   100 === <tt>!AddHog(hogname, botlevel, health, hat)</tt> ===
       
   101 
       
   102 <blockquote>Adds a new hedgehog for current team (last created one), with botlevel and specified health also head.
       
   103 </blockquote>
       
   104 Notice: This works only for singleplayers training missions for now and will desync multiplayer games.
       
   105 
       
   106 Example:
       
   107 
       
   108 <code lang="lua">    local player = !AddHog("HH 1", 0, 100, "!NoHat") -- botlevel 0 means human player
       
   109     !SetGearPosition(player, 1500, 1000)</code>
       
   110 == Functions to get gear properties ==
       
   111 
       
   112 === <tt>!GetGearType(gearUid)</tt> ===
       
   113 
       
   114 <blockquote>returns one of [GearTypes Gear Types] for the specified gear
       
   115 </blockquote>
       
   116 === <tt>!GetGearPosition(gearUid)</tt> ===
       
   117 
       
   118 <blockquote>returns tuple of x,y coordinates for the specified gear
       
   119 </blockquote>
       
   120 === <tt>!GetHogClan(gearUid)</tt> ===
       
   121 
       
   122 <blockquote>returns the clan id of the specified hedgehog gear
       
   123 </blockquote>
       
   124 === <tt>!GetHogName(gearUid)</tt> ===
       
   125 
       
   126 <blockquote>returns the name of the specified hedgehog gear
       
   127 </blockquote>
       
   128 === <tt>GetX(gearUid)</tt> ===
       
   129 
       
   130 <blockquote>returns x coordinate of the gear
       
   131 </blockquote>
       
   132 === <tt>GetY(gearUid)</tt> ===
       
   133 
       
   134 <blockquote>returns y coordinate of the gear
       
   135 </blockquote>
       
   136 === <tt>!GetState(gearUid)</tt> ===
       
   137 
       
   138 <blockquote>returns the state of the gear. This is one of [States]
       
   139 </blockquote>
       
   140 === <tt>!GetFollowGear(gearUid)</tt> ===
       
   141 
       
   142 <blockquote>Returns the uid of the gear that is currently being followed.
       
   143 </blockquote>
       
   144 === <tt>!GetTimer(gearUid)</tt> (0.9.14) ===
       
   145 
       
   146 <blockquote>returns the timer of the gear. This is for example the time it takes for watermelon, mine, etc. to explode. This is also the time used to specify the blowtorch or rcplane time.
       
   147 </blockquote>
       
   148 === <tt>!GetHealth(gearUid)</tt> (0.9.14) ===
       
   149 
       
   150 <blockquote>returns the health of the gear
       
   151 </blockquote>
       
   152 === <tt>!GetBotLevel(gearUid)</tt> (0.9.14) ===
       
   153 
       
   154 <blockquote>returns the bot level from 0 to 5. 0 means human player.
       
   155 </blockquote>
       
   156 == Functions to modify gears ==
       
   157 
       
   158 === <tt>!FindPlace(gearUid, fall, left, right)</tt> ===
       
   159 
       
   160 <blockquote>Finds a place for the specified gear between x=left and x=right and places it there.
       
   161 </blockquote>
       
   162 Example:
       
   163 
       
   164 <code lang="lua">    gear = !AddGear(…)
       
   165     !FindPlace(gear, true, 0, LAND_WIDTH) -- places the gear randomly between 0 and LAND_WIDTH</code>
       
   166 === <tt>!SetGearPosition(gearUid, x, y)</tt> ===
       
   167 
       
   168 <blockquote>Places the specified gear exactly at the position (x,y).
       
   169 </blockquote>
       
   170 === <tt>!SetAmmo(ammoType, count, probability, delay, numberInCrate)</tt> ===
       
   171 
       
   172 <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() even handler.
       
   173 </blockquote>
       
   174 Example:
       
   175 
       
   176 <code lang="lua">    !SetAmmo(amShotgun, 9, 0, 0, 0) -- unlimited amount of shotgun ammo for players
       
   177     !SetAmmo(amGrenade, 0, 0, 0, 3) -- crates should contain always three grenade</code>
       
   178 === <tt>!SetHealth(gearUid, health)</tt> ===
       
   179 
       
   180 <blockquote>Sets the health of the specified gear.
       
   181 </blockquote>
       
   182 === <tt>!SetEffect(gearUid, effect, true/false)</tt> (0.9.14) ===
       
   183 
       
   184 <blockquote>Enables (true) or disables (false) one of the effects <tt>heInvulnerable, heResurrectable, hePoisoned</tt> for the specified hedgehog gear.
       
   185 </blockquote>
       
   186 Example: (sets all bots poisoned)
       
   187 
       
   188 <code lang="lua">    function onGearAdd(gear)
       
   189         if (!GetGearType(gear) === gtHedgehog) and (!GetBotLevel(gear) > 0) then
       
   190             !SetEffect(gear, hePoisoned, true)
       
   191         end
       
   192     end</code>
       
   193 === <tt>!CopyPV(gearUid, gearUid)</tt> ===
       
   194 
       
   195 <blockquote>This sets the position and velocity of the second gear to the first one.
       
   196 </blockquote>
       
   197 === <tt>!CopyPV2(gearUid, gearUid)</tt> ===
       
   198 
       
   199 <blockquote>This sets the position of the second gear to that of the first one, but makes its velocity twice the one of the first.
       
   200 </blockquote>
       
   201 === <tt>!FollowGear(gearUid)</tt> ===
       
   202 
       
   203 <blockquote>Makes the gameclient follow the specifiec gear.
       
   204 </blockquote>
       
   205 === <tt>!SetState(gearUid, state)</tt> ===
       
   206 
       
   207 <blockquote>Sets the state of the specified gear to one of [States]
       
   208 </blockquote>
       
   209 === <tt>!SetTag(gearUid, tag)</tt> ===
       
   210 
       
   211 === <tt>!SetTimer(gearUid, timer)</tt> (0.9.14) ===
       
   212 
       
   213 <blockquote>Sets the timer of the specified gear. Also see GetTimer.
       
   214 </blockquote>
       
   215 
       
   216 == Other Functions ==
       
   217 
       
   218 === <tt>!EndGame()</tt> ===
       
   219 
       
   220 <blockquote>Makes the game end.
       
   221 </blockquote>
       
   222 
       
   223 === <tt>!ParseCommand(string)</tt> ===
       
   224 
       
   225 <blockquote>Makes the gameclient parse the specified custom command.
       
   226 </blockquote>
       
   227 
       
   228 === <tt>!ShowMission(caption, subcaption, text, icon, time)</tt> ===
       
   229 
       
   230 === <tt>!HideMission()</tt> ===
       
   231 
       
   232 === <tt>!PlaySound(soundId)</tt> ===
       
   233 
       
   234 === <tt>!SetZoom(zoomLevel)</tt> (0.9.14) ===
       
   235 
       
   236 <blockquote>Sets the zoom level. The value for maximum zoom is currently 1.0 and for minimum 3.0 The default zoom level is 2.0
       
   237 </blockquote>
       
   238 === <tt>!GetZoom()</tt> (0.9.14) ===
       
   239 
       
   240 <blockquote>Returns the current zoom level
       
   241 </blockquote>
       
   242 == Debugging Functions ==
       
   243 
       
   244 === <tt>!WriteLnToConsole(string)</tt> (0.9.14) ===
       
   245 
       
   246 <blockquote>Guess :D
       
   247 </blockquote>
       
   248