-
Notifications
You must be signed in to change notification settings - Fork 16
/
zp_game_mode_nightmare.sma
382 lines (302 loc) · 11 KB
/
zp_game_mode_nightmare.sma
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/***************************************************************************\
========================================
* || [ZPSp] Game Mode Nightmare || *
========================================
-------------------
*||DESCRIPTION||*
-------------------
This is an example game mode in which there are half Assassins/Nemesis
and half Survivros/Snipers. You can use this plugin as a guide on how to
make custom game modes for Zombie Plague Special.
-------------
*||CVARS||*
-------------
- zp_night_minplayers 2
- Minimum players required for this game mode to be
activated
- zp_night_sniper_hp 1.5
- Snipers HP multiplier
- zp_night_assassin_hp 1.0
- Assassins HP multiplier
- zp_night_survivor_hp 1.5
- Survivors HP multiplier
- zp_night_nemesis_hp 1.0
- Nemesis HP multiplier
- zp_night_inf_ratio 0.5
- Infection ratio of this game mode i.e how many players
will turn into assassins [Total players * infection ratio]
\***************************************************************************/
#include <amxmodx>
#include <fun>
#include <zombie_plague_special>
#include <amx_settings_api>
#if ZPS_INC_VERSION < 44
#assert Zombie Plague Special 4.4 (Beta) Include File Required. Download Link: https://forums.alliedmods.net/showthread.php?t=260845
#endif
new const ZP_CUSTOMIZATION_FILE[] = "zombie_plague_special.ini"
new Array:g_sound_night, g_ambience_sounds, Array:g_sound_amb_night_dur, Array: g_sound_amb_night
// Default Sounds
new const sound_nightmare[][] = { "zombie_plague/nemesis1.wav", "zombie_plague/survivor1.wav" }
new const ambience_night_sound[][] = { "zombie_plague/ambience.wav" }
new const ambience_night_dur[][] = { "17" }
// Variables
new g_gameid, g_maxplayers, cvar_minplayers, cvar_ratio, cvar_sniperhp, cvar_assahp, g_msg_sync, cvar_nemhp, cvar_survhp
new const g_chance = 90
// Enable Ambience?
#define AMBIENCE_ENABLE 0
// Ambience sounds task
#define TASK_AMB 3256
public plugin_init()
{
// Plugin registeration.
register_plugin("[ZP] Nightmare Mode","1.1", "@bdul! | [P]erfec[T] [S]cr[@]s[H]")
// Register some cvars
// Edit these according to your liking
cvar_minplayers = register_cvar("zp_night_minplayers", "2")
cvar_sniperhp = register_cvar("zp_night_sniper_hp", "1.5")
cvar_assahp = register_cvar("zp_night_assassin_hp", "1.0")
cvar_survhp = register_cvar("zp_night_survivor_hp", "1.0")
cvar_nemhp = register_cvar("zp_night_nemesis_hp", "0.3")
cvar_ratio = register_cvar("zp_night_inf_ratio", "0.5")
// Get maxplayers
g_maxplayers = get_maxplayers()
// Hud stuff
g_msg_sync = CreateHudSyncObj()
}
// Game modes MUST be registered in plugin precache ONLY
public plugin_precache()
{
if(!zp_is_special_class_enable(GET_ZOMBIE, NEMESIS) || !zp_is_special_class_enable(GET_ZOMBIE, ASSASSIN)
|| !zp_is_special_class_enable(GET_HUMAN, SURVIVOR) || !zp_is_special_class_enable(GET_HUMAN, SNIPER)) {
set_fail_state("[ZPSp Nightmare mode] Some special class (Nemesis/Survivor/Sniper/Assassin) are disable")
return;
}
// Read the access flag
new user_access[40]
if(!amx_load_setting_string(ZP_CUSTOMIZATION_FILE, "Access Flags", "START MODE NIGHTMARE", user_access, charsmax(user_access)))
{
amx_save_setting_string(ZP_CUSTOMIZATION_FILE, "Access Flags", "START MODE NIGHTMARE", "a")
formatex(user_access, charsmax(user_access), "a")
}
new access_flag = read_flags(user_access)
new i
g_sound_night = ArrayCreate(64, 1)
g_sound_amb_night = ArrayCreate(64, 1)
g_sound_amb_night_dur = ArrayCreate(64, 1)
// Load from external file
amx_load_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Sounds", "ROUND NIGHTMARE", g_sound_night)
// Precache the play sounds
if (ArraySize(g_sound_night) == 0)
{
for (i = 0; i < sizeof sound_nightmare; i++)
ArrayPushString(g_sound_night, sound_nightmare[i])
// Save to external file
amx_save_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Sounds", "ROUND NIGHTMARE", g_sound_night)
}
// Precache sounds
new sound[100]
for (i = 0; i < ArraySize(g_sound_night); i++)
{
ArrayGetString(g_sound_night, i, sound, charsmax(sound))
precache_ambience(sound)
}
// Ambience Sounds
g_ambience_sounds = AMBIENCE_ENABLE
if(!amx_load_setting_int(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "NIGHTMARE ENABLE", g_ambience_sounds))
amx_save_setting_int(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "NIGHTMARE ENABLE", g_ambience_sounds)
amx_load_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "NIGHTMARE SOUNDS", g_sound_amb_night)
amx_load_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "NIGHTMARE DURATIONS", g_sound_amb_night_dur)
// Save to external file
if (ArraySize(g_sound_amb_night) == 0)
{
for (i = 0; i < sizeof ambience_night_sound; i++)
ArrayPushString(g_sound_amb_night, ambience_night_sound[i])
amx_save_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "NIGHTMARE SOUNDS", g_sound_amb_night)
}
if (ArraySize(g_sound_amb_night_dur) == 0)
{
for (i = 0; i < sizeof ambience_night_dur; i++)
ArrayPushString(g_sound_amb_night_dur, ambience_night_dur[i])
amx_save_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "NIGHTMARE DURATIONS", g_sound_amb_night_dur)
}
// Ambience Sounds
new buffer[250]
if (g_ambience_sounds) {
for (i = 0; i < ArraySize(g_sound_amb_night); i++) {
ArrayGetString(g_sound_amb_night, i, buffer, charsmax(buffer))
precache_ambience(buffer)
}
}
// Register our game mode
g_gameid = zpsp_register_gamemode("Nightmare", access_flag, g_chance, 0, ZP_DM_BALANCE)
}
public plugin_natives() {
register_native("zp_is_nightmare_round", "native_is_nightmare_round", 1)
}
// Player spawn post
public zp_player_spawn_post(id)
{
// Check for current mode
static g_random
if(zp_get_current_mode() == g_gameid)
{
// Randonize
g_random = random_num(0, 1)
// Check if the player is a zombie
if(zp_get_alive_specials(GET_ZOMBIE) < zp_get_alive_specials(GET_HUMAN))
{
// Transform user in Assassin/Nemesis
zp_make_user_special(id, g_random ? NEMESIS : ASSASSIN , GET_ZOMBIE)
// Seting Nemesis/Assassin Health
set_user_health(id, floatround(get_user_health(id) * get_pcvar_float(g_random ? cvar_nemhp : cvar_assahp)))
}
else
{
// Transform user in Sniper/Survivor
zp_make_user_special(id, g_random ? SNIPER : SURVIVOR , GET_HUMAN)
// Seting Sniper/Survivor Health
set_user_health(id, floatround(get_user_health(id) * get_pcvar_float(g_random ? cvar_sniperhp : cvar_survhp)))
}
}
}
public zp_game_mode_selected_pre(id, game)
{
if(game != g_gameid)
return PLUGIN_CONTINUE;
if(!zp_is_special_class_enable(GET_ZOMBIE, NEMESIS) || !zp_is_special_class_enable(GET_ZOMBIE, ASSASSIN)
|| !zp_is_special_class_enable(GET_HUMAN, SURVIVOR) || !zp_is_special_class_enable(GET_HUMAN, SNIPER))
return ZP_PLUGIN_SUPERCEDE;
return PLUGIN_CONTINUE;
}
public zp_round_started_pre(game)
{
// Check if it is our game mode
if(game == g_gameid)
{
// Check for min players
if(zp_get_alive_players() < get_pcvar_num(cvar_minplayers))
return ZP_PLUGIN_HANDLED;
if(!zp_is_special_class_enable(GET_ZOMBIE, NEMESIS) || !zp_is_special_class_enable(GET_ZOMBIE, ASSASSIN)
|| !zp_is_special_class_enable(GET_HUMAN, SURVIVOR) || !zp_is_special_class_enable(GET_HUMAN, SNIPER))
return ZP_PLUGIN_HANDLED;
// Start our new mode
start_nightmare_mode()
}
// Make the compiler happy =)
return PLUGIN_CONTINUE
}
public zp_round_started(game, id)
{
// Check if it is our game mode
if(game == g_gameid)
{
// Show HUD notice
set_hudmessage(255, 0, 100, -1.0, 0.17, 1, 0.0, 5.0, 1.0, 1.0, -1)
ShowSyncHudMsg(0, g_msg_sync, "Nightmare Mode !!!")
// Play the starting sound
static sound[100]
ArrayGetString(g_sound_night, random_num(0, ArraySize(g_sound_night) - 1), sound, charsmax(sound))
zp_play_sound(0, sound)
// Remove ambience task affects
remove_task(TASK_AMB)
// Set task to start ambience sounds
set_task(2.0, "start_ambience_sounds", TASK_AMB)
}
}
public zp_game_mode_selected(gameid, id)
{
// Check if our game mode was called
if(gameid == g_gameid)
start_nightmare_mode()
// Make the compiler happy again =)
return PLUGIN_CONTINUE
}
// This function contains the whole code behind this game mode
start_nightmare_mode()
{
// Create and initialize some important vars
static i_max_sp_zombies, id, i_alive, g_random
i_alive = zp_get_alive_players()
id = 0
// Get the no of players we have to turn into assassins/nemesis
i_max_sp_zombies = floatround(i_alive * get_pcvar_float(cvar_ratio), floatround_ceil)
// Randomly turn players into Assassins
while (zp_get_alive_specials(GET_ZOMBIE) < i_max_sp_zombies)
{
// Keep looping through all players
if ((++id) > g_maxplayers) id = 1
// Random chance
if (is_user_alive(id) && random_num(1, 5) == 1)
{
// Randonize
g_random = random_num(0, 1)
// Transform user in Assassin/Nemesis
zp_make_user_special(id, g_random ? NEMESIS : ASSASSIN , GET_ZOMBIE)
// Seting Nemesis/Assassin Health
set_user_health(id, floatround(get_user_health(id) * get_pcvar_float(g_random ? cvar_nemhp : cvar_assahp)))
}
}
// Turn the remaining players into snipers/survivors
for (id = 1; id <= g_maxplayers; id++)
{
// Only those of them who are alive and are not assassins/nemesis
if (is_user_alive(id) && !zp_get_zombie_special_class(id))
{
// Randonize
g_random = random_num(0, 1)
// Transform user in Sniper/Survivor
zp_make_user_special(id, g_random ? SNIPER : SURVIVOR , GET_HUMAN)
// Seting Sniper/Survivor Health
set_user_health(id, floatround(get_user_health(id) * get_pcvar_float(g_random ? cvar_sniperhp : cvar_survhp)))
}
}
}
public start_ambience_sounds()
{
if (!g_ambience_sounds)
return;
// Variables
static amb_sound[64], sound, str_dur[20]
// Select our ambience sound
sound = random_num(0, ArraySize(g_sound_amb_night)-1)
ArrayGetString(g_sound_amb_night, sound, amb_sound, charsmax(amb_sound))
ArrayGetString(g_sound_amb_night_dur, sound, str_dur, charsmax(str_dur))
zp_play_sound(0, amb_sound)
// Start the ambience sounds
set_task(str_to_float(str_dur), "start_ambience_sounds", TASK_AMB)
}
public zp_round_ended(winteam) {
remove_task(TASK_AMB) // Stop ambience sounds on round end
}
stock zp_get_alive_specials(user_class)
{
static special, id
special = 0
for (id = 1; id <= g_maxplayers; id++) {
if(is_user_alive(id) && (zp_get_zombie_special_class(id) && user_class == GET_ZOMBIE
|| zp_get_human_special_class(id) && user_class == GET_HUMAN))
special++
}
return special;
}
public native_is_nightmare_round() {
return (zp_get_current_mode() == g_gameid)
}
precache_ambience(sound[])
{
static buffer[150]
if(equal(sound[strlen(sound)-4], ".mp3")) {
if(!equal(sound, "sound/", 6) && !file_exists(sound) && !equal(sound, "media/", 6))
format(buffer, charsmax(buffer), "sound/%s", sound)
else
format(buffer, charsmax(buffer), "%s", sound)
precache_generic(buffer)
}
else {
if(equal(sound, "sound/", 6))
format(buffer, charsmax(buffer), "%s", sound[6])
else
format(buffer, charsmax(buffer), "%s", sound)
precache_sound(buffer)
}
}