2950
|
1 |
-- Hedgewars Bazooka 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 |
-- At first we put all text we'd like to use in some arrays.
|
|
12 |
-- This way we're able to localize the text to be shown without
|
|
13 |
-- modifying other files.
|
|
14 |
-- The language to be used is stored in the global variable
|
|
15 |
-- 'L' that is set by the game (string).
|
|
16 |
-- Text may then be accessed using "arrayname[L]".
|
|
17 |
|
|
18 |
local caption = {
|
|
19 |
["en"] = "Bazooka Training",
|
|
20 |
["de"] = "Bazooka-Training"
|
2958
|
21 |
-- To add other languages, just add lines similar to the
|
|
22 |
-- existing ones - don't forget the trailing ","!
|
2950
|
23 |
}
|
2958
|
24 |
|
2950
|
25 |
local subcaption = {
|
|
26 |
["en"] = "Aiming Practice",
|
|
27 |
["de"] = "Zielübung"
|
|
28 |
}
|
|
29 |
|
|
30 |
local goal = {
|
|
31 |
["en"] = "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.",
|
|
32 |
["de"] = "Eliminiere alle Ziele bevor die Zeit ausläuft.|Du hast in dieser Mission unbegrenzte Munition."
|
|
33 |
}
|
|
34 |
|
|
35 |
local timeout = {
|
|
36 |
["en"] = "Oh no! Time's up! Just try again.",
|
|
37 |
["de"] = "Oh nein! Die Zeit ist um! Versuche es nochmal."
|
|
38 |
}
|
|
39 |
|
|
40 |
local success = {
|
|
41 |
["en"] = "Congratulations! You've eliminated all targets|within the allowed time frame.",
|
|
42 |
["de"] = "Gratulation! Du hast alle Ziele innerhalb der|verfügbaren Zeit ausgeschaltet."
|
|
43 |
}
|
|
44 |
|
|
45 |
local teamname = {
|
|
46 |
["en"] = "'Zooka Team",
|
|
47 |
["de"] = "Die Knalltüten"
|
|
48 |
}
|
|
49 |
|
|
50 |
local hogname = {
|
|
51 |
["en"] = "Hunter",
|
|
52 |
["de"] = "Jäger"
|
|
53 |
}
|
|
54 |
|
|
55 |
-- To handle missing texts we define a small wrapper function that
|
|
56 |
-- we'll use to retrieve text.
|
|
57 |
local function loc(text)
|
|
58 |
if text == nil then return "**missing**"
|
|
59 |
elseif text[L] == nil then return text["en"]
|
|
60 |
else return text[L]
|
|
61 |
end
|
|
62 |
end
|
|
63 |
|
|
64 |
---------------------------------------------------------------
|
|
65 |
|
|
66 |
-- This variable will hold the number of destroyed targets.
|
|
67 |
local score = 0
|
|
68 |
-- This variable represents the number of targets to destroy.
|
|
69 |
local score_goal = 5
|
|
70 |
-- This variable controls how many milliseconds/ticks we'd
|
|
71 |
-- like to wait before we end the round once all targets
|
|
72 |
-- have been destroyed.
|
|
73 |
local end_timer = 5000 -- 5000 ms = 5 s
|
|
74 |
-- This variable is set to true if the game is lost (i.e.
|
|
75 |
-- time runs out).
|
|
76 |
local game_lost = false
|
|
77 |
-- This variable will point to the hog's gear
|
|
78 |
local player = nil
|
|
79 |
-- This variable will grab the time left at the end of the round
|
|
80 |
local time_goal = 0
|
|
81 |
|
|
82 |
-- This is a custom function to make it easier to
|
|
83 |
-- spawn more targets with just one line of code
|
|
84 |
-- You may define as many custom functions as you
|
|
85 |
-- like.
|
|
86 |
function spawnTarget()
|
|
87 |
-- add a new target gear
|
|
88 |
gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
|
|
89 |
|
|
90 |
-- move it to a random position within 0 and
|
|
91 |
-- LAND_WIDTH - the width of the map
|
|
92 |
FindPlace(gear, true, 0, LAND_WIDTH)
|
|
93 |
|
|
94 |
-- move the target to a higher vertical position
|
|
95 |
-- to ensure it's not somewhere down below
|
|
96 |
x, y = GetGearPosition(gear)
|
|
97 |
SetGearPosition(gear, x, 500)
|
|
98 |
end
|
|
99 |
|
|
100 |
-- This function is called before the game loads its
|
|
101 |
-- resources.
|
|
102 |
-- It's one of the predefined function names that will
|
|
103 |
-- be called by the game. They give you entry points
|
|
104 |
-- where you're able to call your own code using either
|
|
105 |
-- provided instructions or custom functions.
|
|
106 |
function onGameInit()
|
|
107 |
-- At first we have to overwrite/set some global variables
|
|
108 |
-- that define the map, the game has to load, as well as
|
|
109 |
-- other things such as the game rules to use, etc.
|
|
110 |
-- Things we don't modify here will use their default values.
|
|
111 |
|
|
112 |
-- The base number for the random number generator
|
|
113 |
Seed = 0
|
|
114 |
-- Game settings and rules
|
|
115 |
GameFlags = gfMultiWeapon + gfOneClanMode + gfSolidLand
|
|
116 |
-- The time the player has to move each round (in ms)
|
|
117 |
TurnTime = 60000
|
|
118 |
-- The frequency of crate drops
|
|
119 |
CaseFreq = 0
|
2996
|
120 |
-- The number of mines being placed
|
2950
|
121 |
LandAdds = 0
|
2996
|
122 |
-- The number of explosives being placed
|
|
123 |
Explosives = 0
|
2950
|
124 |
-- The delay between each round
|
|
125 |
Delay = 0
|
|
126 |
-- The map to be played
|
|
127 |
Map = "Bamboo"
|
|
128 |
-- The theme to be used
|
|
129 |
Theme = "Bamboo"
|
|
130 |
|
|
131 |
-- Create the player team
|
|
132 |
AddTeam(loc(teamname), 14483456, "Simple", "Island", "Default")
|
|
133 |
-- And add a hog to it
|
|
134 |
player = AddHog(loc(hogname), 0, 1, "NoHat")
|
|
135 |
SetGearPosition(player, 1960, 1160);
|
|
136 |
end
|
|
137 |
|
|
138 |
-- This function is called when the round starts
|
|
139 |
-- it spawns the first target that has to be destroyed.
|
|
140 |
-- In addition it shows the scenario goal(s).
|
|
141 |
function onGameStart()
|
|
142 |
-- Spawn the first target.
|
|
143 |
spawnTarget()
|
|
144 |
|
|
145 |
-- Show some nice mission goals.
|
|
146 |
-- Parameters are: caption, sub caption, description,
|
|
147 |
-- extra text, icon and time to show.
|
|
148 |
-- A negative icon parameter (-n) represents the n-th weapon icon
|
|
149 |
-- A positive icon paramter (n) represents the (n+1)-th mission icon
|
|
150 |
-- A timeframe of 0 is replaced with the default time to show.
|
|
151 |
ShowMission(loc(caption), loc(subcaption), loc(goal), -amBazooka, 0);
|
|
152 |
end
|
|
153 |
|
|
154 |
-- This function is called every game tick.
|
|
155 |
-- Note that there are 1000 ticks within one second.
|
|
156 |
-- You shouldn't try to calculate too complicated
|
|
157 |
-- code here as this might slow down your game.
|
|
158 |
function onGameTick()
|
|
159 |
-- If time's up, set the game to be lost.
|
|
160 |
-- We actually check the time to be "1 ms" as it
|
|
161 |
-- will be at "0 ms" right at the start of the game.
|
|
162 |
if TurnTimeLeft == 1 and score < score_goal then
|
|
163 |
game_lost = true
|
|
164 |
-- ... and show a short message.
|
|
165 |
ShowMission(loc(caption), loc(subcaption), loc(timeout), -amSkip, 0);
|
|
166 |
-- How about killing our poor hog due to his poor performance?
|
|
167 |
SetHealth(player, 0);
|
|
168 |
-- Just to be sure set the goal time to 1 ms
|
|
169 |
time_goal = 1
|
|
170 |
end
|
|
171 |
-- If the goal is reached or we've lost ...
|
|
172 |
if score == score_goal or game_lost then
|
|
173 |
-- ... check to see if the time we'd like to
|
|
174 |
-- wait has passed and then ...
|
|
175 |
if end_timer == 0 then
|
|
176 |
-- ... end the game ...
|
|
177 |
EndGame()
|
|
178 |
else
|
|
179 |
-- ... or just lower the timer by 1.
|
|
180 |
end_timer = end_timer - 1
|
|
181 |
-- Reset the time left to stop the timer
|
|
182 |
TurnTimeLeft = time_goal
|
|
183 |
end
|
|
184 |
end
|
|
185 |
end
|
|
186 |
|
|
187 |
-- This function is called when the game is initialized
|
|
188 |
-- to request the available ammo and probabilities
|
|
189 |
function onAmmoStoreInit()
|
|
190 |
-- add an unlimited supply of bazooka ammo
|
2999
|
191 |
SetAmmo(amBazooka, 9, 0, 0)
|
2950
|
192 |
end
|
|
193 |
|
|
194 |
-- This function is called when a new gear is added.
|
|
195 |
-- We don't need it for this training, so we can
|
|
196 |
-- keep it empty.
|
|
197 |
function onGearAdd(gear)
|
|
198 |
end
|
|
199 |
|
|
200 |
-- This function is called before a gear is destroyed.
|
|
201 |
-- We use it to count the number of targets destroyed.
|
|
202 |
function onGearDelete(gear)
|
|
203 |
-- We're only interested in target gears.
|
|
204 |
if GetGearType(gear) == gtTarget then
|
|
205 |
-- Add one point to our score/counter
|
|
206 |
score = score + 1
|
|
207 |
-- If we haven't reached the goal ...
|
|
208 |
if score < score_goal then
|
|
209 |
-- ... spawn another target.
|
|
210 |
spawnTarget()
|
|
211 |
else
|
|
212 |
if not game_lost then
|
|
213 |
-- Otherwise show that the goal was accomplished
|
|
214 |
ShowMission(loc(caption), loc(subcaption), loc(success), 0, 0);
|
|
215 |
-- Also let the hogs shout "victory!"
|
|
216 |
PlaySound(sndVictory)
|
|
217 |
-- Save the time left so we may keep it.
|
|
218 |
time_goal = TurnTimeLeft
|
|
219 |
end
|
|
220 |
end
|
|
221 |
end
|
2786
|
222 |
end |