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 pathmisc.nut
More file actions
166 lines (143 loc) · 3.84 KB
/
misc.nut
File metadata and controls
166 lines (143 loc) · 3.84 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
Miscellaneous scripts and functions.
Needs to be ran (ScriptRunFile) by the player when they join.
*/
// Functions
/*
Checks if the variable is in the array.
Parameters:
key - Variable to find in the array.
array - Array to be searched.
*/
function IsInArray(key, array)
{
foreach(variable in array)
{
if (variable == key)
{
return true;
}
}
return false;
}
/*
Returns the greater value.
Parameters:
value1 - First value.
value2 - Second value.
*/
function Max(value1, value2)
{
if (value1 >= value2)
{
return value1;
}
return value2;
}
/*
Teleports the player to an entity's origin.
Parameters:
destEntity - The entity handle to teleport the player to.
*/
function TeleportPlayerTo(destEntity)
{
self.SetOrigin(destEntity.GetOrigin());
}
/*
Sets the targeted entity's velocity to 0.
Parameters:
entity - The handle of the entity to set the velocity of.
*/
function SetVelocityToZero(entity)
{
entity.SetVelocity(Vector(0, 0, 0));
}
/*
Rebounds the player (set's their velocity) to bounce them away from the face of the trigger they touched.
Intended for rectangular triggers, and works fine when the player can't hit the corners.
Parameters:
touchedTrigger - The handle of the touched objective gate trigger.
*/
function Rebound(touchedTrigger)
{
local triggerBounds = touchedTrigger.GetBoundingMaxs();
local triggerCenter = touchedTrigger.GetCenter();
local playerCenter = self.GetCenter();
local playerNewVelocity = self.GetVelocity();
if (playerCenter.x < (triggerCenter.x - triggerBounds.x))
{ // Player coming from -x
playerNewVelocity.x = -1 * nl_reboundVelocity;
}
else if (playerCenter.x > (triggerCenter.x + triggerBounds.x))
{ // Player coming from +x
playerNewVelocity.x = nl_reboundVelocity;
}
else if (playerCenter.y < (triggerCenter.y - triggerBounds.y))
{ // Player coming from -y
playerNewVelocity.y = -1 * nl_reboundVelocity;
}
else if (playerCenter.y > (triggerCenter.y + triggerBounds.y))
{ // Player coming from +y
playerNewVelocity.y = nl_reboundVelocity;
}
else if (playerCenter.z < (triggerCenter.z - triggerBounds.z))
{ // Player comnig from -z
playerNewVelocity.z = -1 * nl_reboundVelocity;
}
else
{ // Player coming from +z
playerNewVelocity.z = nl_reboundVelocity;
}
self.SetVelocity(playerNewVelocity);
}
/*
Executes a command in the player's console.
Parameters:
command - String of the command to execute.
*/
function ExecuteCommand(command)
{
local point_clientcommand = Entities.CreateByClassname("point_clientcommand");
EntFireByHandle(point_clientcommand, "Command", command, 0, self, self);
point_clientcommand.Destroy();
}
/*
Plays a sound to the player.
Parameters:
soundPath - Path of the sound file (csgo/sound/soundPath).
*/
function PlaySound(soundPath)
{
ExecuteCommand("play */" + soundPath);
}
/*
Prints a message to the center info panel via env_hudhint.
Parameters:
message - String of the message to display.
*/
function PrintHintText(message)
{
local env_hudhint = Entities.CreateByClassname("env_hudhint");
env_hudhint.__KeyValueFromString("Message", message);
EntFireByHandle(env_hudhint, "ShowHudHint", "", 0, self, self);
env_hudhint.Destroy();
}
/*
Prints a message to the center info panel via game_text.
Parameters:
message - String of the message to display.
*/
function PrintGameText(message)
{
local game_text = Entities.CreateByClassname("game_text");
game_text.__KeyValueFromString("Message", message);
game_text.__KeyValueFromString("color", "255 255 255");
game_text.__KeyValueFromString("effect", "0");
game_text.__KeyValueFromString("fadein", "0.0");
game_text.__KeyValueFromString("fadeout", "0.0");
game_text.__KeyValueFromString("holdtime", "3.0");
game_text.__KeyValueFromString("x", "-1");
game_text.__KeyValueFromString("y", "0.35");
EntFireByHandle(game_text, "Display", "", 0, self, self);
game_text.Destroy();
}