Advertisement
Hyuna

Timeleft and Nextmap Bots

May 28th, 2013 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.17 KB | None | 0 0
  1. // License:
  2.  
  3. /*
  4.     Timeleft And Nextmap Bots v1.0
  5.     Copyright (C) 2013 Hyuna aka NorToN
  6.  
  7.     This program is free software: you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation, either version 3 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20.  
  21. #include <amxmodx>
  22. #include <amxmisc>
  23. #include <cstrike>
  24. #include <fakemeta>
  25.  
  26. new g_nextmapbot,g_timeleftbot,g_timebot;
  27. new g_nextmapcvar,g_timelimitcvar;
  28.  
  29. const Float:g_UpdateTime = 1.0;
  30.  
  31. public plugin_init(){
  32.     register_plugin("Timeleft and Nextmap bots","1.0","Hyuna");
  33.    
  34.     register_forward(FM_ClientUserInfoChanged,"ClientUserInfoChanged");
  35.    
  36.     register_dictionary("nextmap.txt");
  37.     register_dictionary("timeleft.txt");
  38.    
  39.     set_task(5.0,"CreateBots");
  40.    
  41.     g_nextmapcvar = get_cvar_pointer("amx_nextmap");
  42.     g_timelimitcvar = get_cvar_pointer("mp_timelimit");
  43. }
  44.  
  45. public CreateBots(){
  46.     g_nextmapbot = CreateBot();
  47.     g_timeleftbot = CreateBot();
  48.     g_timebot = CreateBot();
  49.    
  50.     updatebotname();
  51.     updatebotname2();
  52.     updatebotname3();
  53. }
  54.  
  55. public ClientUserInfoChanged(id){
  56.     static szOldName[32];
  57.     pev(id,pev_netname,szOldName,charsmax(szOldName));
  58.        
  59.     if(szOldName[0] && (id == g_nextmapbot || id == g_timeleftbot || id == g_timebot))
  60.     {
  61.         static szNewName[32];
  62.         get_user_info(id,"name",szNewName,charsmax(szNewName));
  63.        
  64.         if(!equal(szOldName,szNewName))
  65.         {
  66.             set_pev(id,pev_netname,szNewName);
  67.             return FMRES_HANDLED;
  68.         }
  69.     }
  70.    
  71.     return FMRES_IGNORED;
  72. }  
  73.  
  74. public updatebotname(){
  75.     if (!is_user_connected(g_nextmapbot))
  76.         return;
  77.        
  78.     static some[64],some2[128];
  79.    
  80.     get_pcvar_string(g_nextmapcvar,some,63);
  81.     formatex(some2,128,"%L %s",LANG_SERVER,"NEXT_MAP",some);
  82.     set_user_info(g_nextmapbot,"name",some2);
  83.    
  84.     set_task(g_UpdateTime,"updatebotname");
  85. }
  86.  
  87. public updatebotname2(){
  88.     if (!is_user_connected(g_timeleftbot))
  89.         return;
  90.        
  91.     static some[64];
  92.     static iHours,iMinutes,iSeconds;
  93.    
  94.     if(get_pcvar_float(g_timelimitcvar))
  95.     {  
  96.         iSeconds = get_timeleft();
  97.         iMinutes = iSeconds / 60;
  98.         iHours = iMinutes / 60;
  99.         iSeconds = iSeconds - iMinutes * 60;
  100.         iMinutes = iMinutes - iHours * 60;
  101.                
  102.         if (iHours)
  103.             formatex(some,63,"%L: %d:%02d:%02d",LANG_SERVER,"TIME_LEFT",iHours,iMinutes,iSeconds);
  104.    
  105.         else
  106.             formatex(some,63,"%L: %d:%02d",LANG_SERVER,"TIME_LEFT",iMinutes,iSeconds);
  107.     }
  108.        
  109.     else
  110.         formatex(some,63,"%L: %L",LANG_SERVER,"TIME_LEFT",LANG_SERVER,"NO_T_LIMIT");
  111.        
  112.     set_user_info(g_timeleftbot,"name",some);
  113.    
  114.     set_task(g_UpdateTime,"updatebotname2");
  115. }
  116.  
  117. public updatebotname3(){
  118.     static times[24],some[32];
  119.     get_time("%d/%m/%Y - %H:%M:%S",times,23);
  120.    
  121.     formatex(some,31,"%L: %s",LANG_SERVER,"THE_TIME",times);
  122.    
  123.     set_user_info(g_timebot,"name",some);
  124.    
  125.     set_task(g_UpdateTime,"updatebotname3");
  126. }
  127.  
  128. stock CreateBot(){
  129.     new some[32];
  130.     formatex(some,31,"BOT-%d",random(1337));
  131.     new Bot = engfunc(EngFunc_CreateFakeClient,some);
  132.  
  133.     if (Bot > 0) {
  134.         //Supposed to prevent crashes?
  135.         dllfunc(MetaFunc_CallGameEntity,"player",Bot);
  136.         set_pev(Bot,pev_flags,FL_FAKECLIENT);
  137.  
  138.         //Make Sure they have no model
  139.         set_pev(Bot,pev_model,"");
  140.         set_pev(Bot,pev_viewmodel2,"");
  141.         set_pev(Bot,pev_modelindex,0);
  142.  
  143.         //Make them invisible for good measure
  144.         set_pev(Bot,pev_renderfx,kRenderFxNone);
  145.         set_pev(Bot,pev_rendermode,kRenderTransAlpha);
  146.         set_pev(Bot,pev_renderamt,0.0);
  147.  
  148.         //Set the team if we need to for this mod
  149.         if (cstrike_running())
  150.             cs_set_user_team(Bot,CS_TEAM_UNASSIGNED);
  151.            
  152.         log_amx("Bot ^"%s^" (ID: %d) was successfuly created!",some,Bot);
  153.     }
  154.    
  155.     else
  156.         set_fail_status("ERROR: Falied to create a bot (Invaild bot entity index %d)",Bot);
  157.  
  158.     return Bot;
  159. }
  160.  
  161. stock set_fail_status(err_msg[], any: ...){
  162.     new msg[512];
  163.     vformat(msg,charsmax(msg),err_msg,2);
  164.    
  165.     set_fail_state(msg)
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement