|
1 -- Hedgewars Shotgun Training |
|
2 -- Scripting Example |
|
3 |
|
4 -- Lines such as this one are comments - they are ignored |
|
5 -- by the game, no matter what kind of text is in there. |
|
6 -- It's also possible to place a comment after some real |
|
7 -- instruction as you see below. In short, everything |
|
8 -- following "--" is ignored. |
|
9 |
|
10 --------------------------------------------------------------- |
|
11 |
|
12 -- This variable will hold the number of destroyed targets. |
|
13 score = 0 |
|
14 -- This variable represents the number of targets to destroy. |
|
15 score_goal = 5 |
|
16 -- This variable controls how many milliseconds/ticks we'd |
|
17 -- like to wait before we end the round once all targets |
|
18 -- have been destroyed. |
|
19 end_timer = 5000 -- 5000 ms = 5 s |
|
20 |
|
21 -- This is a custom function to make it easier to |
|
22 -- spawn more targets with just one line of code |
|
23 -- You may define as many custom functions as you |
|
24 -- like. |
|
25 function spawnTarget() |
|
26 -- add a new target gear |
|
27 gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0) |
|
28 |
|
29 -- move it to a random position within 0 and |
|
30 -- LAND_WIDTH - the width of the map |
|
31 FindPlace(gear, true, 0, LAND_WIDTH) |
|
32 |
|
33 -- move the target to a higher vertical position |
|
34 -- to ensure it's not somewhere down below |
|
35 x, y = GetGearPosition(gear) |
|
36 SetGearPosition(gear, x, 500) |
|
37 end |
|
38 |
|
39 -- This function is called before the game loads its |
|
40 -- resources. |
|
41 -- It's one of the predefined function names that will |
|
42 -- be called by the game. They give you entry points |
|
43 -- where you're able to call your own code using either |
|
44 -- provided instructions or custom functions. |
|
45 function onGameInit() |
|
46 -- At first we have to overwrite/set some global variables |
|
47 -- that define the map, the game has to load, as well as |
|
48 -- other things such as the game rules to use, etc. |
|
49 -- Things we don't modify here will use their default values. |
|
50 |
|
51 -- The base number for the random number generator |
|
52 Seed = 0 |
|
53 -- Game settings and rules |
|
54 GameFlags = gfMultiWeapon + gfOneClanMode |
|
55 -- The time the player has to move each round (in ms) |
|
56 TurnTime = 90000 |
|
57 -- The frequency of crate drops |
|
58 CaseFreq = 0 |
|
59 -- The number of land objects being placed |
|
60 LandAdds = 0 |
|
61 -- The delay between each round |
|
62 Delay = 0 |
|
63 -- The map to be played |
|
64 Map = "Bamboo" |
|
65 -- The theme to be used |
|
66 Theme = "Bamboo" |
|
67 |
|
68 -- Create the player team |
|
69 AddTeam("Shotgun Team", 14483456, "Simple", "Island", "Default") |
|
70 -- And add a hog to it |
|
71 hog = AddHog("Hunter", 0, 1, "NoHat") |
|
72 SetGearPosition(hog, 1960, 1160); |
|
73 end |
|
74 |
|
75 -- This function is called when the round starts |
|
76 -- it spawns the first target that has to be destroyed. |
|
77 -- In addition it shows the scenario goal(s). |
|
78 function onGameStart() |
|
79 -- Spawn the first target. |
|
80 spawnTarget() |
|
81 |
|
82 -- Show some nice mission goals. |
|
83 -- Parameters are: caption, sub caption, description, |
|
84 -- extra text, icon and time to show. |
|
85 -- A negative icon parameter (-n) represents the n-th weapon icon |
|
86 -- A positive icon paramter (n) represents the (n+1)-th mission icon |
|
87 -- A timeframe of 0 is replaced with the default time to show. |
|
88 ShowMission("Shotgun Training", "Aiming Practice", "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.", -5, 0); |
|
89 end |
|
90 |
|
91 -- This function is called every game tick. |
|
92 -- Note that there are 1000 ticks within one second. |
|
93 -- You shouldn't try to calculate too complicated |
|
94 -- code here as this might slow down your game. |
|
95 function onGameTick() |
|
96 -- If the goal is reached ... |
|
97 if score == score_goal then |
|
98 -- ... check to see if the time we'd like to |
|
99 -- wait has passed and then ... |
|
100 if end_timer == 0 then |
|
101 -- ... end the game ... |
|
102 EndGame() |
|
103 else |
|
104 -- ... or just lower the timer by 1. |
|
105 end_timer = end_timer - 1 |
|
106 end |
|
107 end |
|
108 end |
|
109 |
|
110 -- This function is called when the game is initialized |
|
111 -- to request the available ammo and probabilities |
|
112 function onAmmoStoreInit() |
|
113 -- add an unlimited supply of shotgun ammo |
|
114 SetAmmo(amShotgun, 9, 0) |
|
115 -- add one optional laser sight |
|
116 SetAmmo(amLaserSight, 1, 0) |
|
117 end |
|
118 |
|
119 -- This function is called when a new gear is added. |
|
120 -- We don't need it for this training, so we can |
|
121 -- keep it empty. |
|
122 function onGearAdd(gear) |
|
123 end |
|
124 |
|
125 -- This function is called before a gear is destroyed. |
|
126 -- We use it to count the number of targets destroyed. |
|
127 function onGearDelete(gear) |
|
128 -- We're only interested in target gears. |
|
129 if GetGearType(gear) == gtTarget then |
|
130 -- Add one point to our score/counter |
|
131 score = score + 1 |
|
132 -- If we haven't reached the goal ... |
|
133 if score < score_goal then |
|
134 -- ... spawn another target. |
|
135 spawnTarget() |
|
136 else |
|
137 -- Otherwise show that the goal was accomplished |
|
138 ShowMission("Shotgun Training", "Aiming Practice", "Congratulations! You've eliminated all targets|within the allowed time frame.", 0, 0); |
|
139 -- Also let the hogs shout "victory!" |
|
140 PlaySound(sndVictory) |
|
141 end |
|
142 end |
|
143 end |