Написание плагинов

7pElllHuK

Участник
Сообщения
1,416
Реакции
465
C-подобный:
ArrayList hList;

public void OnPluginStart()
{
    hList = new ArrayList();
}

public void OnMapStart()
{
    hList.Clear();
}

Action Что-то твое(int client, int args)
{
    char sText[32];

    int iNumber = 2;
    hList.GetString(iNumber, sText, sizeof(sText));
   
    // Далее что-то с текстом делаешь...
}
Написал общий пример обращения с Arraylist
Огромная благодарность, буду пробовать
 

NeLifeASkazka

Участник
Сообщения
128
Реакции
70
Всем привет
Столкнулся с такими ошибками:
[SM] Exception reported: Stack leak detected: sp:-1781916352 should be 24508!
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack

Может кто помочь ?
code:
#pragma semicolon 1

#include <sdktools>
#include <cstrike>
#include <sdkhooks>

#pragma newdecls required

ConVar
    cvTimeSpawn,
    cvTimeDiapazon,
    cvCountBoxRound;

ArrayList arCoords;

Handle hSpawn;

int iCount;
int iLaser[2];

float fSpawn;
float fInterval;

public void OnPluginStart(){
    cvTimeSpawn = CreateConVar("ad_time_spawn", "0.0");
    cvTimeDiapazon = CreateConVar("ad_time_range", "0.0");
    cvCountBoxRound = CreateConVar("ad_airdrops_on_round", "1");
    
    HookEvent("round_start", OnRoundStart);

    RegConsoleCmd("sm_pos", cmd_pos);
    RegConsoleCmd("test", test);
}
public Action test(int client, int args){
    float pos[3]; GetClientAbsOrigin(client, pos);
    TR_TraceRayFilter(pos, view_as<float>({-90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
    if(TR_DidHit())
    {
        float end[3]; TR_GetEndPosition(end);
        float ang[3]; ang[2] = ang[0] = 0.0; ang[1] += GetRandomFloat(-180.0, 180.0);
        int drop = CreateEntityByName("prop_physics_multiplayer");
        if(drop > 0)
        {
            DispatchKeyValue(drop, "model", "models/props/cs_militia/crate_extrasmallmill.mdl");
            DispatchKeyValueVector(drop, "origin", end);
            DispatchKeyValueVector(drop, "angles", ang);
            DispatchKeyValue(drop, "massScale", "100.0");
            DispatchSpawn(drop);

            SetEntProp(drop, Prop_Data, "m_CollisionGroup", 0);
            SetEntProp(drop, Prop_Send, "m_nSolidType", 0);
            //TE_SetupBeamPoints(pos, end, iLaser[0], iLaser[1], 1, 1, 10.0, 3.0, 10.0, 1, 1.0, {255, 0, 0, 255}, 1);
            //TE_SendToAll();

            int parachute = CreateEntityByName("prop_physics_override");
            if(parachute > 0)
            {
                DispatchKeyValue(parachute, "model", "models/parachute/parachute_ark.mdl");
                end[1] -= 7.0; end[2] -= 20.0;
                DispatchKeyValueVector(parachute, "origin", end);
                DispatchKeyValueVector(parachute, "angles", ang);
                DispatchSpawn(parachute);

                SetEntProp(parachute, Prop_Data, "m_CollisionGroup", 0);
                SetEntProp(parachute, Prop_Send, "m_nSolidType", 0);
                SetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity", parachute);

                SetVariantString("!activator");
                AcceptEntityInput(parachute, "SetParent", drop);

                CreateTimer(0.1, CheckHight, drop, TIMER_REPEAT);
            }
        }
    }
}
public Action cmd_pos(int client, int args){
    if(client)
    {
        float pos[3]; GetClientAbsOrigin(client, pos);
        PrintToChat(client, "%.1f %.1f %.1f", pos[0], pos[1], pos[2]);
    }
}

public void OnMapStart(){
    iLaser[0] = PrecacheModel("sprites/laserbeam.vmt");
    iLaser[1] = PrecacheModel("materials/sprites/halo.vmt");
    Download();
    char cBuff[128];
    KeyValues hKV = new KeyValues("AirDrop");
    BuildPath(Path_SM, cBuff, sizeof(cBuff), "configs/HungerGames/AirDrop.ini");

    if(hKV.ImportFromFile(cBuff))
    {
        char cGetMap[64]; GetCurrentMap(cGetMap, sizeof(cGetMap));
        if(hKV.JumpToKey(cGetMap, false))
        {
            arCoords = new ArrayList(ByteCountToCells(32));
            float temp[3];
            if(hKV.GotoFirstSubKey(false))
            {
                do
                {
                    hKV.GetVector(NULL_STRING, temp);
                    arCoords.PushArray(temp);
                }
                while(hKV.GotoNextKey(false));
            }
            // PrintToServer("%s", cGetMap);
            // for(int x; x < arCoords.Length; x++){
            //     arCoords.GetArray(x, temp);
            //     PrintToServer("[%d:%d] %.1f %.1f %.1f", x, arCoords.Length, temp[0], temp[1], temp[2]);
            // }
        }
    }
    delete hKV;
}
public Action OnRoundStart(Event event, const char[] name, bool db){
    delete hSpawn;
    if(arCoords)
    {
        fSpawn = cvTimeSpawn.FloatValue;
        fInterval = cvTimeDiapazon.FloatValue;
        if(cvCountBoxRound.IntValue > 0 && fSpawn > 0.0 && fInterval >= 0.0)
        {
            hSpawn = CreateTimer(fSpawn + GetRandomFloat(0.0, fInterval), SpawnAirDrop, _, TIMER_FLAG_NO_MAPCHANGE);
        }
    }
}
public Action SpawnAirDrop(Handle timer){
    float pos[3]; arCoords.GetArray(GetRandomInt(0, arCoords.Length-1), pos);
    TR_TraceRayFilter(pos, view_as<float>({-90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
    if(TR_DidHit())
    {
        float end[3]; TR_GetEndPosition(end);
        float ang[3]; ang[1] += GetRandomFloat(-180.0, 180.0);
        int drop = CreateEntityByName("prop_physics_multiplayer");
        if(drop > 0)
        {
            DispatchKeyValue(drop, "model", "models/props/cs_militia/crate_extrasmallmill.mdl");
            DispatchKeyValueVector(drop, "origin", end);
            DispatchKeyValueVector(drop, "angles", ang);
            DispatchKeyValue(drop, "massScale", "100.0");
            DispatchSpawn(drop);
            SetEntProp(drop, Prop_Data, "m_CollisionGroup", 0);
            SetEntProp(drop, Prop_Send, "m_nSolidType", 0);
            //TE_SetupBeamPoints(pos, end, iLaser[0], iLaser[1], 1, 1, 10.0, 3.0, 10.0, 1, 1.0, {255, 0, 0, 255}, 1);
            //TE_SendToAll();
        
            int parachute = CreateEntityByName("prop_physics_override");
            if(parachute > 0)
            {
                DispatchKeyValue(parachute, "model", "models/parachute/parachute_ark.mdl");
                end[2] -= 20.0;
                DispatchKeyValueVector(parachute, "origin", end);
                DispatchKeyValueVector(parachute, "angles", ang);
                DispatchSpawn(parachute);
                SetEntProp(parachute, Prop_Data, "m_CollisionGroup", 0);
                SetEntProp(parachute, Prop_Send, "m_nSolidType", 0);
                SetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity", parachute);
        
                SetVariantString("!activator");
                AcceptEntityInput(parachute, "SetParent", drop);

                CreateTimer(0.1, CheckHight, drop, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
                iCount++;
            }
        }
    }
    hSpawn = null;
}
public Action CheckHight(Handle timer, int drop){
    if(IsValidEntity(drop))
    {
        int parachute = GetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity");
        if(IsValidEntity(parachute))
        {
            float pos[3]; GetEntPropVector(drop, Prop_Data, "m_vecOrigin", pos);

            float speed[3] = {0.0, 0.0, -50.0};
            TeleportEntity(drop, NULL_VECTOR, NULL_VECTOR, speed);

            TR_TraceRayFilter(pos, view_as<float>({90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
            if(TR_DidHit())
            {
                float end[3]; TR_GetEndPosition(end);

                if(GetVectorDistance(pos, end) <= 300.0){
                    SetEntProp(drop, Prop_Data, "m_CollisionGroup", 9);
                    SetEntProp(drop, Prop_Send, "m_nSolidType", 6);
                    //SetEntProp(drop, Prop_Data, "m_usSolidFlags", 1);
                    RemoveEntity(parachute);

                    if(iCount < cvCountBoxRound.IntValue)
                        hSpawn = CreateTimer(fSpawn + GetRandomFloat(0.0, fInterval), SpawnAirDrop, _, TIMER_FLAG_NO_MAPCHANGE);

                    return Plugin_Stop;
                }
                return Plugin_Continue;
            }
        }
    }
    return Plugin_Stop;
}
public bool filter(int entity, int mask){
    return entity >= 0;
}


void Download(){
    PrecacheModel("models/parachute/parachute_ark.mdl", false);
    AddFileToDownloadsTable("models/parachute/parachute_ark.dx80.vtx");
    AddFileToDownloadsTable("models/parachute/parachute_ark.dx90.vtx");
    AddFileToDownloadsTable("models/parachute/parachute_ark.mdl");
    AddFileToDownloadsTable("models/parachute/parachute_ark.sw.vtx");
    AddFileToDownloadsTable("models/parachute/parachute_ark.vvd");
    AddFileToDownloadsTable("models/parachute/parachute_ark.xbox.vtx");
    PrecacheDecal("materials/models/parachute/parachute_ark.vmt", false);
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark.vmt");
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark.vtf");
    PrecacheDecal("materials/models/parachute/parachute_ark_backpack.vmt", false);
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark_backpack.vmt");
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark_backpack.vtf");

    PrecacheModel("models/props/cs_militia/crate_extrasmallmill.mdl", false);
}
 

NeLifeASkazka

Участник
Сообщения
128
Реакции
70
@NeLifeASkazka, нужно ArrayList удалять старый перед созданием нового.
Спасибо за поправку, но ошибки не связаны с ArrayList
Первая ошибка:
[SM] Exception reported: Stack leak detected: sp:-1781916352 should be 24508!
Появляется при вызове функции SpawnAirDrop

Ну а последующий спам:
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
...
При вызове функции CheckHight
 

Grey83

не пишу плагины с весны 2022
Сообщения
8,521
Реакции
4,980
@NeLifeASkazka, а плагин компилился той же версией SM, что и установлен на сервере?
 

NeLifeASkazka

Участник
Сообщения
128
Реакции
70
@NeLifeASkazka, а плагин компилился той же версией SM, что и установлен на сервере?
Да
Также добавлю, что если попробовать спавнить пропы через команду !test, тогда никаких ошибок нет, и все работает без проблем
За исключением этой проверки:
code:
public Action CheckHight(Handle timer, int drop){
    if(IsValidEntity(drop))
    {
        int parachute = GetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity");

        if(IsValidEntity(parachute))
        {
            float pos[3]; GetEntPropVector(drop, Prop_Data, "m_vecOrigin", pos);
            float speed[3] = {0.0, 0.0, -50.0};
            TeleportEntity(drop, NULL_VECTOR, NULL_VECTOR, speed);
            TR_TraceRayFilter(pos, view_as<float>({90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
            if(TR_DidHit())
            {
                float end[3]; TR_GetEndPosition(end);
                if(GetVectorDistance(pos, end) <= 300.0){
                    SetEntProp(drop, Prop_Data, "m_CollisionGroup", 9);
                    SetEntProp(drop, Prop_Send, "m_nSolidType", 6);
                    //SetEntProp(drop, Prop_Data, "m_usSolidFlags", 1);
                    RemoveEntity(parachute);

                    // если оно выполняется, тогда снова пишет "Stack leak detected: sp:-1781916192 should be 24668!"
                    // и спамит "Not enough space on the stack"
                    if(iCount < cvCountBoxRound.IntValue)
                        hSpawn = CreateTimer(fSpawn + GetRandomFloat(0.0, fInterval), SpawnAirDrop, _, TIMER_FLAG_NO_MAPCHANGE);

                    return Plugin_Stop;
                }
                return Plugin_Continue;
            }
        }
    }
    return Plugin_Stop;
}

Кажется, будто рекурсия таймерами в Sourcemod не приветствуется :\
 

Grey83

не пишу плагины с весны 2022
Сообщения
8,521
Реакции
4,980
@NeLifeASkazka, попробуй пока так:
C-подобный:
#pragma semicolon 1
#pragma newdecls required

#include <sdktools_entinput>
#include <sdktools_functions>
#include <sdktools_stringtables>
#include <sdktools_trace>
#tryinclude <sdktools_variant_t>

ArrayList
    arCoords;
Handle
    hSpawn;
int
    iCount,
//    iLaser[2],
    iDrops;
float
    fSpawn,
    fInterval;

public void OnPluginStart()
{
    ConVar cvar;
    cvar = CreateConVar("ad_time_spawn", "0.0", _, _, true);
    fSpawn = cvar.FloatValue;
    cvar.AddChangeHook(CVarChange_Time);

    cvar = CreateConVar("ad_time_range", "0.0", _, _, true);
    fInterval = cvar.FloatValue;
    cvar.AddChangeHook(CVarChange_Interval);

    cvar = CreateConVar("ad_airdrops_on_round", "1", _, _, true);
    iDrops = cvar.IntValue;
    cvar.AddChangeHook(CVarChange_Drops);
    AutoExecConfig(true, "airdrops");

    HookEvent("round_start", Event_Round, EventHookMode_PostNoCopy);
    HookEvent("round_end", Event_Round, EventHookMode_PostNoCopy);

    RegConsoleCmd("sm_pos", cmd_pos);
    RegConsoleCmd("test", test);
}

public void CVarChange_Time(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    fSpawn = cvar.FloatValue;
}

public void CVarChange_Interval(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    fInterval = cvar.FloatValue;
}

public void CVarChange_Drops(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    iDrops = cvar.IntValue;
}

public void OnMapStart()
{
    delete arCoords;
/*
    iLaser[0] = PrecacheModel("sprites/laserbeam.vmt");
    iLaser[1] = PrecacheModel("materials/sprites/halo.vmt");
*/
    PrecacheModel("models/parachute/parachute_ark.mdl", false);
    AddFileToDownloadsTable("models/parachute/parachute_ark.dx80.vtx");
    AddFileToDownloadsTable("models/parachute/parachute_ark.dx90.vtx");
    AddFileToDownloadsTable("models/parachute/parachute_ark.mdl");
    AddFileToDownloadsTable("models/parachute/parachute_ark.sw.vtx");
    AddFileToDownloadsTable("models/parachute/parachute_ark.vvd");
    AddFileToDownloadsTable("models/parachute/parachute_ark.xbox.vtx");

    PrecacheDecal("materials/models/parachute/parachute_ark.vmt", false);
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark.vmt");
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark.vtf");

    PrecacheDecal("materials/models/parachute/parachute_ark_backpack.vmt", false);
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark_backpack.vmt");
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark_backpack.vtf");

    PrecacheModel("models/props/cs_militia/crate_extrasmallmill.mdl", false);

    char cBuff[128];
    BuildPath(Path_SM, cBuff, sizeof(cBuff), "configs/HungerGames/AirDrop.ini");

    KeyValues hKV = new KeyValues("AirDrop");
    if(hKV.ImportFromFile(cBuff))
    {
        GetCurrentMap(cBuff, sizeof(cBuff));
        if(hKV.JumpToKey(cBuff, false))
        {
            arCoords = new ArrayList(ByteCountToCells(32));
            float temp[3];
            if(hKV.GotoFirstSubKey(false))
            {
                do
                {
                    hKV.GetVector(NULL_STRING, temp);
                    arCoords.PushArray(temp);
                } while(hKV.GotoNextKey(false));
            }
/*            PrintToServer("%s", cBuff);
            for(int x; x < arCoords.Length; x++)
            {
                arCoords.GetArray(x, temp);
                PrintToServer("[%d:%d] %.1f %.1f %.1f", x, arCoords.Length, temp[0], temp[1], temp[2]);
            }
*/        }
    }
    delete hKV;
}

public Action test(int client, int args)
{
    if(!client || !IsClientInGame(client))
        return Plugin_Handled;

    float pos[3];
    GetClientAbsOrigin(client, pos);
    InitAirDrop(pos);

    return Plugin_Handled;
}

public Action cmd_pos(int client, int args)
{
    if(client && IsClientInGame(client))
    {
        float pos[3];
        GetClientAbsOrigin(client, pos);
        PrintToChat(client, "%.1f %.1f %.1f", pos[0], pos[1], pos[2]);
    }

    return Plugin_Handled;
}

public void Event_Round(Event event, const char[] name, bool db)
{
    delete hSpawn;
    if(name[6] == 'e')
        return;

    iCount = 0;
    if(arCoords && iDrops > 0 && fSpawn > 0.0 && fInterval >= 0.0)
        hSpawn = CreateTimer(fSpawn + GetRandomFloat(0.0, fInterval), Timer_SpawnAirDrop, _, TIMER_FLAG_NO_MAPCHANGE);
}

public Action Timer_SpawnAirDrop(Handle timer)
{
    float pos[3];
    arCoords.GetArray(GetRandomInt(0, arCoords.Length-1), pos);
    if(InitAirDrop(pos)) iCount++;

    hSpawn = null;
    return Plugin_Stop;
}

stock bool InitAirDrop(float pos[3])
{
    TR_TraceRayFilter(pos, view_as<float>({-90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
    if(!TR_DidHit())
        return false;

    int drop = CreateEntityByName("prop_physics_multiplayer");
    if(drop <= MaxClients)
        return false;

    float end[3], ang[3];
    TR_GetEndPosition(end);
    ang[1] = GetRandomFloat(-180.0, 180.0);

    DispatchKeyValue(drop, "model", "models/props/cs_militia/crate_extrasmallmill.mdl");
    DispatchKeyValueVector(drop, "origin", end);
    DispatchKeyValueVector(drop, "angles", ang);
    DispatchKeyValue(drop, "massScale", "100.0");
    if(!DispatchSpawn(drop))
        return false;

    int parachute = CreateEntityByName("prop_physics_override");
    if(parachute <= MaxClients)
    {
#if SOURCEMOD_V_MAJOR == 1 && SOURCEMOD_V_MINOR < 10
        AcceptEntityInput(drop, "Kill");
#else
        RemoveEntity(drop);
#endif
        return false;
    }

    SetEntProp(drop, Prop_Data, "m_CollisionGroup", 0);
    SetEntProp(drop, Prop_Send, "m_nSolidType", 0);

    DispatchKeyValue(parachute, "model", "models/parachute/parachute_ark.mdl");
    end[1] -= 7.0, end[2] -= 20.0;
    DispatchKeyValueVector(parachute, "origin", end);
    DispatchKeyValueVector(parachute, "angles", ang);
    if(!DispatchSpawn(parachute))
    {
#if SOURCEMOD_V_MAJOR == 1 && SOURCEMOD_V_MINOR < 10
        AcceptEntityInput(drop, "Kill");
#else
        RemoveEntity(drop);
#endif
        return false;
    }

    SetEntProp(parachute, Prop_Data, "m_CollisionGroup", 0);
    SetEntProp(parachute, Prop_Send, "m_nSolidType", 0);
    SetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity", parachute);

    SetVariantString("!activator");
    AcceptEntityInput(parachute, "SetParent", drop);

    CreateTimer(0.1, Timer_CheckHight, EntIndexToEntRef(drop), TIMER_REPEAT);

    return true;
}

public bool filter(int entity, int mask)
{
    return entity >= 0;
}

public Action Timer_CheckHight(Handle timer, int ref)
{
    static int drop;
    if((drop = EntRefToEntIndex(ref)) == INVALID_ENT_REFERENCE)
        return Plugin_Stop;

    int parachute = GetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity");
    if(parachute == -1)
        return Plugin_Stop;

    TeleportEntity(drop, NULL_VECTOR, NULL_VECTOR, view_as<float>({0.0, 0.0, -50.0}));

    static float pos[3], end[3];
    GetEntPropVector(drop, Prop_Data, "m_vecOrigin", pos);
    TR_TraceRayFilter(pos, view_as<float>({90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
    if(!TR_DidHit())
        return Plugin_Stop;

    TR_GetEndPosition(end);
    if(GetVectorDistance(pos, end) > 300.0)
        return Plugin_Continue;

    SetEntProp(drop, Prop_Data, "m_CollisionGroup", 9);
    SetEntProp(drop, Prop_Send, "m_nSolidType", 6);
//    SetEntProp(drop, Prop_Data, "m_usSolidFlags", 1);
#if SOURCEMOD_V_MAJOR == 1 && SOURCEMOD_V_MINOR < 10
    AcceptEntityInput(parachute, "Kill");
#else
    RemoveEntity(parachute);
#endif

    if(iCount < iDrops)
        hSpawn = CreateTimer(fSpawn + GetRandomFloat(0.0, fInterval), Timer_SpawnAirDrop, _, TIMER_FLAG_NO_MAPCHANGE);

    return Plugin_Stop;
}
 
Последнее редактирование:

cmb

Участник
Сообщения
15
Реакции
2
как понять что у игрока включен фонарик и принудительно отключить его, а еще поменять звук фонарика на какой-нибудь другой?
 

NeLifeASkazka

Участник
Сообщения
128
Реакции
70
@NeLifeASkazka, попробуй пока так:
C-подобный:
#pragma semicolon 1
#pragma newdecls required

#include <sdktools_entinput>
#include <sdktools_functions>
#include <sdktools_stringtables>
#include <sdktools_trace>
#tryinclude <sdktools_variant_t>

ArrayList
    arCoords;
Handle
    hSpawn;
int
    iCount,
//    iLaser[2],
    iDrops;
float
    fSpawn,
    fInterval;

public void OnPluginStart()
{
    ConVar cvar;
    cvar = CreateConVar("ad_time_spawn", "0.0", _, _, true);
    fSpawn = cvar.FloatValue;
    cvar.AddChangeHook(CVarChange_Time);

    cvar = CreateConVar("ad_time_range", "0.0", _, _, true);
    fInterval = cvar.FloatValue;
    cvar.AddChangeHook(CVarChange_Interval);

    cvar = CreateConVar("ad_airdrops_on_round", "1", _, _, true);
    iDrops = cvar.IntValue;
    cvar.AddChangeHook(CVarChange_Drops);
    AutoExecConfig(true, "airdrops");

    HookEvent("round_start", Event_Round, EventHookMode_PostNoCopy);
    HookEvent("round_end", Event_Round, EventHookMode_PostNoCopy);

    RegConsoleCmd("sm_pos", cmd_pos);
    RegConsoleCmd("test", test);
}

public void CVarChange_Time(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    fSpawn = cvar.FloatValue;
}

public void CVarChange_Interval(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    fInterval = cvar.FloatValue;
}

public void CVarChange_Drops(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    iDrops = cvar.IntValue;
}

public void OnMapStart()
{
    delete arCoords;
/*
    iLaser[0] = PrecacheModel("sprites/laserbeam.vmt");
    iLaser[1] = PrecacheModel("materials/sprites/halo.vmt");
*/
    PrecacheModel("models/parachute/parachute_ark.mdl", false);
    AddFileToDownloadsTable("models/parachute/parachute_ark.dx80.vtx");
    AddFileToDownloadsTable("models/parachute/parachute_ark.dx90.vtx");
    AddFileToDownloadsTable("models/parachute/parachute_ark.mdl");
    AddFileToDownloadsTable("models/parachute/parachute_ark.sw.vtx");
    AddFileToDownloadsTable("models/parachute/parachute_ark.vvd");
    AddFileToDownloadsTable("models/parachute/parachute_ark.xbox.vtx");

    PrecacheDecal("materials/models/parachute/parachute_ark.vmt", false);
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark.vmt");
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark.vtf");

    PrecacheDecal("materials/models/parachute/parachute_ark_backpack.vmt", false);
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark_backpack.vmt");
    AddFileToDownloadsTable("materials/models/parachute/parachute_ark_backpack.vtf");

    PrecacheModel("models/props/cs_militia/crate_extrasmallmill.mdl", false);

    char cBuff[128];
    BuildPath(Path_SM, cBuff, sizeof(cBuff), "configs/HungerGames/AirDrop.ini");

    KeyValues hKV = new KeyValues("AirDrop");
    if(hKV.ImportFromFile(cBuff))
    {
        GetCurrentMap(cBuff, sizeof(cBuff));
        if(hKV.JumpToKey(cBuff, false))
        {
            arCoords = new ArrayList(ByteCountToCells(32));
            float temp[3];
            if(hKV.GotoFirstSubKey(false))
            {
                do
                {
                    hKV.GetVector(NULL_STRING, temp);
                    arCoords.PushArray(temp);
                } while(hKV.GotoNextKey(false));
            }
/*            PrintToServer("%s", cBuff);
            for(int x; x < arCoords.Length; x++)
            {
                arCoords.GetArray(x, temp);
                PrintToServer("[%d:%d] %.1f %.1f %.1f", x, arCoords.Length, temp[0], temp[1], temp[2]);
            }
*/        }
    }
    delete hKV;
}

public Action test(int client, int args)
{
    if(!client || !IsClientInGame(client))
        return Plugin_Handled;

    float pos[3];
    GetClientAbsOrigin(client, pos);
    InitAirDrop(pos);

    return Plugin_Handled;
}

public Action cmd_pos(int client, int args)
{
    if(client && IsClientInGame(client))
    {
        float pos[3];
        GetClientAbsOrigin(client, pos);
        PrintToChat(client, "%.1f %.1f %.1f", pos[0], pos[1], pos[2]);
    }

    return Plugin_Handled;
}

public void Event_Round(Event event, const char[] name, bool db)
{
    delete hSpawn;
    if(name[6] == 'e')
        return;

    iCount = 0;
    if(arCoords && iDrops > 0 && fSpawn > 0.0 && fInterval >= 0.0)
        hSpawn = CreateTimer(fSpawn + GetRandomFloat(0.0, fInterval), Timer_SpawnAirDrop, _, TIMER_FLAG_NO_MAPCHANGE);
}

public Action Timer_SpawnAirDrop(Handle timer)
{
    float pos[3];
    arCoords.GetArray(GetRandomInt(0, arCoords.Length-1), pos);
    if(InitAirDrop(pos)) iCount++;

    hSpawn = null;
    return Plugin_Stop;
}

stock bool InitAirDrop(float pos[3])
{
    TR_TraceRayFilter(pos, view_as<float>({-90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
    if(!TR_DidHit())
        return false;

    int drop = CreateEntityByName("prop_physics_multiplayer");
    if(drop <= MaxClients)
        return false;

    float end[3], ang[3];
    TR_GetEndPosition(end);
    ang[1] = GetRandomFloat(-180.0, 180.0);

    DispatchKeyValue(drop, "model", "models/props/cs_militia/crate_extrasmallmill.mdl");
    DispatchKeyValueVector(drop, "origin", end);
    DispatchKeyValueVector(drop, "angles", ang);
    DispatchKeyValue(drop, "massScale", "100.0");
    if(!DispatchSpawn(drop))
        return false;

    int parachute = CreateEntityByName("prop_physics_override");
    if(parachute <= MaxClients)
    {
#if SOURCEMOD_V_MAJOR == 1 && SOURCEMOD_V_MINOR < 10
        AcceptEntityInput(drop, "Kill");
#else
        RemoveEntity(drop);
#endif
        return false;
    }

    SetEntProp(drop, Prop_Data, "m_CollisionGroup", 0);
    SetEntProp(drop, Prop_Send, "m_nSolidType", 0);

    DispatchKeyValue(parachute, "model", "models/parachute/parachute_ark.mdl");
    end[1] -= 7.0, end[2] -= 20.0;
    DispatchKeyValueVector(parachute, "origin", end);
    DispatchKeyValueVector(parachute, "angles", ang);
    if(!DispatchSpawn(parachute))
    {
#if SOURCEMOD_V_MAJOR == 1 && SOURCEMOD_V_MINOR < 10
        AcceptEntityInput(drop, "Kill");
#else
        RemoveEntity(drop);
#endif
        return false;
    }

    SetEntProp(parachute, Prop_Data, "m_CollisionGroup", 0);
    SetEntProp(parachute, Prop_Send, "m_nSolidType", 0);
    SetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity", parachute);

    SetVariantString("!activator");
    AcceptEntityInput(parachute, "SetParent", drop);

    CreateTimer(0.1, Timer_CheckHight, EntIndexToEntRef(drop), TIMER_REPEAT);

    return true;
}

public bool filter(int entity, int mask)
{
    return entity >= 0;
}

public Action Timer_CheckHight(Handle timer, int ref)
{
    static int drop;
    if((drop = EntRefToEntIndex(ref)) == INVALID_ENT_REFERENCE)
        return Plugin_Stop;

    int parachute = GetEntPropEnt(drop, Prop_Data, "m_hOwnerEntity");
    if(parachute == -1)
        return Plugin_Stop;

    TeleportEntity(drop, NULL_VECTOR, NULL_VECTOR, view_as<float>({0.0, 0.0, -50.0}));

    static float pos[3], end[3];
    GetEntPropVector(drop, Prop_Data, "m_vecOrigin", pos);
    TR_TraceRayFilter(pos, view_as<float>({90.0, 0.0, 0.0}), MASK_SOLID, RayType_Infinite, filter);
    if(!TR_DidHit())
        return Plugin_Stop;

    TR_GetEndPosition(end);
    if(GetVectorDistance(pos, end) > 300.0)
        return Plugin_Continue;

    SetEntProp(drop, Prop_Data, "m_CollisionGroup", 9);
    SetEntProp(drop, Prop_Send, "m_nSolidType", 6);
//    SetEntProp(drop, Prop_Data, "m_usSolidFlags", 1);
#if SOURCEMOD_V_MAJOR == 1 && SOURCEMOD_V_MINOR < 10
    AcceptEntityInput(parachute, "Kill");
#else
    RemoveEntity(parachute);
#endif

    if(iCount < iDrops)
        hSpawn = CreateTimer(fSpawn + GetRandomFloat(0.0, fInterval), Timer_SpawnAirDrop, _, TIMER_FLAG_NO_MAPCHANGE);

    return Plugin_Stop;
}
Такие же ошибки
errors:
[SM] Exception reported: Stack leak detected: sp:-1580080680 should be 23628!
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
[SM] Exception reported: Not enough space on the stack
Сообщения автоматически склеены:

как понять что у игрока включен фонарик и принудительно отключить его, а еще поменять звук фонарика на какой-нибудь другой?

code:
#include <sdktools>
public void OnPluginStart(){
    AddNormalSoundHook(OnSoundHook);
}
public void OnMapStart(){
    PrecacheSound("buttons/bell1.wav", false);
}
public Action OnSoundHook(int clients[64], int &numClients, char sample[PLATFORM_MAX_PATH], int &entity, int &channel, float &volume, int &level, int &pitch, int &flags){
    if(StrContains(sample, "flashlight") != -1){
        if(entity > 0 && entity <= MaxClients && IsClientInGame(entity) && IsPlayerAlive(entity)){
            float pos[3];
            GetClientEyePosition(entity, pos);
            EmitAmbientSound("buttons/bell1.wav", pos, entity);
        }
        return Plugin_Stop;
    }
    return Plugin_Continue;
}
public void OnGameFrame(){
    for(int client = 1; client <= MaxClients; client++){
        if(IsClientInGame(client) && IsPlayerAlive(client)){
            if((GetEntProp(client, Prop_Send, "m_fEffects")) == 4){
                SetEntProp(client, Prop_Send, "m_fEffects", GetEntProp(client, Prop_Send, "m_fEffects")^4);
            }
        }   
    }
}

Проверял на v34, вроде работает
 
Последнее редактирование:

StormRoman

Участник
Сообщения
3
Реакции
0
Можете скинут мне плагин для админов и там было про муты, логи, баны и т.д. Для Garrys's Mod
 
Последнее редактирование:

msl1

Участник
Сообщения
162
Реакции
20
Подскажите после выдачи оружия его не видно в руках как можно исправить ?
PHP:
public Action Timer_Sample(Handle timer, int UserId)
{
    int iClient = GetClientOfUserId(UserId);
    
    if ( iClient && IsClientInGame(iClient) )
    {
        g_iTimer[iClient] = null;
        
        int weapon = GetPlayerWeaponSlot(iClient, CS_SLOT_PRIMARY);
        SetEntPropEnt(iClient, Prop_Send, "m_hActiveWeapon", weapon);
        
        
    }
}
 

KiKiEEKi

🏆 🥇
Сообщения
653
Реакции
513
Подскажите после выдачи оружия его не видно в руках как можно исправить ?
PHP:
public Action Timer_Sample(Handle timer, int UserId)
{
    int iClient = GetClientOfUserId(UserId);
   
    if ( iClient && IsClientInGame(iClient) )
    {
        g_iTimer[iClient] = null;
       
        int weapon = GetPlayerWeaponSlot(iClient, CS_SLOT_PRIMARY);
        SetEntPropEnt(iClient, Prop_Send, "m_hActiveWeapon", weapon);
       
       
    }
}
А где тут функция выдачи оружия?
 

cmb

Участник
Сообщения
15
Реакции
2
как использовать файлы моделей, звуков из hl2/ если они в такой же директории что и cstrike/ и с таким же названием файла?
 

-=|УЧЕНИК|=-

вся жизнь,сплошной цирк.
Сообщения
876
Реакции
212
Всем привет!
Подскажите пожалуйста,как сделать,что не учитывало ботов.
Чтоб подсчет был только игроков.
Заранее благодарю.
 

Вложения

  • c4_plant_control.sp
    1 КБ · Просмотры: 7

NeLifeASkazka

Участник
Сообщения
128
Реакции
70
Всем привет!
Подскажите пожалуйста,как сделать,что не учитывало ботов.
Чтоб подсчет был только игроков.
Заранее благодарю.
code:
#pragma semicolon 1

#include <sourcemod>
#include <cstrike>

public Plugin:myinfo =
{
    name    = "C4 Plant Control",
    author    = "wS (World-Source.Ru)",
    version = "1.0"
};

new g_Need;

public OnPluginStart()
{
    new Handle:cvar = CreateConVar("c4_plant_control", "5", "Если на сервере нет 'x' чел, то бомбу поставить нельзя");
    g_Need = GetConVarInt(cvar); HookConVarChange(cvar, cvar_changed);

    HookEvent("bomb_beginplant", bomb_beginplant, EventHookMode_Post);
}

public cvar_changed(Handle:cvar, const String:OldValue[], const String:NewValue[])
{
    g_Need = StringToInt(NewValue);
}

public bomb_beginplant(Handle:event, const String:name[], bool:silent)
{
    if (GetCountPlayers() < g_Need)
    {
        new client = GetClientOfUserId(GetEventInt(event, "userid"));
        CS_DropWeapon(client, GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"), true, false);
        PrintToChat(client, "\x04На сервере должно быть: %d чел", g_Need);
    }
}
stock int GetCountPlayers(){
    int count;
    for(int client = 1; client <= MaxClients; client++){
        if(IsClientInGame(client) && !IsFakeClient(client)){
            count++;
        }
    }
    return count;
}
 

Raptor01

Участник
Сообщения
4
Реакции
0
Всем привет, у меня такой вопрос.. Возможно очистить или заблокировать на время список строковой таблицы, который я добавил через AddFileToDownloadsTable? Хочу чтоб на время fastdl не работает.
 

Grey83

не пишу плагины с весны 2022
Сообщения
8,521
Реакции
4,980
@Raptor01, если FastDL отсутствует, то клиенты будут пытаться скачать файлы с сервера напрямую.
Зачем эту таблицу чистить?
 

Raptor01

Участник
Сообщения
4
Реакции
0
@Raptor01, если FastDL отсутствует, то клиенты будут пытаться скачать файлы с сервера напрямую.
Зачем эту таблицу чистить?
Потому что хочу чтоб не всегда fastdl работал, а например на переходе между карт.
 
Сверху Снизу