· 6 years ago · Apr 07, 2019, 07:54 PM
1#include <amxmodx>
2#include <amxmisc>
3#include <hamsandwich>
4#include <engine>
5#include <fun>
6#include <colorchat>
7#include <fakemeta>
8#include <cstrike>
9
10native kz_finished_map( id, Float: kztime, cp, tp )
11native Float: get_user_airaccelerate( id )
12
13#define PLUGIN "PrimeKZ"
14#define VERSION "1.0"
15#define AUTHOR "JocA"
16
17#define TASK_TIMER 912
18#define TASK_HOOK 1000
19
20new const FL_ONGROUND2 = ( FL_ONGROUND | FL_PARTIALGROUND | FL_INWATER | FL_CONVEYOR | FL_FLOAT )
21
22new bool: g_bStart[ 33 ]
23new bool: g_Paused[ 33 ]
24new bool: g_timeStarted[ 33 ]
25new bool: g_bCpAlternate[ 33 ]
26new bool: HealsOnMap
27new bool: g_bIsUsingHook[ 33 ]
28
29new Float: g_fTime[ 33 ]
30new Float: g_fPauseTime[ 33 ]
31new Float: Checkpoints[33][2][3]
32new Float: g_fStartOrigin[ 33 ][ 3 ]
33new Float:antihookcheat[ 33 ]
34
35new g_iCheckpoints[ 33 ]
36new g_iGochecks[ 33 ]
37
38new Trie: g_tStarts
39new Trie: g_tStops
40
41new g_iHookOrigin[ 33 ][ 3 ]
42new g_iHookWallOrigin[ 33 ][ 3 ]
43new Float: g_fHookO[ 33 ][ 3 ]
44
45new g_szMapName[ 32 ]
46
47new g_Hook_BeamSprite
48
49public plugin_init()
50{
51 register_plugin( PLUGIN, VERSION, AUTHOR )
52
53 register_clcmd( "say /cp", "Checkpoint" )
54 register_clcmd( "say /tp", "GoCheck" )
55 register_clcmd( "say /stuck", "Stuck" )
56 register_clcmd( "say /reset", "ResetTimer" )
57 register_clcmd( "say /pause", "Pause" )
58 register_clcmd( "say /setstart", "SetStart" )
59 register_clcmd( "say /cs", "SetStart" )
60 register_clcmd( "say /start", "start" )
61 register_clcmd( "say /nc", "NoClip" )
62 register_clcmd( "say /menu", "MenuMain" )
63 register_clcmd( "say /gm", "GodMode" )
64 register_clcmd( "say /godmode", "GodMode" )
65 register_clcmd( "say /spec", "ClCmd_ChangeTeam" )
66 register_clcmd( "say /ct", "ClCmd_ChangeTeam" )
67
68 register_clcmd( "say /myaa", "showaa" )
69
70 register_concmd("+hook","ConCmd_Hook_Enabled")
71 register_concmd("-hook","ConCmd_Hook_Disabled")
72
73 register_message(get_user_msgid("VGUIMenu"), "Message_VGUIMenu")
74 register_message(get_user_msgid("ShowMenu"), "Message_ShowMenu")
75
76 RegisterHam( Ham_Use, "func_button", "fwdUse", 0 )
77 RegisterHam( Ham_Spawn, "player", "FwdHamPlayerSpawn", 1 )
78 RegisterHam( Ham_Killed, "player", "Ham_CBasePlayer_Killed_Post", 1 )
79
80 get_mapname( g_szMapName, charsmax( g_szMapName ) )
81
82 g_tStarts = TrieCreate()
83 g_tStops = TrieCreate()
84
85 new const szStarts[ ][ ] =
86 {
87 "counter_start", "clockstartbutton", "firsttimerelay", "but_start", "counter_start_button",
88 "multi_start", "timer_startbutton", "start_timer_emi", "gogogo"
89 }
90
91 new const szStops[ ][ ] =
92 {
93 "counter_off", "clockstopbutton", "clockstop", "but_stop", "counter_stop_button",
94 "multi_stop", "stop_counter", "m_counter_end_emi"
95 }
96
97 for( new i = 0; i < sizeof szStarts; i++ )
98 TrieSetCell( g_tStarts, szStarts[ i ], 1 )
99
100 for( new i = 0; i < sizeof szStops; i++ )
101 TrieSetCell( g_tStops, szStops[ i ], 1 )
102
103 //set_task( 1.0, "set_tasking", TASK_SPEC, .flags = "b" )
104
105 register_forward( FM_GetGameDescription, "fwd_GetGameDescription" )
106}
107public fwd_GetGameDescription()
108{
109 forward_return( FMV_STRING, "PrimeKZ FULL" )
110 set_task( 60.0, "fwd_GetGameDescription" )
111 return FMRES_SUPERCEDE;
112}
113public showaa( id )
114{
115 client_print( id, print_chat, "your AA: %.02f", get_user_airaccelerate( id ) )
116}
117public plugin_natives()
118{
119 register_native( "is_user_started", "_is_user_started", 1 )
120}
121public plugin_precache()
122{
123 g_Hook_BeamSprite = precache_model("sprites/plasma.spr")
124 RegisterHam( Ham_Spawn, "func_door", "FwdHamDoorSpawn", 1 )
125}
126
127public fwdUse(ent, id)
128{
129 if( !ent || id > 32 || !is_user_alive( id ) )
130 {
131 return HAM_IGNORED;
132 }
133 new name[32]
134 get_user_name( id, name, 31 )
135
136 new szTarget[ 32 ]
137 pev( ent, pev_target, szTarget, 31 )
138
139 if( TrieKeyExists( g_tStarts, szTarget ) )
140 {
141 if ( get_gametime() - antihookcheat[id] < 3.0 )
142 {
143 ColorChat( id, RED, "^4[PrimeKZ]^1 You must^3 wait 3 sec^1 after using hook/noclip!" )
144 return HAM_IGNORED;
145 }
146
147 remove_task( id + TASK_TIMER )
148 g_Paused[ id ] = false
149 g_iCheckpoints[ id ] = 0
150 g_iGochecks[ id ] = 0
151 g_timeStarted[ id ] = true
152
153 g_fTime[ id ] = get_gametime()
154
155 ColorChat( id, BLUE, "^4[PrimeKZ]^3 Timer started!" )
156
157 if( callfunc_begin("enableBot", "prime_demo.amxx") == 1 )
158 {
159 callfunc_push_int( id );
160 callfunc_end();
161 }
162
163 set_task( 1.0, "ShowTime", id + TASK_TIMER, .flags = "b" )
164
165 }
166 if( TrieKeyExists( g_tStops, szTarget ) )
167 {
168
169
170 /*if( callfunc_begin("finishBot", "prime_demo.amxx") == 1 )
171 {
172 callfunc_push_int( id );
173 callfunc_end();
174 }
175 if( callfunc_begin("enableBot", "prime_demo.amxx") == 1 )
176 {
177 callfunc_push_int( id );
178 callfunc_end();
179 } */
180 if( g_timeStarted[id] )
181 {
182 new cl_aa = floatround( get_user_airaccelerate( id ), floatround_round )
183 if( g_iGochecks[ id ] > 0 )
184 ColorChat( 0, BLUE, "^4[PrimeKZ]^3 %n^1 finished in^3 %s^1 [%d/%d]^4 AA = %d^1 !", id, StringTimer( get_gametime() - g_fTime[ id ] ), g_iCheckpoints[ id ], g_iGochecks[ id ], cl_aa )
185 else
186 ColorChat( 0, BLUE, "^4[PrimeKZ]^3 %n^1 finished in^3 %s^1 sec^4 AA = %d^1 !", id, StringTimer( get_gametime() - g_fTime[ id ] ), cl_aa )
187
188 kz_finished_map( id, get_gametime() - g_fTime[ id ], g_iCheckpoints[ id ], g_iGochecks[ id ] )
189 g_timeStarted[ id ] = false
190 g_iCheckpoints[ id ] = 0
191 }
192 else
193 ColorChat( id, RED, "^4[PrimeKZ]^1 Timer not started" )
194
195
196 }
197 return HAM_IGNORED
198}
199public Checkpoint( id )
200{
201 if( !is_user_alive( id ) )
202 {
203 return PLUGIN_HANDLED
204 }
205 if( !( pev( id, pev_flags ) & FL_ONGROUND2 ) ) //add ladder
206 {
207 return PLUGIN_HANDLED
208 }
209
210 if( g_Paused[id] )
211 {
212 return PLUGIN_HANDLED
213 }
214
215 pev(id, pev_origin, Checkpoints[id][g_bCpAlternate[id] ? 1 : 0])
216 g_bCpAlternate[id] = !g_bCpAlternate[id]
217 g_iCheckpoints[ id ]++
218
219 set_dhudmessage( 255, 70, 0, 0.85, 0.80, 0, 0.5, 2.0, 0.0, 0.0 )
220 show_dhudmessage( id, "Checkopint" )
221
222 return PLUGIN_HANDLED
223}
224public GoCheck( id )
225{
226 if( !is_user_alive( id ) || !g_iCheckpoints[ id ] )
227 {
228 return PLUGIN_HANDLED
229 }
230 if( g_Paused[ id ] )
231 {
232 ColorChat( id, GREY, "^4[PrimeKZ]^3 Not possible while in pause" )
233 return PLUGIN_HANDLED
234 }
235 set_pev( id, pev_velocity, Float:{0.0, 0.0, 0.0} );
236 set_pev( id, pev_view_ofs, Float:{ 0.0, 0.0, 12.0 } );
237 set_pev( id, pev_flags, pev(id, pev_flags) | FL_DUCKING );
238 set_pev( id, pev_fuser2, 0.0 );
239 engfunc( EngFunc_SetSize, id, {-16.0, -16.0, -18.0 }, { 16.0, 16.0, 32.0 } );
240 set_pev(id, pev_origin, Checkpoints[ id ][ !g_bCpAlternate[id] ] )
241 g_iGochecks[ id ]++
242
243
244 return PLUGIN_HANDLED
245}
246public Stuck( id )
247{
248 if( !is_user_alive( id ) || g_iCheckpoints[ id ] < 2 )
249 {
250 return PLUGIN_HANDLED
251 }
252 set_pev( id, pev_velocity, Float:{0.0, 0.0, 0.0} )
253 set_pev( id, pev_view_ofs, Float:{ 0.0, 0.0, 12.0 })
254 set_pev( id, pev_flags, pev(id, pev_flags) | FL_DUCKING )
255 set_pev( id, pev_fuser2, 0.0 )
256 engfunc( EngFunc_SetSize, id, {-16.0, -16.0, -18.0 }, { 16.0, 16.0, 32.0 } )
257 set_pev(id, pev_origin, Checkpoints[id][g_bCpAlternate[id]] )
258 g_bCpAlternate[ id ] = !g_bCpAlternate[id];
259 g_iCheckpoints[ id ]++
260
261 return PLUGIN_HANDLED;
262}
263public Pause( id )
264{
265 if( !is_user_alive( id ) || !g_timeStarted[ id ] )
266 return PLUGIN_HANDLED
267
268 if( !g_Paused[ id ] )
269 {
270 g_Paused[ id ] = true
271 g_fPauseTime[ id ] = get_gametime() - g_fTime [ id ]
272 g_fTime[ id ] = 0.0
273
274 //ColorChat( id, BLUE, "time pause: %.02f", g_fPauseTime[ id ] )
275 if( !g_bIsUsingHook[ id ] )
276 set_pev(id, pev_flags, pev(id, pev_flags) | FL_FROZEN)
277 }
278 else
279 {
280 g_fTime[ id ] = get_gametime() - g_fPauseTime[ id ]
281 g_Paused[ id ] = false
282
283 if( g_fHookO[ id ][ 0 ] != 0 )
284 entity_set_origin( id, g_fHookO[ id ] )
285 else
286 set_pev( id, pev_flags, pev(id, pev_flags) & ~FL_FROZEN )
287
288 //ColorChat( id, RED, "Time now: %.02f", g_fPauseTime[ id ] )
289 remove_task( id + TASK_TIMER )
290 set_task( 1.0, "ShowTime", id + TASK_TIMER, .flags = "b" )
291 }
292 return PLUGIN_HANDLED
293}
294public ShowTime( task )
295{
296 new id = task - TASK_TIMER
297 new Float:kreedztime = get_gametime() - ( g_Paused[ id ] ? get_gametime() - g_fPauseTime[ id ] : g_fTime[ id ] )
298 kz_showtime_roundtime( id, floatround( kreedztime ) )
299
300 set_dhudmessage( 255, 70, 0, 0.62, 0.95, 0, 0.1, 1.0, 0.0, 0.0 )
301 if( !g_Paused[ id ] )
302 show_dhudmessage( id, "CP: %d - TP: %d", g_iCheckpoints[ id ], g_iGochecks[ id ] )
303 else
304 show_dhudmessage( id, "PAUSED" )
305}
306stock kz_showtime_roundtime( id, time )
307{
308 if( is_user_connected( id ) )
309 {
310 message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "RoundTime" ), _, id )
311 write_short( time + 1 )
312 message_end()
313 }
314}
315public _is_user_started( id )
316{
317 if( g_timeStarted[ id ] && g_fTime[ id ] > 0.0 )
318 {
319 return true
320 }
321 return false
322}
323public ResetTimer( id )
324{
325 remove_task( id + TASK_TIMER )
326 g_iCheckpoints[ id ] = 0
327 g_iGochecks[ id ] = 0
328 g_fTime[ id ] = 0.0
329 g_timeStarted[ id ] = false
330 g_Paused[ id ] = false
331 ColorChat( id, BLUE, "^4[PrimeKZ]^1 You have reset you time." )
332 return PLUGIN_HANDLED
333
334}
335public NoClip(id)
336{
337 if( !is_user_alive( id ) )
338 {
339 return PLUGIN_HANDLED;
340 }
341 new noclip = get_user_noclip( id );
342 antihookcheat[ id ] = get_gametime();
343
344 if( g_timeStarted[ id ] && !g_Paused[ id ] )
345 {
346 entity_get_vector( id, EV_VEC_origin, g_fHookO[ id ] )
347 g_bIsUsingHook[ id ] = true
348 Pause( id )
349
350 ColorChat( id, BLUE, "^4[PrimeKZ]^1 Your time is paused, because of^3 /noclip" )
351 }
352 set_user_noclip(id, noclip ? false : true);
353
354 return PLUGIN_HANDLED;
355}
356public GodMode(id)
357{
358 if(!is_user_alive(id))
359 {
360 return PLUGIN_HANDLED
361 }
362
363 new godmode = !get_user_godmode(id)
364 set_user_godmode(id, godmode)
365
366
367 return PLUGIN_HANDLED
368}
369public SetStart( id )
370{
371 g_bStart[ id ] = true
372 entity_get_vector( id, EV_VEC_origin, g_fStartOrigin[ id ] )
373 ColorChat( id, BLUE, "^4[PrimeKZ]^1 You have set your^3 custom start^1" )
374 return PLUGIN_HANDLED
375}
376public start( id )
377{
378 if( g_bStart[ id ] )
379 {
380 set_pev(id, pev_velocity, Float:{0.0, 0.0, 0.0})
381 set_pev( id, pev_flags, pev(id, pev_flags) | FL_DUCKING )
382 entity_set_origin( id, g_fStartOrigin[ id ] )
383 ResetTimer( id )
384 }
385 else
386 {
387 ExecuteHamB(Ham_CS_RoundRespawn, id);
388 ColorChat( id, RED, "^4[PrimeKZ]^3 You dont have your start.^1 Write^4 /setstart^1, or from^4 /menu^1." )
389 }
390
391 return PLUGIN_HANDLED
392}
393public MenuMain( id )
394{
395 new menu = menu_create( "Prime Kreedz Menu^n\dEnjoy bro!", "menu_handler" )
396
397 menu_additem( menu, "Checkpoint" )
398 menu_additem( menu, "Gocheck" )
399 menu_additem( menu, "Go to start^n\d____ ___ __ _ ^n" )
400 menu_additem( menu, "Set your start" )
401 menu_additem( menu, "Noclip" )
402 //menu_additem( menu, "Go to finish" )
403
404 menu_display( id, menu )
405 return PLUGIN_HANDLED
406}
407public menu_handler( id, menu, item )
408{
409 switch( item )
410 {
411 case 0: Checkpoint( id )
412 case 1: GoCheck( id )
413 case 2: start( id )
414 case 3: SetStart( id )
415 case 4: NoClip( id )
416 //case 5: client_print( id, print_chat, "You are at the end timer" )
417 case MENU_EXIT:
418 {
419 menu_destroy( menu )
420 return PLUGIN_HANDLED
421 }
422 }
423 menu_destroy( menu )
424 MenuMain( id )
425 return PLUGIN_CONTINUE
426}
427public ClCmd_ChangeTeam(id)
428{
429 new CsTeams:team = cs_get_user_team(id);
430 if(team == CS_TEAM_CT || !team)
431 {
432 strip_user_weapons(id);
433 user_silentkill(id);
434 cs_set_user_team(id, CS_TEAM_SPECTATOR);
435
436 set_pev(id, pev_movetype, MOVETYPE_FLY);
437 set_pev(id, pev_effects, EF_NODRAW);
438 set_pev(id, pev_deadflag, DEAD_DEAD);
439 }
440 else if(team == CS_TEAM_SPECTATOR )
441 {
442 cs_set_user_team(id, CS_TEAM_CT);
443 set_pev(id, pev_effects, 0);
444 set_pev(id, pev_movetype, MOVETYPE_WALK);
445 set_pev(id, pev_deadflag, DEAD_RESPAWNABLE)
446 set_pev(id, pev_flags, pev(id, pev_flags) | FL_FROZEN)
447 set_pev(id, pev_takedamage, DAMAGE_AIM);
448
449 cs_set_user_team(id, CS_TEAM_CT);
450
451 set_pev(id, pev_effects, 0);
452 set_pev(id, pev_movetype, MOVETYPE_WALK);
453 set_pev(id, pev_deadflag, DEAD_NO)
454 ExecuteHamB(Ham_CS_RoundRespawn, id);
455 cs_set_user_deaths(id, 0);
456 }
457 return PLUGIN_HANDLED;
458}
459
460public FwdHamDoorSpawn( iEntity )
461{
462 static const szNull[ ] = "common/null.wav";
463
464 new Float:flDamage;
465 pev( iEntity, pev_dmg, flDamage );
466
467 if( flDamage < -999.0 ) {
468 set_pev( iEntity, pev_noise1, szNull );
469 set_pev( iEntity, pev_noise2, szNull );
470 set_pev( iEntity, pev_noise3, szNull );
471
472 if( !HealsOnMap )
473 HealsOnMap = true
474 }
475}
476public FwdHamPlayerSpawn( id )
477{
478 if( is_user_alive( id ) && HealsOnMap )
479 set_user_health(id, 50175)
480}
481public ConCmd_Hook_Enabled(id)
482{
483 if(is_user_alive(id))
484 {
485 antihookcheat[ id ] = get_gametime()
486 if(!g_bIsUsingHook[id])
487 {
488 get_user_origin( id, g_iHookOrigin[id], 3);
489 g_bIsUsingHook[id] = true;
490
491 Hook_Task(id + TASK_HOOK);
492 set_task(0.1, "Hook_Task", id + TASK_HOOK, _, _, "b");
493 }
494 if( g_timeStarted[ id ] && !g_Paused[ id ] )
495 {
496 entity_get_vector( id, EV_VEC_origin, g_fHookO[ id ] )
497 Pause( id )
498
499 ColorChat( id, BLUE, "^4[PrimeKZ]^1 Your time is paused, because of^3 +hook" )
500 }
501 }
502 return PLUGIN_HANDLED;
503}
504
505public ConCmd_Hook_Disabled(id)
506{
507 remove_task(id + TASK_HOOK);
508
509 message_begin(MSG_BROADCAST, SVC_TEMPENTITY); {
510 write_byte(TE_KILLBEAM);
511 write_short(id);
512 }
513 message_end();
514
515 g_bIsUsingHook[id] = false;
516 return PLUGIN_HANDLED;
517}
518public Hook_Task(id)
519{
520 id-= TASK_HOOK;
521
522 if(!is_user_alive(id))
523 {
524 ConCmd_Hook_Disabled(id);
525 return;
526 }
527
528 message_begin(MSG_BROADCAST, SVC_TEMPENTITY); {
529 write_byte(TE_KILLBEAM);
530 write_short(id);
531 }
532 message_end();
533
534 message_begin(MSG_BROADCAST, SVC_TEMPENTITY); {
535 write_byte(TE_BEAMENTPOINT);
536 write_short(id);
537 write_coord(g_iHookOrigin[id][0]); // origin
538 write_coord(g_iHookOrigin[id][1]); // origin
539 write_coord(g_iHookOrigin[id][2]); // origin
540 write_short(g_Hook_BeamSprite); // sprite index
541 write_byte(1); // start frame
542 write_byte(1); // framerate
543 write_byte(2); // life
544 write_byte(18); // width
545 write_byte(0); // noise
546 write_byte(0); // r
547 write_byte(255); // g
548 write_byte(0); // b
549 write_byte(200); // brightness
550 write_byte(0); // speed
551 }
552 message_end();
553
554 static origin[3], Float:velocity[3], distance, i;
555 get_user_origin( id, origin )
556
557 //g_fHook
558 distance = get_distance(g_iHookOrigin[id], origin);
559
560 set_pev(id , pev_gaitsequence , 6);
561 if(distance > 100)
562 {
563 if(vector_length(Float:g_iHookWallOrigin[id]))
564 {
565 arrayset(g_iHookWallOrigin[id], 0, sizeof(g_iHookWallOrigin[]));
566 }
567 for(i = 0; i < 3; i++)
568 {
569 velocity[i] = (g_iHookOrigin[id][i] - origin[i]) * 700.0 / (distance + 20);
570 }
571 }
572 else if(distance > 20)
573 {
574 if(vector_length(Float:g_iHookWallOrigin[id]))
575 {
576 arrayset(g_iHookWallOrigin[id], 0, sizeof(g_iHookWallOrigin[]));
577 }
578 for(i = 0; i < 3; i++)
579 {
580 velocity[i] = (g_iHookOrigin[id][i] - origin[i]) * 350.0 / (distance + 20);
581 }
582 }
583 else
584 {
585 if(vector_length(Float:g_iHookWallOrigin[id]))
586 {
587 set_pev(id, pev_origin, g_iHookWallOrigin[id]);
588 velocity = Float:{0.0, 0.0, 0.0};
589 }
590 }
591 set_pev(id , pev_velocity, velocity);
592}
593public Message_VGUIMenu(msgId, dest, id)
594{
595 if( is_user_connected( id ) && get_msg_arg_int( 1 ) == 2)
596 {
597 new params[1];
598 params[0] = msgId;
599
600 set_task(0.1, "ForceAutoJoin_Task", id, params, sizeof(params));
601 return PLUGIN_HANDLED;
602 }
603 return PLUGIN_CONTINUE;
604}
605public Message_ShowMenu(msgId, dest, id)
606{
607 new menuCode[32];
608 get_msg_arg_string(4, menuCode, sizeof(menuCode) - 1);
609
610 if(containi(menuCode, "Team_Select") > 0)
611 {
612 new params[1];
613 params[0] = msgId;
614
615 set_task(0.1, "ForceAutoJoin_Task", id, params, sizeof(params));
616 return PLUGIN_HANDLED;
617 }
618 return PLUGIN_CONTINUE;
619}
620public ForceAutoJoin_Task(params[], id)
621{
622 new block = get_msg_block(params[0]);
623 set_msg_block(params[0], BLOCK_SET);
624
625 engclient_cmd(id, "jointeam", "2");
626 engclient_cmd(id, "joinclass", "5");
627
628 set_msg_block(params[0], block);
629}
630public Ham_CBasePlayer_Killed_Post(id)
631{
632 if( cs_get_user_team(id) == CS_TEAM_CT )
633 {
634 set_pev(id, pev_deadflag, DEAD_RESPAWNABLE)
635 }
636}
637stock StringTimer(const Float:flRealTime )
638{
639 new szOutPut[ 25 ]
640 static iMinutes, iSeconds, iMiliSeconds
641
642 iMinutes = floatround(flRealTime / 60, floatround_floor);
643 iSeconds = floatround(flRealTime - (iMinutes * 60), floatround_floor);
644 iMiliSeconds = floatround((flRealTime - (iMinutes * 60 + iSeconds)) * 100, floatround_floor);
645 formatex(szOutPut, charsmax( szOutPut ), "%02d:%02d.%02d", iMinutes, iSeconds, iMiliSeconds);
646 return szOutPut
647}
648#include <amxmodx>
649#include <amxmisc>
650#include <sqlx>
651#include <geoip>
652#include <colorchat>
653
654#define PLUGIN "PrimeKZ MySQL"
655#define VERSION "1.0"
656#define AUTHOR "JocA"
657
658native Float:get_user_airaccelerate( id )
659
660new Host[] = "localhost"
661new User[] = "root"
662new Pass[] = ""
663new Db[] = "primekz"
664
665new Handle:g_SqlTuple
666new g_Error[512]
667new Handle:SqlConnection
668
669new g_iPlayerID[ 33 ]
670new g_iPoints[ 33 ]
671new g_iAA[ 33 ]
672new bool:g_bLoaded[ 33 ]
673
674new g_bHasTime_10[ 33 ] // 0 = not in top, 1 = Pro aa10, 2 = nub aa10
675new g_bHasTime_100[ 33 ] //0 = not in top aa100, 1 = pro aa100, 2 = nub aa100
676new g_szMap[ 32 ]
677new g_iMID
678
679enum _:AAType
680{
681 cl_aa10,
682 cl_aa100
683}
684new Float: g_fProPersonal[ 33 ][ AAType ]
685new Float: g_fNubPersonal[ 33 ][ AAType ]
686
687new prime_host, prime_user, prime_pass, prime_db
688
689public plugin_init()
690{
691 register_plugin(PLUGIN, VERSION, AUTHOR)
692
693 set_task( 0.2, "MySql_Init" )
694
695 register_clcmd( "say /pbest", "show_pbest" )
696
697 register_clcmd( "say /pro15", "prime15_show" )
698
699 prime_host = register_cvar( "primekz_host", "" )
700 prime_user = register_cvar( "primekz_user", "" )
701 prime_pass = register_cvar( "primekz_pass", "" )
702 prime_db = register_cvar( "primekz_db", "" )
703
704 get_mapname( g_szMap, charsmax( g_szMap ) )
705
706}
707public prime15_show( id )
708{
709 show_motd( id, fmt( "http://localhost/primekz-test/pro10aa.php?&mid=%d", g_iMID ) )
710 return PLUGIN_HANDLED
711}
712public plugin_natives()
713{
714 register_native( "kz_finished_map", "_kz_finished_map", 1 )
715}
716public show_pbest( id )
717{
718 if( g_fProPersonal[ id ][ cl_aa10 ] > 0.0 )
719 client_print( id, print_console, "personal PRO aa10: %.02f", g_fProPersonal[ id ][ cl_aa10 ] )
720
721 if( g_fProPersonal[ id ][ cl_aa100 ] > 0.0 )
722 client_print( id, print_console, "personal PRO aa100: %.02f", g_fProPersonal[ id ][ cl_aa100 ] )
723 if( g_fNubPersonal[ id ][ cl_aa10 ] > 0.0 )
724 client_print( id, print_console, "personal NUB aa10: %.02f", g_fNubPersonal[ id ][ cl_aa10 ] )
725
726 if( g_fNubPersonal[ id ][ cl_aa100 ] > 0.0 )
727 client_print( id, print_console, "personal NUB aa100: %.02f", g_fNubPersonal[ id ][ cl_aa100 ] )
728}
729public MySql_Init()
730{
731 new cvar_host[ 50 ], cvar_user[ 50 ], cvar_pass[ 50 ], cvar_db[ 50 ]
732 get_pcvar_string( prime_host, cvar_host, charsmax( cvar_host ) )
733 get_pcvar_string( prime_user, cvar_user, charsmax( cvar_user ) )
734 get_pcvar_string( prime_pass, cvar_pass, charsmax( cvar_pass ) )
735 get_pcvar_string( prime_db, cvar_db, charsmax( cvar_db ) )
736
737 g_SqlTuple = SQL_MakeDbTuple( cvar_host, cvar_user, cvar_pass, cvar_db )
738 new ErrorCode
739 SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
740 if(SqlConnection == Empty_Handle)
741 set_fail_state(g_Error)
742 new Handle:Queries
743 Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `primekz_players`( \
744 id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\
745 steamid TEXT NOT NULL, \
746 nickname TEXT NOT NULL, \
747 ip TEXT NOT NULL, \
748 nationality TEXT NULL, \
749 country TEXT NULL, \
750 points INTEGER, \
751 player_aa INTEGER \
752 )");
753
754 if(!SQL_Execute(Queries))
755 {
756 SQL_QueryError(Queries,g_Error,charsmax(g_Error))
757 set_fail_state(g_Error)
758
759 }
760 SQL_FreeHandle(Queries)
761
762 Queries = SQL_PrepareQuery(SqlConnection, "CREATE TABLE IF NOT EXISTS `primekz_maps`( \
763 mid INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, \
764 mapname TEXT NOT NULL\
765 )");
766
767 if(!SQL_Execute(Queries))
768 {
769 SQL_QueryError(Queries,g_Error,charsmax(g_Error))
770 set_fail_state(g_Error)
771
772 }
773 SQL_FreeHandle(Queries)
774
775 Queries = SQL_PrepareQuery(SqlConnection, "CREATE TABLE IF NOT EXISTS `primekz_records`( \
776 rec_id INT(11) AUTO_INCREMENT PRIMARY KEY, \
777 id INT(11) NOT NULL,\
778 nick_rec TEXT NOT NULL,\
779 mid INT(11) , \
780 his_aa INT(11) NOT NULL, \
781 his_time FLOAT(6,2), \
782 cp INTEGER, \
783 tp INTEGER, \
784 ondate TEXT NOT NULL, \
785 FOREIGN KEY(id) REFERENCES `primekz_players`(id), \
786 FOREIGN KEY(mid)REFERENCES `primekz_maps`(mid) \
787 )");
788
789 if(!SQL_Execute(Queries))
790 {
791 SQL_QueryError(Queries,g_Error,charsmax(g_Error))
792 set_fail_state(g_Error)
793
794 }
795 SQL_FreeHandle(Queries)
796
797 SQL_FreeHandle(SqlConnection)
798
799 set_task( 0.2, "handleThatMap" )
800}
801public handleThatMap()
802{
803 new gszQuery[ 512 ]
804 formatex(gszQuery, charsmax(gszQuery),"SELECT mid FROM `primekz_maps` WHERE `mapname` = '%s '", g_szMap )
805 SQL_ThreadQuery(g_SqlTuple, "handleSelectMap", gszQuery);
806}
807public plugin_end()
808{
809 SQL_FreeHandle(g_SqlTuple)
810}
811public handleSelectMap(failstate, Handle:Query, error[], errnum, data[], size)
812{
813 if(failstate != TQUERY_SUCCESS){
814 log_amx("SQL Insert error: %s",error);
815 return;
816 }
817
818 if(SQL_NumRows(Query) < 1)
819 {
820 new gszQuery[ 512 ]
821 formatex(gszQuery, charsmax(gszQuery), "INSERT INTO `primekz_maps` VALUES ( '0', '%s' )" , g_szMap );
822 SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", gszQuery);
823
824
825 set_task( 0.2, "handleThatMap" )
826 }
827 else
828 {
829 g_iMID = SQL_ReadResult( Query, 0 )
830 //client_print( 0, print_console, "mapa je %d", g_iMID )
831 }
832
833}
834public client_putinserver( id )
835{
836 set_task( 0.1, "Load_MySql", id )
837 set_task( 0.2, "check_10", id )
838 //set_task( 0.4, "check_100", id )
839}
840public check_10( id )
841{
842 new Data[1]
843 Data[0] = id
844 new szTemp[ 512 ]
845 format(szTemp,charsmax(szTemp),"SELECT id, his_aa, his_time, tp FROM `primekz_records` WHERE `mid`='%d' AND `id`='%d'", g_iMID, g_iPlayerID[ id ])
846 SQL_ThreadQuery(g_SqlTuple,"checkMap",szTemp,Data,1)
847}
848public check_100( id )
849{
850 new Data[1]
851 Data[0] = id
852 new szTemp[ 512 ]
853 format(szTemp,charsmax(szTemp),"SELECT id, his_aa, his_time, tp FROM `primekz_records` WHERE `mid`='%d' AND `id`='%d' AND `his_aa` = 100", g_iMID, g_iPlayerID[ id ])
854 SQL_ThreadQuery(g_SqlTuple,"checkMap",szTemp,Data,1)
855}
856public checkMap(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
857{
858 if(FailState == TQUERY_CONNECT_FAILED)
859 {
860 log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
861 }
862 else if(FailState == TQUERY_QUERY_FAILED)
863 {
864 log_amx("Load Query failed. [%d] %s", Errcode, Error)
865 }
866
867 new id
868 id = Data[0]
869
870 if( SQL_NumResults(Query) < 1 )
871 {
872 g_bHasTime_10[ id ] = 0
873 g_bHasTime_100[ id ] = 0
874 }
875 else
876 {
877 while( SQL_MoreResults( Query ) )
878 {
879 if( SQL_ReadResult( Query, 3 ) > 0 )
880 {
881 if( SQL_ReadResult( Query, 1 ) == 10 )
882 {
883 g_bHasTime_10[ id ] = 2
884 SQL_ReadResult( Query, 2, g_fNubPersonal[ id ][ cl_aa10 ] )
885 }
886 else if( SQL_ReadResult( Query, 1 ) == 100 )
887 {
888 g_bHasTime_100[ id ] = 2
889 SQL_ReadResult( Query, 2, g_fNubPersonal[ id ][ cl_aa100 ] )
890 }
891 else
892 {
893 g_bHasTime_10[ id ] = 0
894 g_bHasTime_100[ id ] = 0
895 }
896
897 }
898 else if( SQL_ReadResult( Query, 3 ) == 0 )
899 {
900 if( SQL_ReadResult( Query, 1 ) == 10 )
901 {
902 g_bHasTime_10[ id ] = 1
903 SQL_ReadResult( Query, 2, g_fProPersonal[ id ][ cl_aa10 ] )
904 }
905 else if( SQL_ReadResult( Query, 1 ) == 100 )
906 {
907 g_bHasTime_100[ id ] = 2
908 SQL_ReadResult( Query, 2, g_fProPersonal[ id ][ cl_aa100 ] )
909 }
910 else
911 {
912 g_bHasTime_10[ id ] = 0
913 g_bHasTime_100[ id ] = 0
914 }
915 }
916 SQL_NextRow( Query )
917 }
918 //client_print( id, print_chat, "your ptime: %.02f", g_fPersonalBest[ id ] )
919 }
920}
921public Load_MySql(id)
922{
923 new szSteamId[32], szTemp[512]
924 get_user_authid(id, szSteamId, charsmax(szSteamId))
925
926 new Data[1]
927 Data[0] = id
928 format(szTemp,charsmax(szTemp),"SELECT * FROM `primekz_players` WHERE ( `primekz_players`.`steamid` = '%s' )", szSteamId)
929 SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
930}
931public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
932{
933 if(FailState == TQUERY_CONNECT_FAILED)
934 {
935 log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
936 }
937 else if(FailState == TQUERY_QUERY_FAILED)
938 {
939 log_amx("Load Query failed. [%d] %s", Errcode, Error)
940 }
941
942 new id
943 id = Data[0]
944
945 if(SQL_NumResults(Query) < 1)
946 {
947 new szSteamId[32]
948 get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
949
950 // if its still pending we can't do anything with it
951 if (equal(szSteamId,"ID_PENDING"))
952 return PLUGIN_HANDLED
953
954 new szTemp[512]
955 new g_ip[ 15 ], g_country[ 40 ]
956 new name[ 32 ]
957 // now we will insturt the values into our table.
958
959 get_user_name( id, name, charsmax( name ) )
960
961 SQL_PrepareString( name, name, charsmax( name ));
962
963 get_user_ip( id, g_ip, charsmax( g_ip ), 1 )
964 geoip_country_ex(g_ip, g_country, charsmax( g_country ), -1)
965
966 new szCode[ 5 ]
967
968 getNationality( id, g_ip, szCode);
969
970 format(szTemp,charsmax(szTemp),"INSERT INTO `primekz_players` VALUES ( '0','%s', '%s', '%s', '%s' ,'%s', '0', '10' )",szSteamId, name, g_ip, szCode, g_country)
971
972 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
973
974 set_task( 0.2, "Load_MySql", id )
975 }
976 else
977 {
978 g_iPlayerID[ id ] = SQL_ReadResult( Query, 0 )
979 g_iPoints[ id ] = SQL_ReadResult( Query, 6 )
980 g_iAA[ id ] = SQL_ReadResult( Query, 7 )
981 }
982 g_bLoaded[ id ] = true
983
984 return PLUGIN_HANDLED
985}
986getNationality(id, const szIP[], szCode[5]){
987 new szTemp[3];
988 if(geoip_code2_ex( szIP, szTemp)){
989 copy(szCode, 4, szTemp);
990 }
991 else{
992 get_user_info(id, "lang", szCode, 2);
993 SQL_PrepareString(szCode, szCode, 4);
994 }
995}
996stock SQL_PrepareString(const szQuery[], szOutPut[], size)
997{
998 copy(szOutPut, size, szQuery);
999 replace_all(szOutPut, size, "'", "\'");
1000 replace_all(szOutPut,size, "`", "\`");
1001 replace_all(szOutPut,size, "\\", "\\\\");
1002}
1003public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
1004{
1005 SQL_FreeHandle(Query)
1006
1007 return PLUGIN_HANDLED
1008}
1009public _kz_finished_map( id, Float: kztime, cp, tp )
1010{
1011 if( !g_bLoaded[ id ] )
1012 {
1013 client_print( id, print_console, "[SQL] Problem with your database, please contact any administrator" )
1014 return PLUGIN_HANDLED
1015 }
1016 else
1017 {
1018 new szTemp[ 512 ]
1019 new Data[1]
1020 Data[0] = id
1021
1022 new pAA = floatround( get_user_airaccelerate( id ), floatround_round )
1023
1024 if( tp > 0 )
1025 {
1026 if( pAA == 10 )
1027 {
1028 if( kztime > g_fNubPersonal[ id ][ 0 ] && g_fNubPersonal[ id ][ 0 ] > 0.0 )
1029 {
1030 ColorChat( id, RED, "^4[PrimeKZ]^1 Your personal best time is:^3 %s", StringTimer( g_fNubPersonal[ id ][ 0 ] ) )
1031 return PLUGIN_HANDLED
1032 }
1033 if( g_fNubPersonal[ id ][ 0 ] > 0.0 )
1034 {
1035 format(szTemp,charsmax(szTemp),"UPDATE `primekz_records` SET his_time='%.02f', cp='%d', tp='%d', ondate = NOW() WHERE id='%d' AND mid ='%d' AND his_aa = '10' AND tp > 0", kztime, cp, tp, g_iPlayerID[ id ],g_iMID )
1036 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp,Data,1)
1037
1038 }
1039 else
1040 //if( g_bHasTime_10[ id ] == 2 )
1041 {
1042 format(szTemp,charsmax(szTemp),"INSERT INTO `primekz_records` VALUES( '0', '%d', '%n', '%d', '%d', '%.02f', '%d', '%d', NOW() )", g_iPlayerID[ id ], id, g_iMID, pAA, kztime, cp, tp )
1043 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp,Data,1)
1044 g_bHasTime_10[ id ] = 2
1045 }
1046 g_fNubPersonal[ id ][ cl_aa10 ] = kztime
1047 }
1048 if( pAA == 100 )
1049 {
1050 if( kztime > g_fNubPersonal[ id ][ 1 ] && g_fNubPersonal[ id ][ 1 ] > 0.0 )
1051 {
1052 ColorChat( id, RED, "^4[PrimeKZ]^1 Your personal best time is:^3 %s", StringTimer( g_fNubPersonal[ id ][ 1 ] ) )
1053 return PLUGIN_HANDLED
1054 }
1055 if( g_fNubPersonal[ id ][ 1 ] > 0.0 )
1056 {
1057 format(szTemp,charsmax(szTemp),"UPDATE `primekz_records` SET his_time='%.02f', cp='%d', tp='%d', ondate = NOW() WHERE id='%d' AND mid ='%d' AND his_aa = '100' AND tp > 0", kztime, cp, tp, g_iPlayerID[ id ],g_iMID )
1058 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp,Data,1)
1059
1060 }
1061 else
1062 //if( g_bHasTime_100[ id ] == 2 )
1063 {
1064 format(szTemp,charsmax(szTemp),"INSERT INTO `primekz_records` VALUES( '0','%d', '%n', '%d', '%d', '%.02f', '%d', '%d', NOW() )", g_iPlayerID[ id ], id, g_iMID, pAA, kztime, cp, tp )
1065 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp,Data,1)
1066 g_bHasTime_100[ id ] = 2
1067 }
1068 g_fNubPersonal[ id ][ cl_aa100 ] = kztime
1069 }
1070 }
1071 else
1072 {
1073 if( pAA == 10 )
1074 {
1075 if( kztime > g_fProPersonal[ id ][ 0 ] && g_fProPersonal[ id ][ 0 ] > 0.0 )
1076 {
1077 ColorChat( id, RED, "^4[PrimeKZ]^1 Your personal best time is:^3 %s", StringTimer( g_fProPersonal[ id ][ 0 ] ) )
1078 return PLUGIN_HANDLED
1079 }
1080 if( g_fProPersonal[ id ][ 0 ] > 0.0 )
1081 {
1082 format(szTemp,charsmax(szTemp),"UPDATE `primekz_records` SET his_time='%.02f', ondate = NOW() WHERE id='%d' AND mid ='%d' AND his_aa = '10'", kztime, g_iPlayerID[ id ],g_iMID)
1083 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp,Data,1)
1084
1085 }
1086 //if( g_bHasTime_10[ id ] == 1 )
1087 else
1088 {
1089 format(szTemp,charsmax(szTemp),"INSERT INTO `primekz_records` VALUES( '0','%d', '%n', '%d', '%d', '%.02f', '%d', '%d', NOW() )", g_iPlayerID[ id ], id, g_iMID, pAA, kztime, cp, tp )
1090 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp,Data,1)
1091 g_bHasTime_10[ id ] = 1
1092 }
1093 g_fProPersonal[ id ][ cl_aa10 ] = kztime
1094 }
1095 else if( pAA == 100 )
1096 {
1097 if( kztime > g_fProPersonal[ id ][ 1 ] && g_fProPersonal[ id ][ 1 ] > 0.0 )
1098 {
1099 ColorChat( id, RED, "^4[PrimeKZ]^1 Your personal best time is:^3 %s", StringTimer( g_fProPersonal[ id ][ 1 ] ) )
1100 return PLUGIN_HANDLED
1101 }
1102 if( g_fProPersonal[ id ][ 1 ] > 0.0 )
1103 {
1104 format(szTemp,charsmax(szTemp),"UPDATE `primekz_records` SET his_time='%.02f', ondate = NOW() WHERE id='%d' AND mid ='%d' AND his_aa = '100'", kztime, g_iPlayerID[ id ],g_iMID)
1105 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp,Data,1)
1106
1107 }
1108 //else if( g_bHasTime_100[ id ] == 1 )
1109 else
1110 {
1111 format(szTemp,charsmax(szTemp),"INSERT INTO `primekz_records` VALUES( '0','%d', '%n', '%d', '%d', '%.02f', '%d', '%d', NOW() )", g_iPlayerID[ id ], id, g_iMID, pAA, kztime, cp, tp )
1112 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp,Data,1)
1113 g_bHasTime_100[ id ] = 1
1114 }
1115 g_fProPersonal[ id ][ cl_aa100 ] = kztime
1116 }
1117 }
1118 }
1119 return PLUGIN_CONTINUE
1120}
1121stock StringTimer(const Float:flRealTime )
1122{
1123 new szOutPut[ 25 ]
1124 static iMinutes, iSeconds, iMiliSeconds
1125
1126 iMinutes = floatround(flRealTime / 60, floatround_floor);
1127 iSeconds = floatround(flRealTime - (iMinutes * 60), floatround_floor);
1128 iMiliSeconds = floatround((flRealTime - (iMinutes * 60 + iSeconds)) * 100, floatround_floor);
1129 formatex(szOutPut, charsmax( szOutPut ), "%02d:%02d.%02d", iMinutes, iSeconds, iMiliSeconds);
1130 return szOutPut
1131}