jocasrb

KZ Markers/Levels

Dec 27th, 2019
2,433
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. Say commands:
  4.  
  5. .   /setcp
  6. .   /cpinfo
  7. .   /changecp
  8.  
  9. *Sprite model* REUPLOADED (7.7.2020.): https://drive.google.com/file/d/1ja13CWg6cP6cJKGSlcuaxZOf8-G2Cv4s/view?usp=sharing
  10.  
  11. big thanks for KpoluK from: https://kz-rush.ru/en/
  12. */
  13.  
  14.  
  15. #include <amxmodx>
  16. #include <amxmisc>
  17. #include <colorchat>
  18. #include <hamsandwich>
  19. #include <engine>
  20. #include <fakemeta>
  21.  
  22. #define PLUGIN "KZ Checkpoints/markers"
  23. #define VERSION "1.0"
  24. #define AUTHOR "JocA"
  25.  
  26. #define MAX_MARKERS 15
  27.  
  28. new g_Model[] = "sprites/kz_checkpoint.spr"
  29. new model
  30.  
  31. new bool: g_bStarted[ 33 ]
  32. new Float: g_fTime[ 33 ]
  33. new bool: g_bVisible
  34. new bool: g_bPVis[ 33 ]
  35.  
  36. new Float: g_fOrigin[ MAX_MARKERS ][ 3 ]
  37. new Float: saved_origin[ 3 ]
  38.  
  39. new g_mName[ MAX_MARKERS ][ 32 ]
  40. new saved_mName[ 32 ]
  41. new  mTime[ 10 ]
  42.  
  43. new g_nEnt[ MAX_MARKERS ]
  44. new ent_num
  45. new bool: g_makingIt = false
  46.  
  47. //new bool: g_bPlayerVis[ 33 ]
  48.  
  49. new Float:g_fMarkerTime[ MAX_MARKERS ]
  50.  
  51. new g_bPlayerMarker[ 33 ][ 1500 ]
  52. new playerTouched[ 33 ]
  53.  
  54. new Trie:g_tStarts
  55.  
  56. new saycmd[ 20 ]
  57. new forbiden_say[][] = { "say /start", "say_team /start", "say /nc", "say_team /nc", "say /godmode", "say_team /godmode",
  58.             "say /noclip", "say_team /noclip", "+hook", "-hook", "say /ct", "say /spec" }
  59.            
  60. new file[ 256 ], folder[ 100 ]
  61. new mapname[ 32 ]
  62.            
  63. public plugin_init()
  64. {
  65.     register_plugin( PLUGIN, VERSION, AUTHOR )
  66.     register_clcmd( "say /setcp", "create_menu" )
  67.     register_clcmd( "say /cpinfo", "cp_info" )
  68.     register_clcmd( "say /changecp", "change_cp" )
  69.  
  70.     g_makingIt = true
  71.    
  72.     RegisterHam( Ham_Use, "func_button", "fwdUse", 0 )
  73.    
  74.     g_tStarts = TrieCreate( )
  75.  
  76.     new const szStarts[][] =
  77.     {
  78.         "counter_start", "clockstartbutton", "firsttimerelay", "but_start", "counter_start_button",
  79.         "multi_start", "timer_startbutton", "start_timer_emi", "gogogo", "timer_start"
  80.     }
  81.     for( new i = 0; i < sizeof szStarts; i++ )
  82.         TrieSetCell( g_tStarts, szStarts[ i ], 1 )
  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.     new path[ 32 ]
  90.     get_mapname( mapname, charsmax( mapname ) )
  91.     get_configsdir( path, charsmax( path ) )
  92.     formatex( folder, charsmax( folder ), "%s/kz_checkpoints/", path )
  93.     formatex( file, charsmax( file ), "%s/%s.ini", folder, mapname )
  94.    
  95.     if( !dir_exists( folder ) )
  96.         mkdir( folder )
  97.        
  98.     set_task( 1.0, "load_cp" )
  99.     set_task( 220.0, "show_cp", .flags="b" )
  100. }
  101. public change_cp( id )
  102. {
  103.     g_bPVis[ id ] = !g_bPVis[ id ]
  104.     ColorChat( id, BLUE, "^4[KZ]^1 Markers are now^3 %svisible^1 for you", g_bPVis[ id ] ? "":"in" )
  105. }
  106. public show_cp()
  107. {
  108.     if( ent_num < 1 )
  109.         return
  110.        
  111.     ColorChat( 0, BLUE, "KZ-MARKERS^1 - To see all %d markers:^3 /cpinfo^1 | To change visibility: ^3/changecp", ent_num )
  112. }
  113. public cp_info( id )
  114. {
  115.     if( ent_num < 1 )
  116.         return
  117.    
  118.     client_print( id, print_console,"^nMarkers on this map %d^n", ent_num )
  119.     for( new i = 1; i <= ent_num; i++ )
  120.     {
  121.         new Float:timee = g_fMarkerTime[ i ]
  122.         new min, Float:sec
  123.         min=floatround(timee/60,floatround_floor);
  124.         sec=timee-min*60;
  125.         client_print( id, print_console,"#%d Time: %02d:%s%.02f by: %s", i, min, sec < 10 ? "0" : "",sec, g_mName[ i ] )
  126.     }
  127.     SendCmd_1( id, "toggleconsole" )
  128.    
  129. }
  130. public create_cp1( id )
  131. {
  132.     g_fMarkerTime[ 2 ] = 50.0
  133. }
  134. public plugin_precache()
  135. {
  136.     g_tStarts = TrieCreate();
  137.     precache_model( g_Model )
  138.     model = precache_model( "sprites/kz_checkpoint.spr" )
  139. }
  140. public forbiden( id )
  141. {
  142.     playerTouched[ id ] = 0
  143.     g_bStarted[ id ] = false
  144.    
  145.     arrayset( g_bPlayerMarker[ id ], 0, sizeof g_bPlayerMarker[] )
  146. }
  147. public create_menu( id )
  148. {
  149.     if( !( get_user_flags( id ) & ADMIN_LEVEL_C ) )
  150.         return PLUGIN_HANDLED
  151.        
  152.     new menu_text[ 100 ]; formatex( menu_text, charsmax( menu_text ), "Create Checkpoints^n\dCurrently:\y %d\d CPs^n^n\rPlease reset your time while making them", ent_num )
  153.     new menu = menu_create( menu_text, "menu_handle" )
  154.    
  155.     menu_additem( menu, "Create new checkpoint" )
  156.     menu_additem( menu, "Change CP visibility" )
  157.     menu_additem( menu, "Delete LAST CPs" )
  158.     menu_additem( menu, "Delete all CPs^n" )
  159.     menu_additem( menu, "\ySave all CPs" )
  160.    
  161.     menu_display( id, menu )
  162.     return PLUGIN_HANDLED
  163. }
  164. public menu_handle( id, menu, item )
  165. {
  166.     if( item == MENU_EXIT )
  167.     {
  168.         g_makingIt = false
  169.         menu_destroy( menu )
  170.         return PLUGIN_HANDLED
  171.     }
  172.     switch( item )
  173.     {
  174.         case 0:
  175.         {
  176.             create_cp( id, 0 )
  177.             g_makingIt = true
  178.             ColorChat( id, BLUE, "^4[KZ]^1 Whooop, whoop you made new marker!" )
  179.         }
  180.         case 1:
  181.         {
  182.             g_bVisible = !g_bVisible
  183.             for( new i = 1; i <= ent_num; i++ )
  184.             {
  185.                 if( !g_bVisible )
  186.                     set_pev( g_nEnt[ i ], pev_rendermode, kRenderTransAlpha )
  187.                 else
  188.                     set_pev( g_nEnt[ i ], pev_rendermode, kRenderNormal )
  189.             }
  190.         }
  191.         case 2:
  192.         {
  193.             delete_cp( id, 0 )
  194.             ColorChat( id, BLUE, "^4[KZ]^1 You removed last marker!" )
  195.         }
  196.         case 3:
  197.         {
  198.             delete_cp( id, 1 )
  199.             ColorChat( id, BLUE, "^4[KZ]^1 You removed all markers! Uuuups" )
  200.         }
  201.         case 4:
  202.         {
  203.             g_makingIt = false
  204.             save_cp( id )
  205.             ColorChat( id, BLUE, "^4[KZ]^1 You saved all^3 %d^1 markers!", ent_num )
  206.             //SetPlayerVis( id )
  207.         }
  208.     }
  209.     menu_destroy( menu )
  210.     create_menu( id )
  211.     return PLUGIN_HANDLED
  212. }  
  213. public SetPlayerVis( id )
  214. {
  215.     {
  216.         if( is_user_connected( id ) )
  217.         {
  218.             for( new i = 1; i <= ent_num; i++ )
  219.             {
  220.                 if( !pev_valid( i ) ) continue
  221.  
  222.                 message_begin( MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, .player = id )
  223.                 write_byte( TE_SPRITE )
  224.                 write_coord( floatround(g_fOrigin[ i ][ 0 ] ) )
  225.                 write_coord( floatround(g_fOrigin[ i ][ 1 ] ) )
  226.                 write_coord( floatround(g_fOrigin[ i ][ 2 ] ) )
  227.                 write_short( model )
  228.                 write_byte( 2 )  
  229.                 write_byte( 120 )
  230.                 message_end()
  231.             }
  232.         }
  233.     }
  234. }
  235. public client_putinserver( id )
  236.     g_bPVis[ id ] = true
  237.  
  238. public client_PreThink( id )
  239. {
  240.     //if( is_user_alive(id) || !is_user_bot( id ) )
  241.     //  return PLUGIN_CONTINUE
  242.    
  243.     if( get_gametime() > 10.0 && g_bPVis[ id ] )//&& !is_user_bot( id ) )  
  244.         SetPlayerVis( id )
  245. }
  246. public create_cp( id, load )
  247. {
  248.     ent_num++
  249.    
  250.     new Float: origin[ 3 ]
  251.     entity_get_vector( id, EV_VEC_origin, origin )
  252.    
  253.     if( !load )
  254.     {
  255.         if( !is_user_admin( id ) ) return PLUGIN_HANDLED
  256.        
  257.         g_fOrigin[ ent_num ][ 0 ] = origin[ 0 ]
  258.         g_fOrigin[ ent_num ][ 1 ] = origin[ 1 ]
  259.         g_fOrigin[ ent_num ][ 2 ] = origin[ 2 ]
  260.         g_fMarkerTime[ ent_num ] = 0.0
  261.        
  262.         g_fOrigin[ ent_num ][ 2 ] +=40.0
  263.     }
  264.     else
  265.     {
  266.         g_fOrigin[ ent_num ][ 0 ] = saved_origin[ 0 ]
  267.         g_fOrigin[ ent_num ][ 1 ] = saved_origin[ 1 ]
  268.         g_fOrigin[ ent_num ][ 2 ] = saved_origin[ 2 ]
  269.         formatex( g_mName[ ent_num ], charsmax( g_mName[] ), "%s", saved_mName )
  270.         g_fMarkerTime[ ent_num ] = str_to_float( mTime )
  271.     }
  272.  
  273.     g_nEnt[ ent_num ] = create_entity( "info_target" )
  274.    
  275.     entity_set_origin( g_nEnt[ ent_num ], g_fOrigin[ ent_num ] )
  276.    
  277.     entity_set_string( g_nEnt[ ent_num ], EV_SZ_classname, "kz_checkpoint" )
  278.     entity_set_model( g_nEnt[ ent_num ], g_Model )
  279.    
  280.     entity_set_int( g_nEnt[ ent_num ], EV_INT_solid, SOLID_TRIGGER )
  281.    
  282.     new Float:maxs[ 3 ] = { 70.0, 70.0, 20.0 }
  283.     new Float:mins[ 3 ] = { -70.0, -70.0, -20.0 }
  284.     entity_set_size( g_nEnt[ ent_num ], mins, maxs )
  285.     if( !g_bVisible )
  286.         set_pev( g_nEnt[ ent_num ], pev_rendermode, kRenderGlow )
  287.     else
  288.         set_pev( g_nEnt[ ent_num ], pev_rendermode, kRenderNormal )
  289.        
  290.     //set_pev(dot,pev_renderfx,kRenderFxNone);
  291.    
  292.     return PLUGIN_HANDLED
  293. }  
  294. public fwdUse( ent, id )
  295. {      
  296.     if( !ent || id > 32 || !is_user_alive( id ) )
  297.     {
  298.         return HAM_IGNORED
  299.     }
  300.     new name[32]
  301.     get_user_name(id, name, 31)
  302.    
  303.     new szTarget[ 32 ];
  304.     pev(ent, pev_target, szTarget, 31);
  305.  
  306.     if( TrieKeyExists( g_tStarts, szTarget ) && !g_makingIt )
  307.     {  
  308.         if( ent_num > 0 )
  309.         {
  310.             for( new i = 0; i <= ent_num; i++ )
  311.                 g_bPlayerMarker[ id ][ g_nEnt[ ent_num ] - i ] = false
  312.         }
  313.            
  314.         g_bStarted[ id ] = true
  315.         g_fTime[ id ] = get_gametime()
  316.         playerTouched[ id ] = 0
  317.     }
  318.     return HAM_IGNORED
  319. }
  320. public showit()
  321. {
  322.     client_print( 0, print_chat, "radi botina" )
  323. }
  324. public reset_time( id )
  325. {
  326.     g_bStarted[ id ] = false
  327. }    
  328. public pfn_touch( ent, id )
  329. {  
  330.     new classname[ 32 ], name[ 32 ]
  331.     entity_get_string( ent, EV_SZ_classname, classname, 31 )
  332.    
  333.     if( equal( classname, "kz_checkpoint" ) && !g_makingIt && g_bStarted[ id ] )
  334.     {
  335.         if ( (!(1 <= id <= get_maxplayers() )) )
  336.             return PLUGIN_HANDLED
  337.        
  338.         if( g_bPlayerMarker[ id ][ ent ] )
  339.             return PLUGIN_HANDLED
  340.            
  341.         playerTouched[ id ]++
  342.         g_bPlayerMarker[ id ][ ent ] = true
  343.         get_user_name( id, name, charsmax( name ) )
  344.  
  345.         new Float:timee = get_gametime() - g_fTime[ id ]
  346.         new min, diffmin, Float:sec, Float: diffsec
  347.         min=floatround(timee/60,floatround_floor);
  348.         sec=timee-min*60;
  349.         diffmin = floatround(( g_fMarkerTime[ playerTouched[ id ] ] - timee )/60, floatround_floor )
  350.         diffsec =( g_fMarkerTime[ playerTouched[ id ] ] - timee ) - ( diffmin * 60 )
  351.        
  352.         if( timee < g_fMarkerTime[ playerTouched[ id ] ] && g_fMarkerTime[ playerTouched[ id ] ] > 0.0 )
  353.         {
  354.             ColorChat( 0, RED, "^4[KZ]^3 %s made new rec on #%d in: %02d:%s%.02f^4 (-%02d:%s%.02f)", name, playerTouched[ id ], min, sec < 10 ? "0" : "",sec, diffmin, diffsec < 10 ? "0" : "", diffsec )
  355.             g_fMarkerTime[ playerTouched[ id ] ] = timee
  356.             update_cp( id, playerTouched[ id ], timee )
  357.         }
  358.         else if( g_fMarkerTime[ playerTouched[ id ] ] > 0.0 )
  359.         {
  360.             diffmin = floatround(( timee - g_fMarkerTime[ playerTouched[ id ] ] )/60, floatround_floor )
  361.             diffsec =( timee - g_fMarkerTime[ playerTouched[ id ] ]) - ( diffmin * 60 )
  362.             ColorChat( id, GREY, "^4[KZ]^3 Marker #%d: %02d:%s%.2f^4 (+%02d:%s%.2f by %s)", playerTouched[ id ], min, sec < 10 ? "0" : "", sec, diffmin, diffsec < 10 ? "0" : "", diffsec, g_mName[ playerTouched[ id ] ] )
  363.             new players[ 32 ], pnum, ii, id2
  364.             get_players( players, pnum, "bc" )
  365.             for( new i; i < pnum; i++ )
  366.             {
  367.                 ii = players[ i ]
  368.                 id2 = GetSpectatedPlayer( ii )
  369.                 if( id2 == id )
  370.                     ColorChat( ii, GREY, "^4[KZ]^3 Marker #%d: %02d:%s%.2f^4 (+%02d:%s%.2f by %s)", playerTouched[ id ], min, sec < 10 ? "0" : "", sec, diffmin, diffsec < 10 ? "0" : "", diffsec, g_mName[ playerTouched[ id ] ] )
  371.             }
  372.         }
  373.         if( g_fMarkerTime[ playerTouched[ id ] ] == 0.0 )
  374.         {
  375.             ColorChat( 0, BLUE, "^4[KZ]^3 First record on #%d marker by^3 %s in:^4 %02d:%s%.02f", playerTouched[ id ], name, min, sec < 10 ? "0" : "",sec )
  376.             g_fMarkerTime[ playerTouched[ id ] ] = timee
  377.             update_cp( id, playerTouched[ id ], timee )
  378.         }  
  379.     }
  380.     return PLUGIN_CONTINUE
  381. }
  382. public delete_cp( id, all )
  383. {
  384.     if( all )
  385.     {
  386.         remove_entity_name( "kz_checkpoint" )
  387.         ent_num = 0
  388.     }
  389.     else
  390.         remove_entity( g_nEnt[ ent_num-- ] )
  391. }
  392. public save_cp( id )
  393. {
  394.     new filee = fopen( file, "w+" )
  395.    
  396.     if( filee )
  397.     {
  398.         for( new i = 1; i <= ent_num; i++ )
  399.         {
  400.             fprintf( filee, "%d %.01f %.01f %.01f %.02f NIKOBE^n", i, g_fOrigin[ i ][ 0 ],  g_fOrigin[ i ][ 1 ],  g_fOrigin[ i ][ 2 ], g_fMarkerTime[ i ] )
  401.         }
  402.         fclose( filee )
  403.     }
  404. }
  405. public load_cp() //load markers
  406. {
  407.     new filee = fopen( file, "r" )
  408.     new line = 0
  409.    
  410.     if( filee )
  411.     {
  412.         new Data[ 150 ], file_origin[ 3 ][ 10 ], entNum[ 3 ], name[ 32 ]
  413.         g_makingIt = false
  414.         while( fgets( filee, Data, 149 ) )
  415.         {
  416.             line++
  417.             parse( Data, entNum, 2, file_origin[ 0 ], 9, file_origin[ 1 ], 9, file_origin[ 2 ], 9, mTime, 9, name, 31 )
  418.            
  419.             remove_quotes( name )
  420.            
  421.             saved_origin[ 0 ] = str_to_float( file_origin[ 0 ] )
  422.             saved_origin[ 1 ] = str_to_float( file_origin[ 1 ] )
  423.             saved_origin[ 2 ] = str_to_float( file_origin[ 2 ] )
  424.             formatex( saved_mName, charsmax( saved_mName ), "%s", name )
  425.            
  426.             create_cp( 0, 1 )
  427.         }
  428.     }
  429. }
  430. public update_cp( id, got_num, const Float: player_time )
  431. {
  432.     new file_origin[ 3 ][ 10 ], entNum[ 3 ], name[ 32 ], entNum1
  433.     new i, len, readdata[ 512 ]
  434.     while(read_file(file, i++, readdata, 511, len) )
  435.     {
  436.         parse( readdata, entNum, 2, file_origin[ 0 ], 9, file_origin[ 1 ], 9, file_origin[ 2 ], 9, mTime, 9, name, 31 )
  437.         entNum1 = str_to_num ( entNum )
  438.         if( got_num == entNum1 )
  439.         {
  440.             new msg[256]
  441.             get_user_name( id, g_mName[ i ], charsmax( g_mName[] ) )
  442.             format(msg, 255, "%d %.01f %.01f %.01f %.02f ^"%s^"", i, g_fOrigin[ i ][ 0 ],  g_fOrigin[ i ][ 1 ],  g_fOrigin[ i ][ 2 ], player_time, g_mName[ i ] )
  443.             replace(readdata, 511, readdata, msg)
  444.             write_file(file, readdata, i - 1)
  445.             return PLUGIN_HANDLED
  446.         }
  447.     }
  448.     return PLUGIN_HANDLED
  449. }
  450. stock SendCmd_1( id , text[] )
  451. {
  452.     message_begin( MSG_ONE, 51, _, id )
  453.     write_byte( strlen(text) + 2 )
  454.     write_byte( 10 )
  455.     write_string( text )
  456.     message_end()
  457. }
  458. stock GetSpectatedPlayer(id)
  459. {
  460.     if( !is_user_alive(id)
  461.     && ((1 << pev(id, pev_iuser1)) & ((1 << 1)|(1 << 2)|(1 << 4))) )
  462.     {
  463.         new player = pev( id, pev_iuser2 );
  464.         if( is_user_alive( player ) )
  465.         {
  466.             return player;
  467.         }
  468.     }
  469.    
  470.     return id;
  471. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×