author | nemo |
Mon, 10 May 2010 13:56:20 +0000 | |
changeset 3456 | e19e017691e4 |
parent 3346 | 967fd96f7373 |
child 3476 | 1ec68b8d3bd1 |
permissions | -rw-r--r-- |
3234 | 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", |
|
21 |
["es"] = "Entrenamiento con bazuca", |
|
22 |
["pl"] = "Trening bazooki", |
|
3456
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
23 |
["pt_PT"] = "Treino com Bazuca", |
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
24 |
["pt_BR"] = "Treino com a Bazuca" |
3234 | 25 |
-- To add other languages, just add lines similar to the |
26 |
-- existing ones - don't forget the trailing ","! |
|
27 |
} |
|
28 |
||
29 |
local subcaption = { |
|
30 |
["en"] = "Aiming Practice", |
|
31 |
["de"] = "Zielübung", |
|
32 |
["es"] = "Practica tu puntería", |
|
33 |
["pl"] = "Potrenuj celność", |
|
3456
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
34 |
["pt_PT"] = "Pratica a tua pontaria", |
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
35 |
["pt_BR"] = "Pratique a sua pontaria" |
3234 | 36 |
} |
37 |
||
38 |
local goal = { |
|
39 |
["en"] = "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.", |
|
40 |
["de"] = "Eliminiere alle Ziele bevor die Zeit ausläuft.|Du hast in dieser Mission unbegrenzte Munition.", |
|
41 |
["es"] = "Destruye todos los objetivos antes de que se agote el tiempo.|La munición en esta misión es ilimitada.", |
|
42 |
["pl"] = "Zniszcz wszystkie cele zanim upłynie czas.|W tej misji masz nieskończoną ilość amunicji.", |
|
3456
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
43 |
["pt_PT"] = "Destrói todos os alvos antes do tempo terminar.|Tens munições infinitas para esta missão.", |
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
44 |
["pt_BR"] = "Destrua todos os alvos antes que o tempo acabe.|Você tem munição infinita para esta missão." |
3234 | 45 |
} |
46 |
||
47 |
local timeout = { |
|
48 |
["en"] = "Oh no! Time's up! Just try again.", |
|
49 |
["de"] = "Oh nein! Die Zeit ist um! Versuche es nochmal.", |
|
50 |
["es"] = "¡Oh, no, se te acabó el tiempo! ¿Por qué no lo intentas de nuevo?", |
|
51 |
["pl"] = "Ajajaj! Koniec czasu! Spróbuj jeszcze raz.", |
|
3456
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
52 |
["pt_PT"] = "Oh não! Acabou o tempo! Tenta novamente.", |
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
53 |
["pt_BR"] = "Oh não! O tempo acabou! Tente novamente." |
3234 | 54 |
} |
55 |
||
56 |
local success = { |
|
57 |
["en"] = "Congratulations! You've eliminated all targets|within the allowed time frame.", |
|
58 |
["de"] = "Gratulation! Du hast alle Ziele innerhalb der|verfügbaren Zeit ausgeschaltet.", |
|
59 |
["es"] = "¡Felicidades! Has destruido todos los objectivos|dentro del tiempo establecido.", |
|
3235 | 60 |
["pl"] = "Gratulacje! Zniszczyłeś wszystkie cele przed upłynięciem czasu.", |
3456
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
61 |
["pt_PT"] = "Parabéns! Eliminaste todos os alvos|dentro do tempo limite.", |
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
62 |
["pt_BR"] = "Parabéns! Você eliminou todos os alvos|dentro do tempo limite." |
3234 | 63 |
} |
64 |
||
65 |
local teamname = { |
|
66 |
["en"] = "'Zooka Team", |
|
67 |
["de"] = "Die Knalltüten", |
|
68 |
["es"] = "Bazuqueros", |
|
69 |
["pl"] = "Bazookinierzy", |
|
3456
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
70 |
["pt_PT"] = "Bazuqueiros", |
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
71 |
["pt_BR"] = "Bazuqueiros" |
3234 | 72 |
} |
73 |
||
74 |
local hogname = { |
|
75 |
["en"] = "Hunter", |
|
76 |
["de"] = "Jäger", |
|
77 |
["es"] = "Artillero", |
|
78 |
["pl"] = "Strzelec", |
|
3456
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
79 |
["pt_PT"] = "Comando", |
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
80 |
["pt_BR"] = "Artilheiro" |
3234 | 81 |
} |
82 |
||
83 |
-- To handle missing texts we define a small wrapper function that |
|
84 |
-- we'll use to retrieve text. |
|
85 |
local function loc(text) |
|
86 |
if text == nil then return "**missing**" |
|
87 |
elseif text[L] == nil then return text["en"] |
|
88 |
else return text[L] |
|
89 |
end |
|
90 |
end |
|
91 |
||
92 |
--------------------------------------------------------------- |
|
93 |
||
94 |
-- This variable will hold the number of destroyed targets. |
|
95 |
local score = 0 |
|
96 |
-- This variable represents the number of targets to destroy. |
|
97 |
local score_goal = 5 |
|
98 |
-- This variable controls how many milliseconds/ticks we'd |
|
99 |
-- like to wait before we end the round once all targets |
|
100 |
-- have been destroyed. |
|
101 |
local end_timer = 5000 -- 5000 ms = 5 s |
|
102 |
-- This variable is set to true if the game is lost (i.e. |
|
103 |
-- time runs out). |
|
104 |
local game_lost = false |
|
105 |
-- This variable will point to the hog's gear |
|
106 |
local player = nil |
|
107 |
-- This variable will grab the time left at the end of the round |
|
108 |
local time_goal = 0 |
|
109 |
||
110 |
-- This is a custom function to make it easier to |
|
111 |
-- spawn more targets with just one line of code |
|
112 |
-- You may define as many custom functions as you |
|
113 |
-- like. |
|
114 |
function spawnTarget() |
|
115 |
-- add a new target gear |
|
116 |
gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0) |
|
117 |
||
118 |
-- move it to a random position within 0 and |
|
119 |
-- LAND_WIDTH - the width of the map |
|
120 |
FindPlace(gear, true, 0, LAND_WIDTH) |
|
121 |
||
122 |
-- move the target to a higher vertical position |
|
123 |
-- to ensure it's not somewhere down below |
|
124 |
x, y = GetGearPosition(gear) |
|
125 |
SetGearPosition(gear, x, 500) |
|
126 |
end |
|
127 |
||
128 |
-- This function is called before the game loads its |
|
129 |
-- resources. |
|
130 |
-- It's one of the predefined function names that will |
|
131 |
-- be called by the game. They give you entry points |
|
132 |
-- where you're able to call your own code using either |
|
133 |
-- provided instructions or custom functions. |
|
134 |
function onGameInit() |
|
135 |
-- At first we have to overwrite/set some global variables |
|
136 |
-- that define the map, the game has to load, as well as |
|
137 |
-- other things such as the game rules to use, etc. |
|
138 |
-- Things we don't modify here will use their default values. |
|
139 |
||
140 |
-- The base number for the random number generator |
|
141 |
Seed = 0 |
|
142 |
-- Game settings and rules |
|
143 |
GameFlags = gfMultiWeapon + gfOneClanMode + gfSolidLand |
|
144 |
-- The time the player has to move each round (in ms) |
|
145 |
TurnTime = 60000 |
|
146 |
-- The frequency of crate drops |
|
147 |
CaseFreq = 0 |
|
148 |
-- The number of mines being placed |
|
149 |
LandAdds = 0 |
|
150 |
-- The number of explosives being placed |
|
151 |
Explosives = 0 |
|
152 |
-- The delay between each round |
|
153 |
Delay = 0 |
|
154 |
-- The map to be played |
|
155 |
Map = "Bamboo" |
|
156 |
-- The theme to be used |
|
157 |
Theme = "Bamboo" |
|
158 |
||
159 |
-- Create the player team |
|
160 |
AddTeam(loc(teamname), 14483456, "Simple", "Island", "Default") |
|
161 |
-- And add a hog to it |
|
162 |
player = AddHog(loc(hogname), 0, 1, "NoHat") |
|
163 |
SetGearPosition(player, 1960, 1160); |
|
164 |
end |
|
165 |
||
166 |
-- This function is called when the round starts |
|
167 |
-- it spawns the first target that has to be destroyed. |
|
168 |
-- In addition it shows the scenario goal(s). |
|
169 |
function onGameStart() |
|
170 |
-- Spawn the first target. |
|
171 |
spawnTarget() |
|
172 |
||
173 |
-- Show some nice mission goals. |
|
174 |
-- Parameters are: caption, sub caption, description, |
|
175 |
-- extra text, icon and time to show. |
|
176 |
-- A negative icon parameter (-n) represents the n-th weapon icon |
|
177 |
-- A positive icon paramter (n) represents the (n+1)-th mission icon |
|
178 |
-- A timeframe of 0 is replaced with the default time to show. |
|
179 |
ShowMission(loc(caption), loc(subcaption), loc(goal), -amBazooka, 0); |
|
180 |
end |
|
181 |
||
182 |
-- This function is called every game tick. |
|
183 |
-- Note that there are 1000 ticks within one second. |
|
184 |
-- You shouldn't try to calculate too complicated |
|
185 |
-- code here as this might slow down your game. |
|
186 |
function onGameTick() |
|
187 |
-- If time's up, set the game to be lost. |
|
188 |
-- We actually check the time to be "1 ms" as it |
|
189 |
-- will be at "0 ms" right at the start of the game. |
|
190 |
if TurnTimeLeft == 1 and score < score_goal then |
|
191 |
game_lost = true |
|
192 |
-- ... and show a short message. |
|
193 |
ShowMission(loc(caption), loc(subcaption), loc(timeout), -amSkip, 0); |
|
194 |
-- How about killing our poor hog due to his poor performance? |
|
195 |
SetHealth(player, 0); |
|
196 |
-- Just to be sure set the goal time to 1 ms |
|
197 |
time_goal = 1 |
|
198 |
end |
|
199 |
-- If the goal is reached or we've lost ... |
|
200 |
if score == score_goal or game_lost then |
|
201 |
-- ... check to see if the time we'd like to |
|
202 |
-- wait has passed and then ... |
|
203 |
if end_timer == 0 then |
|
204 |
-- ... end the game ... |
|
205 |
EndGame() |
|
206 |
else |
|
207 |
-- ... or just lower the timer by 1. |
|
208 |
end_timer = end_timer - 1 |
|
209 |
-- Reset the time left to stop the timer |
|
210 |
TurnTimeLeft = time_goal |
|
211 |
end |
|
212 |
end |
|
213 |
end |
|
214 |
||
215 |
-- This function is called when the game is initialized |
|
216 |
-- to request the available ammo and probabilities |
|
217 |
function onAmmoStoreInit() |
|
218 |
-- add an unlimited supply of bazooka ammo |
|
3346 | 219 |
SetAmmo(amBazooka, 9, 0, 0, 0) |
3234 | 220 |
end |
221 |
||
222 |
-- This function is called when a new gear is added. |
|
223 |
-- We don't need it for this training, so we can |
|
224 |
-- keep it empty. |
|
225 |
function onGearAdd(gear) |
|
226 |
end |
|
227 |
||
228 |
-- This function is called before a gear is destroyed. |
|
229 |
-- We use it to count the number of targets destroyed. |
|
230 |
function onGearDelete(gear) |
|
231 |
-- We're only interested in target gears. |
|
232 |
if GetGearType(gear) == gtTarget then |
|
233 |
-- Add one point to our score/counter |
|
234 |
score = score + 1 |
|
235 |
-- If we haven't reached the goal ... |
|
236 |
if score < score_goal then |
|
237 |
-- ... spawn another target. |
|
238 |
spawnTarget() |
|
239 |
else |
|
240 |
if not game_lost then |
|
241 |
-- Otherwise show that the goal was accomplished |
|
242 |
ShowMission(loc(caption), loc(subcaption), loc(success), 0, 0); |
|
243 |
-- Also let the hogs shout "victory!" |
|
244 |
PlaySound(sndVictory) |
|
245 |
-- Save the time left so we may keep it. |
|
246 |
time_goal = TurnTimeLeft |
|
247 |
end |
|
248 |
end |
|
249 |
end |
|
250 |
end |