/
zp_game_mode_assassins_vs_sniper.sma
358 lines (285 loc) · 9.69 KB
/
zp_game_mode_assassins_vs_sniper.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
/***************************************************************************\
========================================
* || [ZPSp] Game Mode Assassin vs Sniper || *
========================================
-------------------
*||DESCRIPTION||*
-------------------
This is an example game mode in which there are half Assassins
and half Snipers. You can use this plugin as a guide on how to
make custom game modes for Zombie Plague Special.
-------------
*||CVARS||*
-------------
- zp_avsm_minplayers 2
- Minimum players required for this game mode to be
activated
- zp_avsm_sniper_hp 1.5
- Snipers HP multiplier
- zp_avsm_assassin_hp 1.0
- Assassins HP multiplier
- zp_avsm_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>
new const ZP_CUSTOMIZATION_FILE[] = "zombie_plague_special.ini"
new Array:g_sound_avs, g_ambience_sounds, Array:g_sound_amb_avs_duration, Array: g_sound_ambience_avs
// Default Sounds
new const sound_avs[][] = { "zombie_plague/nemesis1.wav", "zombie_plague/survivor1.wav" }
new const ambience_avs_sound[][] = { "zombie_plague/ambience.wav" }
new const ambience_avs_dur[][] = { "17" }
// Variables
new g_gameid, g_maxplayers, cvar_minplayers, cvar_ratio, cvar_sniperhp, cvar_assahp, g_msg_sync
new const g_chance = 90
// Ambience sounds task
#define TASK_AMB 3256
public plugin_init()
{
// Plugin registeration.
register_plugin("[ZP] Assassin vs Snipers Mode","1.0", "@bdul! | [P]erfec[T] [S]cr[@]s[H]")
// Register some cvars
// Edit these according to your liking
cvar_minplayers = register_cvar("zp_avsm_minplayers", "2")
cvar_sniperhp = register_cvar("zp_avsm_sniper_hp", "1.0")
cvar_assahp = register_cvar("zp_avsm_assassin_hp", "0.3")
cvar_ratio = register_cvar("zp_avsm_inf_ratio", "0.5")
// Get maxplayers
g_maxplayers = get_maxplayers()
// Hud stuff
g_msg_sync = CreateHudSyncObj()
}
public plugin_natives() {
register_native("zp_is_avs_round", "native_is_avs_round", 1)
}
// Game modes MUST be registered in plugin precache ONLY
public plugin_precache()
{
// Read the access flag
new user_access[40]
if(!amx_load_setting_string(ZP_CUSTOMIZATION_FILE, "Access Flags", "START MODE AVS", user_access, charsmax(user_access)))
{
amx_save_setting_string(ZP_CUSTOMIZATION_FILE, "Access Flags", "START MODE AVS", "a")
formatex(user_access, charsmax(user_access), "a")
}
new access_flag = read_flags(user_access)
new i
g_sound_avs = ArrayCreate(64, 1)
g_sound_ambience_avs = ArrayCreate(64, 1)
g_sound_amb_avs_duration = ArrayCreate(64, 1)
// Load from external file
amx_load_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Sounds", "ROUND AVS", g_sound_avs)
// Precache the play sounds
if (ArraySize(g_sound_avs) == 0)
{
for (i = 0; i < sizeof g_sound_avs; i++)
ArrayPushString(g_sound_avs, sound_avs[i])
// Save to external file
amx_save_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Sounds", "ROUND AVS", g_sound_avs)
}
// Precache sounds
new sound[100]
for (i = 0; i < ArraySize(g_sound_avs); i++)
{
ArrayGetString(g_sound_avs, i, sound, charsmax(sound))
precache_ambience(sound)
}
// Ambience Sounds
g_ambience_sounds = 0
if(!amx_load_setting_int(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "AVS ENABLE", g_ambience_sounds))
amx_save_setting_int(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "AVS ENABLE", g_ambience_sounds)
amx_load_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "AVS SOUNDS", g_sound_ambience_avs)
amx_load_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "AVS DURATIONS", g_sound_amb_avs_duration)
// Save to external file
if (ArraySize(g_sound_ambience_avs) == 0)
{
for (i = 0; i < sizeof ambience_avs_sound; i++)
ArrayPushString(g_sound_ambience_avs, ambience_avs_sound[i])
amx_save_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "AVS SOUNDS", g_sound_ambience_avs)
}
if (ArraySize(g_sound_amb_avs_duration) == 0)
{
for (i = 0; i < sizeof g_sound_amb_avs_duration; i++)
ArrayPushString(g_sound_amb_avs_duration, ambience_avs_dur[i])
amx_save_setting_string_arr(ZP_CUSTOMIZATION_FILE, "Ambience Sounds", "AVS DURATIONS", g_sound_amb_avs_duration)
}
// Ambience Sounds
new buffer[250]
if (g_ambience_sounds) {
for (i = 0; i < ArraySize(g_sound_ambience_avs); i++) {
ArrayGetString(g_sound_ambience_avs, i, buffer, charsmax(buffer))
precache_ambience(buffer)
}
}
// Register our game mode
g_gameid = zp_register_game_mode("Assassin vs Snipers", access_flag, g_chance, 0, ZP_DM_BALANCE)
}
// Player spawn post
public zp_player_spawn_post(id)
{
// Check for current mode
if(zp_get_current_mode() == g_gameid)
{
// Check if the player is a zombie
if(zp_get_user_zombie(id))
{
// Make him an assassin instead
zp_make_user_assassin(id)
// Set his health
set_user_health(id, floatround(get_user_health(id) * get_pcvar_float(cvar_assahp)))
}
else
{
// Make him a sniper
zp_make_user_sniper(id)
// Set his health
set_user_health(id, floatround(get_user_health(id) * get_pcvar_float(cvar_sniperhp)))
}
}
}
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
// Start our new mode
start_avs_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(221, 156, 21, -1.0, 0.17, 1, 0.0, 5.0, 1.0, 1.0, -1)
ShowSyncHudMsg(0, g_msg_sync, "Assassins vs Snipers Mode !!!")
// Play the starting sound
new sound[100]
ArrayGetString(g_sound_avs, random_num(0, ArraySize(g_sound_avs) - 1), sound, charsmax(sound))
PlaySoundToClients(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_avs_mode()
// Make the compiler happy again =)
return PLUGIN_CONTINUE
}
// This function contains the whole code behind this game mode
start_avs_mode()
{
// Create and initialize some important vars
static i_assassins, i_max_assassins, id, i_alive
i_alive = zp_get_alive_players()
id = 0
// Get the no of players we have to turn into assassins
i_max_assassins = floatround((i_alive * get_pcvar_float(cvar_ratio)), floatround_ceil)
i_assassins = 0
// Randomly turn players into Assassins
while (i_assassins < i_max_assassins)
{
// Keep looping through all players
if ((++id) > g_maxplayers) id = 1
// Dead
if (!is_user_alive(id))
continue;
// Random chance
if (random_num(1, 5) == 1)
{
// Make user assassin
zp_make_user_assassin(id)
// Set his health
set_user_health(id, floatround(get_user_health(id) * get_pcvar_float(cvar_assahp)))
// Increase counter
i_assassins++
}
}
// Turn the remaining players into snipers
for (id = 1; id <= g_maxplayers; id++)
{
// Only those of them who are alive and are not assassins
if (!is_user_alive(id) || zp_get_user_assassin(id))
continue;
// Turn into a sniper
zp_make_user_sniper(id)
// Set his health
set_user_health(id, floatround(get_user_health(id) * get_pcvar_float(cvar_sniperhp)))
}
}
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_ambience_avs)-1)
ArrayGetString(g_sound_ambience_avs, sound, amb_sound, charsmax(amb_sound))
ArrayGetString(g_sound_amb_avs_duration, sound, str_dur, charsmax(str_dur))
PlaySoundToClients(amb_sound)
// Start the ambience sounds
set_task(str_to_float(str_dur), "start_ambience_sounds", TASK_AMB)
}
public zp_round_ended(winteam)
{
// Stop ambience sounds on round end
remove_task(TASK_AMB)
}
public native_is_avs_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))
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)
}
}
// Plays a sound on clients
stock PlaySoundToClients(const sound[])
{
static buffer[150]
if(equal(sound[strlen(sound)-4], ".mp3")) {
if(!equal(sound, "sound/", 6))
format(buffer, charsmax(buffer), "sound/%s", sound)
else
format(buffer, charsmax(buffer), "%s", sound)
client_cmd(0, "mp3 play ^"%s^"", buffer)
}
else {
if(equal(sound, "sound/", 6))
format(buffer, charsmax(buffer), "%s", sound[6])
else
format(buffer, charsmax(buffer), "%s", sound)
client_cmd(0, "spk ^"%s^"", buffer)
}
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1046\\ f0\\ fs16 \n\\ par }
*/