TopSpeed

Тема в разделе "Тестовые плагины", создана пользователем The End Is Near..., 14 июн 2016.

  1. The End Is Near...

    The End Is Near... Russian Roulette

    Сообщения:
    893
    Симпатии:
    659
    Была недавно попытка создания плагина, суть которого сохранять скорость игроков для каждой карты

    Изначально данные хранятся в addons/sourcemod/configs/top_speed.txt
    Показать меню: ts
    Включить/выключить показ скорости: ts_switch

    Выглядит файл примерно так:
    PHP:
    "top_speed"
    {
        
    "de_dust"
        
    {
            
    "1"
            
    {
                
    "name"        "The End Is Near..."
                "steamid"        "STEAM_0:0:47497819"
                "speed"        "29.607538"
            
    }
            
    "2"
            
    {
                
    "name"        "Ted"
                "steamid"        "BOT"
                "speed"        "18.155838"
            
    }
        }
        
    "de_dust2"
        
    {
            
    "1"
            
    {
                
    "name"        "The End Is Near..."
                "steamid"        "STEAM_0:0:47497819"
                "speed"        "29.533958"
            
    }
        }
        
    "de_aztec"
        
    {
            
    "1"
            
    {
                
    "name"        "The End Is Near..."
                "steamid"        "STEAM_0:0:47497819"
                "speed"        "38.950150"
            
    }
            
    "2"
            
    {
                
    "name"        "Wayne"
                "steamid"        "BOT"
                "speed"        "20.098288"
            
    }
        }
    }


    Сам плагин:
    PHP:
    #include <sourcemod>
    #include <clientprefs>

    #define PATH_FILE "addons/sourcemod/configs/top_speed.txt"

    #define TOP_SIZE 5

    public Plugin:myinfo =
    {
        
    name "TopSpeed",
        
    author "The End Is Near...",
        
    version "1.0.0",
        
    url "http://world-source.ru/"
    };

    #define ClientName        0
    #define ClientSteamID    1
    #define ClientSpeed        2

    new Handle:g_hKeyValues_TopSpeed        INVALID_HANDLE,
        
    Handle:g_hArray_TopSpeed[3]            = INVALID_HANDLE;

    new 
    Float:g_fMinSpeed 0.0;

    new 
    Float:g_fPosition_Old[MAXPLAYERS 1][3];

    new 
    Handle:g_hClientTimer[MAXPLAYERS 1] = {INVALID_HANDLE, ...};

    new 
    Handle:g_hCookieTopSpeedPref INVALID_HANDLE;

    new 
    bool:g_bClientShowMessage[MAXPLAYERS 1] = {false, ...};

    new 
    bool:g_bDataUpdated true;

    new 
    String:g_szClientName[MAXPLAYERS 1][32],
        
    String:g_szClientSteamID[MAXPLAYERS 1][32];

    public 
    OnPluginStart()
    {
        
    g_hKeyValues_TopSpeed CreateKeyValues("top_speed");

        
    FileToKeyValues(g_hKeyValues_TopSpeedPATH_FILE); 

        for (new 
    03i++)
        {
            
    g_hArray_TopSpeed[i] = CreateArray(32);
        }

        
    g_hCookieTopSpeedPref RegClientCookie("Top Speed""Top Speed"CookieAccess_Private);

        
    HookEvent("player_spawn"Event_OnPlayerSpawn);
        
    HookEvent("player_death"Event_OnPlayerDeath);

        
    RegConsoleCmd("ts"RCC_TopSpeed);
        
    RegConsoleCmd("ts_switch"RCC_TopSpeed_Switch);

        
    OnMapStart();
    }

    public 
    OnMapStart()
    {
        for (new 
    03++)
        {
            
    ClearArray(g_hArray_TopSpeed[i]);
        }

        
    decl String:szCurrentMap[32];
        
    GetCurrentMap(szCurrentMapsizeof(szCurrentMap));

        
    KvRewind(g_hKeyValues_TopSpeed);
        if (
    KvJumpToKey(g_hKeyValues_TopSpeedszCurrentMaptrue) == true)
        {
            if (
    KvGotoFirstSubKey(g_hKeyValues_TopSpeed) == true)
            {
                new 
    iCount 1;

                do
                {
                    
    decl String:szClientSteamID[32];
                    
    KvGetString(g_hKeyValues_TopSpeed"name"szCurrentMapsizeof(szCurrentMap), "PLAYER");
                    
    KvGetString(g_hKeyValues_TopSpeed"steamid"szClientSteamIDsizeof(szClientSteamID), "STEAMID");

                    
    PushArrayString(g_hArray_TopSpeed[ClientName], szCurrentMap);
                    
    PushArrayString(g_hArray_TopSpeed[ClientSteamID], szClientSteamID);

                    
    g_fMinSpeed KvGetFloat(g_hKeyValues_TopSpeed"speed");
                    
    PushArrayCell(g_hArray_TopSpeed[ClientSpeed], g_fMinSpeed);

                    if (
    iCount TOP_SIZE)
                    {
                        
    g_fMinSpeed 0.0;
                        
    iCount++;
                    }
                }
                while (
    KvGotoNextKey(g_hKeyValues_TopSpeed) == true);
            }       
        }

        
    g_bDataUpdated true;
    }

    public 
    OnMapEnd()
    {
        if (
    g_bDataUpdated == true)
        {
            
    Function_SortArray();
        }

        
    decl String:szBuffer[32];
        
    GetCurrentMap(szBuffersizeof(szBuffer));

        
    KvRewind(g_hKeyValues_TopSpeed);
        if (
    KvJumpToKey(g_hKeyValues_TopSpeedszBufferfalse) == true)
        {
            new 
    iSizeArray GetArraySize(g_hArray_TopSpeed[ClientName]);
            for (new 
    0iSizeArrayi++)
            {
                
    FormatEx(szBuffersizeof(szBuffer), "%d"i+1);
                if (
    KvJumpToKey(g_hKeyValues_TopSpeedszBuffertrue) == true)
                {
                    
    GetArrayString(g_hArray_TopSpeed[ClientName], iszBuffersizeof(szBuffer));
                    
    KvSetString(g_hKeyValues_TopSpeed"name"szBuffer);

                    
    GetArrayString(g_hArray_TopSpeed[ClientSteamID], iszBuffersizeof(szBuffer));
                    
    KvSetString(g_hKeyValues_TopSpeed"steamid"szBuffer);

                    
    KvSetFloat(g_hKeyValues_TopSpeed"speed"GetArrayCell(g_hArray_TopSpeed[ClientSpeed], i));
                }

                
    KvGoBack(g_hKeyValues_TopSpeed);
            }
        }

        
    KvRewind(g_hKeyValues_TopSpeed);
        
    KeyValuesToFile(g_hKeyValues_TopSpeedPATH_FILE);
    }

    public 
    OnClientAuthorized(iClient, const String:szAuth[])
    {
        if (
    AreClientCookiesCached(iClient))
        {
            
    decl String:szBuffer[8];
            
    GetClientCookie(iClientg_hCookieTopSpeedPrefszBuffersizeof(szBuffer));
            if(
    strcmp(szBuffer""false) != 0)
            {
                
    g_bClientShowMessage[iClient] = bool:(StringToInt(szBuffer));
            }
            else
            {
                
    g_bClientShowMessage[iClient] = true;
            }
        }

        
    GetClientName(iClientg_szClientName[iClient], sizeof(g_szClientName));
        
    strcopy(g_szClientSteamID[iClient], sizeof(g_szClientSteamID), szAuth);
    }

    public 
    OnClientDisconnect(iClient)
    {
        if (
    g_hClientTimer[iClient] != INVALID_HANDLE)
        {
            
    KillTimer(g_hClientTimer[iClient]);
            
    g_hClientTimer[iClient] = INVALID_HANDLE;
        }
    }

    public 
    Event_OnPlayerSpawn(Handle:hEvent, const String:szEventName[], bool:bSilent)
    {
        new 
    iClient GetClientOfUserId(GetEventInt(hEvent"userid"));

        if (
    iClient && GetClientTeam(iClient)> 1)
        {
            
    CreateTimer(4.0OnTimerStart_PlayerSpawnGetEventInt(hEvent"userid"));

            
    g_fPosition_Old[iClient][0] = g_fPosition_Old[iClient][1] = g_fPosition_Old[iClient][2] = 0.0;
        }
        else
        {
            
    OnClientDisconnect(iClient);
        }   
    }

    public 
    Event_OnPlayerDeath(Handle:hEvent, const String:szEventName[], bool:bSilent)
    {
        
    OnClientDisconnect(GetClientOfUserId(GetEventInt(hEvent"userid")));
    }

    public 
    Action:OnTimerStart_PlayerSpawn(Handle:hTimerany:iUserID)
    {
        
    iUserID GetClientOfUserId(iUserID);
        if (
    iUserID 0)
        {
            if (
    IsClientInGame(iUserID) == true && IsPlayerAlive(iUserID) == true)
            {
                
    OnClientDisconnect(iUserID);

                
    g_hClientTimer[iUserID] = CreateTimer(0.5OnTimerStartiUserIDTIMER_REPEAT);

                
    g_fPosition_Old[iUserID][0] = g_fPosition_Old[iUserID][1] = g_fPosition_Old[iUserID][2] = 0.0;
            }
        }
    }

    public 
    Action:RCC_TopSpeed(iClientiArgs)
    {
        if (
    iClient 0)
        {
            static 
    Handle:g_hGlobalMenu INVALID_HANDLE;
            if (
    g_bDataUpdated == true)
            {
                
    Function_SortArray();

                if (
    g_hGlobalMenu != INVALID_HANDLE)
                {
                    
    CloseHandle(g_hGlobalMenu);
                }

                
    g_hGlobalMenu CreateMenu(MenuHandler);
                
    SetMenuTitle(g_hGlobalMenu"Рейтинг самых быстрых на карте\n");

                
    decl String:szBuffer[32], String:szFormat[64], iSizeArray;

                
    iSizeArray GetArraySize(g_hArray_TopSpeed[ClientName]);
                for (new 
    0iSizeArrayi++)
                {
                    
    GetArrayString(g_hArray_TopSpeed[ClientName], iszBuffersizeof(szBuffer));
                    
    strcopy(szFormatsizeof(szFormat), szBuffer);

                    
    GetArrayString(g_hArray_TopSpeed[ClientSteamID], iszBuffersizeof(szBuffer));
                    
    Format(szFormatsizeof(szFormat), "%s - %s"szFormatszBuffer);

                    
    Format(szFormatsizeof(szFormat), "%s - %.2f км/ч"szFormatGetArrayCell(g_hArray_TopSpeed[ClientSpeed], i));

                    
    AddMenuItem(g_hGlobalMenu""szFormatITEMDRAW_DISABLED);
                }

                
    g_bDataUpdated false;
            }

            
    DisplayMenu(g_hGlobalMenuiClientMENU_TIME_FOREVER);
        }

        return 
    Plugin_Handled;
    }

    public 
    Action:RCC_TopSpeed_Switch(iClientiArgs)
    {
        if (
    iClient 0)
        {
            
    ReplyToCommand(iClient"\x01\x05[TopSpeed] \x01Вы %sключили показ скорости", (g_bClientShowMessage[iClient] = !g_bClientShowMessage[iClient]) ? "в" "от");

            
    decl String:szBuffer[8];
            
    IntToString(g_bClientShowMessage[iClient], szBuffersizeof(szBuffer));
            
    SetClientCookie(iClientg_hCookieTopSpeedPrefszBuffer);
        }

        return 
    Plugin_Handled;
    }

    public 
    MenuHandler(Handle:hMenuMenuAction:iActioniParam1iParam2)
    {
        
    // Code..
    }

    public 
    Action:OnTimerStart(Handle:hTimerany:iClient)
    {
        
    decl Float:fPosition_New[3];

        
    GetClientAbsOrigin(iClientfPosition_New);

        if (
    g_fPosition_Old[iClient][0] == 0.0 && g_fPosition_Old[iClient][1] == 0.0 && g_fPosition_Old[iClient][2] == 0.0)
        {
            
    g_fPosition_Old[iClient][0] = fPosition_New[0];
            
    g_fPosition_Old[iClient][1] = fPosition_New[1];
            
    g_fPosition_Old[iClient][2] = fPosition_New[2];
        }

        new 
    Float:fSpeed SquareRoot(    (fPosition_New[0] - g_fPosition_Old[iClient][0]) * (fPosition_New[0] - g_fPosition_Old[iClient][0])    +
                                        (
    fPosition_New[1] - g_fPosition_Old[iClient][1]) * (fPosition_New[1] - g_fPosition_Old[iClient][1]) +
                                        (
    fPosition_New[2] - g_fPosition_Old[iClient][2]) * (fPosition_New[2] - g_fPosition_Old[iClient][2])) * 0.01905 *3.6;

        
    g_fPosition_Old[iClient][0] = fPosition_New[0];
        
    g_fPosition_Old[iClient][1] = fPosition_New[1];
        
    g_fPosition_Old[iClient][2] = fPosition_New[2];

        if (
    fSpeed g_fMinSpeed)
        {
            
    decl iPosition;
            if ((
    iPosition FindStringInArray(g_hArray_TopSpeed[ClientSteamID], g_szClientSteamID[iClient])) != -1)
            {
                if (
    GetArrayCell(g_hArray_TopSpeed[ClientSpeed], iPosition) < fSpeed)
                {
                    for (new 
    03i++)
                    {
                        
    RemoveFromArray(g_hArray_TopSpeed[i], iPosition);
                    }

                    
    PushArrayString(g_hArray_TopSpeed[ClientName],        g_szClientName[iClient]);
                    
    PushArrayString(g_hArray_TopSpeed[ClientSteamID],    g_szClientSteamID[iClient]);
                    
    PushArrayCell(g_hArray_TopSpeed[ClientSpeed],        fSpeed);
                }
            }
            else
            {
                
    PushArrayString(g_hArray_TopSpeed[ClientName],        g_szClientName[iClient]);
                
    PushArrayString(g_hArray_TopSpeed[ClientSteamID],    g_szClientSteamID[iClient]);
                
    PushArrayCell(g_hArray_TopSpeed[ClientSpeed],        fSpeed);
            }

            
    g_bDataUpdated true;
        }

        if (
    g_bClientShowMessage[iClient] == true)
        {
            
    PrintHintText(iClient"Текущая скорость: %.2f км/ч"fSpeed);
        }
    }

    stock Function_SortArray()
    {
        
    decl Handle:hArray_TopSpeed[3];
        
    hArray_TopSpeed[ClientName]        = CreateArray(32);
        
    hArray_TopSpeed[ClientSteamID]    = CreateArray(32);
        
    hArray_TopSpeed[ClientSpeed]    = CloneArray(g_hArray_TopSpeed[ClientSpeed]);

        
    SortADTArray(hArray_TopSpeed[ClientSpeed], Sort_DescendingSort_Float);

        
    decl iSizeArray;
        if ((
    iSizeArray GetArraySize(hArray_TopSpeed[ClientSpeed])) > TOP_SIZE)
        {
            for (new 
    03i++)
            {
                
    ResizeArray(hArray_TopSpeed[i], TOP_SIZE);
            }
           
            
    iSizeArray TOP_SIZE;
        }

        
    decl String:szBuffer[32], iPosition;

        for (new 
    0iSizeArrayi++)
        {
            if ((
    iPosition FindValueInArray(g_hArray_TopSpeed[ClientSpeed], GetArrayCell(hArray_TopSpeed[ClientSpeed], i))) != -1)
            {
                
    GetArrayString(g_hArray_TopSpeed[ClientName], iPositionszBuffersizeof(szBuffer));
                
    PushArrayString(hArray_TopSpeed[ClientName], szBuffer);

                
    GetArrayString(g_hArray_TopSpeed[ClientSteamID], iPositionszBuffersizeof(szBuffer));
                
    PushArrayString(hArray_TopSpeed[ClientSteamID], szBuffer);

                
    g_fMinSpeed GetArrayCell(g_hArray_TopSpeed[ClientSpeed], iPosition);
                
    //PushArrayCell(hArray_TopSpeed[ClientSpeed], g_fMinSpeed);

                
    if (TOP_SIZE)
                {
                    
    g_fMinSpeed 0.0;
                }
            }
        }

        for (new 
    03i++)
        {
            
    g_hArray_TopSpeed[i] = CloneArray(hArray_TopSpeed[i]);
            
    CloseHandle(hArray_TopSpeed[i]);
        }
    }
     

    Вложения:

    666FoX666 нравится это.
  2. AS TRO

    AS TRO

    Сообщения:
    1.055
    Симпатии:
    508
    А почему в txt? Почему бы не работать с sql? :)
     
  3. vaxa

    vaxa Rock Rulet!

    Сообщения:
    859
    Симпатии:
    102
    @AS TRO, да тут инфы мало для sql,да и пускай будет идти нагрузка на жесткий диск,чем на оперативную память.Чем проще тем лучше:)
     
  4. Monomizer

    Monomizer Мимо пробегал Супер-модератор

    Сообщения:
    1.528
    Симпатии:
    201
    Оффтоп
     
  5. 666FoX666

    666FoX666

    Сообщения:
    628
    Симпатии:
    60
    А можно эту инфу засандалить текстом с правой стороны экрана, а не "менюшкой"?
     
  6. Drumanid

    Drumanid Дилетант

    Сообщения:
    568
    Симпатии:
    193
    L 06/19/2016 - 11:31:54: [SM] Displaying call stack trace for plugin "top_speed.smx":
    L 06/19/2016 - 11:31:54: [SM] [0] Line 129, C:\blablabla\sourcemod-1.7.3-git5302-windows\addons\sourcemod\scripting\top_speed.sp::OnMapEnd()
    L 06/19/2016 - 11:31:55: Error log file session closed.
     
  7. The End Is Near...

    The End Is Near... Russian Roulette

    Сообщения:
    893
    Симпатии:
    659
    весь лог?
     
  8. Drumanid

    Drumanid Дилетант

    Сообщения:
    568
    Симпатии:
    193
    После смены карты вот такая шняга... :D

    L 06/19/2016 - 12:00:26: [SM] Native "GetArrayCell" reported: Invalid index 16 (count: 13)
    L 06/19/2016 - 12:00:26: [SM] Displaying call stack trace for plugin "top_speed.smx":
    L 06/19/2016 - 12:00:26: [SM] [0] Line 293, C:\Users\顯闉\Downloads\sourcemod-1.7.3-git5302-windows\addons\sourcemod\scripting\top_speed.sp::OnTimerStart()
     
  9. The End Is Near...

    The End Is Near... Russian Roulette

    Сообщения:
    893
    Симпатии:
    659
    что-то менял? не вижу такого в данных строках, 293 строка - for (new i = 0; i < 3; i++) - тут нет GetArrayCell, тоже самое и с первой ошибкой постом выше, буду смотреть
     
  10. Drumanid

    Drumanid Дилетант

    Сообщения:
    568
    Симпатии:
    193
    Ничего вроде бы не менял , только лишь раскрасил hud...
    и изменил команды.

    PHP:
    #include <sourcemod>
    #include <clientprefs>

    #define PATH_FILE "addons/sourcemod/configs/top_speed.txt"

    #define TOP_SIZE 5

    public Plugin:myinfo =
    {
        
    name "TopSpeed",
        
    author "The End Is Near...",
        
    version "1.0.0",
        
    url "http://world-source.ru/"
    };

    #define ClientName        0
    #define ClientSteamID    1
    #define ClientSpeed        2

    new Handle:g_hKeyValues_TopSpeed        INVALID_HANDLE,
        
    Handle:g_hArray_TopSpeed[3]            = INVALID_HANDLE;

    new 
    Float:g_fMinSpeed 0.0;

    new 
    Float:g_fPosition_Old[MAXPLAYERS 1][3];

    new 
    Handle:g_hClientTimer[MAXPLAYERS 1] = {INVALID_HANDLE, ...};

    new 
    Handle:g_hCookieTopSpeedPref INVALID_HANDLE;

    new 
    bool:g_bClientShowMessage[MAXPLAYERS 1] = {false, ...};

    new 
    bool:g_bDataUpdated true;

    new 
    String:g_szClientName[MAXPLAYERS 1][32],
        
    String:g_szClientSteamID[MAXPLAYERS 1][32];

    public 
    OnPluginStart()
    {
        
    g_hKeyValues_TopSpeed CreateKeyValues("top_speed");

        
    FileToKeyValues(g_hKeyValues_TopSpeedPATH_FILE);

        for (new 
    03i++)
        {
            
    g_hArray_TopSpeed[i] = CreateArray(32);
        }

        
    g_hCookieTopSpeedPref RegClientCookie("Top Speed""Top Speed"CookieAccess_Private);

        
    HookEvent("player_spawn"Event_OnPlayerSpawn);
        
    HookEvent("player_death"Event_OnPlayerDeath);

        
    RegConsoleCmd("st"RCC_TopSpeed);
        
    RegConsoleCmd("speed"RCC_TopSpeed_Switch);

        
    OnMapStart();
    }

    public 
    OnMapStart()
    {
        for (new 
    03++)
        {
            
    ClearArray(g_hArray_TopSpeed[i]);
        }

        
    decl String:szCurrentMap[32];
        
    GetCurrentMap(szCurrentMapsizeof(szCurrentMap));

        
    KvRewind(g_hKeyValues_TopSpeed);
        if (
    KvJumpToKey(g_hKeyValues_TopSpeedszCurrentMaptrue) == true)
        {
            if (
    KvGotoFirstSubKey(g_hKeyValues_TopSpeed) == true)
            {
                new 
    iCount 1;

                do
                {
                    
    decl String:szClientSteamID[32];
                    
    KvGetString(g_hKeyValues_TopSpeed"name"szCurrentMapsizeof(szCurrentMap), "PLAYER");
                    
    KvGetString(g_hKeyValues_TopSpeed"steamid"szClientSteamIDsizeof(szClientSteamID), "STEAMID");

                    
    PushArrayString(g_hArray_TopSpeed[ClientName], szCurrentMap);
                    
    PushArrayString(g_hArray_TopSpeed[ClientSteamID], szClientSteamID);

                    
    g_fMinSpeed KvGetFloat(g_hKeyValues_TopSpeed"speed");
                    
    PushArrayCell(g_hArray_TopSpeed[ClientSpeed], g_fMinSpeed);

                    if (
    iCount TOP_SIZE)
                    {
                        
    g_fMinSpeed 0.0;
                        
    iCount++;
                    }
                }
                while (
    KvGotoNextKey(g_hKeyValues_TopSpeed) == true);
            }      
        }

        
    g_bDataUpdated true;
    }

    public 
    OnMapEnd()
    {
        if (
    g_bDataUpdated == true)
        {
            
    Function_SortArray();
        }

        
    decl String:szBuffer[32];
        
    GetCurrentMap(szBuffersizeof(szBuffer));

        
    KvRewind(g_hKeyValues_TopSpeed);
        if (
    KvJumpToKey(g_hKeyValues_TopSpeedszBufferfalse) == true)
        {
            new 
    iSizeArray GetArraySize(g_hArray_TopSpeed[ClientName]);
            for (new 
    0iSizeArrayi++)
            {
                
    FormatEx(szBuffersizeof(szBuffer), "%d"i+1);
                if (
    KvJumpToKey(g_hKeyValues_TopSpeedszBuffertrue) == true)
                {
                    
    GetArrayString(g_hArray_TopSpeed[ClientName], iszBuffersizeof(szBuffer));
                    
    KvSetString(g_hKeyValues_TopSpeed"name"szBuffer);

                    
    GetArrayString(g_hArray_TopSpeed[ClientSteamID], iszBuffersizeof(szBuffer));
                    
    KvSetString(g_hKeyValues_TopSpeed"steamid"szBuffer);

                    
    KvSetFloat(g_hKeyValues_TopSpeed"speed"GetArrayCell(g_hArray_TopSpeed[ClientSpeed], i));
                }

                
    KvGoBack(g_hKeyValues_TopSpeed);
            }
        }

        
    KvRewind(g_hKeyValues_TopSpeed);
        
    KeyValuesToFile(g_hKeyValues_TopSpeedPATH_FILE);
    }

    public 
    OnClientAuthorized(iClient, const String:szAuth[])
    {
        if (
    AreClientCookiesCached(iClient))
        {
            
    decl String:szBuffer[8];
            
    GetClientCookie(iClientg_hCookieTopSpeedPrefszBuffersizeof(szBuffer));
            if(
    strcmp(szBuffer""false) != 0)
            {
                
    g_bClientShowMessage[iClient] = bool:(StringToInt(szBuffer));
            }
            else
            {
                
    g_bClientShowMessage[iClient] = true;
            }
        }

        
    GetClientName(iClientg_szClientName[iClient], sizeof(g_szClientName));
        
    strcopy(g_szClientSteamID[iClient], sizeof(g_szClientSteamID), szAuth);
    }

    public 
    OnClientDisconnect(iClient)
    {
        if (
    g_hClientTimer[iClient] != INVALID_HANDLE)
        {
            
    KillTimer(g_hClientTimer[iClient]);
            
    g_hClientTimer[iClient] = INVALID_HANDLE;
        }
    }

    public 
    Event_OnPlayerSpawn(Handle:hEvent, const String:szEventName[], bool:bSilent)
    {
        new 
    iClient GetClientOfUserId(GetEventInt(hEvent"userid"));

        if (
    iClient && GetClientTeam(iClient)> 1)
        {
            
    CreateTimer(4.0OnTimerStart_PlayerSpawnGetEventInt(hEvent"userid"));

            
    g_fPosition_Old[iClient][0] = g_fPosition_Old[iClient][1] = g_fPosition_Old[iClient][2] = 0.0;
        }
        else
        {
            
    OnClientDisconnect(iClient);
        }  
    }

    public 
    Event_OnPlayerDeath(Handle:hEvent, const String:szEventName[], bool:bSilent)
    {
        
    OnClientDisconnect(GetClientOfUserId(GetEventInt(hEvent"userid")));
    }

    public 
    Action:OnTimerStart_PlayerSpawn(Handle:hTimerany:iUserID)
    {
        
    iUserID GetClientOfUserId(iUserID);
        if (
    iUserID 0)
        {
            if (
    IsClientInGame(iUserID) == true && IsPlayerAlive(iUserID) == true)
            {
                
    OnClientDisconnect(iUserID);

                
    g_hClientTimer[iUserID] = CreateTimer(0.5OnTimerStartiUserIDTIMER_REPEAT);

                
    g_fPosition_Old[iUserID][0] = g_fPosition_Old[iUserID][1] = g_fPosition_Old[iUserID][2] = 0.0;
            }
        }
    }

    public 
    Action:RCC_TopSpeed(iClientiArgs)
    {
        if (
    iClient 0)
        {
            static 
    Handle:g_hGlobalMenu INVALID_HANDLE;
            if (
    g_bDataUpdated == true)
            {
                
    Function_SortArray();

                if (
    g_hGlobalMenu != INVALID_HANDLE)
                {
                    
    CloseHandle(g_hGlobalMenu);
                }

                
    g_hGlobalMenu CreateMenu(MenuHandler);
                
    SetMenuTitle(g_hGlobalMenu"Рейтинг самых быстрых на карте\n");

                
    decl String:szBuffer[32], String:szFormat[64], iSizeArray;

                
    iSizeArray GetArraySize(g_hArray_TopSpeed[ClientName]);
                for (new 
    0iSizeArrayi++)
                {
                    
    GetArrayString(g_hArray_TopSpeed[ClientName], iszBuffersizeof(szBuffer));
                    
    strcopy(szFormatsizeof(szFormat), szBuffer);

                    
    GetArrayString(g_hArray_TopSpeed[ClientSteamID], iszBuffersizeof(szBuffer));
                    
    Format(szFormatsizeof(szFormat), "%s - %s"szFormatszBuffer);

                    
    Format(szFormatsizeof(szFormat), "%s - %.2f км/ч"szFormatGetArrayCell(g_hArray_TopSpeed[ClientSpeed], i));

                    
    AddMenuItem(g_hGlobalMenu""szFormatITEMDRAW_DISABLED);
                }

                
    g_bDataUpdated false;
            }

            
    DisplayMenu(g_hGlobalMenuiClientMENU_TIME_FOREVER);
        }

        return 
    Plugin_Handled;
    }

    public 
    Action:RCC_TopSpeed_Switch(iClientiArgs)
    {
        if (
    iClient 0)
        {
            
    ReplyToCommand(iClient" \x07[ \x04Спидометер \x07] \x01Вы %sключили показ скорости", (g_bClientShowMessage[iClient] = !g_bClientShowMessage[iClient]) ? "в" "от");

            
    decl String:szBuffer[8];
            
    IntToString(g_bClientShowMessage[iClient], szBuffersizeof(szBuffer));
            
    SetClientCookie(iClientg_hCookieTopSpeedPrefszBuffer);
        }

        return 
    Plugin_Handled;
    }

    public 
    MenuHandler(Handle:hMenuMenuAction:iActioniParam1iParam2)
    {
        
    // Code..
    }

    public 
    Action:OnTimerStart(Handle:hTimerany:iClient)
    {
        
    decl Float:fPosition_New[3];

        
    GetClientAbsOrigin(iClientfPosition_New);

        if (
    g_fPosition_Old[iClient][0] == 0.0 && g_fPosition_Old[iClient][1] == 0.0 && g_fPosition_Old[iClient][2] == 0.0)
        {
            
    g_fPosition_Old[iClient][0] = fPosition_New[0];
            
    g_fPosition_Old[iClient][1] = fPosition_New[1];
            
    g_fPosition_Old[iClient][2] = fPosition_New[2];
        }

        new 
    Float:fSpeed SquareRoot(    (fPosition_New[0] - g_fPosition_Old[iClient][0]) * (fPosition_New[0] - g_fPosition_Old[iClient][0])    +
                                        (
    fPosition_New[1] - g_fPosition_Old[iClient][1]) * (fPosition_New[1] - g_fPosition_Old[iClient][1]) +
                                        (
    fPosition_New[2] - g_fPosition_Old[iClient][2]) * (fPosition_New[2] - g_fPosition_Old[iClient][2])) * 0.01905 *3.6;

        
    g_fPosition_Old[iClient][0] = fPosition_New[0];
        
    g_fPosition_Old[iClient][1] = fPosition_New[1];
        
    g_fPosition_Old[iClient][2] = fPosition_New[2];

        if (
    fSpeed g_fMinSpeed)
        {
            
    decl iPosition;
            if ((
    iPosition FindStringInArray(g_hArray_TopSpeed[ClientSteamID], g_szClientSteamID[iClient])) != -1)
            {
                if (
    GetArrayCell(g_hArray_TopSpeed[ClientSpeed], iPosition) < fSpeed)
                {
                    for (new 
    03i++)
                    {
                        
    RemoveFromArray(g_hArray_TopSpeed[i], iPosition);
                    }

                    
    PushArrayString(g_hArray_TopSpeed[ClientName],        g_szClientName[iClient]);
                    
    PushArrayString(g_hArray_TopSpeed[ClientSteamID],    g_szClientSteamID[iClient]);
                    
    PushArrayCell(g_hArray_TopSpeed[ClientSpeed],        fSpeed);
                }
            }
            else
            {
                
    PushArrayString(g_hArray_TopSpeed[ClientName],        g_szClientName[iClient]);
                
    PushArrayString(g_hArray_TopSpeed[ClientSteamID],    g_szClientSteamID[iClient]);
                
    PushArrayCell(g_hArray_TopSpeed[ClientSpeed],        fSpeed);
            }

            
    g_bDataUpdated true;
        }

        if (
    g_bClientShowMessage[iClient] == true)
        {
            
    PrintHintText(iClient"Текущая скорость: <font color='#00FF1E'>%.2f</font> км/ч"fSpeed);
        }
    }

    stock Function_SortArray()
    {
        
    decl Handle:hArray_TopSpeed[3];
        
    hArray_TopSpeed[ClientName]        = CreateArray(32);
        
    hArray_TopSpeed[ClientSteamID]    = CreateArray(32);
        
    hArray_TopSpeed[ClientSpeed]    = CloneArray(g_hArray_TopSpeed[ClientSpeed]);

        
    SortADTArray(hArray_TopSpeed[ClientSpeed], Sort_DescendingSort_Float);

        
    decl iSizeArray;
        if ((
    iSizeArray GetArraySize(hArray_TopSpeed[ClientSpeed])) > TOP_SIZE)
        {
            for (new 
    03i++)
            {
                
    ResizeArray(hArray_TopSpeed[i], TOP_SIZE);
            }
          
            
    iSizeArray TOP_SIZE;
        }

        
    decl String:szBuffer[32], iPosition;

        for (new 
    0iSizeArrayi++)
        {
            if ((
    iPosition FindValueInArray(g_hArray_TopSpeed[ClientSpeed], GetArrayCell(hArray_TopSpeed[ClientSpeed], i))) != -1)
            {
                
    GetArrayString(g_hArray_TopSpeed[ClientName], iPositionszBuffersizeof(szBuffer));
                
    PushArrayString(hArray_TopSpeed[ClientName], szBuffer);

                
    GetArrayString(g_hArray_TopSpeed[ClientSteamID], iPositionszBuffersizeof(szBuffer));
                
    PushArrayString(hArray_TopSpeed[ClientSteamID], szBuffer);

                
    g_fMinSpeed GetArrayCell(g_hArray_TopSpeed[ClientSpeed], iPosition);
                
    //PushArrayCell(hArray_TopSpeed[ClientSpeed], g_fMinSpeed);

                
    if (TOP_SIZE)
                {
                    
    g_fMinSpeed 0.0;
                }
            }
        }

        for (new 
    03i++)
        {
            
    g_hArray_TopSpeed[i] = CloneArray(hArray_TopSpeed[i]);
            
    CloseHandle(hArray_TopSpeed[i]);
        }
    }
     
  11. The End Is Near...

    The End Is Near... Russian Roulette

    Сообщения:
    893
    Симпатии:
    659
    заметил пару грубых ошибок, попробую исправить, если не лень, потестишь?)
     
  12. Drumanid

    Drumanid Дилетант

    Сообщения:
    568
    Симпатии:
    193
    Без проблем, закидывай в личку или сразу сюда.
     
  13. The End Is Near...

    The End Is Near... Russian Roulette

    Сообщения:
    893
    Симпатии:
    659
    --- Добавлено позже ---
    хотя, смотрю еще, вроде не исправил ошибку
     

    Вложения:

    • top_speed.sp
      Размер файла:
      10,2 КБ
      Просмотров:
      7
    Последнее редактирование: 19 июн 2016
  14. Drumanid

    Drumanid Дилетант

    Сообщения:
    568
    Симпатии:
    193
    Ошибки нету, работает нормально, посмотрим что дальше будет.