Плагин на отсчёт до взрыва бомбы

AD4M

Участник
Сообщения
373
Реакции
58
Ребята, здравствуйте, хотелось бы спросить кое-чего по поводу кода.
Решил сделать плагин на отсчёт до взрыва бомбы к себе на паблик, но возникли большие проблемы:
Показывается это и всё, таймер утихает, хотя я вроде бы сделал его в милисекундах и каждую милисекунду обновления.

44270

#include <sourcemod>

#pragma newdecls required

public Plugin myinfo ={
name = "TimerBomb",
author = "D3vil",
description = "This plugin allows know that how much time to defuse the bomb",
version = "1.0",
url = "vk.com/adamia3"
};

Handle g_hTimer = INVALID_HANDLE;
float g_fExplosionTime;
float g_fCount;

public void OnPluginStart(){
if(GetEngineVersion() != Engine_CSGO){
SetFailState("This plugin only for CS:GO");
}

g_fCount = 0.01;

HookEvent("bomb_planted", Event_BombPlanted, EventHookMode_Pre);
HookEvent("bomb_defused", Event_BombDefused, EventHookMode_Post);
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
}

public Action Event_BombPlanted(Event hEvent, const char[] name, bool bDontBroadcast){
g_fExplosionTime = 40.0;

g_hTimer = CreateTimer((g_fCount), TimerCountDown, TIMER_REPEAT);
return Plugin_Continue;
}

public Action Event_BombDefused(Event hEvent, const char[] name, bool bDontBroadcast){
for(int i = 1; i <= MaxClients; i++){
if(IsClientInGame(i) && !IsFakeClient(i)){
PrintCenterText(i, "Бомба разминирована!");
}
}

if(g_hTimer){
KillTimer(g_hTimer);
g_hTimer = null;
}
}

public Action TimerCountDown(Handle hTimer, any data){
g_fExplosionTime -= g_fCount;

if(g_fExplosionTime <= 0.0){
KillTimer(g_hTimer);
g_hTimer = null;

for(int i = 1; i <= MaxClients; i++){
if(IsClientInGame(i) && !IsFakeClient(i)){
PrintCenterText(i, "Бомба взорвалась!");
}
}
}

for(int i = 1; i <= MaxClients; i++){
if(IsClientInGame(i) && !IsFakeClient(i)){
PrintCenterText(i, "До взрыва бомбы осталось: [%2f]", g_fExplosionTime);
}
}
}

public Action Event_RoundStart(Event hEvent, const char[] name, bool bDontBroadcast){
if(g_hTimer){
KillTimer(g_hTimer);
g_hTimer = null;
}
}
 

AD4M

Участник
Сообщения
373
Реакции
58
C-подобный:
#include <sourcemod>

#pragma newdecls required

public Plugin myinfo ={
    name = "TimerBomb",
    author = "D3vil",
    description = "This plugin allows know that how much time to defuse the bomb",
    version = "1.0",
    url = "vk.com/adamia3"
};

Handle g_hTimer = INVALID_HANDLE;
float g_fExplosionTime;
float g_fCount;

public void OnPluginStart(){
    if(GetEngineVersion() != Engine_CSGO){
        SetFailState("This plugin only for CS:GO");
    }
    
    g_fCount = 0.01;
    
    HookEvent("bomb_planted", Event_BombPlanted, EventHookMode_Pre);
    HookEvent("bomb_defused", Event_BombDefused, EventHookMode_Post);
    HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
}

public Action Event_BombPlanted(Event hEvent, const char[] name, bool bDontBroadcast){
    g_fExplosionTime = 40.0;
    
    g_hTimer = CreateTimer((g_fCount), TimerCountDown, TIMER_REPEAT);
    return Plugin_Continue;
}

public Action Event_BombDefused(Event hEvent, const char[] name, bool bDontBroadcast){
    for(int i = 1; i <= MaxClients; i++){
        if(IsClientInGame(i) && !IsFakeClient(i)){
            PrintCenterText(i, "Бомба разминирована!");
        }
    }
    
    if(g_hTimer){
        KillTimer(g_hTimer);
        g_hTimer = null;
    }
}

public Action TimerCountDown(Handle hTimer, any data){   
    g_fExplosionTime -= g_fCount;
    
    if(g_fExplosionTime <= 0.0){
        KillTimer(g_hTimer);
        g_hTimer = null;
        
        for(int i = 1; i <= MaxClients; i++){
            if(IsClientInGame(i) && !IsFakeClient(i)){
                PrintCenterText(i, "Бомба взорвалась!");
        }
    }
    }
    
    for(int i = 1; i <= MaxClients; i++){
        if(IsClientInGame(i) && !IsFakeClient(i)){
            PrintCenterText(i, "До взрыва бомбы осталось: [%2f]", g_fExplosionTime);
        }
    }
}

public Action Event_RoundStart(Event hEvent, const char[] name, bool bDontBroadcast){
    if(g_hTimer){
        KillTimer(g_hTimer);
        g_hTimer = null;
    }
}
 

iLoco

Пишу плагины за печеньки 🍪🍪🍪
Сообщения
2,265
Реакции
1,323
C-подобный:
#include <sourcemod>

#pragma newdecls required

public Plugin myinfo ={
    name = "TimerBomb",
    author = "D3vil",
    description = "This plugin allows know that how much time to defuse the bomb",
    version = "1.0",
    url = "vk.com/adamia3"
};

Handle g_hTimer = INVALID_HANDLE;
float g_fExplosionTime;
float g_fCount;

public void OnPluginStart(){
    if(GetEngineVersion() != Engine_CSGO){
        SetFailState("This plugin only for CS:GO");
    }
  
    g_fCount = 0.01;
  
    HookEvent("bomb_planted", Event_BombPlanted, EventHookMode_Pre);
    HookEvent("bomb_defused", Event_BombDefused, EventHookMode_Post);
    HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
}

public Action Event_BombPlanted(Event hEvent, const char[] name, bool bDontBroadcast){
    g_fExplosionTime = 40.0;
  
    g_hTimer = CreateTimer((g_fCount), TimerCountDown, TIMER_REPEAT);
    return Plugin_Continue;
}

public Action Event_BombDefused(Event hEvent, const char[] name, bool bDontBroadcast){
    for(int i = 1; i <= MaxClients; i++){
        if(IsClientInGame(i) && !IsFakeClient(i)){
            PrintCenterText(i, "Бомба разминирована!");
        }
    }
  
    if(g_hTimer){
        KillTimer(g_hTimer);
        g_hTimer = null;
    }
}

public Action TimerCountDown(Handle hTimer, any data){ 
    g_fExplosionTime -= g_fCount;
  
    if(g_fExplosionTime <= 0.0){
        KillTimer(g_hTimer);
        g_hTimer = null;
      
        for(int i = 1; i <= MaxClients; i++){
            if(IsClientInGame(i) && !IsFakeClient(i)){
                PrintCenterText(i, "Бомба взорвалась!");
        }
    }
    }
  
    for(int i = 1; i <= MaxClients; i++){
        if(IsClientInGame(i) && !IsFakeClient(i)){
            PrintCenterText(i, "До взрыва бомбы осталось: [%2f]", g_fExplosionTime);
        }
    }
}

public Action Event_RoundStart(Event hEvent, const char[] name, bool bDontBroadcast){
    if(g_hTimer){
        KillTimer(g_hTimer);
        g_hTimer = null;
    }
}
PHP:
#include <sourcemod>
#pragma newdecls required
public Plugin myinfo ={
    name = "TimerBomb",
    author = "D3vil",
    description = "This plugin allows know that how much time to defuse the bomb",
    version = "1.0",
    url = "vk.com/adamia3"
};
Handle g_hTimer = INVALID_HANDLE;
int g_fExplosionTime;
public void OnPluginStart()
{
    if(GetEngineVersion() != Engine_CSGO){
        SetFailState("This plugin only for CS:GO");
    }
    HookEvent("bomb_planted", Event_BombPlanted, EventHookMode_Pre);
    HookEvent("bomb_defused", Event_BombDefused, EventHookMode_Post);
    HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
}
public Action Event_BombPlanted(Event hEvent, const char[] name, bool bDontBroadcast)
{
    g_fExplosionTime = GetConVarInt(FindConVar("mp_c4timer"));
    
    g_hTimer = CreateTimer(1.0, TimerCountDown, TIMER_REPEAT);
    return Plugin_Continue;
}
public Action Event_BombDefused(Event hEvent, const char[] name, bool bDontBroadcast)
{
    PrintCenterTextAll("Бомба разминирована!");
    StopTimer();
}
public Action TimerCountDown(Handle hTimer, any data)
{   
    --g_fExplosionTime;
    
    if(g_fExplosionTime > 0) PrintCenterTextAll("До взрыва бомбы осталось: [%i]", g_fExplosionTime);
    else
    { 
        StopTimer();
        PrintCenterTextAll("Бомба взорвалась!");
    }
    
    
}
public Action Event_RoundStart(Event hEvent, const char[] name, bool bDontBroadcast)
{
    StopTimer();
}
void StopTimer()
{
    if(g_hTimer){
        KillTimer(g_hTimer);
        g_hTimer = null;
    }
}
 

Grey83

не пишу плагины с весны 2022
Сообщения
8,558
Реакции
5,060
я себе несколько иначе делал (правда без сообщения о взрыве):
C++:
#pragma semicolon 1
#pragma newdecls required

int iCDStart;
float fC4Timer;

public void OnPluginStart()
{
    ConVar cvar;
    (cvar = FindConVar("mp_c4timer")).AddChangeHook(CVarChanged_Timer);
    fC4Timer = cvar.FloatValue;

    HookEvent("bomb_planted", Event_BombPlanted, EventHookMode_PostNoCopy);
    HookEvent("bomb_beep", Event_BombBeep, EventHookMode_PostNoCopy);
}

public void CVarChanged_Timer(ConVar cvar, const char[] oldVal, const char[] newVal)
{
    fC4Timer = cvar.FloatValue;
}

public void Event_BombPlanted(Event hEvent, const char[] name, bool dontBroadcast)
{
    iCDStart = GetTime();
}

public void Event_BombBeep(Event event, const char[] name, bool dontBroadcast)
{
    static int diff;
    if((diff = GetTime() - iCDStart) >= 0 && diff <= fC4Timer)
        PrintCenterTextAll("C4: %d sec", RoundFloat(fC4Timer) - diff);
}
 

AD4M

Участник
Сообщения
373
Реакции
58
Не работает
PHP:
#include <sourcemod>
#pragma newdecls required
public Plugin myinfo ={
    name = "TimerBomb",
    author = "D3vil",
    description = "This plugin allows know that how much time to defuse the bomb",
    version = "1.0",
    url = "vk.com/adamia3"
};
Handle g_hTimer = INVALID_HANDLE;
int g_fExplosionTime;
public void OnPluginStart()
{
    if(GetEngineVersion() != Engine_CSGO){
        SetFailState("This plugin only for CS:GO");
    }
    HookEvent("bomb_planted", Event_BombPlanted, EventHookMode_Pre);
    HookEvent("bomb_defused", Event_BombDefused, EventHookMode_Post);
    HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
}
public Action Event_BombPlanted(Event hEvent, const char[] name, bool bDontBroadcast)
{
    g_fExplosionTime = GetConVarInt(FindConVar("mp_c4timer"));
   
    g_hTimer = CreateTimer(1.0, TimerCountDown, TIMER_REPEAT);
    return Plugin_Continue;
}
public Action Event_BombDefused(Event hEvent, const char[] name, bool bDontBroadcast)
{
    PrintCenterTextAll("Бомба разминирована!");
    StopTimer();
}
public Action TimerCountDown(Handle hTimer, any data)
{  
    --g_fExplosionTime;
   
    if(g_fExplosionTime > 0) PrintCenterTextAll("До взрыва бомбы осталось: [%i]", g_fExplosionTime);
    else
    {
        StopTimer();
        PrintCenterTextAll("Бомба взорвалась!");
    }
   
   
}
public Action Event_RoundStart(Event hEvent, const char[] name, bool bDontBroadcast)
{
    StopTimer();
}
void StopTimer()
{
    if(g_hTimer){
        KillTimer(g_hTimer);
        g_hTimer = null;
    }
}
 

Djddd

Участник
Сообщения
1
Реакции
0
Если заработает скинь в лс. На свой сервак поставлю)
 

Grey83

не пишу плагины с весны 2022
Сообщения
8,558
Реакции
5,060
кстати
C++:
    if(g_hTimer){
        KillTimer();
        g_hTimer = null;
    }
равнозначноif(g_hTimer) delete g_hTimer;
D3vil, попробуй так:
C++:
#pragma semicolon 1
#pragma newdecls required

Handle g_hTimer;
int iTimer,
    iC4Timer;

public Plugin myinfo =
{
    name        = "TimerBomb",
    version        = "1.0.1",
    description    = "This plugin allows know that how much time to defuse the bomb",
    author        = "D3vil (rewritten by Grey83)",
    url            = "vk.com/adamia3"
};

public void OnPluginStart()
{
    ConVar cvar;
    (cvar = FindConVar("mp_c4timer")).AddChangeHook(CVarChanged_Timer);
    iC4Timer = cvar.IntValue;

    HookEvent("bomb_planted", Event_Bomb, EventHookMode_PostNoCopy);
    HookEvent("bomb_defused", Event_Bomb, EventHookMode_PostNoCopy);
    HookEvent("bomb_exploded", Event_Bomb, EventHookMode_PostNoCopy);
    HookEvent("round_start", Event_Bomb, EventHookMode_PostNoCopy);
}

public void CVarChanged_Timer(ConVar cvar, const char[] oldVal, const char[] newVal)
{
    iC4Timer = cvar.IntValue;
}

public void OnMapEnd()
{
    if(g_hTimer) delete g_hTimer;
}

public void Event_Bomb(Event event, const char[] name, bool dontBroadcast)
{
    OnMapEnd();

    switch(name[5])
    {
        case 'p':
        {
            PrintCenterTextAll("До взрыва бомбы осталось: [%i]", iC4Timer);
            iTimer = iC4Timer;
            g_hTimer = CreateTimer(1.0, TimerCountDown, _, TIMER_REPEAT);
        }
        case 'd':    PrintCenterTextAll("Бомба разминирована!");
        case 'e':    PrintCenterTextAll("Бомба взорвалась!");
    }
}

public Action TimerCountDown(Handle hTimer)
{
    if(--iTimer > 0) PrintCenterTextAll("До взрыва бомбы осталось: [%i]", iTimer);
    else OnMapEnd();
}
 

AD4M

Участник
Сообщения
373
Реакции
58
Попробуем, отпишу
кстатиравнозначноif(g_hTimer) delete g_hTimer;
D3vil, попробуй так:
C++:
#pragma semicolon 1
#pragma newdecls required

Handle g_hTimer;
int iTimer,
    iC4Timer;

public Plugin myinfo =
{
    name        = "TimerBomb",
    version        = "1.0.1",
    description    = "This plugin allows know that how much time to defuse the bomb",
    author        = "D3vil (rewritten by Grey83)",
    url            = "vk.com/adamia3"
};

public void OnPluginStart()
{
    ConVar cvar;
    (cvar = FindConVar("mp_c4timer")).AddChangeHook(CVarChanged_Timer);
    iC4Timer = cvar.IntValue;

    HookEvent("bomb_planted", Event_Bomb, EventHookMode_PostNoCopy);
    HookEvent("bomb_defused", Event_Bomb, EventHookMode_PostNoCopy);
    HookEvent("bomb_exploded", Event_Bomb, EventHookMode_PostNoCopy);
    HookEvent("round_start", Event_Bomb, EventHookMode_PostNoCopy);
}

public void CVarChanged_Timer(ConVar cvar, const char[] oldVal, const char[] newVal)
{
    iC4Timer = cvar.IntValue;
}

public void OnMapEnd()
{
    if(g_hTimer) delete g_hTimer;
}

public void Event_Bomb(Event event, const char[] name, bool dontBroadcast)
{
    OnMapEnd();

    switch(name[5])
    {
        case 'p':
        {
            PrintCenterTextAll("До взрыва бомбы осталось: [%i]", iC4Timer);
            iTimer = iC4Timer;
            g_hTimer = CreateTimer(1.0, TimerCountDown, _, TIMER_REPEAT);
        }
        case 'd':    PrintCenterTextAll("Бомба разминирована!");
        case 'e':    PrintCenterTextAll("Бомба взорвалась!");
    }
}

public Action TimerCountDown(Handle hTimer)
{
    if(--iTimer > 0) PrintCenterTextAll("До взрыва бомбы осталось: [%i]", iTimer);
    else OnMapEnd();
}
 
Сверху Снизу