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