[Half-Life AMXX] / mapsmenu.sma Repository:
ViewVC logotype

Diff of /mapsmenu.sma

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 16, Fri Nov 16 15:12:40 2007 UTC revision 17, Fri Nov 16 15:29:57 2007 UTC
# Line 35  Line 35 
35  #include <amxmodx>  #include <amxmodx>
36  #include <amxmisc>  #include <amxmisc>
37    
38  #define MAX_MAPS 64  new Array:g_mapName;
   
 new g_mapName[MAX_MAPS][32]  
39  new g_mapNums  new g_mapNums
40  new g_menuPosition[33]  new g_menuPosition[33]
41    
# Line 64  Line 62 
62          register_menucmd(register_menuid("Votemap Menu"), 1023, "actionVoteMapMenu")          register_menucmd(register_menuid("Votemap Menu"), 1023, "actionVoteMapMenu")
63          register_menucmd(register_menuid("The winner: "), 3, "actionResult")          register_menucmd(register_menuid("The winner: "), 3, "actionResult")
64    
65            g_mapName=ArrayCreate(32);
66    
67          new maps_ini_file[64];          new maps_ini_file[64];
68          get_configsdir(maps_ini_file, 63);          get_configsdir(maps_ini_file, 63);
69          format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file);          format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file);
70    
71          if (!file_exists(maps_ini_file))          if (!file_exists(maps_ini_file))
72                    get_cvar_string("mapcyclefile", maps_ini_file, sizeof(maps_ini_file) - 1);
73    
74            if (!file_exists(maps_ini_file))
75                  format(maps_ini_file, 63, "mapcycle.txt")                  format(maps_ini_file, 63, "mapcycle.txt")
76    
77          load_settings(maps_ini_file)          load_settings(maps_ini_file)
# Line 99  Line 102 
102                                  message_end()                                  message_end()
103                          }                          }
104    
105                          set_task(2.0, "delayedChange", 0, g_mapName[g_choosed], strlen(g_mapName[g_choosed]) + 1)                          new tempMap[32];
106                            ArrayGetString(g_mapName, g_choosed, tempMap, charsmax(tempMap));
107    
108                            set_task(2.0, "delayedChange", 0, tempMap, strlen(tempMap) + 1)
109                          log_amx("Vote: %L", "en", "RESULT_ACC")                          log_amx("Vote: %L", "en", "RESULT_ACC")
110                          client_print(0, print_chat, "%L", LANG_PLAYER, "RESULT_ACC")                          client_print(0, print_chat, "%L", LANG_PLAYER, "RESULT_ACC")
111                  }                  }
# Line 129  Line 135 
135          if (iResult >= iRatio)          if (iResult >= iRatio)
136          {          {
137                  g_choosed = g_voteSelected[id][a]                  g_choosed = g_voteSelected[id][a]
138                  client_print(0, print_chat, "%L %s", LANG_PLAYER, "VOTE_SUCCESS", g_mapName[g_choosed])                  new tempMap[32];
139                  log_amx("Vote: %L %s", "en", "VOTE_SUCCESS", g_mapName[g_choosed])                  ArrayGetString(g_mapName, g_choosed, tempMap, charsmax(tempMap));
140                    client_print(0, print_chat, "%L %s", LANG_PLAYER, "VOTE_SUCCESS", tempMap);
141                    log_amx("Vote: %L %s", "en", "VOTE_SUCCESS", tempMap);
142          }          }
143    
144          if (g_choosed != -1)          if (g_choosed != -1)
# Line 138  Line 146 
146                  if (is_user_connected(id))                  if (is_user_connected(id))
147                  {                  {
148                          new menuBody[512]                          new menuBody[512]
149                          new len = format(menuBody, 511, g_coloredMenus ? "\y%L: \w%s^n^n" : "%L: %s^n^n", id, "THE_WINNER", g_mapName[g_choosed])                          new tempMap[32];
150                            ArrayGetString(g_mapName, g_choosed, tempMap, charsmax(tempMap));
151                            new len = format(menuBody, 511, g_coloredMenus ? "\y%L: \w%s^n^n" : "%L: %s^n^n", id, "THE_WINNER", tempMap)
152    
153                          len += format(menuBody[len], 511 - len, g_coloredMenus ? "\y%L^n\w" : "%L^n", id, "WANT_CONT")                          len += format(menuBody[len], 511 - len, g_coloredMenus ? "\y%L^n\w" : "%L^n", id, "WANT_CONT")
154                          format(menuBody[len], 511-len, "^n1. %L^n2. %L", id, "YES", id, "NO")                          format(menuBody[len], 511-len, "^n1. %L^n2. %L", id, "YES", id, "NO")
# Line 154  Line 164 
164                                  message_begin(MSG_ALL, SVC_INTERMISSION)                                  message_begin(MSG_ALL, SVC_INTERMISSION)
165                                  message_end()                                  message_end()
166                          }                          }
167                            new tempMap[32];
168                          set_task(2.0, "delayedChange", 0, g_mapName[g_choosed], strlen(g_mapName[g_choosed]) + 1)                          ArrayGetString(g_mapName, g_choosed, tempMap, charsmax(tempMap));
169                            set_task(2.0, "delayedChange", 0, tempMap, strlen(tempMap) + 1)
170                  }                  }
171          } else {          } else {
172                  client_print(0, print_chat, "%L", LANG_PLAYER, "VOTE_FAILED")                  client_print(0, print_chat, "%L", LANG_PLAYER, "VOTE_FAILED")
# Line 214  Line 225 
225          if (end > g_mapNums)          if (end > g_mapNums)
226                  end = g_mapNums                  end = g_mapNums
227    
228            new tempMap[32];
229          for (new a = start; a < end; ++a)          for (new a = start; a < end; ++a)
230          {          {
231                    ArrayGetString(g_mapName, a, tempMap, charsmax(tempMap));
232                  if (g_voteSelectedNum[id] == 4 || isMapSelected(id, pos * 7 + b))                  if (g_voteSelectedNum[id] == 4 || isMapSelected(id, pos * 7 + b))
233                  {                  {
234                          ++b                          ++b
   
235                          if (g_coloredMenus)                          if (g_coloredMenus)
236                                  len += format(menuBody[len], 511-len, "\d%d. %s^n\w", b, g_mapName[a])                                  len += format(menuBody[len], 511-len, "\d%d. %s^n\w", b, tempMap)
237                          else                          else
238                                  len += format(menuBody[len], 511-len, "#. %s^n", g_mapName[a])                                  len += format(menuBody[len], 511-len, "#. %s^n", tempMap)
239                  } else {                  } else {
240                          keys |= (1<<b)                          keys |= (1<<b)
241                          len += format(menuBody[len], 511-len, "%d. %s^n", ++b, g_mapName[a])                          len += format(menuBody[len], 511-len, "%d. %s^n", ++b, tempMap)
242                  }                  }
243          }          }
244    
# Line 254  Line 266 
266          for (new c = 0; c < 4; c++)          for (new c = 0; c < 4; c++)
267          {          {
268                  if (c < g_voteSelectedNum[id])                  if (c < g_voteSelectedNum[id])
269                          len += format(menuBody[len], 511-len, "%s^n", g_mapName[g_voteSelected[id][c]])                  {
270                            ArrayGetString(g_mapName, g_voteSelected[id][c], tempMap, charsmax(tempMap));
271                            len += format(menuBody[len], 511-len, "%s^n", tempMap)
272                    }
273                  else                  else
274                          len += format(menuBody[len], 511-len, "^n")                          len += format(menuBody[len], 511-len, "^n")
275          }          }
# Line 310  Line 325 
325    
326  public actionVoteMapMenu(id, key)  public actionVoteMapMenu(id, key)
327  {  {
328            new tempMap[32];
329          switch (key)          switch (key)
330          {          {
331                  case 7:                  case 7:
# Line 348  Line 364 
364    
365                                  for (new c = 0; c < g_voteSelectedNum[id]; ++c)                                  for (new c = 0; c < g_voteSelectedNum[id]; ++c)
366                                  {                                  {
367                                          len += format(menuBody[len], 511, "%d. %s^n", c + 1, g_mapName[g_voteSelected[id][c]])                                          ArrayGetString(g_mapName, g_voteSelected[id][c], tempMap, charsmax(tempMap));
368                                            len += format(menuBody[len], 511, "%d. %s^n", c + 1, tempMap)
369                                          keys |= (1<<c)                                          keys |= (1<<c)
370                                  }                                  }
371    
372                                  keys |= (1<<8)                                  keys |= (1<<8)
373                                  len += format(menuBody[len], 511, "^n9. %L^n", id, "NONE")                                  len += format(menuBody[len], 511, "^n9. %L^n", id, "NONE")
374                          } else {                          } else {
375                                  len = format(menuBody, 511, g_coloredMenus ? "\y%L^n%s?^n\w^n1. %L^n2. %L^n" : "%L^n%s?^n^n1. %L^n2. %L^n", id, "CHANGE_MAP_TO", g_mapName[g_voteSelected[id][0]], id, "YES", id, "NO")                                  ArrayGetString(g_mapName, g_voteSelected[id][0], tempMap, charsmax(tempMap));
376                                    len = format(menuBody, 511, g_coloredMenus ? "\y%L^n%s?^n\w^n1. %L^n2. %L^n" : "%L^n%s?^n^n1. %L^n2. %L^n", id, "CHANGE_MAP_TO", tempMap, id, "YES", id, "NO")
377                                  keys = MENU_KEY_1|MENU_KEY_2                                  keys = MENU_KEY_1|MENU_KEY_2
378                          }                          }
379    
# Line 375  Line 393 
393                          get_user_authid(id, authid, 31)                          get_user_authid(id, authid, 31)
394                          get_user_name(id, name, 31)                          get_user_name(id, name, 31)
395    
396                          switch (get_cvar_num("amx_show_activity"))                          show_activity_key("ADMIN_V_MAP_1", "ADMIN_V_MAP_2", name);
397    
398                            new tempMapA[32];
399                            new tempMapB[32];
400                            new tempMapC[32];
401                            new tempMapD[32];
402                            if (g_voteSelectedNum[id] > 0)
403                            {
404                                    ArrayGetString(g_mapName, g_voteSelected[id][0], tempMapA, charsmax(tempMapA));
405                            }
406                            else
407                            {
408                                    copy(tempMapA, charsmax(tempMapA), "");
409                            }
410                            if (g_voteSelectedNum[id] > 1)
411                            {
412                                    ArrayGetString(g_mapName, g_voteSelected[id][1], tempMapB, charsmax(tempMapB));
413                            }
414                            else
415                            {
416                                    copy(tempMapB, charsmax(tempMapB), "");
417                            }
418                            if (g_voteSelectedNum[id] > 2)
419                            {
420                                    ArrayGetString(g_mapName, g_voteSelected[id][2], tempMapC, charsmax(tempMapC));
421                            }
422                            else
423                            {
424                                    copy(tempMapC, charsmax(tempMapC), "");
425                            }
426                            if (g_voteSelectedNum[id] > 3)
427                            {
428                                    ArrayGetString(g_mapName, g_voteSelected[id][3], tempMapD, charsmax(tempMapD));
429                            }
430                            else
431                          {                          {
432                                  case 2: client_print(0, print_chat, "%L", LANG_PLAYER, "ADMIN_V_MAP_2", name)                                  copy(tempMapD, charsmax(tempMapD), "");
                                 case 1: client_print(0, print_chat, "%L", LANG_PLAYER, "ADMIN_V_MAP_1")  
433                          }                          }
434    
435                          log_amx("Vote: ^"%s<%d><%s><>^" vote maps (map#1 ^"%s^") (map#2 ^"%s^") (map#3 ^"%s^") (map#4 ^"%s^")",                          log_amx("Vote: ^"%s<%d><%s><>^" vote maps (map#1 ^"%s^") (map#2 ^"%s^") (map#3 ^"%s^") (map#4 ^"%s^")",
436                                          name, get_user_userid(id), authid,                                          name, get_user_userid(id), authid,
437                                          g_voteSelectedNum[id] > 0 ? g_mapName[g_voteSelected[id][0]] : "",                                          tempMapA, tempMapB, tempMapC, tempMapD)
                                         g_voteSelectedNum[id] > 1 ? g_mapName[g_voteSelected[id][1]] : "",  
                                         g_voteSelectedNum[id] > 2 ? g_mapName[g_voteSelected[id][2]] : "",  
                                         g_voteSelectedNum[id] > 3 ? g_mapName[g_voteSelected[id][3]] : "")  
438                  }                  }
439                  case 8: displayVoteMapsMenu(id, ++g_menuPosition[id])                  case 8: displayVoteMapsMenu(id, ++g_menuPosition[id])
440                  case 9: displayVoteMapsMenu(id, --g_menuPosition[id])                  case 9: displayVoteMapsMenu(id, --g_menuPosition[id])
# Line 423  Line 471 
471                          get_user_authid(id, authid, 31)                          get_user_authid(id, authid, 31)
472                          get_user_name(id, name, 31)                          get_user_name(id, name, 31)
473    
474                          switch (get_cvar_num("amx_show_activity"))                          new tempMap[32];
475                          {                          ArrayGetString(g_mapName, a, tempMap, charsmax(tempMap));
                                 case 2: client_print(0, print_chat, "%L", LANG_PLAYER, "ADMIN_CHANGEL_2", name, g_mapName[a])  
                                 case 1: client_print(0, print_chat, "%L", LANG_PLAYER, "ADMIN_CHANGEL_1", g_mapName[a])  
                         }  
476    
477                          log_amx("Cmd: ^"%s<%d><%s><>^" changelevel ^"%s^"", name, get_user_userid(id), authid, g_mapName[a])                          show_activity_key("ADMIN_CHANGEL_1", "ADMIN_CHANGEL_2", name, tempMap);
478                          set_task(2.0, "delayedChange", 0, g_mapName[a], strlen(g_mapName[a]) + 1)  
479                            log_amx("Cmd: ^"%s<%d><%s><>^" changelevel ^"%s^"", name, get_user_userid(id), authid, tempMap)
480                            set_task(2.0, "delayedChange", 0, tempMap, strlen(tempMap) + 1)
481                          /* displayMapsMenu(id, g_menuPosition[id]) */                          /* displayMapsMenu(id, g_menuPosition[id]) */
482                  }                  }
483          }          }
# Line 444  Line 491 
491                  return                  return
492    
493          new menuBody[512]          new menuBody[512]
494            new tempMap[32]
495          new start = pos * 8          new start = pos * 8
496          new b = 0          new b = 0
497    
# Line 460  Line 508 
508          for (new a = start; a < end; ++a)          for (new a = start; a < end; ++a)
509          {          {
510                  keys |= (1<<b)                  keys |= (1<<b)
511                  len += format(menuBody[len], 511-len, "%d. %s^n", ++b, g_mapName[a])                  ArrayGetString(g_mapName, a, tempMap, charsmax(tempMap));
512                    len += format(menuBody[len], 511-len, "%d. %s^n", ++b, tempMap)
513          }          }
514    
515          if (end != g_mapNums)          if (end != g_mapNums)
# Line 476  Line 525 
525    
526          show_menu(id, keys, menuBody, -1, menuName)          show_menu(id, keys, menuBody, -1, menuName)
527  }  }
528    stock bool:ValidMap(mapname[])
529    {
530            if ( is_map_valid(mapname) )
531            {
532                    return true;
533            }
534            // If the is_map_valid check failed, check the end of the string
535            new len = strlen(mapname) - 4;
536    
537            // The mapname was too short to possibly house the .bsp extension
538            if (len < 0)
539            {
540                    return false;
541            }
542            if ( equali(mapname[len], ".bsp") )
543            {
544                    // If the ending was .bsp, then cut it off.
545                    // the string is byref'ed, so this copies back to the loaded text.
546                    mapname[len] = '^0';
547    
548                    // recheck
549                    if ( is_map_valid(mapname) )
550                    {
551                            return true;
552                    }
553            }
554    
555            return false;
556    }
557    
558  load_settings(filename[])  load_settings(filename[])
559  {  {
560          if (!file_exists(filename))          new fp = fopen(filename, "r");
561                  return 0  
562            if (!fp)
563            {
564                    return 0;
565            }
566    
567    
568            new text[256];
569            new tempMap[32];
570    
571          new text[256]          while (!feof(fp))
572          new a, pos = 0          {
573                    fgets(fp, text, charsmax(text));
574    
575          while (g_mapNums < MAX_MAPS && read_file(filename, pos++, text, 255, a))                  if (text[0] == ';')
576                    {
577                            continue;
578                    }
579                    if (parse(text, tempMap, charsmax(tempMap)) < 1)
580          {          {
581                  if (text[0] == ';') continue                          continue;
582                  if (parse(text, g_mapName[g_mapNums], 31) < 1) continue                  }
583                  if (!is_map_valid(g_mapName[g_mapNums])) continue                  if (!ValidMap(tempMap))
584                    {
585                            continue;
586                    }
587    
588                  g_mapNums++                  ArrayPushString(g_mapName, tempMap);
589                    g_mapNums++;
590          }          }
591    
592          return 1          return 1;
593  }  }

Legend:
Removed from v.16  
changed lines
  Added in v.17

Contact
ViewVC Help
Powered by ViewVC 1.0.4