This repository was archived by the owner on Apr 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnonlinear.nut
More file actions
109 lines (88 loc) · 3.03 KB
/
nonlinear.nut
File metadata and controls
109 lines (88 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
Implementation of a non-linear, objective-based system.
The player must gather objectives to increase their objective count.
Their objective count can be used to control the actions of entities.
For example, an 'objective gate' has been implemented, which requires
a certain number of objectives for the player to pass through it.
!!!IMPORTANT!!!
Needs to be ran (ScriptRunFile) by the player when they join.
Requires misc.nut to be ran by the player.
*/
// Includes
DoIncludeScript("danzay/nonlinear_resource.nut", self.GetScriptScope());
// Global Variables
const nl_reboundVelocity = 500; // Velocity at which the objective gates rebound the player.
nl_collectedObjectives <- []; // An array of the handles of the objectives the player has collected.
nl_objectivesRequired <- null; // The number of objectives required by a touched objective gate.
// Functions
/* GetNumberOfObjectivesCollected()
Returns the number of objectives that have been collected.
*/
function GetNumberOfObjectivesCollected()
{
return nl_collectedObjectives.len();
}
/* ResetObjectivesCollected()
Called when player touches objective reset trigger.
Resets the player's collected objectives by clearing the related array.
*/
function ResetObjectivesCollected()
{
if (nl_collectedObjectives.len() > 0)
{
nl_collectedObjectives.clear();
PrintGameText(GetMessageObjectiveReset());
}
}
/*
Called when player touches an objective trigger.
Adds the objective to the collected objectives list if the player hasn't collected it already.
Parameters:
touchedObjective - The handle of the touched objective trigger.
*/
function OnObjectiveTouch(touchedObjective)
{
if (IsInArray(touchedObjective, nl_collectedObjectives))
{
PrintGameText(GetMessageAlreadyCollectedObjective());
}
else
{
nl_collectedObjectives.append(touchedObjective);
PlaySound(GetSoundObjectiveGet());
PrintGameText(GetMessageObjectiveGet());
}
}
/*
Called when player touches an objective gate (rebound type).
Checks if the player has enough objectives to pass, and rebounds them if they don't.
Parameters:
touchedGate - The handle of the touched objective gate trigger.
*/
function OnObjectiveGateReboundTouch(touchedGate)
{
local nl_objectivesRequired = touchedGate.GetName().tointeger();
if (GetNumberOfObjectivesCollected() < nl_objectivesRequired)
{
PrintGameText(GetMessageObjectiveGateFail(nl_objectivesRequired));
PlaySound(GetSoundObjectiveFail());
Rebound(touchedGate);
}
}
/*
Called when player touches a objective gate (teleport type).
Checks if the player has enough objectives to pass, and teleports them if they don't.
Parameters:
touchedGate - The handle of the touched objective gate trigger.
*/
function OnObjectiveGateTeleportTouch(touchedGate)
{
local nl_objectivesRequired = touchedGate.GetName().tointeger();
if (GetNumberOfObjectivesCollected() < nl_objectivesRequired)
{
PrintGameText(GetMessageObjectiveGateFail(nl_objectivesRequired));
PlaySound(GetSoundObjectiveFail());
TeleportPlayerTo(touchedGate);
SetVelocityToZero(self);
}
}