author | nemo |
Wed, 30 Oct 2013 15:25:17 -0400 | |
changeset 9658 | c97e8ecc7457 |
parent 9657 | 2d8cae3c0855 |
child 9659 | e9c00dd31b07 |
permissions | -rw-r--r-- |
4506
37744d5c877e
Finnished up the lua translations by adding training maps, campaign is ignored for now
Henek
parents:
4503
diff
changeset
|
1 |
-- Hedgewars - Roperace for 2+ Players |
4188 | 2 |
|
9093 | 3 |
HedgewarsScriptLoad("/Scripts/Locale.lua") |
4188 | 4 |
|
5 |
-- store number of hedgehogs |
|
6 |
local numhhs = 0 |
|
7 |
||
8 |
-- store hedgehog gears |
|
9 |
local hhs = {} |
|
10 |
||
11 |
-- store best time per team |
|
12 |
local clantimes = {} |
|
13 |
||
14 |
-- store best times |
|
15 |
local times = {} |
|
16 |
||
17 |
-- in milisseconds |
|
18 |
local maxtime = 99000 |
|
19 |
||
20 |
-- define start area (left, top, width, height) |
|
21 |
local start_area = {1606, 498, 356, 80} |
|
22 |
||
23 |
-- define goal area (left, top, width, height) |
|
24 |
local goal_area = {2030, 300, 56, 280} |
|
25 |
||
26 |
-- last active hog |
|
27 |
local lasthog = nil |
|
28 |
||
29 |
-- active hog reached the goal? |
|
30 |
local reached = false |
|
31 |
||
32 |
-- hog with best time |
|
33 |
local besthog = nil |
|
9411
d95ac9992529
Fix script flaw in detection of best team when sending achievement info
unc0rr
parents:
9409
diff
changeset
|
34 |
local besthogteam = "" |
4188 | 35 |
|
36 |
-- hog with worst time (per round) |
|
37 |
local worsthog = nil |
|
38 |
||
39 |
-- best time |
|
40 |
local besttime = maxtime + 1 |
|
41 |
||
42 |
-- worst time (per round) |
|
43 |
local worsttime = 0 |
|
9657
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
44 |
local startTime = 0; |
4188 | 45 |
|
46 |
function onGameInit() |
|
9657
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
47 |
GameFlags = gfSolidLand + gfInvulnerable |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
48 |
TurnTime = maxtime |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
49 |
CaseFreq = 0 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
50 |
MinesNum = 0 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
51 |
Explosives = 0 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
52 |
Delay = 500 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
53 |
SuddenDeathTurns = 99999 -- "disable" sudden death |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
54 |
Theme = 'Olympics' |
4188 | 55 |
end |
56 |
||
57 |
function onGameStart() |
|
9657
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
58 |
ShowMission(loc("TrophyRace"), "", loc("Use your rope to get from start to finish as fast as you can!"), -amRope, 0) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
59 |
started = true |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
60 |
p=1820 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
61 |
for i = 0, numhhs - 1 do |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
62 |
p = p + 50 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
63 |
SetGearPosition(hhs[i], p, 0) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
64 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
65 |
|
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
66 |
for i=0, ClansCount-1 do |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
67 |
clantimes[i] = 0 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
68 |
end |
4188 | 69 |
end |
70 |
||
71 |
function onAmmoStoreInit() |
|
9657
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
72 |
SetAmmo(amRope, 9, 2, 0) |
4188 | 73 |
end |
74 |
||
7771 | 75 |
function onGameTick20() |
9658 | 76 |
if startTime == 0 and TurnTimeLeft < maxtime then |
9657
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
77 |
startTime = GameTime |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
78 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
79 |
if CurrentHedgehog ~= nil and TurnTimeLeft <= 20 and TurnTimeLeft > 0 then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
80 |
SetHealth(CurrentHedgehog, 0) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
81 |
x, y = GetGearPosition(CurrentHedgehog) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
82 |
AddGear(x, y, gtShell, 0, 0, 0, 0) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
83 |
worsttime = 99999 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
84 |
worsthog = nil |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
85 |
elseif TurnTimeLeft > maxtime - 25 and CurrentHedgehog ~= nil then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
86 |
if lasthog ~= nil then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
87 |
SetGearPosition(lasthog, p , 0) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
88 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
89 |
reached = false |
7771 | 90 |
SetGearVelocity(CurrentHedgehog, 1, 0) |
9657
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
91 |
SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2) |
7771 | 92 |
ParseCommand("setweap " .. string.char(amRope)) |
9657
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
93 |
lasthog = CurrentHedgehog |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
94 |
elseif CurrentHedgehog ~= nil then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
95 |
x, y = GetGearPosition(CurrentHedgehog) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
96 |
if not reached and x > goal_area[1] and x < goal_area[1] + goal_area[3] and y > goal_area[2] and y < goal_area[2] + goal_area[4] then -- hog is within goal rectangle |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
97 |
reached = true |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
98 |
local ttime = GameTime-startTime |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
99 |
startTime = 0 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
100 |
--give it a sound;) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
101 |
if ttime < besttime then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
102 |
PlaySound (sndHomerun) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
103 |
else |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
104 |
PlaySound (sndHellish) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
105 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
106 |
for i = 0, numhhs - 1 do |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
107 |
if hhs[i] == CurrentHedgehog then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
108 |
times[numhhs] = ttime |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
109 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
110 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
111 |
|
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
112 |
local hscore = "| |" |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
113 |
local clan = GetHogClan(CurrentHedgehog) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
114 |
if ttime < clantimes[clan] or clantimes[clan] == 0 then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
115 |
clantimes[clan] = ttime |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
116 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
117 |
if ttime < besttime then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
118 |
besttime = ttime |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
119 |
besthog = CurrentHedgehog |
9411
d95ac9992529
Fix script flaw in detection of best team when sending achievement info
unc0rr
parents:
9409
diff
changeset
|
120 |
besthogteam = GetHogTeamName(besthog) |
9657
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
121 |
hscore = hscore .. loc("NEW fastest lap: ") |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
122 |
else |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
123 |
hscore = hscore .. loc("Fastest lap: ") |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
124 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
125 |
if ttime > worsttime then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
126 |
worsttime = ttime |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
127 |
worsthog = CurrentHedgehog |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
128 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
129 |
hscore = hscore .. GetHogName(besthog) .. " - " .. (besttime / 1000) .. " s | |" .. loc("Best laps per team: ") |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
130 |
|
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
131 |
if clan == ClansCount -1 then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
132 |
-- Time for elimination - worst hog is out and the worst hog vars are reset. |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
133 |
SetHealth(worsthog, 0) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
134 |
--Place a grenade to make inactive slowest hog active |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
135 |
x, y = GetGearPosition(worsthog) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
136 |
AddGear(x, y, gtShell, 0, 0, 0, 0) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
137 |
worsttime = 0 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
138 |
worsthog = nil |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
139 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
140 |
|
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
141 |
for i=0, ClansCount -1 do |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
142 |
local tt = "" .. (clantimes[i] / 1000) .. " s" |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
143 |
if clantimes[i] == 0 then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
144 |
tt = "--" |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
145 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
146 |
hscore = hscore .. "|" .. string.format(loc("Team %d: "), i+1) .. tt |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
147 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
148 |
|
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
149 |
ShowMission(loc("TrophyRace"), "", loc("You've reached the goal!| |Time: ") .. (ttime / 1000) .. " s" .. hscore, 0, 0) |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
150 |
TurnTimeLeft = 0 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
151 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
152 |
end |
4188 | 153 |
end |
154 |
||
155 |
function onGearAdd(gear) |
|
9657
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
156 |
if GetGearType(gear) == gtHedgehog then |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
157 |
hhs[numhhs] = gear |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
158 |
times[numhhs] = 0 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
159 |
numhhs = numhhs + 1 |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
160 |
end |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
161 |
-- elseif GetGearType(gear) == gtRope then -- rope is shot |
4188 | 162 |
end |
163 |
||
7771 | 164 |
--function onGearDelete(gear) |
9657
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
165 |
-- if GetGearType(gear) == gtRope then -- rope deletion - hog didn't manage to rerope |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
166 |
-- --TurnTimeLeft = 0 -- end turn or not? hm... |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
167 |
-- lasthog = CurrentHedgehog |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
168 |
-- |
2d8cae3c0855
use gameticks instead of turn timer. untested. also replaced tabs with spaces
nemo
parents:
9411
diff
changeset
|
169 |
-- end |
7771 | 170 |
--end |
9397 | 171 |
|
172 |
function onAchievementsDeclaration() |
|
173 |
if besthog ~= nil then |
|
9411
d95ac9992529
Fix script flaw in detection of best team when sending achievement info
unc0rr
parents:
9409
diff
changeset
|
174 |
DeclareAchievement("rope race", besthogteam, "TrophyRace", besttime) |
9397 | 175 |
end |
176 |
end |