LuaGuide.wiki
changeset 35 532bb2509f0b
parent 32 5f66adfa478c
child 36 f66efe81d8c0
equal deleted inserted replaced
34:bb98d418d1e3 35:532bb2509f0b
    36 end
    36 end
    37 
    37 
    38 function onGearDelete(gear)
    38 function onGearDelete(gear)
    39 end
    39 end
    40 }}}
    40 }}}
       
    41 
       
    42 These are event handlers and are called on different events by the engine. Now lets look at the initiation events.
       
    43 
       
    44 == The initiation events ==
       
    45 
       
    46 The two most important event handlers are onGameInit and onAmmoStoreInit. They are used instead of loading a game scheme and weapon scheme and in Campaign or Missions onGameInit is also used to add teams and hogs.
       
    47 
       
    48 === onGameInit ===
       
    49 
       
    50 First we have onGameInit. On this event we should add all game modifiers and team setup. If you are making a Mission you only need to specify the things you want to change on this event, everything not changed will be set to default. The available game modifiers can be found here: http://code.google.com/p/hedgewars/wiki/LuaAPI#onGameInit()
       
    51 
       
    52 An example of setting up barrel mayhem in a mission:
       
    53 {{{
       
    54 function onGameInit()
       
    55     GameFlags = gfRandomOrder + gfSharedAmmo
       
    56     TurnTime = 30000
       
    57     CaseFreq = 0
       
    58     MinesNum = 0
       
    59     MinesTime = 0
       
    60     Explosives = 40
       
    61 end
       
    62 }}}
       
    63 
       
    64 If you are doing a Training or Campaign you should also set Seed, Map and Theme. But you must also add teams and hogs on this event. This is done by using !AddTeam and !AddHog. An example of adding one team with one hog:
       
    65 {{{
       
    66 AddTeam("Team", 14483456, "Simple", "Island", "Default")
       
    67 AddHog("Hedgehog", 0, 1, "NoHat")
       
    68 }}}
       
    69 To be able to play you must add another team and hog that should have another team color (this team has 14483456) or if you only want one team add the game flag gfOneClanMode. Look in the LuaAPI to see what the other parameters of !AddTeam and !AddHog is.
       
    70 
       
    71 === onAmmoStoreInit ===
       
    72 
       
    73 This is where you set what weapons is available in the game for every weapon run [http://code.google.com/p/hedgewars/wiki/LuaAPI#SetAmmo_(ammoType,_count,_probability,_delay,_numberInCrate) SetAmmo].
       
    74 
       
    75 Here is an example of initiation of a Training map:
       
    76 {{{
       
    77 function onGameInit()
       
    78     Seed = 0
       
    79     GameFlags = gfMultiWeapon + gfOneClanMode
       
    80     TurnTime = 25000
       
    81     CaseFreq = 0
       
    82     MinesNum = 0
       
    83     Explosives = 0
       
    84     Delay = 0
       
    85     Map = "Mushrooms"
       
    86     Theme = "Nature"
       
    87 
       
    88     AddTeam("Team", 14483456, "Simple", "Island", "Default")
       
    89     AddHog("Hedgehog", 0, 1, "NoHat")
       
    90 end
       
    91 
       
    92 function onAmmoStoreInit()
       
    93     SetAmmo(amShotgun, 9, 0, 0, 0)
       
    94 end
       
    95 }}}