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

Черная вдова

Участник
Сообщения
2,795
Реакции
670
Не по глазам было)
--- Добавлено позже ---

Я не так давно в сурс мод пришел, могу ошибаться, но как я понимаю это сохраняет ид игрока или что то такое.
какого игрока и зачем тебе его сохранят, да и вообще скинь логи
 

Someone

Участник
Сообщения
1,933
Реакции
1,653

Обычно я так делаю:
PHP:
public void OnPluginStart()
{
    RegConsoleCmd("sm_timer", CMD_TIMER);
}

public Action CMD_TIMER(int iClient, int iArgs)
{
    CreateTimer(1.0, TIMER, _, TIMER_REPEAT);
    return Plugin_Handled;
}

public Action TIMER(Handle hTimer)
{
    static int iTimer = 5;
    if(--iTimer == 0)
    {
        PrintToChatAll("Время вышло.");
        return Plugin_Stop;
    }
    PrintToChatAll("Осталось %d секунд.", iTimer);
   
    return Plugin_Continue;
}
 
Последнее редактирование:

Fox1qqq

Крякнем, плюнем и надежно склеим скотчем!
Сообщения
247
Реакции
145
Обычно я так делаю:
PHP:
g_iTimer;

public void OnPluginStart()
{
    RegConsoleCmd("sm_timer", CMD_TIMER);
}

public Action CMD_TIMER(int iClient, int iArgs)
{
    g_iTimer = 30;
    CreateTimer(1.0, TIMER, _, TIMER_REPEAT);
    return Plugin_Handled;
}

public Action TIMER(Handle hTimer)
{
    if(--g_iTimer == 0)
    {
        PrintToChatAll("Время вышло.");
        return Plugin_Stop;
    }
    PrintToChatAll("Осталось %d секунд.", g_iTimer);
  
    return Plugin_Continue;
}
А вот если в этом блоке:

C-подобный:
public Action:Timer_StopContest(Handle:timer, any:userid)
{
    new client = CID(userid);
    if ( !client ) return Plugin_Handled;
    PrintToChat(client, "Время на ответ вышло");
    g_timer[client] = INVALID_HANDLE;
    return Plugin_Handled;
}
 

Someone

Участник
Сообщения
1,933
Реакции
1,653
А вот если в этом блоке:

C-подобный:
public Action:Timer_StopContest(Handle:timer, any:userid)
{
    new client = CID(userid);
    if ( !client ) return Plugin_Handled;
    PrintToChat(client, "Время на ответ вышло");
    g_timer[client] = INVALID_HANDLE;
    return Plugin_Handled;
}

А чем тебе свой вариант не нравится ? Ну разве что
Plugin_Handled на Plugin_Stop заменить.
 

Allen

love society
Сообщения
352
Реакции
274
Не по глазам было)
--- Добавлено позже ---

Я не так давно в сурс мод пришел, могу ошибаться, но как я понимаю это сохраняет ид игрока или что то такое.
PHP:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>

#pragma tabsize 0
#pragma newdecls required

#define PLUGIN_VERSION "1.2"

int flash_client;

public Plugin myinfo =
{
    version = PLUGIN_VERSION,
};

public void OnPluginStart()
{
    HookEvent("flashbang_detonate", flashbang_detonate);
    HookEvent("player_blind", player_blind);
}

public void flashbang_detonate(Event event, const char[] name, bool silent)
{
    flash_client = GetClientOfUserId(GetEventInt(event, "userid"));
}

public void player_blind(Event event, const char[] name, bool silent)
{
    CreateTimer(0.01, TIMER_player_blind, GetEventInt(event, "userid"));
}

public Action TIMER_player_blind(Handle timer, any client)
{
    if (flash_client == client && IsClientInGame(client) && !IsPlayerAlive(client) && GetClientTeam(client) == 1)
{
    SetEntPropFloat(client, Prop_Send, "m_flFlashDuration", 0.0);
    SetEntPropFloat(client, Prop_Send, "m_flFlashMaxAlpha", 0.0);
    ClientCommand(client, "dsp_player 0.0");
    }  
  return Plugin_Stop;
}
Чекни, да и логи скинь, че писало.
 
Последнее редактирование:

Kruzya

Участник
Сообщения
12,970
Реакции
10,914
@.SN., на кой чёрт тут таймер?
RequestFrame · functions · SourceMod Scripting API Reference
Выполнит переданную функцию с переданным аргументом в следующем серверном тике. Куда быстрее, чем таймер на 0.1, и куда точнее.

Далее я уже молчу, что в одном тике может взорваться сразу две гранаты, и, соответственно, одна проигнорируется. Лучше в массив сохранять игроков, которые взрывают гранаты, до выполнения следующего тика.
 

HESOYAM

Участник
Сообщения
11
Реакции
0
Вот логи.
C-подобный:
L 06/07/2017 - 15:51:51: [SM] Native "IsClientInGame" reported: Client index 19 is invalid
L 06/07/2017 - 15:51:51: [SM] Displaying call stack trace for plugin "no_spec_flash.smx":
L 06/07/2017 - 15:51:51: [SM] [0] Line 35, D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp::TIMER_player_blind()
L 06/07/2017 - 16:07:19: Error log file session closed.
 

Kruzya

Участник
Сообщения
12,970
Реакции
10,914
@HESOYAM,с мобилки набросал.
PHP:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>

#pragma tabsize 0
#pragma newdecls required

#define PLUGIN_VERSION "1.2"

// int flash_client;
Handle g_hFlashers;

public Plugin myinfo =
{
    version = PLUGIN_VERSION,
};

public void OnPluginStart()
{
    HookEvent("flashbang_detonate", flashbang_detonate);
    HookEvent("player_blind", player_blind);
    g_hFlashers = CreateArray(ByteCountToCells(4));
}

public void flashbang_detonate(Event event, const char[] name, bool silent)
{
    PushArrayCell(g_hFlashers, GetClientOfUserId(GetEventInt(event, "userid")));
}

public void player_blind(Event event, const char[] name, bool silent)
{
    RequestFrame(OnBlindedPlayer, GetEventInt(event, "userid"));
}

public void OnBlindedPlayer(int client)
{
    client = GetClientOfUserId (client);
    if (iClient && FindValueInArray(g_hFlashers, client) != -1 && IsClientInGame(client) && GetClientTeam(client) < 2)
    {
        SetEntPropFloat(client, Prop_Send, "m_flFlashDuration", 0.0);
        SetEntPropFloat(client, Prop_Send, "m_flFlashMaxAlpha", 0.0);
        ClientCommand(client, "dsp_player 0.0");
    }
}
 

HESOYAM

Участник
Сообщения
11
Реакции
0
@HESOYAM,с мобилки набросал.
PHP:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>

#pragma tabsize 0
#pragma newdecls required

#define PLUGIN_VERSION "1.2"

// int flash_client;
Handle g_hFlashers;

public Plugin myinfo =
{
    version = PLUGIN_VERSION,
};

public void OnPluginStart()
{
    HookEvent("flashbang_detonate", flashbang_detonate);
    HookEvent("player_blind", player_blind);
    g_hFlashers = CreateArray(ByteCountToCells(4));
}

public void flashbang_detonate(Event event, const char[] name, bool silent)
{
    PushArrayCell(g_hFlashers, GetClientOfUserId(GetEventInt(event, "userid")));
}

public void player_blind(Event event, const char[] name, bool silent)
{
    RequestFrame(OnBlindedPlayer, GetEventInt(event, "userid"));
}

public void OnBlindedPlayer(int client)
{
    client = GetClientOfUserId (client);
    if (iClient && FindValueInArray(g_hFlashers, client) != -1 && IsClientInGame(client) && GetClientTeam(client) < 2)
    {
        SetEntPropFloat(client, Prop_Send, "m_flFlashDuration", 0.0);
        SetEntPropFloat(client, Prop_Send, "m_flFlashMaxAlpha", 0.0);
        ClientCommand(client, "dsp_player 0.0");
    }
}

//SourceMod Batch Compiler
// by the SourceMod Dev Team

C-подобный:
//// noteamflash.sp
// D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp(6) : warnin
g 207: unknown #pragma
// D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp(6) : error
038: extra characters on line
// D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp(11) : error
 010: invalid function or declaration
// D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp(13) : error
 001: expected token: ";", but found "-identifier-"
// D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp(16) : error
 010: invalid function or declaration
// D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp(18) : error
 001: expected token: ";", but found "-identifier-"
// D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp(25) : error
 021: symbol already defined: "void"
// D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp(25) : error
 017: undefined symbol "event"
// D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp(25) : error
 029: invalid expression, assumed zero
// D:\Games\Server\cstrike\addons\sourcemod\scripting\noteamflash.sp(25) : fatal
 error 127: too many error messages on one line
//
// Compilation aborted.
// 9 Errors.
 

Kruzya

Участник
Сообщения
12,970
Реакции
10,914
@HESOYAM, у Вас странный компилятор.
Screenshot_2017-06-08-10-21-33-293_org.mozilla.firefox.png
 

BaFeR

Добрый человек
Сообщения
721
Реакции
216
PHP:
            if((GetClientTeam(client) == CS_TEAM_CT)&&(GetTeamClientCount(CS_TEAM_CT)==1)&&(GetTeamClientCount(CS_TEAM_T)>=1))
            {
                ChangeClientTeam(client, team);
                if((GetTeamClientCount(CS_TEAM_CT))==0)
                {
                    int randomClient;
                    if (GetArraySize(g_aGuardQueue))
                    {
                        randomClient = GetArrayCell(g_aGuardQueue, 0);
                        RemovePlayerFromGuardQueue(randomClient);
  
                        CGOPrintToChatAll("%t %t", "ratio_tag", "ratio_find", randomClient);
                    }
                    else if (gc_bBalanceTerror.BoolValue)
                    {
                        randomClient = GetRandomClientFromTeam(CS_TEAM_T);
                        CGOPrintToChatAll("%t %t", "ratio_tag", "ratio_random", randomClient);
                    }
                    else
                    {
                        return;
                    }
 
                    if (!IsValidClient(randomClient, true, true))
                    {
                        CGOPrintToChatAll("%t %t", "ratio_tag", "ratio_novalid");
                    }
 
                    SetClientPendingTeam(randomClient, CS_TEAM_CT);
                    SetClientListeningFlags(randomClient, VOICE_NORMAL); // unmute if sm_hosties or admin has muted prisoners on round start
                    MinusDeath(randomClient);
                }
            }
Почему после переброса не идёт размут?
 

Kruzya

Участник
Сообщения
12,970
Реакции
10,914
@Forever Alone, лишние скобки у вызова функции получения кол-ва людей.
 

Kruzya

Участник
Сообщения
12,970
Реакции
10,914
@Forever Alone, выделил жирным, и подчеркнул.
if((GetTeamClientCount(CS_TEAM_CT))==0)
 

Черная вдова

Участник
Сообщения
2,795
Реакции
670
Исправил,но мут всё равно не убирает.
Добавь дебаг информационные сообщения и сам посмотри
Например
C-подобный:
                    if (GetArraySize(g_aGuardQueue))
                    {
                        PrintToChatAll("условие 1.1")
                        randomClient = GetArrayCell(g_aGuardQueue, 0);
                        PrintToChatAll("randomclient это игрок с ником %N", randomClient)
                        RemovePlayerFromGuardQueue(randomClient);
 
                        CGOPrintToChatAll("%t %t", "ratio_tag", "ratio_find", randomClient);
                    }
                    else if (gc_bBalanceTerror.BoolValue)
                    PrintToChatAll("условие 1.2")
                    {
 

BaFeR

Добрый человек
Сообщения
721
Реакции
216
Добавь дебаг информационные сообщения и сам посмотри
Например
C-подобный:
                    if (GetArraySize(g_aGuardQueue))
                    {
                        PrintToChatAll("условие 1.1")
                        randomClient = GetArrayCell(g_aGuardQueue, 0);
                        PrintToChatAll("randomclient это игрок с ником %N", randomClient)
                        RemovePlayerFromGuardQueue(randomClient);
 
                        CGOPrintToChatAll("%t %t", "ratio_tag", "ratio_find", randomClient);
                    }
                    else if (gc_bBalanceTerror.BoolValue)
                    PrintToChatAll("условие 1.2")
                    {
Хорошо,а так нет ошибок примерно в коде?
--- Добавлено позже ---
randomclient это игрок с ником {BLABLABLA}
Но всё равно игрок в муте,хотя всё верно пишет.
 
Последнее редактирование:

Черная вдова

Участник
Сообщения
2,795
Реакции
670
Хорошо,а так нет ошибок примерно в коде?
--- Добавлено позже ---
randomclient это игрок с ником {BLABLABLA}
Но всё равно игрок в муте,хотя всё верно пишет.
Тебе надо все сделать в дебаг форме и самому анализировать информацию
 
Сверху Снизу