author | Wuzzy <almikes@aol.com> |
Thu, 24 Nov 2016 00:50:40 +0100 | |
changeset 12057 | 144264948277 |
parent 11034 | a9bafac12634 |
child 12229 | d62d6f8ebef1 |
permissions | -rw-r--r-- |
11034
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
1 |
--[=[ |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
2 |
Speed Shoppa Mission Framework for Hedgewars |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
3 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
4 |
This is a simple library intended to make setting up simple training missions a trivial |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
5 |
task. The library has been created to reduce redundancy in Lua scripts. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
6 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
7 |
The framework generates complete and fully Speed Shoppa missions by just |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
8 |
one function call. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
9 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
10 |
The missions generated by this script are all the same: |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
11 |
- The player will get a team with a single hedgehog. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
12 |
- The team gets infinite ropes. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
13 |
- A fixed set of crates will spawn at predefined positions. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
14 |
- The mission ends successfully when all crates have been collected |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
15 |
- The mission ends unsuccessfully when the time runs out or the hedgehog dies |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
16 |
- When the mission ends, the time it took to finish the mission is shown |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
17 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
18 |
To use this library, you first have to load it and to call SpeedShoppaMission once with |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
19 |
the appropriate parameters. Really, that’s all! |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
20 |
See the comment of SpeedShoppaMission for a specification of all parameters. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
21 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
22 |
]=] |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
23 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
24 |
HedgewarsScriptLoad("/Scripts/Locale.lua") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
25 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
26 |
--[[ |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
27 |
SpeedShoppaMission(params) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
28 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
29 |
This function sets up the *entire* mission and needs one argument: params. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
30 |
The argument “params” is a table containing fields which describe the training mission. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
31 |
mandatory fields: |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
32 |
- map: the name of the map to be used |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
33 |
- theme: the name of the theme (does not need to be a standalone theme) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
34 |
- time: the time limit in milliseconds |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
35 |
- crates: The coordinates of where the crates will be spawned. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
36 |
It is a table containing tables containing coordinates of format |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
37 |
{ x=value, y=value }. Example: |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
38 |
crates = { |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
39 |
{ x = 324, y = 43 }, |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
40 |
{ x = 123, y = 56 }, |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
41 |
{ x = 6, y = 0 }, |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
42 |
} |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
43 |
There must be at least 1 crate. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
44 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
45 |
optional fields: |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
46 |
- missionTitle: the name of the mission (optional but highly recommended) (default: "Speed Shoppa") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
47 |
- hogHat: hat of the hedgehog (default: "NoHat") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
48 |
- hogName: name of the hedgehog (default: "Roper") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
49 |
- teamName: name of the hedgehog’s team (default: "Shoppers") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
50 |
- teamGrave: name of the hedgehog’s grave (default: "Statue") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
51 |
- teamFlag: name of the team’s flag (default: "cm_shoppa") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
52 |
- clanColor: color of the (only) clan (default: 0xFF0204, which is a red tone) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
53 |
- goalText: A short string explaining the goal of the mission |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
54 |
(default: "Use your rope to collect all crates as fast as possible.") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
55 |
- faceLeft: If true, the hog faces to the left initially, if false, it faces to the right. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
56 |
(default: false (=right)) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
57 |
- crateType Specify the type of crate (this has no gameplay effect), pick one of |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
58 |
"ammo", "utility", "health". Default: "ammo" |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
59 |
- extra_onGameStart: A function which is called at the end of this script's onGameStart. It takes no parameters. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
60 |
You could use this to spawn additional gears like girders or mines. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
61 |
- extra_onGameInit: A function which is called at the end of this script's onGameInit. |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
62 |
]] |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
63 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
64 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
65 |
local playerHog |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
66 |
local gameStarted = false |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
67 |
local cratesCollected = 0 |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
68 |
local gameEnded = false |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
69 |
local timeOut = false |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
70 |
local hogHurt = false |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
71 |
local endTime |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
72 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
73 |
local crates |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
74 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
75 |
function SpeedShoppaMission(params) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
76 |
if params.hogHat == nil then params.hogHat = "NoHat" end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
77 |
if params.hogName == nil then params.hogName = loc("Roper") end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
78 |
if params.teamName == nil then params.teamName = loc("Shoppers") end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
79 |
if params.goalText == nil then params.goalText = loc("Use your rope to collect all crates as fast as possible.") end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
80 |
if params.missionTitle == nil then params.missionTitle = loc("Speed Shoppa") end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
81 |
if params.clanColor == nil then params.clanColor = 0xFF0204 end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
82 |
if params.teamGrave == nil then params.teamGrave = "Statue" end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
83 |
if params.teamFlag == nil then params.teamFlag = "cm_shoppa" end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
84 |
if params.extra_onGameInit == nil then params.extra_onGameInit = function() end end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
85 |
if params.extra_onGameStart == nil then params.extra_onGameStart = function() end end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
86 |
if params.faceLeft == nil then params.faceLeft = false end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
87 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
88 |
crates = params.crates |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
89 |
startTime = params.time |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
90 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
91 |
_G.onGameInit = function() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
92 |
GameFlags = gfDisableWind + gfOneClanMode + gfBorder + gfSolidLand |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
93 |
TurnTime = startTime |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
94 |
CaseFreq = 0 |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
95 |
MinesNum = 0 |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
96 |
Explosives = 0 |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
97 |
Delay = 10 |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
98 |
Theme = params.theme |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
99 |
Map = params.map |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
100 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
101 |
AddTeam(params.teamName, params.clanColor, params.teamGrave, "Castle", "Default", params.teamFlag) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
102 |
playerHog = AddHog(params.hogName, 0, 1, params.hogHat) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
103 |
HogTurnLeft(playerHog, params.faceLeft) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
104 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
105 |
SetGearPosition(playerHog, params.hog_x, params.hog_y) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
106 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
107 |
params.extra_onGameInit() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
108 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
109 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
110 |
_G.onAmmoStoreInit = function() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
111 |
SetAmmo(amRope, 9, 0, 0, 1) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
112 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
113 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
114 |
_G.onGameStart = function() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
115 |
SendHealthStatsOff() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
116 |
ShowMission(params.missionTitle, loc("Challenge"), params.goalText, -amRope, 5000) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
117 |
for i=1,#crates do |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
118 |
spawnCrate(crates[i].x, crates[i].y) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
119 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
120 |
params.extra_onGameStart() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
121 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
122 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
123 |
_G.onNewTurn = function() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
124 |
SetWeapon(amRope) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
125 |
gameStarted = true |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
126 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
127 |
_G.onGearDelete = function(gear) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
128 |
if GetGearType(gear) == gtCase and not hogHurt and not timeOut then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
129 |
cratesCollected = cratesCollected + 1 |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
130 |
PlaySound(sndShotgunReload) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
131 |
if cratesCollected == #crates then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
132 |
endTime = TurnTimeLeft |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
133 |
finalize() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
134 |
else |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
135 |
AddCaption(string.format(loc("%d crate(s) remaining"), #crates - cratesCollected)) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
136 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
137 |
elseif gear == playerHog then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
138 |
finalize() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
139 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
140 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
141 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
142 |
_G.onGearDamage = function(gear) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
143 |
if gear == playerHog then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
144 |
hogHurt = true |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
145 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
146 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
147 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
148 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
149 |
_G.onGameTick20 = function() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
150 |
if TurnTimeLeft < 40 and TurnTimeLeft > 0 and gameStarted and not timeOut and not gameEnded then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
151 |
timeOut = true |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
152 |
AddCaption(loc("Time's up!")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
153 |
SetHealth(playerHog, 0) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
154 |
hogHurt = true |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
155 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
156 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
157 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
158 |
_G.finalize = function() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
159 |
if not gameEnded then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
160 |
if cratesCollected == #crates then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
161 |
PlaySound(sndVictory, playerHog) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
162 |
SetState(playerHog, bor(GetState(playerHog), gstWinner)) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
163 |
SetState(playerHog, band(GetState(playerHog), bnot(gstHHDriven))) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
164 |
AddCaption(loc("Challenge completed!")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
165 |
SendStat(siGameResult, loc("Challenge completed!")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
166 |
SendStat(siPointType, loc("milliseconds")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
167 |
local time = startTime - endTime |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
168 |
SendStat(siPlayerKills, tostring(time), params.teamName) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
169 |
SendStat(siCustomAchievement, string.format(loc("You have finished the challenge in %.3f s."), (time/1000))) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
170 |
TurnTimeLeft = 0 |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
171 |
else |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
172 |
SendStat(siGameResult, loc("Challenge failed!")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
173 |
SendStat(siPointType, loc("crate(s)")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
174 |
SendStat(siPlayerKills, tostring(cratesCollected), params.teamName) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
175 |
SendStat(siCustomAchievement, string.format(loc("You have collected %d out of %d crate(s)."), cratesCollected, #crates)) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
176 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
177 |
gameEnded = true |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
178 |
EndGame() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
179 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
180 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
181 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
182 |
_G.spawnCrate = function(x, y) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
183 |
if params.crateType == "utility" then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
184 |
SpawnFakeUtilityCrate(x, y, false, false) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
185 |
elseif params.crateType == "ammo" then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
186 |
SpawnFakeAmmoCrate(x, y, false, false) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
187 |
elseif params.crateType == "health" then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
188 |
SpawnFakeHealthCrate(x, y, false, false) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
189 |
else |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
190 |
SpawnFakeAmmoCrate(x, y, false, false) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
191 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
192 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
193 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
194 |
end |