Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 33 and Version 34 of content/LevelHowTo


Ignore:
Timestamp:
Feb 23, 2012, 5:38:08 PM (12 years ago)
Author:
jo
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • content/LevelHowTo

    v33 v34  
    198198
    199199== Lua ==
    200 Lua is the scripting language we use in our levels. At the beginning of the file templates for spaceships, the hud and more are loaded. What lua does is in fact editing the XML file before the level is loaded. (that's why you cannot rely on the line numbers displayed when an error occurs.
     200Lua is the scripting language we use in our levels. At the beginning of the file templates for spaceships, the hud and more are loaded. What lua does in this context is editing the XML file and inserting the concerning XML (of the spaceships, hud, ..) before the level is loaded. That's why you cannot rely on the line numbers displayed when an error occurs, since before loading lua changes the file.
    201201
    202202What lua can do:
    203203 * load external skripts: for example the cuboid spacestation.
    204204{{{
    205 <!-- First, the script has to be included. -->
    206 #!xml <?lua
    207     dofile("includes/CuboidSpaceStation.lua")
    208 ?>
    209 
    210 <!-- Usage: Creates a modular space station -->
    211 <StaticEntity scale=1 position="4650,5350,-11050" name=base visible=true active=true yaw=60>
    212     <attached>
    213         <?lua
    214             createSpaceStationPar(9851,2,1,2,1,2,1,100)
    215         ?>
    216     </attached>
    217 </StaticEntity>
     205#!xml
     206<!-- First, the script has to be included (only once). -->
     207<?lua
     208    dofile("includes/asteroidField.lua")
     209?>
     210
     211<!-- Usage: Creates an asteroid belt -->
     212<?lua
     213     asteroidBelt(20000, 0, 13000, -48, -34, 70, 100, 200, 22000, 20000, 500, 1)
     214?>
     215<!-- asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog) -->
    218216}}}
    219217
    220218 * Create a bunch of objects (depending on the index i). Whatever is placed within those lua tags will be created several times.
    221219{{{
    222 #!xml <?lua
     220#!xml
     221<!-- A for loop. The index i starts from 1, is increased up to 10 by adding +1. -->
     222<?lua
    223223for i = 1, 10, 1 do
    224224?>
    225 
     225    <SpawnPoint team=0 position="<?lua print(i*100 + 50) ?>,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
    226226<?lua end ?>
    227 <!-- A for loop. the index i starts from 1, is increased up to 10 by adding +1. -->
    228 }}}
    229 
    230  * Insert randomized values. By doing so your level's appearance is slightly changing whenever it is loaded.
    231 {{{
    232 #!xml
    233 <?lua print(math.random() * 10 + 5) ?>
     227}}}
     228 Note that '''<?lua print(i*100 + 50) ?>''' directly inserts the calculated value when the level is loaded.
     229
     230 * Randomized values, sinus, cosinus and more. (Via sinus and cosinus circular shapes can be created easily. The randomization changes your level's appearance whenever it is reloaded.)
     231{{{
     232#!xml
     233<?lua
     234max = 16
     235for i = 0, max, 1
     236do
     237    y = math.sin(i/max*6)*750
     238    z = math.cos(i/max*6)*750
     239?>
     240    <StaticEntity position="<?lua print(y) ?>,0,<?lua print(z) ?>" scale="<?lua print(math.random() * 10 + 5) ?>" collisionType="static" >
     241<?lua end ?>
     242
     243
    234244}}}
    235245