author | nemo |
Fri, 03 May 2013 23:46:15 -0400 | |
changeset 8955 | b8cae4fe8edb |
parent 8043 | da083f8d95e6 |
child 10290 | 42efccba0711 |
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 |
|
17 |
||
18 |
local WaitTime = 10000 -- Wait 10sec before quit |
|
19 |
local FollowTime = 1500 -- For use with FollowGear |
|
20 |
local FollowingGear = false |
|
21 |
local BaseballIntro = false -- Fail safe for ticker |
|
22 |
local TargetNumber = 0 -- The current target number |
|
23 |
||
24 |
local TargetPos = {} -- Tabel of targets |
|
25 |
local Timers = {} |
|
26 |
local GetTime = 0 |
|
27 |
||
28 |
TargetPos[ 1 ] = { X = 1100, Y = 1100, Message = loc("Now find the next target! |Tip: Normally you lose health by falling down, so be careful!") } |
|
29 |
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") } |
|
30 |
TargetPos[ 3 ] = { X = 2200, Y = 800, Message = loc("The next one is pretty hard! |Tip: You have to do multiple swings!") } |
|
31 |
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!") } |
|
32 |
TargetPos[ 5 ] = { X = 4000, Y = 1750, Message = "" } |
|
33 |
TargetPos[ 6 ] = { Modifier = true, Func = function() -- Last target is ALWAYS the "winning" target! |
|
7827
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
34 |
Info( loc("Congratulations"), loc("Congratulations! You've completed the Rope tutorial! |- Tutorial ends in 10 seconds!"), 0 ) -- Congrats |
6501 | 35 |
HogSay( Player, loc("Victory!"), SAY_SHOUT) -- You win! |
36 |
PlaySound( sndVictory ) |
|
37 |
||
38 |
if TurnTimeLeft >= 250000 then -- If you very fast, unlock the ahievement "Rope Master!" |
|
39 |
AddCaption( loc( "Achievement Unlocked" ) .. ": " .. loc( "Rope Master!" ),0xffba00ff,capgrpAmmoinfo ) |
|
40 |
PlaySound( sndHomerun ) |
|
41 |
end |
|
42 |
||
43 |
Objective = true |
|
44 |
end } |
|
45 |
||
46 |
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
|
47 |
ShowMission( loc("Rope Training"), Title, Text, Icon, 0 ) |
6501 | 48 |
end |
49 |
||
50 |
function NewFollowGear( Gear ) |
|
51 |
FollowingGear = true |
|
52 |
FollowGear( Gear ) |
|
53 |
end |
|
54 |
||
55 |
function SpawnTarget( PosX, PosY ) |
|
56 |
Target = AddGear( 0, 0, gtTarget, 0, 0, 0, 0 ) -- Create a new target |
|
57 |
SetGearPosition( Target, PosX, PosY ) -- Set the position of the target |
|
58 |
NewFollowGear( Target ) |
|
59 |
end |
|
60 |
||
61 |
function AutoSpawn() -- Auto spawn the next target after you've killed the current target! |
|
62 |
TargetNumber = TargetNumber + 1 |
|
63 |
||
64 |
if TargetPos[ TargetNumber ].Modifier then -- If there is a modifier, run the function, only used in the winning target! |
|
65 |
TargetPos[ TargetNumber ].Func() |
|
66 |
return true |
|
67 |
end |
|
68 |
||
69 |
if TargetNumber > 1 then |
|
7827
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
70 |
Info(loc("Aiming Practice"), TargetPos[ TargetNumber - 1 ].Message, -amRope ) |
6501 | 71 |
end |
72 |
||
73 |
SpawnTarget( TargetPos[ TargetNumber ].X, TargetPos[ TargetNumber ].Y ) -- Spawn target on the next position |
|
74 |
end |
|
75 |
||
76 |
function InRange( Gear, PosX, PosY, Distance ) -- Fix as the default function didn't do quite what I needed |
|
77 |
GearX, GearY = GetGearPosition( Gear ) |
|
78 |
||
79 |
return GearX >= PosX - Distance and GearX <= PosX + Distance and GearY >= PosY and GearY - Distance <= PosY + Distance |
|
80 |
end |
|
81 |
||
82 |
function CheckPosition( Hog, Distance ) -- Show a message when you get close to the current target! |
|
83 |
if (not BaseballIntro and not Objective) and (CurrentHedgehog ~= nil) then --Fail safe check |
|
84 |
if InRange( Hog, 1100, 1100, Distance ) then -- Check if the player is within predefined position of the first target |
|
85 |
BaseballIntro = true |
|
7827
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
86 |
Info(loc("Aiming Practice"), loc("Great work! Now hit it with your Baseball Bat! |Tip: You can change weapon with 'Right Click'!"), -amRope ) -- Guide them |
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
87 |
Timer( 10000, loc("Remember: The rope only bend around objects, |if it doesn't hit anything it's always stright!")) |
6501 | 88 |
end |
89 |
end |
|
90 |
end |
|
91 |
||
92 |
function Timer( Delay, Message ) |
|
93 |
local Timer = {} |
|
94 |
Timer.End = GetTime + Delay |
|
95 |
Timer.Message = Message |
|
96 |
||
97 |
table.insert( Timers, Timer ) |
|
98 |
end |
|
99 |
||
100 |
function onGameInit() -- Called when the game loads |
|
101 |
Seed = 1 -- The base number for the random number generator |
|
102 |
GameFlags = gfInfAttack + gfOneClanMode + gfSolidLand + gfInvulnerable + gfBorder -- Game settings and rules, going with a border to make it easier |
|
103 |
TurnTime = 300000 -- Player can move for 5min each round |
|
104 |
CaseFreq = 0 -- No random crate drops |
|
105 |
MinesNum = 0 -- Never place any mines on the map |
|
106 |
Explosives = 0 -- Never place any explosives |
|
107 |
Delay = 1 -- We don't wont to wait between each round ( as the only is one ) |
|
108 |
Map = "Ropes" -- Map name |
|
109 |
Theme = "Nature" -- Map theme |
|
110 |
||
111 |
AddTeam( loc( "Rope Team" ), 14483456, "Simple", "Island", "Default" ) -- Lets make the team |
|
112 |
Player = AddHog( loc( "Hunter" ), 0, 1, "StrawHat" ) -- Add a hog for it, and name it "Hunter" |
|
113 |
SetGearPosition( Player, 420, 1750 ) -- Set player position |
|
114 |
||
7838 | 115 |
SetEffect( Player, heResurrectable, 1 ) -- By Suggestion :) |
6501 | 116 |
end |
117 |
||
118 |
function onGameStart() -- Called when the game starts |
|
119 |
AutoSpawn() -- Spawn our 1st target using the wrapper function |
|
120 |
||
121 |
SetHealth( Player, 100 ) -- Give the player 100 Health points |
|
122 |
||
7827
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
123 |
Info(loc("Aiming Practice"), loc("Get to the target using your rope! |Controls: Left & Right to swing the rope - Up & Down to Contract and Expand!"), -amRope ) -- Short intro to tell the player what to do |
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
124 |
Timer( 10000, 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 | 125 |
end |
126 |
||
127 |
function onNewTurn() |
|
128 |
ParseCommand( "setweap " .. string.char( amRope ) ) -- Set the default weapon to Rope |
|
129 |
end |
|
130 |
||
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
|
131 |
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
|
132 |
if TurnTimeLeft < 40 and TurnTimeLeft > 0 then -- Round starts at 0, so we check if the round is finished by using 1 |
6501 | 133 |
GameLost = true -- You lost the game |
7827
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
134 |
Info(loc("Aiming Practice"), loc("You did not make it in time, try again!"), -amSkip ) |
6501 | 135 |
SetHealth( Player, 0 ) -- Kill the player so he can't keep moving! |
136 |
||
7838 | 137 |
SetEffect( Player, heResurrectable, 0 ) |
6501 | 138 |
|
139 |
end |
|
140 |
||
141 |
-- If the player gets to the last target, they win OR |
|
142 |
-- If round is finished and your not at the target you lose |
|
143 |
-- in either case, end the game |
|
144 |
if (Objective == true) or (GameLost == true) then |
|
145 |
if (WaitTime == 0) then |
|
146 |
ParseCommand("teamgone " .. loc( "Rope Team" )) |
|
147 |
||
148 |
--SetHealth( Player, 0 ) -- Kill the player so he can't keep moving! |
|
7838 | 149 |
--SetEffect( Player, heResurrectable, 0 ) |
6501 | 150 |
TurnTimeLeft = 1 |
151 |
||
152 |
WaitTime = -1 |
|
153 |
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
|
154 |
WaitTime = WaitTime - 20 |
6501 | 155 |
end |
156 |
end |
|
157 |
||
158 |
if FollowingGear == true then |
|
159 |
if FollowTime == 0 then |
|
160 |
FollowingGear = false |
|
161 |
FollowTime = 1500 |
|
162 |
FollowGear( Player ) |
|
163 |
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
|
164 |
FollowTime = FollowTime - 20 |
6501 | 165 |
end |
166 |
end |
|
167 |
||
168 |
for k, v in pairs( Timers ) do |
|
169 |
if v.End <= GetTime then |
|
7827
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
170 |
Info(loc("Aiming Practice"), v.Message, -amRope ) |
6501 | 171 |
Timers[ k ] = nil |
172 |
end |
|
173 |
end |
|
174 |
||
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
|
175 |
GetTime = GetTime + 20 |
6501 | 176 |
|
177 |
CheckPosition( Player, 70 ) -- Run the CheckPosition function to check if the player is close to a target |
|
178 |
end |
|
179 |
||
180 |
function onAmmoStoreInit() |
|
181 |
SetAmmo( amRope, 9, 2, 0, 0 ) -- Player ammo, Rope |
|
182 |
SetAmmo( amBaseballBat, 9, 2, 0, 0 ) --Baseball bat |
|
183 |
end |
|
184 |
||
185 |
function onGearResurrect( Gear ) |
|
186 |
if TargetNumber > 1 then |
|
187 |
SetGearPosition( Player, TargetPos[ TargetNumber - 1 ].X, TargetPos[ TargetNumber - 1 ].Y ) -- If the player dies spawn him where he last killed a target |
|
7827
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
188 |
Info(loc("Aiming Practice"), loc("You have been respawned, at your last checkpoint!"), -amRope ) |
6501 | 189 |
else |
190 |
SetGearPosition( Player, 420, 1750 ) -- If the player dies and didn't kill a target just spawn him at the default spawn |
|
7827
353d90ddc188
Fix bad loc calls in campaign, rope training. Regenerate lua. Untested.
nemo
parents:
7165
diff
changeset
|
191 |
Info(loc("Aiming Practice"), loc("You have been respawned, be more carefull next time!"), -amRope ) |
6501 | 192 |
end |
193 |
end |
|
194 |
||
195 |
function onGearDelete( Gear ) |
|
196 |
if GetGearType( Gear ) == gtTarget then |
|
197 |
AutoSpawn() -- When a target is deleted / destroyed, spawn a new one! |
|
198 |
end |
|
199 |
end |