Заказать игровой сервер Контакты (заказать плагин/исправить ошибки/другое) Поиск

[ вход ]
[ последние сообщения ]

  • Страница 1 из 1
  • 1
Форум » SourceMod >> CS:Source >> CSGO » Обсуждение » Проблема с кодом
Проблема с кодом
Vitaminoz Дата: Понедельник, 03.03.2014, 20:45:10 | Сообщение # 1
Сообщений: 142
Репутация: 1 [ +/- ]
Всем привет.
Наисал код
Код
#include <zombie_horde>

new bool:is_vote[MAXPLAYERS];
new max_votes;
new vote_counts;

public Plugin:myinfo =
{
  name = "ChangeMap System",
  author = "Vitamin",
  description = "This plugin used standalone Valve Command changelevel_next",
  version = "1.0"
}

public OnPluginStart()
{
  RegConsoleCmd("sm_changemap", ChangeMap_Func, "Used console command changelevel_next");
  LoadTranslations("mapsysteam.phrases");
}

public Action:ChangeMap_Func(client, args)
{
  if (!args)
  {
   if (Round_Hook() != BossRound_Hook())
   {
    if (max_votes >= 4)
    {
     if (is_vote[client] == false)
     {
      is_vote[client] = true;
      new vote_count_half = max_votes / 2;
      if (vote_count_half == vote_counts++)
      {
       ServerCommand("changelevel_next");
      }
      else
      {
       decl String:map_name[32];
       decl String:level_name[32];
       GetCurrentMap(map_name, sizeof(map_name));
       new Handle:map_file = OpenFile("cfg/mapcycle.txt", "r");
       do
       {
        if (IsEndOfFile(map_file))
        {
         CloseHandle(map_file);
         map_file = OpenFile("cfg/mapcycle.txt", "r");
         ReadFileLine(map_file, level_name, sizeof(level_name));
         TrimString(level_name);
        }
        else
        {
         ReadFileLine(map_file, level_name, sizeof(level_name));
         TrimString(level_name);
         if (StrEqual(level_name, map_name, false))
         {
          ReadFileLine(map_file, level_name, sizeof(level_name));
          TrimString(level_name);
          break;
         }
        }
       }
       while (!IsEndOfFile(map_file))
       CloseHandle(map_file);
       for (new i_client = 1;i_client <= MaxClients; i_client++)
       {
        if (!IsClientInGame(i_client) || IsFakeClient(i_client))
        {
         continue;
        }
        decl String:name_include[MAX_NAME_LENGTH];
        decl String:map_include[32];
        decl String:vote_string[16];
        FormatEx(name_include, sizeof(name_include), "\x04%N\x01", client);
        FormatEx(map_include, sizeof(map_include), "\x04%s\x01", level_name);
        FormatEx(vote_string, sizeof(vote_string), "[\x04%i\x01/\x04%i\x01]", vote_counts, vote_count_half);
        PrintToChat(i_client, "\x03[SM]\x01 %t", "Vote Client", name_include, map_include);
        PrintToChat(i_client, "\x03[SM]\x01 %t", "Vote Counts", vote_string);
       }
      }
     }
     else
     {
      PrintToChat(client, "\x03[SM]\x01 %t", "Vote Already");
     }
    }
    else
    {
     PrintToChat(client, "\x03[SM]\x01 %t", "More Players");
    }
   }
   else
   {
    PrintToChat(client, "\x03[SM]\x01 %t", "Boss Round");
   }
  }
  return Plugin_Handled;
}

public OnClientDisconnect(client)
{
  if (IsClientInGame(client))
  {
   max_votes--;
   if (is_vote[client] == true)
   {
    is_vote[client] = false;
    vote_counts--;
   }
  }
}

public OnClientPutInServer(client)
{
  max_votes++;
}

Проблема в том, что к примеру вmapcycle.txt последняя строчка (карта какая нибудь), к примеру de_dust2 не хочет переходить в 1 строчку файла (ReadFileLine) уже не знаю как делать ...

Добавлено (03.03.2014, 20:03:57)
---------------------------------------------
Народ помогите пожалуйста уже замучался ...

Добавлено (03.03.2014, 20:45:10)
---------------------------------------------
Вообщем код получился, может тут что нибудь надо изменить или подправить ? В плане оптимизации скажите скриптеры.

Код
#include <zombie_horde>

new bool:is_vote[MAXPLAYERS];
new max_votes;
new vote_counts;

public Plugin:myinfo =
{
  name = "ChangeMap System",
  author = "Vitamin",
  description = "This plugin used standalone Valve Command changelevel_next",
  version = "1.0"
}

public OnPluginStart()
{
  RegConsoleCmd("sm_changemap", ChangeMap_Func, "Used console command changelevel_next");
  LoadTranslations("mapsysteam.phrases");
}

public Action:ChangeMap_Func(client, args)
{
  if (!args)
  {
   if (Round_Hook() != BossRound_Hook())
   {
    if (max_votes >= 4)
    {
     if (is_vote[client] == false)
     {
      is_vote[client] = true;
      new vote_count_half = max_votes / 2;
      if (vote_count_half == vote_counts++)
      {
       ServerCommand("changelevel_next");
      }
      else
      {
       decl String:map_name[32];
       decl String:level_name[32];
       GetCurrentMap(map_name, sizeof(map_name));
       new Handle:map_file = OpenFile("cfg/mapcycle.txt", "r");
       new bool:test_end_file = false;
       while (!IsEndOfFile(map_file))
       {
        ReadFileLine(map_file, level_name, sizeof(level_name));
        TrimString(level_name);
        if (StrEqual(map_name, level_name, false))
        {
         if (!IsEndOfFile(map_file))
         {
          ReadFileLine(map_file, level_name, sizeof(level_name));
          TrimString(level_name);
          break;
         }
         else
         {
          test_end_file = true;
         }
        }
       }
       if (test_end_file)
       {
        CloseHandle(map_file);
        map_file = OpenFile("cfg/mapcycle.txt", "r");
        ReadFileLine(map_file, level_name, sizeof(level_name));
        TrimString(level_name);
       }
       CloseHandle(map_file);
       for (new i_client = 1;i_client <= MaxClients; i_client++)
       {
        if (!IsClientInGame(i_client) || IsFakeClient(i_client))
        {
         continue;
        }
        decl String:name_include[MAX_NAME_LENGTH];
        decl String:map_include[32];
        decl String:vote_string[16];
        FormatEx(name_include, sizeof(name_include), "\x04%N\x01", client);
        FormatEx(map_include, sizeof(map_include), "\x04%s\x01", level_name);
        FormatEx(vote_string, sizeof(vote_string), "[\x04%i\x01/\x04%i\x01]", vote_counts, vote_count_half);
        PrintToChat(i_client, "\x03[SM]\x01 %t", "Vote Client", name_include, map_include);
        PrintToChat(i_client, "\x03[SM]\x01 %t", "Vote Counts", vote_string);
       }
      }
     }
     else
     {
      PrintToChat(client, "\x03[SM]\x01 %t", "Vote Already");
     }
    }
    else
    {
     PrintToChat(client, "\x03[SM]\x01 %t", "More Players");
    }
   }
   else
   {
    PrintToChat(client, "\x03[SM]\x01 %t", "Boss Round");
   }
  }
  return Plugin_Handled;
}

public OnClientDisconnect(client)
{
  if (IsClientInGame(client))
  {
   max_votes--;
   if (is_vote[client] == true)
   {
    is_vote[client] = false;
    vote_counts--;
   }
  }
}

public OnClientPutInServer(client)
{
  max_votes++;
}
 
Форум » SourceMod >> CS:Source >> CSGO » Обсуждение » Проблема с кодом
  • Страница 1 из 1
  • 1
Поиск: