RichieBurundi commited on
Commit
b40783c
·
verified ·
1 Parent(s): ed59cc2

Upload How to create A Custom Mode.txt

Browse files
Files changed (1) hide show
  1. How to create A Custom Mode.txt +624 -0
How to create A Custom Mode.txt ADDED
@@ -0,0 +1,624 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1- First we will include the necessary include files
2
+ Code:
3
+ #include < amxmodx >
4
+ #include < fun >
5
+ #include < zombie_plague_advance >
6
+ Instead of using fake meta to set the default attributes for players, i will be using fun because it is not only efficient but is also easy for beginners to understand.
7
+
8
+ 2- Now we will make a customizations section where users can customize the game modes according to there requirements
9
+ Code:
10
+ // This is the chance value according to which this game mode will be called
11
+ // The higher the value the lesser the chance of calling this game mode
12
+ new const g_chance = 15
13
+
14
+ // This is the access flag required to start the game mode
15
+ // through the admin menu. Look in users.ini for more details
16
+ new const g_access_flag[] = "a"
17
+
18
+ // This is the sound which is played when the game mode is triggered
19
+ // Add as many as you want [Randomly chosen if more than one]
20
+ new const g_play_sounds[][] =
21
+ {
22
+ "zombie_plague/nemesis1.wav" ,
23
+ "zombie_plague/survivor1.wav"
24
+ }
25
+
26
+ // Comment the following line to disable ambience sounds
27
+ // Just add two slashes ( // )
28
+ #define AMBIENCE_SOUNDS
29
+
30
+ #if defined AMBIENCE_SOUNDS
31
+ // Ambience Sounds (only .wav and .mp3 formats supported)
32
+ // Add as many as you want [Randomly chosen if more than one]
33
+ new const g_sound_ambience[][] =
34
+ {
35
+ "zombie_plague/swarm.mp3" ,
36
+ "zombie_plague/plague.mp3"
37
+ }
38
+ // Duration in seconds of each sound
39
+ new const Float:g_sound_ambience_duration[] = { 58.0 , 56.0 }
40
+ #endif
41
+ Now were done with the customizations section we have added support for all necassary things which make a gamemode more enjoy able to play
42
+
43
+ 3- Now we will create the plugin init and declare some variables
44
+ I have commented it well so it will be easy to understand:
45
+ Code:
46
+ // Variables
47
+ new g_gameid, g_maxplayers, cvar_minplayers, cvar_ratio, cvar_sniperhp, cvar_assahp, g_msg_sync
48
+
49
+ // Ambience sounds task
50
+ // This value should be different from other task values present in other plugins
51
+ // Change it every time you make a new game mode
52
+ #define TASK_AMB 2957
53
+
54
+ public plugin_init( )
55
+ {
56
+ // Plugin registeration.
57
+ register_plugin ( "[ZP] Example Game Mode","1.0", "@bdul!" )
58
+
59
+ // Register some cvars
60
+ // Edit these according to your liking
61
+
62
+ // Min players required for this game mode
63
+ cvar_minplayers = register_cvar ( "zp_avsm_minplayers", "2" )
64
+
65
+ // Sniper's HP multiplier
66
+ cvar_sniperhp = register_cvar ( "zp_avsm_sniper_hp", "1.5" )
67
+
68
+ // Assassin's HP multiplier
69
+ cvar_assahp = register_cvar ( "zp_avsm_assassin_hp", "1.0" )
70
+
71
+ // Infection ratio i.e this number * alive players = no of assassins
72
+ cvar_ratio = register_cvar ( "zp_avsm_inf_ratio", "0.5" )
73
+
74
+ // Get maxplayers
75
+ g_maxplayers = get_maxplayers( )
76
+
77
+ // Hud stuff needed
78
+ g_msg_sync = CreateHudSyncObj( )
79
+ }
80
+
81
+ 4- Now we will precache our resources this is very necessary
82
+ Game Modes MUST be registered in plugin precache ONLY
83
+ Code:
84
+ public plugin_precache( )
85
+ {
86
+ // Read the access flags
87
+ // Convert them in to bitsums
88
+ new access_flag = read_flags( g_access_flag )
89
+ new i
90
+
91
+ // Loop through all play sounds
92
+ // Precache the play sounds
93
+ for (i = 0; i < sizeof g_play_sounds; i++)
94
+ precache_sound( g_play_sounds[i] )
95
+
96
+ // Precache the ambience sounds
97
+ #if defined AMBIENCE_SOUNDS
98
+ new sound[100]
99
+ for (i = 0; i < sizeof g_sound_ambience; i++)
100
+ {
101
+ // If mp3 sounds then precache them seperately
102
+ if (equal(g_sound_ambience[i][strlen(g_sound_ambience[i])-4], ".mp3"))
103
+ {
104
+ formatex(sound, sizeof sound - 1, "sound/%s", g_sound_ambience[i])
105
+
106
+ // mp3 sounds are generic resources to half life
107
+ precache_generic( sound )
108
+ }
109
+ else
110
+ {
111
+ // Precache the sound normally
112
+ precache_sound( g_sound_ambience[i] )
113
+ }
114
+ }
115
+ #endif
116
+
117
+ // Register our game mode
118
+ g_gameid = zp_register_game_mode( "Assassin vs Snipers Mode", access_flag, g_chance, 0, ZP_DM_BALANCE )
119
+ }
120
+ Now we have registered our game mode
121
+ zp_register_game_mode takes 5 parameters
122
+ The first parameter is its normal name
123
+ The second parameter is the access flag required to activate this game mode manually through the admin menu
124
+ The third parameter is its chance level....setting this to zero will cause the game mode to be always called by the main plugin
125
+ The fourth parameter is whether to allow infection in this round or not
126
+ set this to 1 and attacks by zombies on humans will infect them instead of killing them
127
+ The fifth parameter is the type of deathmatch you want during this game mode
128
+ I will paste the code from Zombie Plague Advance's include file regarding deathmatch modes
129
+ Code:
130
+ /* Death Match modes for zp_register_game_mode */
131
+ enum
132
+ {
133
+ ZP_DM_NONE = 0, // Disable death match during the custom mode round
134
+ ZP_DM_HUMAN, // Respawn as human only
135
+ ZP_DM_ZOMBIE, // Respawn as zombie only
136
+ ZP_DM_RANDOM, // Respawn randomly as humans or zombies
137
+ ZP_DM_BALANCE // Respawn as humans or zombies to keep both team balanced
138
+ }
139
+
140
+ 5- In order to catch the game mode we will use the zp_round_started_pre forward instead of zp_round_started because the first one is called for custom game modes and allows them to either start or stop while informing the main plugin whether to give other game modes a chance or not.
141
+ Code:
142
+ public zp_round_started_pre( game )
143
+ {
144
+ // Check if it is our game mode
145
+ if( game == g_gameid )
146
+ {
147
+ // Check for min players
148
+ if( fn_get_alive_players() < get_pcvar_num(cvar_minplayers) )
149
+ {
150
+ /**
151
+ * Note:
152
+ * This very necessary, you should return ZP_PLUGIN_HANDLED if
153
+ * some conditions required by your game mode are not met
154
+ * This will inform the main plugin that you have rejected
155
+ * the offer and so the main plugin will allow other game modes
156
+ * to be given a chance
157
+ */
158
+ return ZP_PLUGIN_HANDLED
159
+ }
160
+ // Start our new mode
161
+ start_avs_mode( )
162
+ }
163
+
164
+ // Make the compiler happy =)
165
+ return PLUGIN_CONTINUE
166
+ }
167
+ start_avs_mode is the function where our code for the game mode will be present
168
+
169
+ 6- Now we will catch the round started forward from ZP to check if our game mode has started fully so we can show a hudmessage for it and start play sounds and ambience sounds.
170
+ Code:
171
+ public zp_round_started( game, id )
172
+ {
173
+ // Check if it is our game mode
174
+ if( game == g_gameid )
175
+ {
176
+ // Show HUD notice
177
+ set_hudmessage(221, 156, 21, -1.0, 0.17, 1, 0.0, 5.0, 1.0, 1.0, -1)
178
+ ShowSyncHudMsg(0, g_msg_sync, "Assassins vs Snipers Mode !!!")
179
+
180
+ // Play the starting sound
181
+ client_cmd(0, "spk ^"%s^"", g_play_sounds[ random_num(0, sizeof g_play_sounds -1) ] )
182
+
183
+ // Remove ambience task affects
184
+ remove_task( TASK_AMB )
185
+
186
+ // Set task to start ambience sounds
187
+ #if defined AMBIENCE_SOUNDS
188
+ set_task( 2.0, "start_ambience_sounds", TASK_AMB )
189
+ #endif
190
+ }
191
+ }
192
+
193
+ 7- Next we will check if our game mode was manually selected
194
+ if so, then start our game mode with out any checks.
195
+ Code:
196
+ // This is called when an admin selects a custom game mode
197
+ public zp_game_mode_selected( gameid, id )
198
+ {
199
+ // Check if our game mode was called
200
+ if( gameid == g_gameid )
201
+ start_avs_mode( )
202
+
203
+ // Make the compiler happy again =)
204
+ return PLUGIN_CONTINUE
205
+ }
206
+
207
+ 8- Now lets create a function where our actual game mode is hidden
208
+ Code:
209
+ // This function contains the whole code behind this game mode
210
+ start_avs_mode( )
211
+ {
212
+ // Create and initialize some important vars
213
+ static i_assassins, i_max_assassins, id, i_alive
214
+
215
+ // Get alive players
216
+ // This function will be discussed later in the tutorial
217
+ i_alive = fn_get_alive_players()
218
+ id = 0
219
+
220
+ // Get the no of players we have to turn into assassins
221
+ i_max_assassins = floatround( ( i_alive * get_pcvar_float( cvar_ratio ) ), floatround_ceil )
222
+ i_assassins = 0
223
+
224
+ // Randomly turn players into Assassins
225
+ while (i_assassins < i_max_assassins)
226
+ {
227
+ // Keep looping through all players
228
+ // As the while loop continues, 1 is added to the "id" variable so every single time the
229
+ // while loop completes a new player is selected for the task of making him into an assassin
230
+ // If the variable "id" has exceeded max players number than its value is reset 1 so we
231
+ // can loop through the players again
232
+ if ( (++id) > g_maxplayers) id = 1
233
+
234
+ // Dead
235
+ if ( !is_user_alive(id) )
236
+ continue;
237
+
238
+ // Random chance to convert players so we dont convert players with a smaller id
239
+ if (random_num(1, 5) == 1)
240
+ {
241
+ // Make user assassin
242
+ zp_make_user_assassin(id)
243
+
244
+ // Set his health
245
+ set_user_health( id, floatround(get_user_health(id) * get_pcvar_float(cvar_assahp)) )
246
+
247
+ // Increase counter
248
+ i_assassins++
249
+ }
250
+ }
251
+
252
+ // Turn the remaining players into snipers
253
+ for (id = 1; id <= g_maxplayers; id++)
254
+ {
255
+ // Only those of them who are alive and are not assassins
256
+ if ( !is_user_alive(id) || zp_get_user_assassin(id) )
257
+ continue;
258
+
259
+ // Turn into a sniper
260
+ zp_make_user_sniper(id)
261
+
262
+ // Set his health
263
+ set_user_health( id, floatround(get_user_health(id) * get_pcvar_float(cvar_sniperhp)) )
264
+ }
265
+ }
266
+
267
+ 9- Now i will display the code to start our ambience sound
268
+ i wont be explaning it more since i have commented it well.
269
+ Code:
270
+ #if defined AMBIENCE_SOUNDS
271
+ public start_ambience_sounds( )
272
+ {
273
+ // Variables
274
+ static amb_sound[64], sound, Float:duration
275
+
276
+ // Select our ambience sound randomly
277
+ sound = random_num( 0, sizeof g_sound_ambience - 1 )
278
+
279
+ // Copy the string into the amb_sound variable
280
+ copy( amb_sound, sizeof amb_sound - 1 , g_sound_ambience[ sound ] )
281
+
282
+ // Get the duration for the ambience sound
283
+ duration = g_sound_ambience_duration[ sound ]
284
+
285
+ // Check whether it's a wav or mp3, then play it on clients
286
+ if ( equal( amb_sound[ strlen( amb_sound ) - 4 ], ".mp3" ) )
287
+ client_cmd( 0, "mp3 play ^"sound/%s^"", amb_sound )
288
+ else
289
+ client_cmd( 0, "spk ^"%s^"", sound )
290
+
291
+ // Start the ambience sounds again after the duration is completed
292
+ set_task( duration, "start_ambience_sounds", TASK_AMB )
293
+ }
294
+ public zp_round_ended( winteam )
295
+ {
296
+ // Stop ambience sounds on round end
297
+ remove_task( TASK_AMB )
298
+ }
299
+ #endif
300
+
301
+ 10- Now we will transform a player into an assassin or a sniper after he respawns
302
+ We cant use Hamsandwich's spawn forward because it is not called for CZ bots and for CZ bots we need to register ham forwards seperately
303
+ which wil not only lengthen the tutorial but will also confuse beginners
304
+ so we will use ZPA's own spawn forward which i made specially for game modes:
305
+ Code:
306
+ // Player spawn post
307
+ public zp_player_spawn_post( id, should_be_zombie )
308
+ {
309
+ // Check for current mode
310
+ if( zp_get_current_mode() == g_gameid )
311
+ {
312
+ // Check if the player was to be made a zombie
313
+ if( zp_get_user_zombie( id ))
314
+ {
315
+ // Make him an assassin instead
316
+ zp_make_user_assassin( id )
317
+
318
+ // Set his health
319
+ set_user_health( id, floatround(get_user_health(id) * get_pcvar_float(cvar_assahp)) )
320
+ }
321
+ else
322
+ {
323
+ // Make him a sniper
324
+ zp_make_user_sniper( id )
325
+
326
+ // Set his health
327
+ set_user_health( id, floatround(get_user_health(id) * get_pcvar_float(cvar_sniperhp)) )
328
+ }
329
+ }
330
+ }
331
+ The first parameter of this forward is the index of the player who is spawning
332
+ if the second parameter is 1 then it means that the main plugin wanted the guy to be a zombie . If it is 0 than the player should be a human
333
+
334
+ 11- The final step is to add a function to return the number of alive players
335
+ You can use this in your script to get no of alive players
336
+ Code:
337
+ // This function returns the no of alive players
338
+ fn_get_alive_players( )
339
+ {
340
+ static i_alive, id
341
+ i_alive = 0
342
+
343
+ for ( id = 1; id <= g_maxplayers; id++ )
344
+ {
345
+ if ( is_user_alive ( id ) )
346
+ i_alive++
347
+ }
348
+ return i_alive;
349
+ }
350
+
351
+ So finally in the end it will look like this:
352
+ PHP Code:
353
+ #include < amxmodx >
354
+ #include < fun >
355
+ #include < zombie_plague_advance >
356
+
357
+ /****************[ Customizations Section ]***************/
358
+
359
+ // This is the chance value according to which this game mode will be called
360
+ // The higher the value the lesser the chance of calling this game mode
361
+ new const g_chance = 15
362
+
363
+ // This is the access flag required to start the game mode
364
+ // through the admin menu. Look in users.ini for more details
365
+ new const g_access_flag[] = "a"
366
+
367
+ // This is the sound which is played when the game mode is triggered
368
+ // Add as many as you want [Randomly chosen if more than one]
369
+ new const g_play_sounds[][] =
370
+ {
371
+ "zombie_plague/nemesis1.wav" ,
372
+ "zombie_plague/survivor1.wav"
373
+ }
374
+
375
+ // Comment the following line to disable ambience sounds
376
+ // Just add two slashes ( // )
377
+ #define AMBIENCE_SOUNDS
378
+
379
+ #if defined AMBIENCE_SOUNDS
380
+ // Ambience Sounds (only .wav and .mp3 formats supported)
381
+ // Add as many as you want [Randomly chosen if more than one]
382
+ new const g_sound_ambience[][] =
383
+ {
384
+ "zombie_plague/ambience.wav"
385
+ }
386
+
387
+ // Duration in seconds of each sound
388
+ new const Float:g_sound_ambience_duration[] = { 58.0 , 56.0 }
389
+ #endif
390
+
391
+ /****************[ Customizations End....!!! ]***************/
392
+
393
+ // Variables
394
+ new g_gameid, g_maxplayers, cvar_minplayers, cvar_ratio, cvar_sniperhp, cvar_assahp, g_msg_sync
395
+
396
+ // Ambience sounds task
397
+ #define TASK_AMB 3256
398
+
399
+ public plugin_init( )
400
+ {
401
+ // Plugin registeration.
402
+ register_plugin( "[ZP] Example Game Mode","1.0", "@bdul!" )
403
+
404
+ // Register some cvars
405
+ // Edit these according to your liking
406
+ cvar_minplayers = register_cvar("zp_avsm_minplayers", "2")
407
+ cvar_sniperhp = register_cvar("zp_avsm_sniper_hp", "1.5")
408
+ cvar_assahp = register_cvar("zp_avsm_assassin_hp", "1.0")
409
+ cvar_ratio = register_cvar("zp_avsm_inf_ratio", "0.5")
410
+
411
+ // Get maxplayers
412
+ g_maxplayers = get_maxplayers( )
413
+
414
+ // Hud stuff
415
+ g_msg_sync = CreateHudSyncObj()
416
+ }
417
+
418
+ // Game modes MUST be registered in plugin precache ONLY
419
+ public plugin_precache( )
420
+ {
421
+ // Read the access flag
422
+ new access_flag = read_flags( g_access_flag )
423
+ new i
424
+
425
+ // Precache the play sounds
426
+ for (i = 0; i < sizeof g_play_sounds; i++)
427
+ precache_sound( g_play_sounds[i] )
428
+
429
+ // Precache the ambience sounds
430
+ #if defined AMBIENCE_SOUNDS
431
+ new sound[100]
432
+ for (i = 0; i < sizeof g_sound_ambience; i++)
433
+ {
434
+ if (equal(g_sound_ambience[i][strlen(g_sound_ambience[i])-4], ".mp3"))
435
+ {
436
+ formatex(sound, sizeof sound - 1, "sound/%s", g_sound_ambience[i])
437
+ precache_generic( sound )
438
+ }
439
+ else
440
+ {
441
+ precache_sound( g_sound_ambience[i] )
442
+ }
443
+ }
444
+ #endif
445
+
446
+ // Register our game mode
447
+ g_gameid = zp_register_game_mode( "Assassin vs Snipers Mode", access_flag, g_chance, 0, ZP_DM_BALANCE )
448
+ }
449
+
450
+ // Player spawn post
451
+ public zp_player_spawn_post( id, should_be_zombie )
452
+ {
453
+ // Check for current mode
454
+ if( zp_get_current_mode() == g_gameid )
455
+ {
456
+ // Check if the player was to be made a zombie
457
+ if( zp_get_user_zombie( id ))
458
+ {
459
+ // Make him an assassin instead
460
+ zp_make_user_assassin( id )
461
+
462
+ // Set his health
463
+ set_user_health( id, floatround(get_user_health(id) * get_pcvar_float(cvar_assahp)) )
464
+ }
465
+ else
466
+ {
467
+ // Make him a sniper
468
+ zp_make_user_sniper( id )
469
+
470
+ // Set his health
471
+ set_user_health( id, floatround(get_user_health(id) * get_pcvar_float(cvar_sniperhp)) )
472
+ }
473
+ }
474
+ }
475
+
476
+ public zp_round_started_pre( game )
477
+ {
478
+ // Check if it is our game mode
479
+ if( game == g_gameid )
480
+ {
481
+ // Check for min players
482
+ if( fn_get_alive_players() < get_pcvar_num(cvar_minplayers) )
483
+ {
484
+ /**
485
+ * Note:
486
+ * This very necessary, you should return ZP_PLUGIN_HANDLED if
487
+ * some conditions required by your game mode are not met
488
+ * This will inform the main plugin that you have rejected
489
+ * the offer and so the main plugin will allow other game modes
490
+ * to be given a chance
491
+ */
492
+ return ZP_PLUGIN_HANDLED
493
+ }
494
+ // Start our new mode
495
+ start_avs_mode( )
496
+ }
497
+ // Make the compiler happy =)
498
+ return PLUGIN_CONTINUE
499
+ }
500
+
501
+ public zp_round_started( game, id )
502
+ {
503
+ // Check if it is our game mode
504
+ if( game == g_gameid )
505
+ {
506
+ // Show HUD notice
507
+ set_hudmessage(221, 156, 21, -1.0, 0.17, 1, 0.0, 5.0, 1.0, 1.0, -1)
508
+ ShowSyncHudMsg(0, g_msg_sync, "Assassins vs Snipers Mode !!!")
509
+
510
+ // Play the starting sound
511
+ client_cmd(0, "spk ^"%s^"", g_play_sounds[ random_num(0, sizeof g_play_sounds -1) ] )
512
+
513
+ // Remove ambience task affects
514
+ remove_task( TASK_AMB )
515
+
516
+ // Set task to start ambience sounds
517
+ #if defined AMBIENCE_SOUNDS
518
+ set_task( 2.0, "start_ambience_sounds", TASK_AMB )
519
+ #endif
520
+ }
521
+ }
522
+
523
+ public zp_game_mode_selected( gameid, id )
524
+ {
525
+ // Check if our game mode was called
526
+ if( gameid == g_gameid )
527
+ start_avs_mode( )
528
+
529
+ // Make the compiler happy again =)
530
+ return PLUGIN_CONTINUE
531
+ }
532
+
533
+ // This function contains the whole code behind this game mode
534
+ start_avs_mode( )
535
+ {
536
+ // Create and initialize some important vars
537
+ static i_assassins, i_max_assassins, id, i_alive
538
+ i_alive = fn_get_alive_players()
539
+ id = 0
540
+
541
+ // Get the no of players we have to turn into assassins
542
+ i_max_assassins = floatround( ( i_alive * get_pcvar_float( cvar_ratio ) ), floatround_ceil )
543
+ i_assassins = 0
544
+
545
+ // Randomly turn players into Assassins
546
+ while (i_assassins < i_max_assassins)
547
+ {
548
+ // Keep looping through all players
549
+ if ( (++id) > g_maxplayers) id = 1
550
+
551
+ // Dead
552
+ if ( !is_user_alive(id) )
553
+ continue;
554
+
555
+ // Random chance
556
+ if (random_num(1, 5) == 1)
557
+ {
558
+ // Make user assassin
559
+ zp_make_user_assassin(id)
560
+
561
+ // Set his health
562
+ set_user_health( id, floatround(get_user_health(id) * get_pcvar_float(cvar_assahp)) )
563
+
564
+ // Increase counter
565
+ i_assassins++
566
+ }
567
+ }
568
+
569
+ // Turn the remaining players into snipers
570
+ for (id = 1; id <= g_maxplayers; id++)
571
+ {
572
+ // Only those of them who are alive and are not assassins
573
+ if ( !is_user_alive(id) || zp_get_user_assassin(id) )
574
+ continue;
575
+
576
+ // Turn into a sniper
577
+ zp_make_user_sniper(id)
578
+
579
+ // Set his health
580
+ set_user_health( id, floatround(get_user_health(id) * get_pcvar_float(cvar_sniperhp)) )
581
+ }
582
+ }
583
+
584
+ #if defined AMBIENCE_SOUNDS
585
+ public start_ambience_sounds( )
586
+ {
587
+ // Variables
588
+ static amb_sound[64], sound, Float:duration
589
+
590
+ // Select our ambience sound
591
+ sound = random_num( 0, sizeof g_sound_ambience - 1 )
592
+ copy( amb_sound, sizeof amb_sound - 1 , g_sound_ambience[ sound ] )
593
+ duration = g_sound_ambience_duration[ sound ]
594
+
595
+ // Check whether it's a wav or mp3, then play it on clients
596
+ if ( equal( amb_sound[ strlen( amb_sound ) - 4 ], ".mp3" ) )
597
+ client_cmd( 0, "mp3 play ^"sound/%s^"", amb_sound )
598
+ else
599
+ client_cmd( 0, "spk ^"%s^"", sound )
600
+
601
+ // Start the ambience sounds
602
+ set_task( duration, "start_ambience_sounds", TASK_AMB )
603
+ }
604
+
605
+ public zp_round_ended( winteam )
606
+ {
607
+ // Stop ambience sounds on round end
608
+ remove_task( TASK_AMB )
609
+ }
610
+ #endif
611
+
612
+ // This function returns the no. of alive players
613
+ fn_get_alive_players( )
614
+ {
615
+ static i_alive, id
616
+ i_alive = 0
617
+
618
+ for ( id = 1; id <= g_maxplayers; id++ )
619
+ {
620
+ if( is_user_alive( id ) )
621
+ i_alive++
622
+ }
623
+ return i_alive;
624
+ }