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