SpawnTools 7 не показывает дефолтные спавны на карте

Тема в разделе "Counter-Strike: Global Offensive", создана пользователем NiGaByte, 21 май 2016.

  1. NiGaByte

    NiGaByte

    Сообщения:
    501
    Симпатии:
    84
    В принципе вся проблема в названии темы, SpawnTools 7 не показывает дефолтные спавны на карте, с одной лишь оговоркой, это zm_ карты, вот у меня вопрос, так и должно быть?
    Я просто подумал, если буду делать сервер на 64 игрока, хватит ли мне места чтобы заспавнить всех, решил проверить, и вот как это выглядит:
    Безымянный.jpg
    Если попытаюсь добавить точку, в чат сообщение получу, а вот в хинт нет, всё будет по нулям.
     
  2. Hejter

    Hejter Mapper Source Engine

    Сообщения:
    1.771
    Симпатии:
    259
    @NiGaByte, дай версию которую используешь.
     
  3. NiGaByte

    NiGaByte

    Сообщения:
    501
    Симпатии:
    84
    Точно, забыл ;D
    Код:
    /*
        [SPAWN<>TOOLS<>7]
    */
    #pragma semicolon 1
    
    #include <sourcemod>
    #include <sdktools>
    #undef REQUIRE_PLUGIN
    #include <adminmenu>
    
    #define VERSION "0.9"
    
    public Plugin:myinfo =
    {
        name = "spawntools7",
        author = "meng",
        description = "spawn point editing tools",
        version = VERSION,
        url = ""
    }
    
    new Handle:AdminMenu;
    new Handle:KillSpawnsADT;
    new Handle:CustSpawnsADT;
    new bool:RemoveDefSpawns;
    new bool:InEditMode;
    new String:MapCfgPath[PLATFORM_MAX_PATH];
    new RedGlowSprite;
    new BlueGlowSprite;
    
    public OnPluginStart()
    {
        CreateConVar("sm_spawntools7_version", VERSION, "Spawn Tools 7 Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
        decl String:configspath[PLATFORM_MAX_PATH];
        BuildPath(Path_SM, configspath, sizeof(configspath), "configs/spawntools7");
        if (!DirExists(configspath))
            CreateDirectory(configspath, 0x0265);
    
        new Handle:topmenu;
        if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
            OnAdminMenuReady(topmenu);
    
        KillSpawnsADT = CreateArray(3);
        CustSpawnsADT = CreateArray(5);
    }
    
    public OnMapStart()
    {
        RemoveDefSpawns = false;
        InEditMode = false;
    
        decl String:mapName[64];
        GetCurrentMap(mapName, sizeof(mapName));
        BuildPath(Path_SM, MapCfgPath, sizeof(MapCfgPath), "configs/spawntools7/%s.cfg", mapName);
        ReadConfig();
    
        RedGlowSprite = PrecacheModel("sprites/purpleglow1.vmt");
        BlueGlowSprite = PrecacheModel("sprites/blueglow1.vmt");
    }
    
    ReadConfig()
    {
        new Handle:kv = CreateKeyValues("ST7Root");
        if (FileToKeyValues(kv, MapCfgPath))
        {
            new num;
            decl String:sBuffer[32], Float:fVec[3], Float:DataFloats[5];
            if (KvGetNum(kv, "remdefsp"))
            {
                RemoveAllDefaultSpawns();
                RemoveDefSpawns = true;
            }
            else
            {
                Format(sBuffer, sizeof(sBuffer), "rs:%d:pos", num);
                KvGetVector(kv, sBuffer, fVec);
                while (fVec[0] != 0.0)
                {
                    RemoveSingleDefaultSpawn(fVec);
                    PushArrayArray(KillSpawnsADT, fVec);
                    num++;
                    Format(sBuffer, sizeof(sBuffer), "rs:%d:pos", num);
                    KvGetVector(kv, sBuffer, fVec);
                }
            }
            num = 0;
            Format(sBuffer, sizeof(sBuffer), "ns:%d:pos", num);
            KvGetVector(kv, sBuffer, fVec);
            while (fVec[0] != 0.0)
            {
                DataFloats[0] = fVec[0];
                DataFloats[1] = fVec[1];
                DataFloats[2] = fVec[2];
                Format(sBuffer, sizeof(sBuffer), "ns:%d:ang", num);
                DataFloats[3] = KvGetFloat(kv, sBuffer);
                Format(sBuffer, sizeof(sBuffer), "ns:%d:team", num);
                DataFloats[4] = KvGetFloat(kv, sBuffer);
                CreateSpawn(DataFloats, false);
                PushArrayArray(CustSpawnsADT, DataFloats);
                num++;
                Format(sBuffer, sizeof(sBuffer), "ns:%d:pos", num);
                KvGetVector(kv, sBuffer, fVec);
            }
        }
    
        CloseHandle(kv);
    }
    
    public OnLibraryRemoved(const String:name[])
    {
        if (StrEqual(name, "adminmenu"))
            AdminMenu = INVALID_HANDLE;
    }
    
    public OnAdminMenuReady(Handle:topmenu)
    {
        if (topmenu == AdminMenu)
            return;
    
        AdminMenu = topmenu;
        new TopMenuObject:serverCmds = FindTopMenuCategory(AdminMenu, ADMINMENU_SERVERCOMMANDS);
        AddToTopMenu(AdminMenu, "sm_spawntools7", TopMenuObject_Item, TopMenuHandler, serverCmds, "sm_spawntools7", ADMFLAG_RCON);
    }
    
    public TopMenuHandler(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
    {
        if (action == TopMenuAction_DisplayOption)
            Format(buffer, maxlength, "Spawn Tools 7");
    
        else if (action == TopMenuAction_SelectOption)
            ShowToolzMenu(param);
    }
    
    ShowToolzMenu(client)
    {
        new Handle:menu = CreateMenu(MainMenuHandler);
        SetMenuTitle(menu, "Spawn Tools 7");
        decl String:menuItem[64];
        Format(menuItem, sizeof(menuItem), "%s Edit Mode", InEditMode == false ? "Enable" : "Disable");
        AddMenuItem(menu, "0", menuItem);
        Format(menuItem, sizeof(menuItem), "%s Default Spawn Removal", RemoveDefSpawns == false ? "Enable" : "Disable");
        AddMenuItem(menu, "1", menuItem);
        AddMenuItem(menu, "2", "Add T Spawn");
        AddMenuItem(menu, "3", "Add CT Spawn");
        AddMenuItem(menu, "4", "Remove Spawn");
        AddMenuItem(menu, "5", "Save Configuration");
        DisplayMenu(menu, client, MENU_TIME_FOREVER);
    }
    
    public MainMenuHandler(Handle:menu, MenuAction:action, client, selection)
    {
        if (action == MenuAction_Select)
        {
            if (selection == 0)
            {
                InEditMode = InEditMode == false ? true : false;
                PrintToChatAll("[SpawnTools7] Edit Mode %s.", InEditMode == false ? "Disabled" : "Enabled");
                if (InEditMode)
                    CreateTimer(1.0, ShowEditModeGoodies, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
    
                ShowToolzMenu(client);
            }
            else if (selection == 1)
            {
                RemoveDefSpawns = RemoveDefSpawns == false ? true : false;
                PrintToChatAll("[SpawnTools7] Default Spawn Removal will be %s.", RemoveDefSpawns == false ? "Disabled" : "Enabled");
                ShowToolzMenu(client);
            }
            else if (selection == 2)
            {
                InitializeNewSpawn(client, 2);
                ShowToolzMenu(client);
            }
            else if (selection == 3)
            {
                InitializeNewSpawn(client, 3);
                ShowToolzMenu(client);
            }
            else if (selection == 4)
            {
                if (!RemoveSpawn(client))
                    PrintToChatAll("[SpawnTools7] No valid spawn point found.");
                else
                    PrintToChatAll("[SpawnTools7] Spawn point removed!");
    
                ShowToolzMenu(client);
            }
            else if (selection == 5)
            {
                SaveConfiguration();
                ShowToolzMenu(client);
            }
        }
        else if (action == MenuAction_End)
            CloseHandle(menu);
    }
    
    public Action:ShowEditModeGoodies(Handle:timer)
    {
        if (!InEditMode)
            return Plugin_Stop;
    
        new maxEnt = GetMaxEntities(), tsCount, ctsCount;
        decl String:sClassName[64], Float:fVec[3];
        for (new i = MaxClients; i < maxEnt; i++)
        {
            if (IsValidEdict(i) && IsValidEntity(i) && GetEdictClassname(i, sClassName, sizeof(sClassName)))
            {
                if (StrEqual(sClassName, "info_player_terrorist"))
                {
                    tsCount++;
                    GetEntPropVector(i, Prop_Data, "m_vecOrigin", fVec);
                    TE_SetupGlowSprite(fVec, RedGlowSprite, 1.0, 0.4, 249);
                    TE_SendToAll();
                }
                else if (StrEqual(sClassName, "info_player_counterterrorist"))
                {
                    ctsCount++;
                    GetEntPropVector(i, Prop_Data, "m_vecOrigin", fVec);
                    TE_SetupGlowSprite(fVec, BlueGlowSprite, 1.0, 0.3, 237);
                    TE_SendToAll();
                }
            }
        }
        PrintHintTextToAll("T Spawns: %i \nCT Spawns: %i", tsCount, ctsCount);
    
        return Plugin_Continue;
    }
    
    RemoveAllDefaultSpawns()
    {
        new maxent = GetMaxEntities();
        decl String:sClassName[64];
        for (new i = MaxClients; i < maxent; i++)
        {
            if (IsValidEdict(i) && IsValidEntity(i) && GetEdictClassname(i, sClassName, sizeof(sClassName)) &&
            (StrEqual(sClassName, "info_player_terrorist") || StrEqual(sClassName, "info_player_counterterrorist")))
                RemoveEdict(i);
        }
    }
    
    RemoveSingleDefaultSpawn(Float:fVec[3])
    {
        new maxent = GetMaxEntities();
        decl String:sClassName[64], Float:ent_fVec[3];
        for (new i = MaxClients; i < maxent; i++)
        {
            if (IsValidEdict(i) && IsValidEntity(i) && GetEdictClassname(i, sClassName, sizeof(sClassName)) &&
            (StrEqual(sClassName, "info_player_terrorist") || StrEqual(sClassName, "info_player_counterterrorist")))
            {
                GetEntPropVector(i, Prop_Data, "m_vecOrigin", ent_fVec);
                if (fVec[0] == ent_fVec[0])
                {
                    RemoveEdict(i);
                    break;
                }
            }
        }
    }
    
    InitializeNewSpawn(client, team)
    {
        decl Float:DataFloats[5], Float:posVec[3], Float:angVec[3];
        GetClientAbsOrigin(client, posVec);
        GetClientEyeAngles(client, angVec);
        DataFloats[0] = posVec[0];
        DataFloats[1] = posVec[1];
        DataFloats[2] = (posVec[2] + 16.0);
        DataFloats[3] = angVec[1];
        DataFloats[4] = float(team);
    
        if (CreateSpawn(DataFloats, true))
            PrintToChatAll("[SpawnTools7] New spawn point created!");
        else
            LogError("failed to create new sp entity");
    }
    
    CreateSpawn(Float:DataFloats[5], bool:isNew)
    {
        decl Float:posVec[3], Float:angVec[3];
        posVec[0] = DataFloats[0];
        posVec[1] = DataFloats[1];
        posVec[2] = DataFloats[2];
        angVec[0] = 0.0;
        angVec[1] = DataFloats[3];
        angVec[2] = 0.0;
    
        new entity = CreateEntityByName(DataFloats[4] == 2.0 ? "info_player_terrorist" : "info_player_counterterrorist");
        if (DispatchSpawn(entity))
        {
            TeleportEntity(entity, posVec, angVec, NULL_VECTOR);
            if (isNew)
                PushArrayArray(CustSpawnsADT, DataFloats);
    
            return true;
        }
    
        return false;
    }
    
    RemoveSpawn(client)
    {
        new arraySize = GetArraySize(CustSpawnsADT);
        new maxent = GetMaxEntities();
        decl Float:client_posVec[3], Float:DataFloats[5], String:sClassName[64], Float:ent_posVec[3], i, d;
        GetClientAbsOrigin(client, client_posVec);
        client_posVec[2] += 16;
        for (d = MaxClients; d < maxent; d++)
        {
            if (IsValidEdict(d) && IsValidEntity(d) && GetEdictClassname(d, sClassName, sizeof(sClassName)) &&
            (StrEqual(sClassName, "info_player_terrorist") || StrEqual(sClassName, "info_player_counterterrorist")))
            {
                GetEntPropVector(d, Prop_Data, "m_vecOrigin", ent_posVec);
                if (GetVectorDistance(client_posVec, ent_posVec) < 42.7)
                {
                    for (i = 0; i < arraySize; i++)
                    {
                        GetArrayArray(CustSpawnsADT, i, DataFloats);
                        if (DataFloats[0] == ent_posVec[0])
                        {
                            /* spawn was custom */
                            RemoveFromArray(CustSpawnsADT, i);
                            RemoveEdict(d);
    
                            return true;
                        }
                    }
                    /* spawn was default */
                    PushArrayArray(KillSpawnsADT, ent_posVec);
                    RemoveEdict(d);
    
                    return true;
                }
            }
        }
    
        return false;
    }
    
    SaveConfiguration()
    {
        new Handle:kv = CreateKeyValues("ST7Root");
        decl arraySize, String:sBuffer[32], Float:DataFloats[5], Float:posVec[3];
        KvJumpToKey(kv, "smdata", true);
        KvSetNum(kv, "remdefsp", RemoveDefSpawns == true ? 1 : 0);
        arraySize = GetArraySize(CustSpawnsADT);
        if (arraySize)
        {
            for (new i = 0; i < arraySize; i++)
            {
                GetArrayArray(CustSpawnsADT, i, DataFloats);
                posVec[0] = DataFloats[0];
                posVec[1] = DataFloats[1];
                posVec[2] = DataFloats[2];
                Format(sBuffer, sizeof(sBuffer), "ns:%d:pos", i);
                KvSetVector(kv, sBuffer, posVec);
                Format(sBuffer, sizeof(sBuffer), "ns:%d:ang", i);
                KvSetFloat(kv, sBuffer, DataFloats[3]);
                Format(sBuffer, sizeof(sBuffer), "ns:%d:team", i);
                KvSetFloat(kv, sBuffer, DataFloats[4]);
            }
        }
        arraySize = GetArraySize(KillSpawnsADT);
        if (arraySize)
        {
            for (new i = 0; i < arraySize; i++)
            {
                GetArrayArray(KillSpawnsADT, i, posVec);
                Format(sBuffer, sizeof(sBuffer), "rs:%d:pos", i);
                KvSetVector(kv, sBuffer, posVec);
            }
        }
        if (KeyValuesToFile(kv, MapCfgPath))
            PrintToChatAll("[SpawnTools7] Configuration Saved!");
        else
            LogError("failed to save to key values");
    
        CloseHandle(kv);
    }
    
    public OnMapEnd()
    {
        ClearArray(KillSpawnsADT);
        ClearArray(CustSpawnsADT);
    }
     
  4. Hejter

    Hejter Mapper Source Engine

    Сообщения:
    1.771
    Симпатии:
    259
    Так вроде дефолтные спавны можно удалить или они сами автоматом удаляютя когда стоит этот плагин.
    Чистая версия для CSGO CSGO how to add spawn now - AlliedModders переписанная на новый синтаксис.
     
    Последнее редактирование: 21 май 2016
    NiGaByte нравится это.
  5. NiGaByte

    NiGaByte

    Сообщения:
    501
    Симпатии:
    84
    мне не нужно удалять дефолтные, я же сказал мне нужно просто узнать кол-во спавнов на той или иной карте, если их не 64, то добавить ещё.
    Если стоит этот плагин дефолтные спавны не удаляются.
     
  6. Hejter

    Hejter Mapper Source Engine

    Сообщения:
    1.771
    Симпатии:
    259
    @NiGaByte, ну я же тебе скинул плагин, где все работает. Все равно у тебя игра CSGO, так почему не использовать то что написали для ксго с оптимизацией?
     
  7. Yura7181

    Yura7181

    Сообщения:
    367
    Симпатии:
    293
  8. NiGaByte

    NiGaByte

    Сообщения:
    501
    Симпатии:
    84
    @Hejter, всё хорошо работает. Только вот у меня есть не большая прозьба.
    Дело в том что раньше я юзал SpawnTools7Full.sp
    Добавлял необходимые точки, после чего отключал этот плагин и ставил SpawnTools7Lite.sp
    Он отличается тем, то что в нём убраны все функции редактирования точек, проще говоря этот код просто берёт из конфига позиции точек, и всё, в нём нет функций редактирования.
    Вот может быть кто сделает тоже самое с вот этим кодом?
    Код:
    /*
        [SPAWN<>TOOLS<>7]
    */
    
    #include <sourcemod>
    #include <sdktools>
    #include <sdkhooks>
    #undef REQUIRE_PLUGIN
    #include <adminmenu>
    #pragma newdecls required
    
    #define VERSION "1.0.1"
    
    public Plugin myinfo =
    {
        name = "[CS:GO] SpawnTools7",
        author = "meng & IDDQD",
        description = "spawn point editing tools",
        version = VERSION,
        url = "https://forums.alliedmods.net/showthread.php?t=115496"
    }
    
    Handle AdminMenu
    bool g_bRemoveDefSpawns = false, g_bInEditMode = false, g_bMapStarted = false, g_bCustomSpawnPoints = false;
    char MapCfgPath[PLATFORM_MAX_PATH], g_sWorkShopID[PLATFORM_MAX_PATH];
    int g_iBlueGlowSprite, g_iRedGlowSprite, g_iMapSpawnsNum = 0, g_iKilledSpawnsNum = 0, g_iCustomSpawnsNum = 0, g_iDefSpawnsClearNum = 0, g_iEditModeActivator = 0
    ArrayList g_hMapSpawns, g_hSpawnTeamNum, g_hKilledSpawns, g_hCustomSpawns, g_hCustomSpawnIndexes
    
    public void OnPluginStart()
    {
        char configspath[PLATFORM_MAX_PATH];
        BuildPath(Path_SM, configspath, sizeof(configspath), "configs/spawntools7")
        if (!DirExists(configspath))
            //S/fix by ch4os
            //CreateDirectory(configspath, 0x0265)
            CreateDirectory(configspath, 509)
            //E/fix by ch4os
          
        BuildPath(Path_SM, configspath, sizeof(configspath), "configs/spawntools7/workshop")
        if (!DirExists(configspath))
            //S/fix by ch4os
            //CreateDirectory(configspath, 0x0265)
            CreateDirectory(configspath, 509)
            //E/fix by ch4os
    
        Handle topmenu;
        if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
            OnAdminMenuReady(topmenu);
    
        g_hKilledSpawns = CreateArray(3)
        g_hCustomSpawns = CreateArray(5)
        g_hCustomSpawnIndexes = CreateArray()
        g_hMapSpawns = CreateArray()
        g_hSpawnTeamNum = CreateArray()
    }
    
    public void OnMapStart()
    {
        CreateTimer(0.1, TimerOnMapStart, _, TIMER_FLAG_NO_MAPCHANGE) // some maps, like de_cache, need a small delay before creating spawn points
    }
    
    public Action TimerOnMapStart(Handle timer)
    {
        if(!g_iCustomSpawnsNum)
            return
    
        float DataFloats[5]
        g_bCustomSpawnPoints = true
        for(int i = 0; i < g_iCustomSpawnsNum; ++i)
        {
            GetArrayArray(g_hCustomSpawns, i, DataFloats)
            CreateSpawn(DataFloats)
        }
        g_bCustomSpawnPoints = false
        PrintToServer("[SpawnTools7] Map has %i spawn points, %i%s killed, %i custom", g_iMapSpawnsNum, g_bRemoveDefSpawns ? g_iDefSpawnsClearNum : g_iKilledSpawnsNum, g_bRemoveDefSpawns ? " default spawns" : "", g_iCustomSpawnsNum)
    }
    
    public void OnEntityCreated(int entity, const char[] classname)
    {
        if(!g_bMapStarted)
        {
            if(!entity)
                return
    
            g_bMapStarted = true
            UTIL_MapStarted()
        }
    
        if(classname[0] == 'i' && classname[4] == '_' && classname[11] == '_')
        {
            switch(classname[12])
            {
                case 't': SDKHook(entity, SDKHook_SpawnPost, OnTsEntitySpawnPost)
                case 'c': SDKHook(entity, SDKHook_SpawnPost, OnCTsEntitySpawnPost)
            }
        }
    }
    
    public void OnTsEntitySpawnPost(int EntRef)
    {
        int entity = EntRefToEntIndex(EntRef)
      
        if((g_bRemoveDefSpawns && !g_bCustomSpawnPoints) || UTIL_IsDeadEntity(entity))
        {
            if(g_bRemoveDefSpawns)
                g_iDefSpawnsClearNum++
    
            AcceptEntityInput(entity, "Kill")
            return
        }
      
        if(g_bCustomSpawnPoints)
            PushArrayCell(g_hCustomSpawnIndexes, entity)
      
        g_iMapSpawnsNum++
        PushArrayCell(g_hSpawnTeamNum, 2)
        PushArrayCell(g_hMapSpawns, entity)
        SDKUnhook(entity, SDKHook_SpawnPost, OnTsEntitySpawnPost)
    }
    
    public void OnCTsEntitySpawnPost(int EntRef)
    {
        int entity = EntRefToEntIndex(EntRef)
    
        if((g_bRemoveDefSpawns && !g_bCustomSpawnPoints) || UTIL_IsDeadEntity(entity))
        {
            if(g_bRemoveDefSpawns)
                g_iDefSpawnsClearNum++
    
            AcceptEntityInput(entity, "Kill")
            return
        }
      
        if(g_bCustomSpawnPoints)
            PushArrayCell(g_hCustomSpawnIndexes, entity)
      
        g_iMapSpawnsNum++
        PushArrayCell(g_hSpawnTeamNum, 3)
        PushArrayCell(g_hMapSpawns, entity)
        SDKUnhook(entity, SDKHook_SpawnPost, OnCTsEntitySpawnPost)
    }
    
    void ReadConfig()
    {
        Handle kv = CreateKeyValues("ST7Root");
        if (FileToKeyValues(kv, MapCfgPath))
        {
            char sBuffer[32]
            float fVec[3], DataFloats[5];
            if (KvGetNum(kv, "remdefsp"))
                g_bRemoveDefSpawns = true;
            else
            {
                Format(sBuffer, 31, "rs:%d:pos", g_iKilledSpawnsNum);
                KvGetVector(kv, sBuffer, fVec);
                while (fVec[0] != 0.0)
                {
                    PushArrayArray(g_hKilledSpawns, fVec);
                    g_iKilledSpawnsNum++;
                    Format(sBuffer, 31, "rs:%d:pos", g_iKilledSpawnsNum);
                    KvGetVector(kv, sBuffer, fVec);
                }
            }
    
            Format(sBuffer, 31, "ns:%d:pos", g_iCustomSpawnsNum);
            KvGetVector(kv, sBuffer, fVec);
            while (fVec[0] != 0.0)
            {
                DataFloats[0] = fVec[0];
                DataFloats[1] = fVec[1];
                DataFloats[2] = fVec[2];
                Format(sBuffer, 31, "ns:%d:ang", g_iCustomSpawnsNum);
                DataFloats[3] = KvGetFloat(kv, sBuffer);
                Format(sBuffer, 31, "ns:%d:team", g_iCustomSpawnsNum);
                DataFloats[4] = KvGetFloat(kv, sBuffer);
                PushArrayArray(g_hCustomSpawns, DataFloats);
                g_iCustomSpawnsNum++;
                Format(sBuffer, 31, "ns:%d:pos", g_iCustomSpawnsNum);
                KvGetVector(kv, sBuffer, fVec);
            }
        }
        CloseHandle(kv);
    }
    
    public void OnLibraryRemoved(const char[] name)
    {
        if (strcmp(name, "adminmenu") == 0)
            AdminMenu = INVALID_HANDLE;
    }
    
    public void OnClientDisconnect(int client)
    {
        if(g_iEditModeActivator == client)
        {
            g_iEditModeActivator = 0
            g_bInEditMode = false
        }
    }
    
    public void OnAdminMenuReady(Handle topmenu)
    {
        if (topmenu == AdminMenu)
            return;
    
        AdminMenu = topmenu;
        TopMenuObject serverCmds = FindTopMenuCategory(AdminMenu, ADMINMENU_SERVERCOMMANDS);
        AddToTopMenu(AdminMenu, "sm_spawntools7", TopMenuObject_Item, TopMenuHandler, serverCmds, "sm_spawntools7", ADMFLAG_RCON);
    }
    
    public void TopMenuHandler(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
    {
        if (action == TopMenuAction_DisplayOption)
            Format(buffer, maxlength, "Spawn Tools 7");
    
        else if (action == TopMenuAction_SelectOption)
            ShowToolzMenu(param);
    }
    
    void ShowToolzMenu(int client)
    {
        Panel panel = CreatePanel();
        SetPanelTitle(panel, "Spawn Tools 7");
        char sText[256];
        FormatEx(sText, 255, "1. %s Edit Mode\n2. %s Default Spawn Removal\n3. Add T Spawn\n4. Add CT Spawn\n5. Remove Spawn\n6. Remove All T Spawns\n7. Remove All CT Spawns\n8. Save Configuration\n\n9. Exit", g_bInEditMode == false ? "Enable" : "Disable", g_bRemoveDefSpawns == false ? "Enable" : "Disable")
        DrawPanelText(panel, sText)
        SetPanelKeys(panel, ((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)))
        SendPanelToClient(panel, client, MainMenuHandler, MENU_TIME_FOREVER)
        delete panel
    }
    
    public int MainMenuHandler(Handle menu, MenuAction action, int client, int selection)
    {
        switch(action)
        {
            case MenuAction_Select:
            {
                switch(selection)
                {
                    case 1:
                    {
                        g_bInEditMode = !g_bInEditMode
                        PrintToChat(client, "[SpawnTools7] Edit Mode %s.", !g_bInEditMode ? "Disabled" : "Enabled");
                        if (g_bInEditMode)
                        {
                            CreateTimer(1.0, ShowEditModeGoodies, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
                            g_iEditModeActivator = client
                        }
                        else
                            g_iEditModeActivator = 0
    
                        ShowToolzMenu(client);
                    }
                    case 2:
                    {
                        g_bRemoveDefSpawns = !g_bRemoveDefSpawns
                        PrintToChat(client, "[SpawnTools7] Default Spawn Removal will be %s.", !g_bRemoveDefSpawns ? "Disabled" : "Enabled");
                        ShowToolzMenu(client);
                    }
                    case 3:
                    {
                        if(!g_bInEditMode)
                        {
                            PrintToChat(client, "You must enable the edit mode!")
                            ShowToolzMenu(client)
                            return
                        }
    
                        bool bCacheData = g_bRemoveDefSpawns
                        g_bRemoveDefSpawns = false
                        InitializeNewSpawn(client, 2);
                        g_bRemoveDefSpawns = bCacheData
                        ShowToolzMenu(client);
                    }
                    case 4:
                    {
                        if(!g_bInEditMode)
                        {
                            PrintToChat(client, "You must enable the edit mode!")
                            ShowToolzMenu(client)
                            return
                        }
    
                        bool bCacheData = g_bRemoveDefSpawns
                        g_bRemoveDefSpawns = false
                        InitializeNewSpawn(client, 3);
                        g_bRemoveDefSpawns = bCacheData
                        ShowToolzMenu(client);
                    }
                    case 5:
                    {
                        if(!g_bInEditMode)
                        {
                            PrintToChat(client, "You must enable the edit mode!")
                            ShowToolzMenu(client)
                            return
                        }
    
                        if (!RemoveSpawn(client))
                            PrintToChat(client, "[SpawnTools7] No valid spawn point found.");
                        else
                            PrintToChat(client, "[SpawnTools7] Spawn point removed!");
    
                        ShowToolzMenu(client);
                    }
                    case 6:
                    {
                        if(!g_bInEditMode)
                        {
                            PrintToChat(client, "You must enable the edit mode!")
                            ShowToolzMenu(client)
                            return
                        }
    
                        int entity, iCustom
                        float vOrigin[3]
                        for(int i = 0; i < g_iMapSpawnsNum; i++)
                        {
                            if(UTIL_GetSpawnEntityTeamNum(i) != 2)
                                continue
                          
                            if((iCustom = UTIL_IsCustomSpawn((entity = UTIL_GetSpawnEntityIndex(i)))) != -1)
                            {
                                g_iCustomSpawnsNum--
                                RemoveFromArray(g_hCustomSpawns, iCustom)
                                RemoveFromArray(g_hCustomSpawnIndexes, iCustom)
                            }
                            else
                            {
                                g_iKilledSpawnsNum++
                                GetEntPropVector(entity, Prop_Data, "m_vecOrigin", vOrigin)
                                PushArrayArray(g_hKilledSpawns, vOrigin)
                            }
    
                            RemoveFromArray(g_hMapSpawns, i)
                            AcceptEntityInput(entity, "Kill")
                            RemoveFromArray(g_hSpawnTeamNum, i)
                          
                            g_iMapSpawnsNum--, i--
                        }
                        ShowToolzMenu(client);
                    }
                    case 7:
                    {
                        if(!g_bInEditMode)
                        {
                            PrintToChat(client, "You must enable the edit mode!")
                            ShowToolzMenu(client)
                            return
                        }
    
                        int entity, iCustom
                        float vOrigin[3]
                        for(int i = 0; i < g_iMapSpawnsNum; i++)
                        {
                            if(UTIL_GetSpawnEntityTeamNum(i) != 3)
                                continue
                          
                            if((iCustom = UTIL_IsCustomSpawn((entity = UTIL_GetSpawnEntityIndex(i)))) != -1)
                            {
                                g_iCustomSpawnsNum--
                                RemoveFromArray(g_hCustomSpawns, iCustom)
                                RemoveFromArray(g_hCustomSpawnIndexes, iCustom)
                            }
                            else
                            {
                                g_iKilledSpawnsNum++
                                GetEntPropVector(entity, Prop_Data, "m_vecOrigin", vOrigin)
                                PushArrayArray(g_hKilledSpawns, vOrigin)
                            }
    
                            RemoveFromArray(g_hMapSpawns, i)
                            AcceptEntityInput(entity, "Kill")
                            RemoveFromArray(g_hSpawnTeamNum, i)
                          
                            g_iMapSpawnsNum--, i--
                        }
                        ShowToolzMenu(client);
                    }
                    case 8:
                    {
                        SaveConfiguration() ? PrintToChat(client, "[SpawnTools7] Configuration Saved!") : LogError("failed to save to key values")
                        ShowToolzMenu(client);
                    }
                    case 9:
                    {
                        g_bInEditMode = false
                        g_iEditModeActivator = 0
                    }
                }
            }
            case MenuAction_Cancel:
            {
                if(selection == MenuCancel_Interrupted)
                {
                    g_bInEditMode = false
                    g_iEditModeActivator = 0
                }
            }
        }
    
    }
    
    public Action ShowEditModeGoodies(Handle timer)
    {
        if (!g_bInEditMode)
            return Plugin_Stop;
    
        int tsCount, ctsCount
        float fVec[3];
        for (int i = 0; i < g_iMapSpawnsNum; i++)
        {
            if (UTIL_GetSpawnEntityTeamNum(i) == 2)
            {
                tsCount++;
                GetEntPropVector(UTIL_GetSpawnEntityIndex(i), Prop_Data, "m_vecOrigin", fVec);
                TE_SetupGlowSprite(fVec, g_iRedGlowSprite, 1.0, 0.4, 249);
                TE_SendToAll();
            }
            else
            {
                ctsCount++;
                GetEntPropVector(UTIL_GetSpawnEntityIndex(i), Prop_Data, "m_vecOrigin", fVec);
                TE_SetupGlowSprite(fVec, g_iBlueGlowSprite, 1.0, 0.3, 237);
                TE_SendToAll();
            }
        }
        PrintHintText(g_iEditModeActivator, "T Spawns: %i \nCT Spawns: %i", tsCount, ctsCount)
        return Plugin_Continue;
    }
    
    void InitializeNewSpawn(int client, int team)
    {
        float DataFloats[5], posVec[3], angVec[3];
        GetClientAbsOrigin(client, posVec);
        GetClientEyeAngles(client, angVec);
        DataFloats[0] = posVec[0];
        DataFloats[1] = posVec[1];
        DataFloats[2] = (posVec[2] + 16.0);
        DataFloats[3] = angVec[1];
        DataFloats[4] = float(team);
    
        if (CreateSpawn(DataFloats, true))
            PrintToChat(client, "[SpawnTools7] New spawn point created!");
        else
            LogError("failed to create new sp entity");
    }
    
    bool CreateSpawn(float DataFloats[5], bool isNew = false) // if 2 spawn entities will closer than 42 unit, the server will flood in console "BUG: CCSGameMovement::CheckParameters - too many stacking levels.", you may not worry about it if convar mp_solid_teammates is 0
    {
        float posVec[3], angVec[3];
        posVec[0] = DataFloats[0];
        posVec[1] = DataFloats[1];
        posVec[2] = DataFloats[2];
        angVec[0] = 0.0;
        angVec[1] = DataFloats[3];
        angVec[2] = 0.0;
    
        int RefEnt = CreateEntityByName(DataFloats[4] == 2.0 ? "info_player_terrorist" : "info_player_counterterrorist");
        if (DispatchSpawn(RefEnt))
        {
            int entity = EntRefToEntIndex(RefEnt)
            TeleportEntity(entity, posVec, angVec, NULL_VECTOR);
          
            if(isNew)
            {
                g_iCustomSpawnsNum++
                PushArrayArray(g_hCustomSpawns, DataFloats)
                PushArrayCell(g_hCustomSpawnIndexes, entity)
            }
            return true;
        }
    
        return false;
    }
    
    bool RemoveSpawn(int client)
    {
        float client_posVec[3], ent_posVec[3]
        int i, d, iCustom
        GetClientAbsOrigin(client, client_posVec);
        client_posVec[2] += 16;
        for (i = 0; i < g_iMapSpawnsNum; i++)
        {
            GetEntPropVector((d = UTIL_GetSpawnEntityIndex(i)), Prop_Data, "m_vecOrigin", ent_posVec);
            if (GetVectorDistance(client_posVec, ent_posVec) < 42.7)
            {
                if((iCustom = UTIL_IsCustomSpawn(d)) != -1)
                {
                    g_iCustomSpawnsNum--
                    RemoveFromArray(g_hCustomSpawns, iCustom)
                    RemoveFromArray(g_hCustomSpawnIndexes, iCustom)
                }
                else
                {
                    g_iKilledSpawnsNum++
                    PushArrayArray(g_hKilledSpawns, ent_posVec)
                }
    
                g_iMapSpawnsNum--
                AcceptEntityInput(d, "Kill")
                RemoveFromArray(g_hMapSpawns, i)
                RemoveFromArray(g_hSpawnTeamNum, i)
                return true;
            }
        }
        return false;
    }
    
    bool SaveConfiguration()
    {
        //S/fix by ch4os
        char sMapName[64];
        GetCurrentMap(sMapName, 63);
      
        if (StrContains(sMapName, "workshop", false) != -1)
        {
            char configspath[PLATFORM_MAX_PATH];
            BuildPath(Path_SM, configspath, sizeof(configspath), "configs/spawntools7/workshop/%s", g_sWorkShopID);
            if (!DirExists(configspath))
                CreateDirectory(configspath, 509)
        }
        //E/fix by ch4os
    
        KeyValues kv = CreateKeyValues("ST7Root");
        char sBuffer[32]
        float DataFloats[5], posVec[3];
        KvJumpToKey(kv, "smdata", true);
        KvSetNum(kv, "remdefsp", g_bRemoveDefSpawns ? 1 : 0);
        if (g_iCustomSpawnsNum)
        {
            for (int i = 0; i < g_iCustomSpawnsNum; i++)
            {
                GetArrayArray(g_hCustomSpawns, i, DataFloats);
                posVec[0] = DataFloats[0];
                posVec[1] = DataFloats[1];
                posVec[2] = DataFloats[2];
                Format(sBuffer, 31, "ns:%d:pos", i);
                KvSetVector(kv, sBuffer, posVec);
                Format(sBuffer, 31, "ns:%d:ang", i);
                KvSetFloat(kv, sBuffer, DataFloats[3]);
                Format(sBuffer, 31, "ns:%d:team", i);
                KvSetFloat(kv, sBuffer, DataFloats[4]);
            }
        }
    
        if (g_iKilledSpawnsNum)
        {
            if(g_bRemoveDefSpawns)
            {
                ClearArray(g_hKilledSpawns)
                g_iKilledSpawnsNum = 0
            }
            else
            {
                for (int i = 0; i < g_iKilledSpawnsNum; i++)
                {
                    GetArrayArray(g_hKilledSpawns, i, posVec);
                    Format(sBuffer, sizeof(sBuffer), "rs:%d:pos", i);
                    KvSetVector(kv, sBuffer, posVec);
                }
            }
        }
    
        bool RetVal = KeyValuesToFile(kv, MapCfgPath)
        delete kv;
        return RetVal
    }
    
    stock int UTIL_ArrayIndexOfSpawnEntity(int entity)
    {
        if(!g_iMapSpawnsNum)
            return -1
    
        for(int i = 0; i < g_iMapSpawnsNum; ++i)
            if(GetArrayCell(g_hMapSpawns, i) == entity)
                return i
    
        return -1
    }
    
    int UTIL_GetSpawnEntityIndex(int cell)
    {
        return GetArrayCell(g_hMapSpawns, cell)
    }
    
    int UTIL_GetSpawnEntityTeamNum(int cell)
    {
        return GetArrayCell(g_hSpawnTeamNum, cell)
    }
    
    int UTIL_IsCustomSpawn(int entity)
    {
        if(!g_iCustomSpawnsNum)
            return -1
    
        for(int i = 0; i < g_iCustomSpawnsNum; ++i)
            if(GetArrayCell(g_hCustomSpawnIndexes, i) == entity)
                return i
      
        return -1
    }
    
    bool UTIL_IsDeadEntity(int entity)
    {
        if(!g_iKilledSpawnsNum)
            return false
    
        float vOrigin[3], vOrigin2[3]
        for(int i = 0; i < g_iKilledSpawnsNum; ++i)
        {
            GetArrayArray(g_hKilledSpawns, i, vOrigin)
            GetEntPropVector(entity, Prop_Data, "m_vecOrigin", vOrigin2)
          
            if(RoundToFloor(vOrigin[0]) == RoundToFloor(vOrigin2[0]) && RoundToFloor(vOrigin[1]) == RoundToFloor(vOrigin2[1]))
                return true
        }
        return false
    }
    
    void UTIL_MapStarted()
    {
        char sMapName[64], sBuffer[64];
        GetCurrentMap(sMapName, 63);
      
        if (StrContains(sMapName, "workshop", false) != -1)
        {
            GetCurrentWorkshopMap(sBuffer, 63, g_sWorkShopID, sizeof(g_sWorkShopID) - 1)
            BuildPath(Path_SM, MapCfgPath, sizeof(MapCfgPath), "configs/spawntools7/workshop/%s/%s.cfg", g_sWorkShopID, sBuffer)
        }
        else
            BuildPath(Path_SM, MapCfgPath, sizeof(MapCfgPath), "configs/spawntools7/%s.cfg", sMapName)
    
        ReadConfig();
    
        g_iRedGlowSprite = PrecacheModel("sprites/purpleglow1.vmt");
        g_iBlueGlowSprite = PrecacheModel("sprites/blueglow1.vmt");
    }
    
    void GetCurrentWorkshopMap(char[] szMap, int iMapBuf, char[] szWorkShopID, int iWorkShopBuf)
    {
        char szCurMap[128]
        char szCurMapSplit[2][64]
    
        GetCurrentMap(szCurMap, 127)
        ReplaceString(szCurMap, sizeof(szCurMap), "workshop/", "", false)
        ExplodeString(szCurMap, "/", szCurMapSplit, 2, 63)
    
        strcopy(szMap, iMapBuf, szCurMapSplit[1])
        strcopy(szWorkShopID, iWorkShopBuf, szCurMapSplit[0])
    }
    
    public void OnMapEnd()
    {
        ClearArray(g_hMapSpawns)
        ClearArray(g_hKilledSpawns);
        ClearArray(g_hCustomSpawns);
        ClearArray(g_hSpawnTeamNum);
        ClearArray(g_hCustomSpawnIndexes);
        g_iMapSpawnsNum = g_iKilledSpawnsNum = g_iCustomSpawnsNum = g_iDefSpawnsClearNum = g_iEditModeActivator = 0
        g_bRemoveDefSpawns = g_bInEditMode = g_bMapStarted = g_bCustomSpawnPoints = false
    }
    
    public void OnPluginEnd()
    {
        delete g_hMapSpawns
        delete g_hCustomSpawns
        delete g_hKilledSpawns
        delete g_hSpawnTeamNum
        delete g_hCustomSpawnIndexes
    }
    Было бы не плохо.
     

    Вложения:

  9. Hejter

    Hejter Mapper Source Engine

    Сообщения:
    1.771
    Симпатии:
    259
    @NiGaByte, мне кажется ты просто заморачиваешься с этим. Используй как есть, да и все.
     
  10. NiGaByte

    NiGaByte

    Сообщения:
    501
    Симпатии:
    84
    да я заморачиваюсь, и не фигово так. Просто зачем мне функции администрирования плагина, если я один раз скачал кучу карт, отредактировал как мне надо, и больше никогда туда не полезу, мне просто не понадобится этот функционал больше. А если понадобится то включу, да и то только на тестовом сервере, чтобы в будущем перенести изменения на основной.
     
  11. SAZONISCHE

    SAZONISCHE

    Сообщения:
    114
    Симпатии:
    28
    Забирай для кс го + все workshop и т. д. фиксы на сегодняшний день!
     

    Вложения:

    • SpawnTools7.sp
      Размер файла:
      17,9 КБ
      Просмотров:
      4
  12. NiGaByte

    NiGaByte

    Сообщения:
    501
    Симпатии:
    84
    Чувак это не то, спавны я уже отредактировал для 50-ти карт, дело в том что мне нужно вырезать из плагина функции редактирования вообще, что бы остались только функции чтения новых точек, и всё. Как бы я получается одним плагином создаю точки, а другой ставлю для их работы. А то что дал ты, имеет функции редактирования, это понятно даже по этому кусочку кода:
    Код:
    void ShowToolzMenu(int client)
    {
        Panel panel = CreatePanel();
        SetPanelTitle(panel, "Редактор спавнов");
        char sText[256];
        FormatEx(sText, 255, "1. %s Редактор\n2. %s Стд спавны\n3. Добавить TT\n4. Добавить CT\n5. Удалить\n6. Удалить всех TT\n7. Удалить всех CT\n8. Схранить\n\n9. Выйти", g_bInEditMode == false ? "Вкл" : "Откл", g_bRemoveDefSpawns == false ? "Вкл" : "Откл")
        DrawPanelText(panel, sText)
        SetPanelKeys(panel, ((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)))
        SendPanelToClient(panel, client, MainMenuHandler, MENU_TIME_FOREVER)
        delete panel
    }