author | Wuzzy <almikes@aol.com> |
Fri, 25 Nov 2016 01:20:03 +0100 | |
changeset 12072 | 10aad1cafc10 |
parent 12050 | daf63e2a21d2 |
child 12344 | 877f55c77a3f |
permissions | -rw-r--r-- |
6501 | 1 |
--Created by Patrick Nielsen |
2 |
--It's been so fun to create this, your welcome to contact me at Trivkz@gmail.com |
|
3 |
-- |
|
4 |
--I've tried to keep the code as clear as possible and with comments. |
|
5 |
--But as English is not my first language there may be spelling / grammar mistakes. |
|
6 |
-- |
|
7 |
--I know there need to be more "tutorial" specefic messages, but I had a hard timer figuring out what to type / what would be the best technical description. |
|
8 |
||
9 |
||
8043 | 10 |
HedgewarsScriptLoad("/Scripts/Locale.lua") |
11 |
HedgewarsScriptLoad("/Scripts/Utils.lua") -- For the gearIsInBox function, wrote my own, but decided it was a waste to include it |
|
6501 | 12 |
|
13 |
local Player = nil -- Pointer to hog created in: onGameInit |
|
14 |
local Target = nil -- Pointer to target hog |
|
15 |
local GameLost = false -- You lost the game |
|
16 |
local Objective = false -- Get to the target |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
17 |
local RopeMaster = false -- Achievement |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
18 |
local StatsSent = false -- Remember whether the stats have been sent already |
6501 | 19 |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
20 |
local WaitTime = 1000 -- Wait 1sec before quit |
6501 | 21 |
local FollowTime = 1500 -- For use with FollowGear |
22 |
local FollowingGear = false |
|
23 |
local BaseballIntro = false -- Fail safe for ticker |
|
24 |
local TargetNumber = 0 -- The current target number |
|
25 |
||
26 |
local TargetPos = {} -- Tabel of targets |
|
27 |
local Timers = {} |
|
28 |
local GetTime = 0 |
|
29 |
||
30 |
TargetPos[ 1 ] = { X = 1100, Y = 1100, Message = loc("Now find the next target! |Tip: Normally you lose health by falling down, so be careful!") } |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
31 |
TargetPos[ 2 ] = { X = 1500, Y = 1490, Message = loc("You're getting pretty good! |Tip: When you shorten you rope, you move faster!|And when you lengthen it, you move slower.") } |
6501 | 32 |
TargetPos[ 3 ] = { X = 2200, Y = 800, Message = loc("The next one is pretty hard! |Tip: You have to do multiple swings!") } |
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
33 |
TargetPos[ 4 ] = { X = 2870, Y = 400, Message = loc("I don't know how you did that .. But good work! |The next one should be easy as cake for you!") } |
6501 | 34 |
TargetPos[ 5 ] = { X = 4000, Y = 1750, Message = "" } |
35 |
TargetPos[ 6 ] = { Modifier = true, Func = function() -- Last target is ALWAYS the "winning" target! |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
36 |
Info( loc("Congratulations"), loc("Congratulations! You've completed the Basic Rope Training!"), 0 ) -- Congrats |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
37 |
PlaySound( sndVictory, Player ) |
6501 | 38 |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
39 |
AddCaption( loc( "Victory!" )) |
6501 | 40 |
if TurnTimeLeft >= 250000 then -- If you very fast, unlock the ahievement "Rope Master!" |
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
41 |
RopeMaster = true |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
42 |
AddCaption( loc( "Achievement obtained: Rope Master!" ),0xffba00ff,capgrpAmmoinfo ) |
6501 | 43 |
PlaySound( sndHomerun ) |
44 |
end |
|
45 |
Objective = true |
|
46 |
end } |
|
47 |
||
48 |
function Info( Title, Text, Icon ) -- I made a small wrapper to ease the process |
|
7827
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
49 |
ShowMission( loc("Rope Training"), Title, Text, Icon, 0 ) |
6501 | 50 |
end |
51 |
||
52 |
function NewFollowGear( Gear ) |
|
53 |
FollowingGear = true |
|
54 |
FollowGear( Gear ) |
|
55 |
end |
|
56 |
||
57 |
function SpawnTarget( PosX, PosY ) |
|
58 |
Target = AddGear( 0, 0, gtTarget, 0, 0, 0, 0 ) -- Create a new target |
|
59 |
SetGearPosition( Target, PosX, PosY ) -- Set the position of the target |
|
60 |
NewFollowGear( Target ) |
|
61 |
end |
|
62 |
||
63 |
function AutoSpawn() -- Auto spawn the next target after you've killed the current target! |
|
64 |
TargetNumber = TargetNumber + 1 |
|
65 |
||
66 |
if TargetPos[ TargetNumber ].Modifier then -- If there is a modifier, run the function, only used in the winning target! |
|
67 |
TargetPos[ TargetNumber ].Func() |
|
68 |
return true |
|
69 |
end |
|
70 |
||
71 |
if TargetNumber > 1 then |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
72 |
Info(loc("Training"), TargetPos[ TargetNumber - 1 ].Message, -amRope ) |
6501 | 73 |
end |
74 |
||
75 |
SpawnTarget( TargetPos[ TargetNumber ].X, TargetPos[ TargetNumber ].Y ) -- Spawn target on the next position |
|
76 |
end |
|
77 |
||
78 |
function InRange( Gear, PosX, PosY, Distance ) -- Fix as the default function didn't do quite what I needed |
|
79 |
GearX, GearY = GetGearPosition( Gear ) |
|
80 |
||
81 |
return GearX >= PosX - Distance and GearX <= PosX + Distance and GearY >= PosY and GearY - Distance <= PosY + Distance |
|
82 |
end |
|
83 |
||
84 |
function CheckPosition( Hog, Distance ) -- Show a message when you get close to the current target! |
|
85 |
if (not BaseballIntro and not Objective) and (CurrentHedgehog ~= nil) then --Fail safe check |
|
86 |
if InRange( Hog, 1100, 1100, Distance ) then -- Check if the player is within predefined position of the first target |
|
87 |
BaseballIntro = true |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
88 |
Info(loc("Training"), loc("Great work! Now hit it with your Baseball Bat! |Tip: You can change weapon with 'Right Click'!"), -amRope ) -- Guide them |
7827
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
89 |
Timer( 10000, loc("Remember: The rope only bend around objects, |if it doesn't hit anything it's always stright!")) |
6501 | 90 |
end |
91 |
end |
|
92 |
end |
|
93 |
||
94 |
function Timer( Delay, Message ) |
|
95 |
local Timer = {} |
|
96 |
Timer.End = GetTime + Delay |
|
97 |
Timer.Message = Message |
|
98 |
||
99 |
table.insert( Timers, Timer ) |
|
100 |
end |
|
101 |
||
102 |
function onGameInit() -- Called when the game loads |
|
103 |
Seed = 1 -- The base number for the random number generator |
|
104 |
GameFlags = gfInfAttack + gfOneClanMode + gfSolidLand + gfInvulnerable + gfBorder -- Game settings and rules, going with a border to make it easier |
|
105 |
TurnTime = 300000 -- Player can move for 5min each round |
|
106 |
CaseFreq = 0 -- No random crate drops |
|
107 |
MinesNum = 0 -- Never place any mines on the map |
|
108 |
Explosives = 0 -- Never place any explosives |
|
109 |
Delay = 1 -- We don't wont to wait between each round ( as the only is one ) |
|
110 |
Map = "Ropes" -- Map name |
|
111 |
Theme = "Nature" -- Map theme |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
112 |
-- Disable Sudden Death |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
113 |
SuddenDeathTurns = 50 |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
114 |
WaterRise = 0 |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
115 |
HealthDecrease = 0 |
6501 | 116 |
|
12049
030464f34d47
Tweak flags used in all missions to fit more to the theme
Wuzzy <almikes@aol.com>
parents:
10290
diff
changeset
|
117 |
AddTeam( loc( "Rope Team" ), 14483456, "Simple", "Island", "Default", "cm_shoppa" ) -- Lets make the team |
6501 | 118 |
Player = AddHog( loc( "Hunter" ), 0, 1, "StrawHat" ) -- Add a hog for it, and name it "Hunter" |
119 |
SetGearPosition( Player, 420, 1750 ) -- Set player position |
|
120 |
||
7838 | 121 |
SetEffect( Player, heResurrectable, 1 ) -- By Suggestion :) |
6501 | 122 |
end |
123 |
||
124 |
function onGameStart() -- Called when the game starts |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
125 |
SendHealthStatsOff() |
6501 | 126 |
AutoSpawn() -- Spawn our 1st target using the wrapper function |
127 |
||
128 |
SetHealth( Player, 100 ) -- Give the player 100 Health points |
|
129 |
||
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
130 |
PlaceGirder(46,1783, 0) -- Place a girder to prevent the player falling into the water |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
131 |
|
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
132 |
local message = loc("Get to the target using your rope!") .. "|" .. loc("Controls: Hold the Attack key (space by default) to|fire the rope, then, once attached use:|Left and Right to swing the rope;|Up and Down to contract and expand.") |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
133 |
Info(loc("Training"), message, -amRope ) -- Short intro to tell the player what to do |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
134 |
Timer( 10000, message .. "|" .. loc("Tip: The rope physics are different than in the real world, |use it to your advantage!") ) -- After 15 sec, give them more help |
6501 | 135 |
end |
136 |
||
137 |
function onNewTurn() |
|
10290 | 138 |
SetWeapon(amRope) -- Set the default weapon to Rope |
6501 | 139 |
end |
140 |
||
7165
aad1aea05f1e
add onGameTick20 to basic training, extend laser sight out way more (it was visible at top when completely zoomed out), move call of new turn to after AfterSwitchHedgehog to avoid lua issues in onNewTurn - if this causes problems, lua can do delayed actions in onGameTick
nemo
parents:
6501
diff
changeset
|
141 |
function onGameTick20() |
aad1aea05f1e
add onGameTick20 to basic training, extend laser sight out way more (it was visible at top when completely zoomed out), move call of new turn to after AfterSwitchHedgehog to avoid lua issues in onNewTurn - if this causes problems, lua can do delayed actions in onGameTick
nemo
parents:
6501
diff
changeset
|
142 |
if TurnTimeLeft < 40 and TurnTimeLeft > 0 then -- Round starts at 0, so we check if the round is finished by using 1 |
6501 | 143 |
GameLost = true -- You lost the game |
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
144 |
Info(loc("Training"), loc("You did not make it in time, try again!"), -amSkip ) |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
145 |
if not StatsSent then |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
146 |
SendStat(siGameResult, loc("You failed!")) |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
147 |
SendStat(siCustomAchievement, loc("You did not make it in time, try again!")) |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
148 |
StatsSent = true |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
149 |
end |
6501 | 150 |
SetHealth( Player, 0 ) -- Kill the player so he can't keep moving! |
151 |
||
7838 | 152 |
SetEffect( Player, heResurrectable, 0 ) |
6501 | 153 |
|
154 |
end |
|
155 |
||
156 |
-- If the player gets to the last target, they win OR |
|
157 |
-- If round is finished and your not at the target you lose |
|
158 |
-- in either case, end the game |
|
159 |
if (Objective == true) or (GameLost == true) then |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
160 |
if (WaitTime == 0 and not StatsSent) then |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
161 |
SendStat(siGameResult, loc("You have finished the Basic Rope Training!")) |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
162 |
SendStat(siCustomAchievement, loc("Good job!")) |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
163 |
SendStat(siPlayerKills, "0", loc("Rope Team")) |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
164 |
if RopeMaster then |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
165 |
SendStat(siCustomAchievement, loc("You earned the \"Rope Master\" achievement for finishing in under 50 seconds.")) |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
166 |
end |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
167 |
StatsSent = true |
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
168 |
EndGame() |
6501 | 169 |
else |
7165
aad1aea05f1e
add onGameTick20 to basic training, extend laser sight out way more (it was visible at top when completely zoomed out), move call of new turn to after AfterSwitchHedgehog to avoid lua issues in onNewTurn - if this causes problems, lua can do delayed actions in onGameTick
nemo
parents:
6501
diff
changeset
|
170 |
WaitTime = WaitTime - 20 |
6501 | 171 |
end |
172 |
end |
|
173 |
||
174 |
if FollowingGear == true then |
|
175 |
if FollowTime == 0 then |
|
176 |
FollowingGear = false |
|
177 |
FollowTime = 1500 |
|
178 |
FollowGear( Player ) |
|
179 |
else |
|
7165
aad1aea05f1e
add onGameTick20 to basic training, extend laser sight out way more (it was visible at top when completely zoomed out), move call of new turn to after AfterSwitchHedgehog to avoid lua issues in onNewTurn - if this causes problems, lua can do delayed actions in onGameTick
nemo
parents:
6501
diff
changeset
|
180 |
FollowTime = FollowTime - 20 |
6501 | 181 |
end |
182 |
end |
|
183 |
||
184 |
for k, v in pairs( Timers ) do |
|
185 |
if v.End <= GetTime then |
|
12050
daf63e2a21d2
Rewrite some help texts in the basic rope training mission
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
186 |
Info(loc("Training"), v.Message, -amRope ) |
6501 | 187 |
Timers[ k ] = nil |
188 |
end |
|
189 |
end |
|
190 |
||
7165
aad1aea05f1e
add onGameTick20 to basic training, extend laser sight out way more (it was visible at top when completely zoomed out), move call of new turn to after AfterSwitchHedgehog to avoid lua issues in onNewTurn - if this causes problems, lua can do delayed actions in onGameTick
nemo
parents:
6501
diff
changeset
|
191 |
GetTime = GetTime + 20 |
6501 | 192 |
|
193 |
CheckPosition( Player, 70 ) -- Run the CheckPosition function to check if the player is close to a target |
|
194 |
end |
|
195 |
||
196 |
function onAmmoStoreInit() |
|
197 |
SetAmmo( amRope, 9, 2, 0, 0 ) -- Player ammo, Rope |
|
198 |
SetAmmo( amBaseballBat, 9, 2, 0, 0 ) --Baseball bat |
|
199 |
end |
|
200 |
||
201 |
function onGearDelete( Gear ) |
|
202 |
if GetGearType( Gear ) == gtTarget then |
|
203 |
AutoSpawn() -- When a target is deleted / destroyed, spawn a new one! |
|
204 |
end |
|
205 |
end |