· 7 years ago · Nov 05, 2018, 01:22 PM
1#include <amxmodx>
2#include <amxmisc>
3#include <fakemeta>
4#include <engine>
5#include <fun>
6#include <colorchat>
7#include <dhudmessage>
8#include <sqlx>
9
10#define SHOW_SC
11
12#define TASK_TELEPORT 12345
13
14#define VERSION "2.3"
15
16#define MAX_MARKERS 1500 //not the max marker NUMBER but ent's id
17
18new bool: find_origin = false
19
20new bool: allWant_duel, bool: pWant_duel[ 33 ], d_started, bool: teleporting_p[ 33 ] = false
21
22new g_pInCup = 0, g_pNumber = 0
23
24new Float:fPrepareTime
25
26new g_StartedName[ 32 ]
27
28new spec_nick[ 33 ][ 32 ]
29
30new Float:origins[ 33 ][ 3 ]
31new g_TimeCup = 1
32
33new r = 50, g = 35, b = 170
34
35new playerNum, players[ 32 ]
36
37new forbiden_say[][] = { "say /cp", "say /tp", "say /gc", "+hook", "say /nc", "say /pause", "say /noclip",
38 "say /savepos", "say /checkpoint", "say /spec", "say_team /cp", "say_team /tp", "say_team /gc",
39 "say_team /ct", "say_team /ct", "say_team /spec", "say_team /spec" }
40new saycmd[ 12 ]
41
42new p_inDuel[ 33 ], currentPlayer[ 33 ] = 0
43
44new currMap[ 32 ]
45
46new Float:fOrigin[ MAX_MARKERS ][ 3 ]
47new ent[ MAX_MARKERS ]
48new g_mPos = 0
49new bool:g_fixCheck[ 33 ][ MAX_MARKERS ]
50new g_Model[] = "sprites/esp_friend.spr"
51new g_playerTouched[ 33 ]
52new g_pBestTouch[ 33 ]
53new bool:g_markerVis = false
54new filename[ 256 ]
55new Float:test_origin[ 3 ]
56
57new Handle:g_SQLTuple , g_szQueryCache[ 1024 ] , g_szSteamID[ 33 ][ 35 ], g_szName[ 33 ]
58
59new bool:g_pRead[ 33 ]
60new bool:faster_nc[ 33 ]
61
62new g_timetime[ 33 ]
63
64new Float:stime[ 33 ]
65
66public plugin_init()
67{
68 register_plugin( "AUTOCUP Plugin", VERSION, "JocA" )
69
70 register_clcmd( "say /startcup", "duel_open_pre" )
71 register_clcmd( "say /joincup", "join_duel" )
72 register_clcmd( "say /exit", "exitCup" )
73
74 register_clcmd( "say /cup", "cup_menu" ) //admin menu
75
76 register_clcmd( "say /cup15", "cupTop15" ) //sqlite top15
77
78 register_concmd( "amx_cup_delete", "deletePlayer" ) //delete by steamid
79
80 register_forward( FM_CmdStart, "FwdCmdStart" ) // for faster noclip
81
82 register_cvar( "AutoCupKZ", "1", FCVAR_SERVER | FCVAR_SPONLY )
83
84 for( new i = 0; i < sizeof( forbiden_say ); i++ )
85 {
86 formatex( saycmd, charsmax( saycmd ), "%s", forbiden_say[ i ] )
87 register_clcmd( saycmd, "forbiden" )
88 }
89
90 get_mapname( currMap, 31 )
91 get_configsdir( filename, 255 )
92 format( filename, 255, "%s/Cup_maker/%s.txt", filename, currMap )
93
94 set_task( 2.0, "load_files", 0 )
95
96 CreateTable()
97}
98public plugin_precache()
99{
100 precache_model(g_Model)
101}
102public plugin_end()
103{
104 SQL_FreeHandle(g_SQLTuple)
105}
106public FwdCmdStart( client, ucHandle ) //Hawk552 (Exolent)
107{
108 if( !is_user_alive( client )
109 || pev( client, pev_movetype ) != MOVETYPE_NOCLIP
110 || !( pev( client, pev_button ) & IN_FORWARD ) || !faster_nc[ client ] )
111 {
112 return FMRES_IGNORED;
113 }
114
115 static Float:fForward, Float:fSide;
116 get_uc( ucHandle, UC_ForwardMove, fForward );
117 get_uc( ucHandle, UC_SideMove, fSide );
118
119 if( fForward == 0.0 && fSide == 0.0 )
120 {
121 return FMRES_IGNORED;
122 }
123
124 static Float:fMaxSpeed;
125 pev( client, pev_maxspeed, fMaxSpeed );
126
127
128 {
129 static Float:vOrigin[ 3 ];
130 pev( client, pev_origin, vOrigin );
131
132 static Float:vAngle[ 3 ];
133 pev( client, pev_v_angle, vAngle );
134 engfunc( EngFunc_MakeVectors, vAngle );
135 global_get( glb_v_forward, vAngle );
136
137 vOrigin[ 0 ] += ( vAngle[ 0 ] * 10.0 );
138 vOrigin[ 1 ] += ( vAngle[ 1 ] * 10.0 );
139 vOrigin[ 2 ] += ( vAngle[ 2 ] * 10.0 );
140
141 engfunc( EngFunc_SetOrigin, client, vOrigin );
142 }
143 return FMRES_IGNORED;
144}
145
146public timer( id ) //DarkGL
147{
148 new poruka[55]
149 format( poruka, charsmax( poruka ), "Cup time: %02d:%02d sec; Players: %d", (g_timetime[ id ]/60), (g_timetime[ id ]%60), g_pInCup)
150
151 static msgStatusText=0;
152 if(!msgStatusText)
153 msgStatusText = get_user_msgid("StatusText");
154
155 g_timetime[ id ] -= 1
156 if( g_timetime[ id ] >= 1 && d_started && pWant_duel[ id ] )
157 {
158 message_begin(MSG_ONE_UNRELIABLE, msgStatusText, _, id);
159 write_byte(0);
160 write_string(poruka);
161 message_end();
162 set_task( 0.95, "timer", id )
163 }
164 else
165 {
166 message_begin(MSG_ONE_UNRELIABLE, msgStatusText, _, id);
167 write_byte(0);
168 write_string("");
169 message_end();
170 }
171 return PLUGIN_CONTINUE
172}
173public deletePlayer( id )
174{
175 if( !is_user_admin( id ) )
176 return PLUGIN_HANDLED
177
178 new Handle:SqlConnection , ErrorCode;
179 SqlConnection = SQL_Connect( g_SQLTuple , ErrorCode , g_szQueryCache , charsmax( g_szQueryCache ) );
180
181 if( SqlConnection == Empty_Handle )
182 set_fail_state( g_szQueryCache );
183
184 new szarg1[32]
185 read_argv( 1, szarg1, 32 )
186
187 if( containi( szarg1, "STEAM" ) != -1 )
188 {
189 formatex( g_szQueryCache, charsmax( g_szQueryCache ) , "DELETE FROM cup_info WHERE steamid='%s'", szarg1 );
190 SQL_ThreadQuery( g_SQLTuple , "SelectHandle" , g_szQueryCache , _, _ );
191
192
193 ColorChat( id, BLUE, "^4[CUP]^1 Successfully deleted:^4 %s", szarg1 )
194 }
195 return PLUGIN_HANDLED
196}
197public cupTop15( id )
198{
199 new Data[ 1 ]; Data[ 0 ] = id;
200 get_user_authid( id , g_szSteamID[ id ] , charsmax( g_szSteamID[] ) )
201
202 formatex( g_szQueryCache,charsmax( g_szQueryCache ),"SELECT * FROM ( SELECT *, (CAST( wins AS float )/CAST( cups AS float)) AS winns FROM cup_info ) ORDER BY winns*players DESC, cups DESC, wins DESC LIMIT 15;" )
203 SQL_ThreadQuery( g_SQLTuple, "cup15Format", g_szQueryCache, Data, sizeof( Data ) )
204}
205public cup15Format( FailState , Handle:Query , Error[] , Errcode , Data[] , DataSize )
206{
207 new g_sBuffer[2048]
208 if( FailState == TQUERY_CONNECT_FAILED )
209 {
210 return set_fail_state("Could not connect to SQL database." );
211 }
212 else if( FailState == TQUERY_QUERY_FAILED )
213 {
214 log_amx( "Query error: %s" , Error );
215 return set_fail_state( g_szQueryCache );
216 }
217 if( Errcode )
218 return log_amx( "Error on query: %s" , Error );
219
220 new id = Data[ 0 ];
221 new rows1 = SQL_NumResults( Query )
222 new Name[ 33 ][ 32 ], cups[ 20 ], wins[ 20 ], plrs[ 20 ]
223 new Float:skill_result
224
225 if( SQL_MoreResults( Query ) )
226 {
227 for(new i = 0 ; i < rows1 ; i++)
228 {
229 SQL_ReadResult( Query, 1, Name[ i ], 31 )
230
231 cups[ i ] = SQL_ReadResult( Query, 2 )
232 wins[ i ] = SQL_ReadResult( Query, 3 )
233 plrs[ i ] = SQL_ReadResult( Query, 4 )
234
235 SQL_NextRow(Query)
236 }
237 }
238
239 if( rows1 > 0 )
240 {
241
242 new iLen=0;
243 iLen = format( g_sBuffer[iLen], 2047, "<meta charset=utf-8><body><center><style type=^"text/css^">body {background: url(^"https://ak8.picdn.net/shutterstock/videos/83248/thumb/1.jpg^") no-repeat center center fixed;background-size: cover;}table{margin-top: 10px;font-size:11px;font-family: Tahoma;border-collapse: collapse;text-align:center;color: #ffe1c6;line-height: 19px;border-bottom: 1px solid;}")
244 iLen += format( g_sBuffer[iLen], 2047 - iLen, "thead {border-bottom: 1px solid #ffe1c6;color:#ffb777;}tr:nth-child(even) {background: #962019;}</style><table width=90%%><thead><tr height=50px ><th width=5%%>#<th width=37%%>Name<th width=8%%>Cups<th width=8%%>Wins<th width=11%%>Played with<th width=10%%>Skill</thead>" )
245 for(new i = 0 ; i < rows1 ; i++)
246 {
247 skill_result = (float(wins[i])/(float(cups[i])))*plrs[i]
248
249 iLen += format( g_sBuffer[iLen], 2047 - iLen, "<tr><td>%d<td>%s<td>%d<td>%d<td>%d<td>%.01f", i + 1, Name[i], cups[i], wins[i], plrs[i], skill_result )
250
251
252
253 }
254 show_motd(id, g_sBuffer, "Top15 CUP")
255 }
256 return PLUGIN_HANDLED
257}
258stock clear(src[]) //secure the sql
259{
260 new len = strlen( src );
261 replace_all(src, len, "\", "\\");
262 replace_all(src, len, "'", "\'");
263 replace_all(src, len, "^"", "\^"");
264 replace_all(src, len, "^n", "\^n");
265 replace_all(src, len, "^r", "\^n");
266 replace_all(src, len, "^x1A", "\^x1A");
267 replace_all(src, len, "^x00", "\^x00");
268}
269public client_putinserver( id )
270{
271 if( is_user_bot( id ) )
272 return PLUGIN_HANDLED
273
274 g_pRead[ id ] = false
275 stime[ id ] = 15.0
276
277 new Data[ 1 ]; Data[ 0 ] = id;
278 get_user_authid( id , g_szSteamID[ id ] , charsmax( g_szSteamID[] ) );
279
280 formatex( g_szQueryCache, charsmax( g_szQueryCache ) , "SELECT * FROM `cup_info` WHERE steamid='%s';" , g_szSteamID[ id ] )
281 SQL_ThreadQuery( g_SQLTuple , "SelectHandle" , g_szQueryCache , Data , sizeof( Data ) )
282
283 set_task( 1.0, "loadPlayer", id )
284
285 return PLUGIN_HANDLED
286}
287public loadPlayer( id )
288{
289 if( !g_pRead[ id ] )
290 {
291 new Data[ 1 ]; Data[ 0 ] = id;
292 get_user_name( id, g_szName, charsmax( g_szName ) )
293 clear(g_szName);
294 formatex( g_szQueryCache, charsmax( g_szQueryCache ) , "INSERT INTO cup_info(cups, wins, players, name, steamid) VALUES(0, 0, 0, '%s', '%s');" , g_szName, g_szSteamID[ id ] );
295 SQL_ThreadQuery( g_SQLTuple , "SelectHandle" , g_szQueryCache , Data , sizeof( Data ) );
296 g_pRead[ id ] = true
297 }
298}
299public set_winner( check )
300{
301 new Data[ 1 ];
302 for( new i = 0; i <= g_pInCup; i++ )
303 {
304 if( p_inDuel[ i ] == check )//winner
305 {
306 Data[ 0 ] = check
307 get_user_authid( check , g_szSteamID[ check ] , charsmax( g_szSteamID[] ) )
308 formatex( g_szQueryCache, charsmax( g_szQueryCache ) , "UPDATE cup_info SET cups=cups+1, wins=wins+1, players=players+%d-1 WHERE steamid='%s';" , g_pNumber, g_szSteamID[ check ] );
309 SQL_ThreadQuery( g_SQLTuple , "SelectHandle" , g_szQueryCache , Data , sizeof( Data ) );
310 }
311 else //all others
312 {
313 Data[ 0 ] = p_inDuel[ i ]
314 get_user_authid( p_inDuel[ i ] , g_szSteamID[ p_inDuel[ i ] ] , charsmax( g_szSteamID[] ) )
315 formatex( g_szQueryCache, charsmax( g_szQueryCache ) , "UPDATE cup_info SET cups=cups+1, players=players+%d-1 WHERE steamid='%s';" , g_pNumber, g_szSteamID[ p_inDuel[ i ] ] );
316 SQL_ThreadQuery( g_SQLTuple , "SelectHandle" , g_szQueryCache , Data , sizeof( Data ) );
317 }
318 }
319}
320
321public CreateTable() //by bugsy's post, hope he doesnt mind heh
322{
323 SQL_SetAffinity( "sqlite" );
324
325 g_SQLTuple = SQL_MakeDbTuple("", "", "", "cup_version_one" )
326
327 new Handle:SqlConnection , ErrorCode;
328 SqlConnection = SQL_Connect( g_SQLTuple , ErrorCode , g_szQueryCache , charsmax( g_szQueryCache ) );
329
330 if( SqlConnection == Empty_Handle )
331 set_fail_state( g_szQueryCache );
332
333 RunQuery( SqlConnection , "CREATE TABLE IF NOT EXISTS cup_info (steamid VARCHAR(35) UNIQUE, name CHAR(32), cups INTEGER, wins INTEGER, players INTEGER );" );
334}
335public RunQuery( Handle:SQLConnection , const szQuery[] )
336{
337 new Handle:Query = SQL_PrepareQuery( SQLConnection , szQuery );
338
339 if( !SQL_Execute( Query ) )
340 {
341 SQL_QueryError( Query , g_szQueryCache , 100 );
342 set_fail_state( g_szQueryCache );
343 }
344}
345public SelectHandle( FailState , Handle:Query , Error[] , Errcode , Data[] , DataSize )
346{
347 if( FailState == TQUERY_CONNECT_FAILED )
348 {
349 return set_fail_state("Could not connect to SQL database." );
350 }
351 else if( FailState == TQUERY_QUERY_FAILED )
352 {
353 log_amx( "Query error: %s" , Error );
354 return set_fail_state( g_szQueryCache );
355 }
356
357 if( Errcode )
358 return log_amx( "Error on query: %s" , Error );
359
360 new id = Data[ 0 ];
361
362
363 if ( SQL_NumResults( Query ) )
364 {
365 g_pRead[ id ] = true;
366 }
367
368 return PLUGIN_CONTINUE;
369}
370public load_files() //load markers
371{
372 new file = fopen( filename, "r" )
373 new line = 0
374
375 if( file )
376 {
377 new Data[ 150 ], file_origin[ 3 ][ 10 ]
378
379 while( fgets( file, Data, 149 ) )
380 {
381 line++
382 parse( Data, file_origin[ 0 ], 9, file_origin[ 1 ], 9, file_origin[ 2 ], 9 )
383
384 test_origin[ 0 ] = str_to_float( file_origin[ 0 ] )
385 test_origin[ 1 ] = str_to_float( file_origin[ 1 ] )
386 test_origin[ 2 ] = str_to_float( file_origin[ 2 ] )
387
388 create_marker( 0, 0 )
389 }
390 }
391}
392public forbiden( id )
393{
394 if( d_started && pWant_duel[ id ] )
395 {
396 ColorChat( id, RED, "^1[CUP] Sorry,^3 not possible^1 while in Cup." )
397 return PLUGIN_HANDLED
398 }
399 return PLUGIN_CONTINUE
400}
401public client_disconnect( id )
402{
403 remove_task( id )
404 if( pWant_duel[ id ] )
405 {
406 ColorChat( 0, BLUE, "Player from cup left the server :/" )
407 pWant_duel[ id ] = false
408 g_pInCup -= 1
409 }
410}
411public cup_menu( id )
412{
413 if( !is_user_admin( id ) )
414 return PLUGIN_HANDLED
415
416 new menu_c_text[ 50 ]; formatex( menu_c_text, charsmax( menu_c_text ), "\yCup Markers Menu^n^n\wMarkers now:\y %d\w", g_mPos )
417 new menu_visible[ 100 ]; formatex( menu_visible, charsmax( menu_visible), "Markers visible: %s", g_markerVis ? "\yYes^n":"\dNo^n" )
418 new fasternc[ 100 ]; formatex( fasternc, charsmax( fasternc ), "\rFaster Noclip: %s", faster_nc[ id ] ? "\yYes":"\dNo" )
419 new menuC = menu_create( menu_c_text, "cup_m_handler" )
420
421 menu_additem( menuC, "Create new marker" )
422 menu_additem( menuC, menu_visible )
423
424 menu_additem( menuC, "Delete last marker" )
425 menu_additem( menuC, "Delete ALL markers^n" )
426
427 menu_additem( menuC, "\ySave ALL markers^n" )
428
429 menu_additem( menuC, fasternc )
430
431 menu_display( id, menuC )
432
433 return PLUGIN_CONTINUE
434}
435public cup_m_handler( id, menuC, itemC )
436{
437 if( itemC == MENU_EXIT )
438 {
439 faster_nc[ id ] = true
440 menu_destroy( menuC )
441 return PLUGIN_HANDLED
442 }
443
444 switch( itemC )
445 {
446 case 0:
447 {
448 create_marker( id, 1 )
449 }
450 case 1:
451 {
452 g_markerVis = !g_markerVis
453 for( new o = 1; o <= g_mPos; o++ )
454 {
455 if( !g_markerVis )
456 {
457 set_pev( ent[ o ], pev_rendermode, kRenderTransAlpha )
458 }
459 else
460 {
461 set_pev( ent[ o ], pev_rendermode, kRenderNormal )
462 }
463 }
464 }
465 case 2:
466 {
467 if( g_mPos > 0 )
468 {
469 ColorChat( id, RED, "^4[CUP]^1 Removed last marker." )
470 remove_marker( id, 0 )
471 }
472 else
473 ColorChat( id, RED, "^4[CUP]^1 There's zero markers, shame on you !" )
474 }
475 case 3:
476 {
477 remove_marker( id, 1 )
478 }
479 case 4:
480 {
481 if( g_mPos > 2 )
482 save_to_file( id )
483 else
484 ColorChat( id, RED, "^4[CUP]^1 Denied. Minimum markers are:^3 3" )
485 }
486 case 5:
487 {
488 if( faster_nc[ id ] )
489 {
490 set_user_noclip( id, 0 )
491 faster_nc[ id ] = false
492 }
493 else
494 {
495 set_user_noclip( id, 1 )
496 faster_nc[ id ] = true
497 }
498 }
499 }
500 cup_menu( id )
501 return PLUGIN_HANDLED
502}
503public save_to_file( id ) //save markers
504{
505 new file = fopen( filename, "w+" )
506
507 if( file )
508 {
509 for( new o = 1; o <= g_mPos; o++ )
510 {
511 fprintf( file, "%.01f %.01f %.01f^n", fOrigin[ o ][ 0 ], fOrigin[ o ][ 1 ], fOrigin[ o ][ 2 ] )
512 }
513 ColorChat( 0, BLUE, "^4[CUP]^1 Saved^3 %d markers^1 for this map.", g_mPos )
514 fclose( file )
515 }
516 else
517 {
518 ColorChat( 0, BLUE, "^4[CUP]^1 Not found file:^4 %s", filename )
519 }
520 return PLUGIN_HANDLED
521}
522public winner()
523{
524 new bestIS = get_best_player( 1 )
525 new name[ 32 ]; get_user_name( bestIS, name, 31 )
526 new Float:velocity[3];
527 entity_get_vector( bestIS, EV_VEC_velocity, velocity );
528
529 if( bestIS > 0 )
530 {
531 ColorChat( 0, BLUE, "^4[CUP]^1 Winner is:^3 %s%s^1> %.00f%% completed", name, velocity[2] !=0.0 ? " ^4[in air] ":" ", (( float( ( g_pBestTouch[ bestIS ] + 1 ) - ent[ 1 ] ) / ( float( g_mPos )) ) * 100 ) )
532 set_winner( bestIS )
533 }
534}
535public get_best_player( final ) //most important if markers are on that map
536{
537 new bestvalue = 1 //let it be first marker
538 new id
539 new Float:pOrigin[ 3 ], Float:markerOrigin[ 3 ]
540 new wanted_id = 0
541 new Float: best_distance, Float: distance
542 new Float: previousMarker[ 3 ]
543 new Float: nextMarker[ 3 ]
544 new Float: nextDiff
545
546 for( new i = 0; i <= g_pInCup; i++ )
547 {
548 if( final == 1 )
549 id = p_inDuel[ i ]
550 else
551 id = pWant_duel[ i ]
552
553 if( g_pBestTouch[ id ] >= bestvalue )
554 {
555 entity_get_vector( id, EV_VEC_origin, pOrigin )
556
557 if( g_pBestTouch[ id ] == ent[ g_mPos ] )
558 {
559 bestvalue = g_pBestTouch[ id ]
560 best_distance = distance
561 wanted_id = id
562 return wanted_id
563 }
564 else
565 {
566 entity_get_vector( ( g_pBestTouch[ id ] ), EV_VEC_origin, markerOrigin )
567 entity_get_vector( ( g_pBestTouch[ id ] + 1 ), EV_VEC_origin, nextMarker )
568 entity_get_vector( ( g_pBestTouch[ id ] - 1 ), EV_VEC_origin, previousMarker )
569 }
570
571 distance = get_distance_f( pOrigin, nextMarker )
572
573 if( g_pBestTouch[ id ] > bestvalue )
574 {
575 new Float:fallDist = floatabs( pOrigin[ 2 ] - markerOrigin[ 2 ] )
576
577 if( fallDist > 250.0 )
578 { //didnt fall too deep
579 nextDiff = floatabs( markerOrigin[ 2 ] - nextMarker[ 2 ] )
580
581 if( nextDiff < 150.0 )
582 {
583 if( floatabs( pOrigin[ 2 ] - nextMarker[ 2 ] ) < 150.0 )
584 {
585 bestvalue = g_pBestTouch[ id ]
586 best_distance = distance
587 wanted_id = id
588 //client_print( 0, print_console, "^1winner info^4 to next:^3 %.01f^4 to prev:^3 %.01f^4 Z:^1 %.01f", distance, prevMarker, fallDist )
589 }
590 else
591 {
592 ColorChat( 0, RED, " --- We think one player fall at the last second of cup ---" )
593 //client_print( 0, print_console, "*failer info: marker difference: %.01f - player/nextm: %.01f", floatabs( markerOrigin[ 2 ] - nextMarker[ 2 ] ), floatabs( pOrigin[ 2 ] - nextMarker[ 2 ] ) )
594 }
595 }
596 else
597 {
598 if( floatabs( pOrigin[ 2 ] - nextMarker[ 2 ] ) < 300.0 && pOrigin[ 2 ] > nextMarker[ 2 ] )
599 {
600 bestvalue = g_pBestTouch[ id ]
601 best_distance = distance
602 wanted_id = id
603 //client_print( 0, print_console, "^1***winner info^4 to next:^3 %.01f^4 to prev:^3 %.01f^4 Z:^1 %.01f", distance, prevMarker, fallDist )
604 }
605 else
606 {
607 ColorChat( 0, RED, " --- We think one player fall at the last second of cup ---" )
608 //client_print( 0, print_console, "^1failer info: marker difference: %.01f - player/nextm: %.01f", floatabs( markerOrigin[ 2 ] - nextMarker[ 2 ] ), floatabs( pOrigin[ 2 ] - nextMarker[ 2 ] ) )
609 }
610 }
611 }
612 else
613 {
614 bestvalue = g_pBestTouch[ id ]
615 best_distance = distance
616 wanted_id = id
617 //client_print( 0, print_console, "^1**winner info^4 to next:^3 %.01f^4 to prev:^3 %.01f^4 Z:^1 %.01f", distance, prevMarker, fallDist )
618 }
619 }
620 else if( distance < best_distance )
621 {
622 best_distance = distance
623 wanted_id = id
624 }
625 }
626
627 }
628 return wanted_id
629}
630public create_marker( id, check )
631{
632 new origin[ 3 ]
633
634 g_mPos++
635 ent[ g_mPos ] = create_entity( "info_target" )
636
637 if( check == 1 )
638 {
639 get_user_origin( id, origin, 3 )
640
641 fOrigin[ g_mPos ][ 0 ] = float( origin[ 0 ] )
642 fOrigin[ g_mPos ][ 1 ] = float( origin[ 1 ] )
643 fOrigin[ g_mPos ][ 2 ] = float( origin[ 2 ] )
644
645 fOrigin[ g_mPos ][ 2 ] +=70.0
646 }
647 else
648 {
649 fOrigin[ g_mPos ][ 0 ] = test_origin[ 0 ]
650 fOrigin[ g_mPos ][ 1 ] = test_origin[ 1 ]
651 fOrigin[ g_mPos ][ 2 ] = test_origin[ 2 ]
652 }
653 entity_set_origin( ent[ g_mPos ], fOrigin[ g_mPos ] );
654
655 entity_set_string( ent[ g_mPos ], EV_SZ_classname, "cup_marker" )
656 entity_set_model( ent[ g_mPos ], g_Model );
657
658 entity_set_int( ent[ g_mPos ], EV_INT_solid, 1 )
659
660 new Float:maxs[ 3 ] = { 50.0, 50.0, 20.0 }
661 new Float:mins[ 3 ] = { -50.0, -50.0, -20.0 }
662 entity_set_size( ent[ g_mPos ], mins, maxs )
663
664 if( !g_markerVis )
665 set_pev( ent[ g_mPos ], pev_rendermode, kRenderTransAlpha)
666}
667public remove_marker( id, all )
668{
669 if( !all )
670 {
671 remove_entity( ent[ g_mPos-- ] )
672 }
673 else
674 {
675 remove_entity_name( "cup_marker" )
676 g_mPos = 0
677 }
678}
679
680public pfn_touch( ent1, id )
681{
682 new classname[ 32 ], name[ 32 ]
683 entity_get_string( ent1, EV_SZ_classname, classname, 31 )
684
685 if( equal( classname, "cup_marker" ) )
686 {
687 if ( !(1 <= id <= get_maxplayers() && pWant_duel[ id ]) || !d_started ) //check if only player entity touch //klippy
688 return PLUGIN_HANDLED
689
690 get_user_name( id, name, charsmax( name ) )
691 #if defined SHOW_SC
692 if( g_playerTouched[ id ] > 2 && ( ( ent1 - g_pBestTouch[ id ] ) >= 3 ) )
693 {
694 set_dhudmessage( 255, 85, 0, 0.03, 0.23, 0, 2.5, 2.5 )
695 show_dhudmessage( id, "ALERT! %s did a sc!", name )
696 }
697 #endif
698 g_pBestTouch[ id ] = ent1
699 if( !g_fixCheck[ id ][ ent1 ] )
700 {
701 g_playerTouched[ id ]++
702 if( g_playerTouched[ id ] > 1 )
703 {
704 for( new o = 1; o < g_playerTouched[ id ]; o++ )
705 {
706 if( ( ent1 - o ) > ( ent1 - g_playerTouched[ id ] ) )
707 {
708 g_fixCheck[ id ][ ent1-o ] = false
709 }
710 }
711 }
712 if( ent[ g_mPos ] == ent1 && !teleporting_p[ id ] )
713 {
714 client_print( 0, print_console, "The winner touched last marker: %d", ent1 )
715
716 get_players( players, playerNum, "a" )
717 for( new i = 0; i < playerNum; i++ )
718 {
719 if( pWant_duel[ players[ i ] ] )
720 {
721 remove_task( players[ i ] )
722 finish_Cup( players[ i ] )
723 }
724 }
725 }
726
727 }
728 g_fixCheck[ id ][ ent1 ] = true
729 }
730 return PLUGIN_CONTINUE
731}
732public duel_open_pre( id )
733{
734 if( allWant_duel )
735 {
736 ColorChat( id, GREY, "^4[CUP]^1 It's already started, wait some moments." )
737 return PLUGIN_HANDLED
738 }
739 new g_TimeCup_text[ 150 ]; formatex( g_TimeCup_text, 149, "Time of the battle:\y %d minutes^n^n%s", g_TimeCup, g_mPos > 0 ? "\r- With markers \d/cup15 gets updated^n" :"\rWithout markers \djust 4 fun, no winner^n" )
740 new menu = menu_create( "Start the cup!^n\dVersion: 2.3", "cupHandled" )
741
742 menu_additem( menu, g_TimeCup_text )
743
744 menu_additem( menu, "\yStart your cup!" )
745
746 menu_display( id, menu, 0 )
747
748 return PLUGIN_CONTINUE
749}
750public cupHandled( id, menu, item )
751{
752 if( d_started || allWant_duel )
753 {
754 ColorChat( id, BLUE, "^4[CUP]^1 Sorry, cup is already started." )
755 menu_destroy( menu )
756 return PLUGIN_HANDLED
757 }
758
759 switch( item )
760 {
761 case 0:
762 {
763 switch( g_TimeCup )
764 {
765 case 1:
766 {
767 g_TimeCup += 1
768 duel_open_pre( id )
769 }
770 case 2:
771 {
772 g_TimeCup += 1
773 duel_open_pre( id )
774 }
775 case 3:
776 {
777 g_TimeCup = 5
778 duel_open_pre( id )
779 }
780 case 5:
781 {
782 g_TimeCup = 7
783 duel_open_pre( id )
784 }
785 case 7:
786 {
787 g_TimeCup = 1
788 duel_open_pre( id )
789 }
790 }
791 }
792 case 1:
793 {
794 duel_open( id )
795 }
796 }
797 menu_destroy( menu )
798 return PLUGIN_HANDLED
799}
800public duel_open( id )
801{
802 get_user_name( id, g_StartedName, charsmax( g_StartedName ) )
803
804 pWant_duel[ id ] = true
805 g_pInCup++
806
807 allWant_duel = true
808 fPrepareTime = get_gametime()
809
810 ColorChat( 0, BLUE, "^4[CUP]^1 Cup started by:^4 %s^1 %dmin.^4 15sec^1 waiting for others to join...", g_StartedName, g_TimeCup )
811 set_task( 15.0, "kraj_open", id )
812
813 get_players( players, playerNum, "a" )
814 for( new i=0; i < playerNum; i++ )
815 count_Start( players[ i ] )
816}
817public count_Start( id )
818{
819 if( !is_user_connected( id ) )
820 return PLUGIN_HANDLED
821
822 new poruka[55]
823 format( poruka, charsmax( poruka ), "%s's CUP, say /joincup; Remaining: %.01f", g_StartedName, stime[ id ] )
824
825 static msgStatusText=0;
826 if(!msgStatusText)
827 msgStatusText = get_user_msgid("StatusText");
828
829 stime[ id ] -= 0.1
830 if( stime[ id ] >= 0 )
831 {
832 message_begin(MSG_ONE_UNRELIABLE, msgStatusText, _, id);
833 write_byte(0);
834 write_string(poruka);
835 message_end();
836 set_task( 0.1, "count_Start", id )
837 }
838 else
839 {
840 message_begin(MSG_ONE_UNRELIABLE, msgStatusText, _, id);
841 write_byte(0);
842 write_string("");
843 message_end();
844 stime[ id ] = 15.0
845 }
846 return PLUGIN_CONTINUE
847}
848
849public join_duel( id )
850{
851 new name[ 32 ], Float: get_timing, Float: pred_polazak
852 get_user_name( id, name, charsmax( name ) )
853
854 if( pWant_duel[ id ] )
855 return PLUGIN_HANDLED
856
857 get_timing = get_gametime() - fPrepareTime
858 if( get_timing >= 15.0 && d_started)
859 {
860 ColorChat( id, GREY, "^4[CUP]^1 Someone is already playing,^3 wait or go /spec ;)" )
861 return PLUGIN_HANDLED
862 }
863 else
864 {
865 pred_polazak = 15.0 - get_timing
866 set_task( pred_polazak, "pocetak_CUPa", id )
867 return PLUGIN_HANDLED
868 }
869
870 if( allWant_duel && !d_started )
871 {
872 pWant_duel[ id ] = true
873 g_pInCup++
874 ColorChat( 0, BLUE, "^4[CUP]^3 %s^1 joined! Cup name:^4 %s", name, g_StartedName )
875 return PLUGIN_HANDLED
876 }
877 if( !allWant_duel )
878 {
879 ColorChat( id, BLUE, "^4[CUP]^1 No one started, go /startcup." )
880 return PLUGIN_HANDLED
881 }
882 return PLUGIN_HANDLED
883}
884public kraj_open( id )
885{
886 if( g_pInCup <= 1 )
887 {
888 ColorChat( id, BLUE, "^1[CUP] No enought players, sorry." )
889 }
890 else
891 {
892 set_dhudmessage( 255, 85, 0, -1.0, 0.4, 0, 2.5, 2.5 )
893 show_dhudmessage( id, "It's starting BOIIIZ ! GL !^nPlayers: %d", g_pInCup )
894 pocetak_CUPa( id )
895 }
896}
897public pocetak_CUPa( id )
898{
899 if( pWant_duel[ id ] )
900 {
901 SendCmd_1( id, "say /start" )
902
903 set_task( 0.1, "frozen", id )
904 ColorChat( id, BLUE, "^4[CUP]^1 Starts in 5....4....3....." )
905
906 set_user_rendering(id, kRenderFxGlowShell, r, g, b, kRenderNormal, 8)
907 d_started = true
908 set_task( 5.0, "start_CUP", id )
909 find_origin = false
910 }
911}
912public frozen( id )
913{
914 fm_set_user_frozen( id, 1 )
915
916 ScreenFade( id )
917}
918
919public start_CUP( id )
920{
921 new Float: originp[ 3 ]
922 entity_get_vector( id, EV_VEC_origin, originp )
923 g_timetime[ id ] = 60*g_TimeCup
924 originp[2]+=40.0
925 entity_set_origin( id, originp )
926 timer( id )
927 fm_set_user_frozen( id, 0 )
928 set_pev( id, pev_velocity, Float:{0.0, 0.0, 0.0} );
929 engfunc( EngFunc_SetSize, id, {-16.0, -16.0, -18.0 }, { 16.0, 16.0, 32.0 } );
930 ColorChat( id, BLUE, "^4[CUP]^1 Started ! GL & HF !^4 %dmin^1 remainig", g_TimeCup )
931 set_task( 60.0*g_TimeCup, "finish_Cup", id )
932}
933public exitCup( id )
934{
935 if( pWant_duel[ id ] )
936 {
937 new name[ 32 ]; get_user_name( id, name, charsmax( name ) )
938 if( d_started )
939 {
940 g_pInCup -= 1
941 pWant_duel[ id ] = false
942
943 remove_task( id )
944 if( g_pInCup <= 1 )
945 {
946 real_end( id )
947 ColorChat( 0, GREY, "^4[CUP]^1 All players left the cup, you can^4 /startcup^1 now" )
948 }
949 else
950 ColorChat( 0, RED, "^4[CUP]^1 One player left the cup:^3 %s", name )
951 set_user_rendering( id )
952 }
953 else
954 {
955 pWant_duel[ id ] = false
956 remove_task( id )
957 }
958 }
959 else
960 {
961 client_print( id, print_chat, "[CUP] From where to exit lol ?" )
962 }
963 return PLUGIN_HANDLED
964}
965
966public finish_Cup( id )
967{
968 teleporting_p[ id ] = true
969 set_user_rendering( id ) //reset glow
970 g_pNumber = g_pInCup
971 fm_set_user_frozen( id, 1 )
972 ScreenFade( id )
973 remove_task( id )
974
975 if( !find_origin )//must be executed once per cup
976 {
977 Find_origins()
978 find_origin = true
979
980 if( g_mPos > 2 )
981 winner()
982 }
983 SendCmd_1( id, "say /start" )
984
985 set_task( 4.0, "teleport_origin", id + TASK_TELEPORT )
986
987 set_task( 4.0*g_pNumber+4.0, "real_end", id ) //real finish
988}
989public Find_origins()
990{
991 new id, x=0
992 get_players( players, playerNum, "a" )
993
994 for( new i = 0; i < playerNum; i++ )
995 {
996 id = players[ i ]
997 if( pWant_duel[ id ] )
998 {
999 entity_get_vector( id, EV_VEC_origin, origins[ id ] )
1000
1001 get_user_name( id, spec_nick[ id ], charsmax( spec_nick[] ) )
1002 p_inDuel[ x++ ] = id //thanks kushfield
1003
1004 }
1005 }
1006}
1007public teleport_origin( id )
1008{
1009 id = id - TASK_TELEPORT;
1010
1011 engfunc( EngFunc_SetOrigin, id, origins[ p_inDuel[ currentPlayer[ id ]]] )
1012
1013 set_dhudmessage( 255, 85, 0, -1.0, 0.4, 0, 2.5, 2.5 )
1014 show_dhudmessage( id, "Teleported to: %s", spec_nick[ p_inDuel[ currentPlayer[ id ]]] )
1015 currentPlayer[ id ]++
1016
1017 if( g_pInCup > currentPlayer[ id ] )
1018 set_task( 4.0, "teleport_origin", id+ TASK_TELEPORT )
1019}
1020public real_end( id )
1021{
1022 set_dhudmessage( 255, 85, 0, -1.0, 0.4, 0, 3.0, 3.0)
1023 show_dhudmessage( id, "THE END! Players: %d^nWe are sorry if the winner is not the choosen player ! :)", g_pNumber )
1024 ColorChat( id, BLUE, "^4[CUP]^1 It's finished^1 GG ! For another one, go ^4/startcup^1 !" )
1025 d_started = false
1026 g_pInCup = 0
1027 //g_pNumber = 0
1028 pWant_duel[ id ] = false
1029 allWant_duel = false
1030 g_StartedName = ""
1031 fm_set_user_frozen( id, 0 )
1032 remove_task( id )
1033 teleporting_p[ id ] = false
1034 client_cmd( id, "say /start" )
1035 g_TimeCup = 1
1036 find_origin = false
1037 currentPlayer[ id ] = 0
1038
1039 g_playerTouched[ id ] = 0
1040 g_pBestTouch[ id ] = 0
1041 for( new o = 1; o <= g_mPos; o++ )
1042 {
1043 g_fixCheck[ id ][ ent[ g_mPos - o ] ] = false
1044 }
1045 g_fixCheck[ id ][ ent[ g_mPos ] ] = false
1046}
1047stock fm_set_user_frozen(client, frozen)
1048{
1049 if( !is_user_alive(client) ) return 0;
1050
1051 new flags = pev(client, pev_flags);
1052 if( frozen && !(flags & FL_FROZEN) )
1053 {
1054 set_pev(client, pev_flags, (flags | FL_FROZEN))
1055
1056 }
1057 else if( !frozen && (flags & FL_FROZEN) )
1058 {
1059 set_pev(client, pev_flags, (flags & ~FL_FROZEN));
1060 }
1061
1062 return 1;
1063}
1064
1065public ScreenFade(id )
1066{
1067 message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
1068 write_short((1<<10)*4)
1069 write_short((1<<10)*15)
1070 write_short(0x0000)
1071 write_byte(150)
1072 write_byte(100)
1073 write_byte(5)
1074 write_byte(90)
1075 message_end()
1076}
1077stock SendCmd_1( id , text[] ) //cuz filtercmd 1
1078{
1079 message_begin( MSG_ONE, 51, _, id )
1080 write_byte( strlen(text) + 2 )
1081 write_byte( 10 )
1082 write_string( text )
1083 message_end()
1084}