author | Henek |
Wed, 08 Dec 2010 22:35:29 +0100 | |
changeset 4493 | 45db8e97d282 |
parent 4350 | cdb3d7a39fa2 |
child 4506 | 37744d5c877e |
permissions | -rw-r--r-- |
3234 | 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 |
-- 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"] = "Shotgun Training", |
|
20 |
["de"] = "Schrotflinten-Training", |
|
21 |
["es"] = "Entrenamiento con escopeta", |
|
22 |
["pl"] = "Trening strzelecki", |
|
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 Caçadeira", |
3476
1ec68b8d3bd1
Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents:
3456
diff
changeset
|
24 |
["pt_BR"] = "Treino com a Escopeta", |
4350 | 25 |
["sv"] = "Hagelgevärsträning", |
26 |
["sk"] = "Tréning s brokovnicou" |
|
3234 | 27 |
-- To add other languages, just add lines similar to the |
28 |
-- existing ones - don't forget the trailing ","! |
|
29 |
} |
|
30 |
||
31 |
local subcaption = { |
|
32 |
["en"] = "Aiming Practice", |
|
33 |
["de"] = "Zielübung", |
|
34 |
["es"] = "Practica tu puntería", |
|
35 |
["pl"] = "Potrenuj celność", |
|
3456
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
36 |
["pt_PT"] = "Pratica a tua pontaria", |
3476
1ec68b8d3bd1
Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents:
3456
diff
changeset
|
37 |
["pt_BR"] = "Pratique a sua pontaria", |
4350 | 38 |
["sv"] = "Siktesövning", |
39 |
["sk"] = "Tréning presnosti" |
|
3234 | 40 |
} |
41 |
||
42 |
local goal = { |
|
43 |
["en"] = "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.", |
|
44 |
["de"] = "Eliminiere alle Ziele bevor die Zeit ausläuft.|Du hast in dieser Mission unbegrenzte Munition.", |
|
45 |
["es"] = "Destruye todos los objetivos antes de que se agote el tiempo.|La munición en esta misión es ilimitada.", |
|
46 |
["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
|
47 |
["pt_PT"] = "Destrói todos os alvos antes do tempo terminar.|Tens munições infinitas para esta missão.", |
3476
1ec68b8d3bd1
Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents:
3456
diff
changeset
|
48 |
["pt_BR"] = "Destrua todos os alvos antes que o tempo acabe.|Você tem munição infinita para esta missão.", |
4350 | 49 |
["sv"] = "Förstör alla målen innan din tid tar slut.|Du har obegränsad ammunition för deta uppdrag", |
50 |
["sk"] = "Zneškodnite všetky ciele pred vypršaním času.|Na túto misiu máte neobmedzené množstvo streliva." |
|
3234 | 51 |
} |
52 |
||
53 |
local timeout = { |
|
54 |
["en"] = "Oh no! Time's up! Just try again.", |
|
55 |
["de"] = "Oh nein! Die Zeit ist um! Versuche es nochmal.", |
|
56 |
["es"] = "¡Oh, no, se te acabó el tiempo! ¿Por qué no lo intentas de nuevo?", |
|
57 |
["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
|
58 |
["pt_PT"] = "Oh não! Acabou o tempo! Tenta novamente.", |
3476
1ec68b8d3bd1
Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents:
3456
diff
changeset
|
59 |
["pt_BR"] = "Oh não! O tempo acabou! Tente novamente.", |
4350 | 60 |
["sv"] = "Åh nej! Tiden är ute! Pröva igen.", |
61 |
["sk"] = "Ale nie! Čas vypršal! Tak to skúste znovu." |
|
3234 | 62 |
} |
63 |
||
64 |
local success = { |
|
65 |
["en"] = "Congratulations! You've eliminated all targets|within the allowed time frame.", |
|
66 |
["de"] = "Gratulation! Du hast alle Ziele innerhalb der|verfügbaren Zeit ausgeschaltet.", |
|
67 |
["es"] = "¡Felicidades! Has destruido todos los objectivos|dentro del tiempo establecido.", |
|
3235 | 68 |
["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
|
69 |
["pt_PT"] = "Parabéns! Eliminaste todos os alvos|dentro do tempo limite.", |
3476
1ec68b8d3bd1
Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents:
3456
diff
changeset
|
70 |
["pt_BR"] = "Parabéns! Você eliminou todos os alvos|dentro do tempo limite.", |
4350 | 71 |
["sv"] = "Grattis! Du har förstört alla målen inom den|tillåtna tidsramen.", |
72 |
["sk"] = "Gratulujem! Zneškodnili ste všetky ciele|v stanovenom čase." |
|
3234 | 73 |
} |
74 |
||
75 |
local teamname = { |
|
76 |
["en"] = "Shotgun Team", |
|
77 |
["de"] = "Die Knalltüten", |
|
78 |
["es"] = "Escopeteros", |
|
79 |
["pl"] = "Shotgun Team", |
|
3456
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
80 |
["pt_PT"] = "Caçadores", |
3476
1ec68b8d3bd1
Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents:
3456
diff
changeset
|
81 |
["pt_PT"] = "Carabineiros", |
4350 | 82 |
["sv"] = "Hagelgevärslaget", |
83 |
["sk"] = "Shotgun tím" |
|
3234 | 84 |
} |
85 |
||
86 |
local hogname = { |
|
87 |
["en"] = "Hunter", |
|
88 |
["de"] = "Jäger", |
|
89 |
["es"] = "Cazador", |
|
3247
045a76b9f32f
Shotgun Training: * '["en"]' was supposed to be '["pl"]' (Mmmmh, copypasta :D)
sheepluva
parents:
3235
diff
changeset
|
90 |
["pl"] = "Strzelec", |
3456
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
91 |
["pt_PT"] = "Comando", |
e19e017691e4
More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents:
3346
diff
changeset
|
92 |
["pt_BR"] = "Caçador", |
4350 | 93 |
["sv"] = "Jägare", |
94 |
["sk"] = "Lovec" |
|
3234 | 95 |
} |
96 |
||
97 |
-- To handle missing texts we define a small wrapper function that |
|
98 |
-- we'll use to retrieve text. |
|
99 |
local function loc(text) |
|
100 |
if text == nil then return "**missing**" |
|
101 |
elseif text[L] == nil then return text["en"] |
|
102 |
else return text[L] |
|
103 |
end |
|
104 |
end |
|
105 |
||
106 |
--------------------------------------------------------------- |
|
107 |
||
108 |
-- This variable will hold the number of destroyed targets. |
|
109 |
local score = 0 |
|
110 |
-- This variable represents the number of targets to destroy. |
|
111 |
local score_goal = 5 |
|
112 |
-- This variable controls how many milliseconds/ticks we'd |
|
113 |
-- like to wait before we end the round once all targets |
|
114 |
-- have been destroyed. |
|
115 |
local end_timer = 5000 -- 5000 ms = 5 s |
|
116 |
-- This variable is set to true if the game is lost (i.e. |
|
117 |
-- time runs out). |
|
118 |
local game_lost = false |
|
119 |
-- This variable will point to the hog's gear |
|
120 |
local player = nil |
|
121 |
-- This variable will grab the time left at the end of the round |
|
122 |
local time_goal = 0 |
|
123 |
||
124 |
-- This is a custom function to make it easier to |
|
125 |
-- spawn more targets with just one line of code |
|
126 |
-- You may define as many custom functions as you |
|
127 |
-- like. |
|
128 |
function spawnTarget() |
|
129 |
-- add a new target gear |
|
130 |
gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0) |
|
131 |
||
132 |
-- move it to a random position within 0 and |
|
133 |
-- LAND_WIDTH - the width of the map |
|
134 |
FindPlace(gear, true, 0, LAND_WIDTH) |
|
135 |
||
136 |
-- move the target to a higher vertical position |
|
137 |
-- to ensure it's not somewhere down below |
|
138 |
x, y = GetGearPosition(gear) |
|
139 |
SetGearPosition(gear, x, 500) |
|
140 |
end |
|
141 |
||
142 |
-- This function is called before the game loads its |
|
143 |
-- resources. |
|
144 |
-- It's one of the predefined function names that will |
|
145 |
-- be called by the game. They give you entry points |
|
146 |
-- where you're able to call your own code using either |
|
147 |
-- provided instructions or custom functions. |
|
148 |
function onGameInit() |
|
149 |
-- At first we have to overwrite/set some global variables |
|
150 |
-- that define the map, the game has to load, as well as |
|
151 |
-- other things such as the game rules to use, etc. |
|
152 |
-- Things we don't modify here will use their default values. |
|
153 |
||
154 |
-- The base number for the random number generator |
|
155 |
Seed = 0 |
|
156 |
-- Game settings and rules |
|
157 |
GameFlags = gfMultiWeapon + gfOneClanMode |
|
158 |
-- The time the player has to move each round (in ms) |
|
159 |
TurnTime = 25000 |
|
160 |
-- The frequency of crate drops |
|
161 |
CaseFreq = 0 |
|
162 |
-- The number of mines being placed |
|
4162 | 163 |
MinesNum = 0 |
3234 | 164 |
-- The number of explosives being placed |
165 |
Explosives = 0 |
|
166 |
-- The delay between each round |
|
167 |
Delay = 0 |
|
168 |
-- The map to be played |
|
169 |
Map = "Mushrooms" |
|
170 |
-- The theme to be used |
|
171 |
Theme = "Nature" |
|
172 |
||
173 |
-- Create the player team |
|
174 |
AddTeam(loc(teamname), 14483456, "Simple", "Island", "Default") |
|
175 |
-- And add a hog to it |
|
176 |
player = AddHog(loc(hogname), 0, 1, "NoHat") |
|
4493
45db8e97d282
removing all ; from lua script as an act of temporary rage and perfectionism
Henek
parents:
4350
diff
changeset
|
177 |
SetGearPosition(player, 2334, 1254) |
3234 | 178 |
end |
179 |
||
180 |
-- This function is called when the round starts |
|
181 |
-- it spawns the first target that has to be destroyed. |
|
182 |
-- In addition it shows the scenario goal(s). |
|
183 |
function onGameStart() |
|
184 |
-- Spawn the first target. |
|
185 |
spawnTarget() |
|
186 |
||
187 |
-- Show some nice mission goals. |
|
188 |
-- Parameters are: caption, sub caption, description, |
|
189 |
-- extra text, icon and time to show. |
|
190 |
-- A negative icon parameter (-n) represents the n-th weapon icon |
|
191 |
-- A positive icon paramter (n) represents the (n+1)-th mission icon |
|
192 |
-- A timeframe of 0 is replaced with the default time to show. |
|
4493
45db8e97d282
removing all ; from lua script as an act of temporary rage and perfectionism
Henek
parents:
4350
diff
changeset
|
193 |
ShowMission(loc(caption), loc(subcaption), loc(goal), -amShotgun, 0) |
3234 | 194 |
end |
195 |
||
196 |
-- This function is called every game tick. |
|
197 |
-- Note that there are 1000 ticks within one second. |
|
198 |
-- You shouldn't try to calculate too complicated |
|
199 |
-- code here as this might slow down your game. |
|
200 |
function onGameTick() |
|
201 |
-- If time's up, set the game to be lost. |
|
202 |
-- We actually check the time to be "1 ms" as it |
|
203 |
-- will be at "0 ms" right at the start of the game. |
|
204 |
if TurnTimeLeft == 1 and score < score_goal then |
|
205 |
game_lost = true |
|
206 |
-- ... and show a short message. |
|
4493
45db8e97d282
removing all ; from lua script as an act of temporary rage and perfectionism
Henek
parents:
4350
diff
changeset
|
207 |
ShowMission(loc(caption), loc(subcaption), loc(timeout), -amSkip, 0) |
3234 | 208 |
-- How about killing our poor hog due to his poor performance? |
4493
45db8e97d282
removing all ; from lua script as an act of temporary rage and perfectionism
Henek
parents:
4350
diff
changeset
|
209 |
SetHealth(player, 0) |
3234 | 210 |
-- Just to be sure set the goal time to 1 ms |
211 |
time_goal = 1 |
|
212 |
end |
|
213 |
-- If the goal is reached or we've lost ... |
|
214 |
if score == score_goal or game_lost then |
|
215 |
-- ... check to see if the time we'd like to |
|
216 |
-- wait has passed and then ... |
|
217 |
if end_timer == 0 then |
|
218 |
-- ... end the game ... |
|
219 |
EndGame() |
|
220 |
else |
|
221 |
-- ... or just lower the timer by 1. |
|
222 |
end_timer = end_timer - 1 |
|
223 |
-- Reset the time left to stop the timer |
|
224 |
TurnTimeLeft = time_goal |
|
225 |
end |
|
226 |
end |
|
227 |
end |
|
228 |
||
229 |
-- This function is called when the game is initialized |
|
230 |
-- to request the available ammo and probabilities |
|
231 |
function onAmmoStoreInit() |
|
232 |
-- add an unlimited supply of shotgun ammo |
|
3346 | 233 |
SetAmmo(amShotgun, 9, 0, 0, 0) |
3234 | 234 |
end |
235 |
||
236 |
-- This function is called when a new gear is added. |
|
237 |
-- We don't need it for this training, so we can |
|
238 |
-- keep it empty. |
|
239 |
function onGearAdd(gear) |
|
240 |
end |
|
241 |
||
242 |
-- This function is called before a gear is destroyed. |
|
243 |
-- We use it to count the number of targets destroyed. |
|
244 |
function onGearDelete(gear) |
|
245 |
-- We're only interested in target gears. |
|
246 |
if GetGearType(gear) == gtTarget then |
|
247 |
-- Add one point to our score/counter |
|
248 |
score = score + 1 |
|
249 |
-- If we haven't reached the goal ... |
|
250 |
if score < score_goal then |
|
251 |
-- ... spawn another target. |
|
252 |
spawnTarget() |
|
253 |
else |
|
254 |
if not game_lost then |
|
255 |
-- Otherwise show that the goal was accomplished |
|
4493
45db8e97d282
removing all ; from lua script as an act of temporary rage and perfectionism
Henek
parents:
4350
diff
changeset
|
256 |
ShowMission(loc(caption), loc(subcaption), loc(success), 0, 0) |
3234 | 257 |
-- Also let the hogs shout "victory!" |
258 |
PlaySound(sndVictory) |
|
259 |
-- Save the time left so we may keep it. |
|
260 |
time_goal = TurnTimeLeft |
|
261 |
end |
|
262 |
end |
|
263 |
end |
|
264 |
end |