-
Notifications
You must be signed in to change notification settings - Fork 0
/
outerwall_purplecoin.nut
226 lines (175 loc) · 6.79 KB
/
outerwall_purplecoin.nut
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
const PURPLECOIN_COUNT = 120;
const PURPLECOIN_COINPATH = "purplecoin_coin_";
const PURPLECOIN_COINPATH_ENCORE = "encore_purplecoin_coin_";
const PURPLECOIN_ANNOTATE_RADAR_COOLDOWN = 25;
const COINTOUCHRADIUS = 64;
::PlayerLastUseRadar <- array(MAX_PLAYERS, 0)
::PlayerRadarReady <- array(MAX_PLAYERS, false)
::PlayerCoinStatus <- ConstructTwoDimArray(MAX_PLAYERS, PURPLECOIN_COUNT, false)
::PlayerCoinCount <- array(MAX_PLAYERS, PURPLECOIN_COUNT)
::SetTransmitCoinActive <- false;
const PURPLECOIN_READY_MESSAGE_LENGTH = 2;
::PlayerLastRadarReadyMessageSet <- array(MAX_PLAYERS, 0)
::PlayerCurrentRadarMessage <- array(MAX_PLAYERS, 0)
::ResetPurpleCoinArena <- function()
{
local player_index = activator.GetEntityIndex();
ResetPlayerPurpleCoinArenaArray(player_index);
DebugPrint("Reset Purple Coin Arena for player " + player_index);
}
::ResetPlayerPurpleCoinArenaArray <- function(player_index)
{
PlayerCoinCount[player_index] = PURPLECOIN_COUNT;
for(local iArrayIndex = 0; iArrayIndex < PURPLECOIN_COUNT; iArrayIndex++)
{
PlayerCoinStatus[player_index][iArrayIndex] = true;
//DebugPrint("Array Index: " + iArrayIndex + " = " + PlayerCoinStatus[player_index][iArrayIndex]);
}
if(SetTransmitCoinActive)
PluginResetPlayerCoinCount(player_index);
}
::PurpleCoinHudThink <- function(client)
{
local player_index = client.GetEntityIndex();
if(PlayerZoneList[player_index] != eCourses.SandPit)
return;
local count_prefix = "";
if(PlayerCoinCount[player_index] < 10)
count_prefix = "00";
else if(PlayerCoinCount[player_index] < 100)
count_prefix = "0";
local radar_message = "";
if(!SetTransmitCoinActive)
{
if(PlayerRadarReady[player_index])
{
if(PlayerLastRadarReadyMessageSet[player_index] + PURPLECOIN_READY_MESSAGE_LENGTH <= Time())
{
PlayerLastRadarReadyMessageSet[player_index] = Time();
PlayerCurrentRadarMessage[player_index] = PlayerCurrentRadarMessage[player_index] == 0 ? 1 : 0;
}
radar_message = TranslateString(HUD_COINRADAR_READY[PlayerCurrentRadarMessage[player_index]], player_index);
}
else
{
local time = round((PlayerLastUseRadar[player_index] - Time()) + PURPLECOIN_ANNOTATE_RADAR_COOLDOWN, 1);
local pretime = time < 10 ? "0" : "";
local posttime = time == time.tointeger() ? ".0" : "";
radar_message = format(TranslateString(HUD_COINRADAR_NOTREADY, player_index), (pretime + time.tostring() + posttime).tostring());
}
}
EntFire(BONUS_PLAYERHUDTEXT + player_index, "addoutput", ("message " + radar_message + "\n\n" + TranslateString(HUD_COIN, player_index) + count_prefix + PlayerCoinCount[player_index]));
}
::CachedCoinPositions <- array(PURPLECOIN_COUNT, Vector(0,0,0))
::PrecacheCoinPositions <- function()
{
for (local i = 0; i < PURPLECOIN_COUNT; i++)
{
local coin = Entities.FindByName(null, PURPLECOIN_COINPATH + (i + 1));
if(!coin)
continue;
CachedCoinPositions[i] = coin.GetOrigin();
}
}
::CheckPurpleCoinAnnotateButton <- function(client)
{
//annotations dont work when over 32 players
if(SetTransmitCoinActive || MaxClients().tointeger() > 32)
return;
local player_index = client.GetEntityIndex();
if(PlayerZoneList[player_index] != eCourses.SandPit)
return;
local buttons = GetPropInt(client, "m_nButtons");
if(!PlayerRadarReady[player_index] && PlayerLastUseRadar[player_index] + PURPLECOIN_ANNOTATE_RADAR_COOLDOWN <= Time())
{
PlayerRadarReady[player_index] = true;
EmitSoundOnClient(SND_PURPLECOIN_RADAR_READY, client);
return;
}
//If our previous key capture doesn't contain attack key && new one does.
if(!(!(PreviousButtons[player_index] & IN_ATTACK) && buttons & IN_ATTACK))
return;
if(PlayerLastUseRadar[player_index] + PURPLECOIN_ANNOTATE_RADAR_COOLDOWN > Time())
{
EmitSoundOnClient("Player.DenyWeaponSelection", client);
return;
}
local bitfield = (1 << player_index);
local coinpath = !!!PlayerEncoreStatus[player_index] ? PURPLECOIN_COINPATH : PURPLECOIN_COINPATH_ENCORE;
foreach(i, coin in PlayerCoinStatus[player_index])
{
if(!coin)
continue;
local coin_position = CachedCoinPositions[i];
local annotate_data = {
worldPosX = coin_position.x
worldPosY = coin_position.y
worldPosZ = coin_position.z + 32
id = (player_index.tostring() + i.tostring()).tointeger()
text = "!"
lifetime = 6.5
visibilityBitfield = bitfield
play_sound = "/misc/null.wav"
};
SendGlobalGameEvent("show_annotation", annotate_data);
}
PlayerLastUseRadar[player_index] = Time();
PlayerRadarReady[player_index] = false;
EmitSoundOnClient(SND_PURPLECOIN_RADAR, client);
}
::CoinTouch <- function()
{
local player_index = activator.GetEntityIndex();
if(PlayerZoneList[player_index] != eCourses.SandPit || PlayerCoinCount[player_index] == 0)
return;
local coinpath = !!!PlayerEncoreStatus[player_index] ? PURPLECOIN_COINPATH : PURPLECOIN_COINPATH_ENCORE;
//get closest purplecoin prop_dynamic and get its name
local player_origin = activator.GetOrigin();
local CoinHandle = Entities.FindByNameWithin(null, coinpath + "*", player_origin, COINTOUCHRADIUS);
//DebugDrawBox(player_origin, Vector(-COINTOUCHRADIUS, -COINTOUCHRADIUS, -COINTOUCHRADIUS), Vector(COINTOUCHRADIUS, COINTOUCHRADIUS, COINTOUCHRADIUS), 255, 0, 0, 155, 10)
if(!CoinHandle)
{
player_origin.z += 96;
CoinHandle = Entities.FindByNameWithin(null, coinpath + "*", player_origin, COINTOUCHRADIUS);
//DebugDrawBox(player_origin, Vector(-COINTOUCHRADIUS, -COINTOUCHRADIUS, -COINTOUCHRADIUS), Vector(COINTOUCHRADIUS, COINTOUCHRADIUS, COINTOUCHRADIUS), 0, 255, 0, 155, 10)
}
if(!CoinHandle)
return;
local strCoinName = GetPropString(CoinHandle, "m_iName");
local TriggerID = strCoinName.slice(PURPLECOIN_COINPATH.len()).tointeger() - 1;
if(PlayerCoinStatus[player_index][TriggerID] == false)
return;
PlayerCoinStatus[player_index][TriggerID] = false;
//DebugPrint("Set Trigger ID " + (TriggerID + 1) + " to " + PlayerCoinStatus[player_index][TriggerID]);
if(SetTransmitCoinActive)
PluginCollectCoin(player_index, TriggerID);
PlayerCoinCount[player_index] -= 1;
//DebugPrint("Coins Collected for player " + player_index + ": " + PlayerCoinCount[player_index]);
//show particle and play sound
local coin_location = CoinHandle.GetOrigin();
coin_location.z += 16;
DispatchParticleEffect("purplecoin_collect", coin_location, Vector(0,90,0));
activator.EmitSound(SND_PURPLECOIN_COLLECT);
//Collected all coins
if(PlayerCoinCount[player_index] == 0)
{
DebugPrint("All Coins Collected for player " + player_index);
DoGoal(6, activator);
//TeleportPlayerToZone(6, activator);
}
else if(PlayerCoinCount[player_index] == 80)
{
SetPlayerCheckpoint(1);
}
else if(PlayerCoinCount[player_index] == 40)
{
SetPlayerCheckpoint(2);
}
if(!SetTransmitCoinActive)
{
local annotate_data = {
id = (player_index.tostring() + TriggerID.tostring()).tointeger()
};
SendGlobalGameEvent("hide_annotation", annotate_data);
}
}