AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [L4D2] Nuke - Timer Issue (https://forums.alliedmods.net/showthread.php?t=338718)

alasfourom 07-22-2022 15:49

[L4D2] Nuke - Timer Issue
 
Hello guys

Explaining The plugin:
Nuke/Explode Survivors After A Period Of Time
Currently only slayed

I'm trying to understand some concepts here,

My always issues are with timers, I'm trying to stop timer + repeated timers when round end

The 2nd issue, need to fix the countdown, how to replace the 600 sec with the ConVar

PHP Code:

ExplodingTime g_CountDown-- + 600


Marttt 07-22-2022 16:54

Re: [L4D2] How to stop timers + countdown issue
 
Usually I create a "global" timer variable

PHP Code:

Handle g_tMyTimer

Then on LeftStartArea you could delete the timer:

PHP Code:

delete g_tMyTimer;
g_tMyTimer CreateTimer (1.0Timer_CountDownclientTIMER_REPEAT); 

And on RoundEnd just

PHP Code:

delete g_tMyTimer

Also, you aren't returning "Plugin_Stop" at some point for a repeatable timer.

I recommend you read Dragokas's post about timers.

alasfourom 07-22-2022 17:16

Re: [L4D2] How to stop timers + countdown issue
 
Thank you Marttt I will definitely take a look at it, can you also explain to me why this is not working

PHP Code:

 ExplodingTime g_CountDown-- + GetConVarFloat(NukeTimer); 


Marttt 07-22-2022 17:28

Re: [L4D2] How to stop timers + countdown issue
 
I didn't understand what this variable is for. Seems more of a logic error to me.
If is a countdown usually I set the var in LeftSafeArea to "e.g." 10, then keep decrementing inside the repeat_timer
If the value is <= 0 then you should Stop the timer.

alasfourom 07-22-2022 17:39

Re: [L4D2] How to stop timers + countdown issue
 
because I want it to countdown the ConVar NukeTimer which can be changed

PHP Code:

 NukeTimer CreateConVar ("l4d2_nuke_time""600.0""Set The Time At Which Players Will Be Nuked" ,FCVAR_NOTIFYtrue1.0true3600.0); 

Since NukeTimer is adjustable and can be changed, so the countdown should also be changed

I hope you got my point

Marttt 07-22-2022 18:25

Re: [L4D2] How to stop timers + countdown issue
 
not much reason to use a float here
btw is just change the "10" example for the one I mentioned

g_CountDown = GetConVarInt(NukeTimer); on round start

and

ExplodingTime = g_CountDown--;

alasfourom 07-22-2022 18:47

Re: [L4D2] How to stop timers + countdown issue
 
Worked like a charm

Thank you Marttt :up::up:

alasfourom 07-23-2022 00:16

Re: [L4D2] How to stop timers + countdown issue
 
I have another issue now :oops:

The First Issue, is this error, I have no clue how to fix this > Line 58 I pointed it in the script > delete g_Timer_NukePlayers;

PHP Code:

L 07/23/2022 07:13:13SourceMod error session started
L 07
/23/2022 07:13:13Info (map "c1m1_hotel") (file "C:\Servers\L4D2\TheCrew\left4dead2\addons\sourcemod\logs\errors_20220723.log")
L 07/23/2022 07:13:13: [SMException reportedHandle 69c00789 is invalid (error 3)
L 07/23/2022 07:13:13: [SMBlamingL4D_Nuke.smx
L 07
/23/2022 07:13:13: [SMCall stack trace:
L 07/23/2022 07:13:13: [SM]   [0CloseHandle
L 07
/23/2022 07:13:13: [SM]   [1Line 58C:\Users\Omar Alasfour\Desktop\L4D_Nuke.sp::Event_RoundEnd 

The Second Issue, which is probably the same as first one, delete timer on round end is not working

PHP Code:

#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0"
#define SOUND_NUKE "animation/overpass_jets.wav"

ConVar NukeTimer;
ConVar Announcer;

Handle g_Timer_NukePlayers;
Handle g_Timer_CountDown

int g_CountDown;
int g_Announcer;
int ExplodingTime;

public 
Plugin myinfo 
{
    
name "L4D2 Nuke",
    
author "alasfour",
    
description "Nuke Players With Countdown After Leaving Saferoom",
    
version "1.0",
    
url "https://forums.alliedmods.net/"
};

public 
void OnPluginStart() 
{
    
CreateConVar ("l4d2_nuke_version"PLUGIN_VERSION"L4D2 Nuke" ,FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
NukeTimer CreateConVar ("l4d2_nuke_timer""600.0""Set The Time At Which Players Will Be Nuked [Should Be Higher Than Announcer Time]" ,FCVAR_NOTIFYtrue1.0true3600.0);
    
Announcer CreateConVar ("l4d2_nuke_announcer""90.0""Set The Time At Which Nuke Countdown Will Be Announced To Players [Should Be Lower Than Nuke Time]" ,FCVAR_NOTIFYtrue1.0true3600.0);
    
AutoExecConfig (true"L4D2_Nuke");

    
HookEvent("player_left_start_area"Event_LeftStartArea);
    
HookEvent("round_end"Event_RoundEnd);

    
PrecacheSound(SOUND_NUKE);
}

public 
Action Event_LeftStartArea(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    {
        
g_CountDown GetConVarInt(NukeTimer);
        
g_Announcer GetConVarInt(Announcer);
        
PrintToChatAll("\x04[Warning] \x01Nuke Countdown Started: \x03%d min %d sec"g_CountDown 60g_CountDown 60);
        
        
g_Timer_CountDown CreateTimer (1.0Timer_CountDownclientTIMER_REPEAT);
    }
    for (
int i 1<= MaxClientsi++)
    {
        
g_Timer_NukePlayers CreateTimer (GetConVarFloat(NukeTimer), Timer_NukePlayersi);
    }
}

public 
Action Event_RoundEnd (Event event, const char[] namebool dontBroadcast)
{
    
delete g_Timer_CountDown;
    
delete g_Timer_NukePlayers;         // Line 58
}

public 
Action Timer_NukePlayers (Handle timerint client)
{
    if (
IsValidClient(client) && IsClientInGame(client) && IsPlayerAlive(client))
    {
        
ForcePlayerSuicide(client);
        
//Exploding Effect
        
if (ExplodingTime <= 1EmitSoundToAll(SOUND_NUKE);
    }
    return 
Plugin_Handled;
}

public 
Action Timer_CountDown (Handle timerint client)
{
    
ExplodingTime g_CountDown-- -1;
    
    if (
ExplodingTime 0) return Plugin_Stop;
    
    if (
ExplodingTime <= g_AnnouncerPrintHintTextToAll("Nuke Time: %d"ExplodingTime);    
    
    return 
Plugin_Continue;
}

stock bool IsValidClient(int client)
{
    return 
client && client <= MaxClients && IsClientInGame (client);



Grey83 07-23-2022 03:53

Re: [L4D2] Nuke - Timer Issue
 
alasfourom,
PHP Code:

g_CountDown--; 

equals to
PHP Code:

g_CountDown g_CountDown 1


Grey83 07-23-2022 03:56

Re: [L4D2] How to stop timers + countdown issue
 
Quote:

Originally Posted by alasfourom (Post 2784473)
The First Issue, is this error, I have no clue how to fix this > Line 58 I pointed it in the script > delete g_Timer_NukePlayers;

PHP Code:

public Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    ...
    
delete g_Timer_NukePlayers;         // Line 58
}

public 
Action Timer_NukePlayers(Handle timerint client)
{
    ...
    return 
Plugin_Handled;


==>
PHP Code:

public Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    ...
    if(
g_Timer_NukePlayersdelete g_Timer_NukePlayers;         // Line 58
}

public 
Action Timer_NukePlayers(Handle timerint client)
{
    ...
    
g_Timer_NukePlayers null;
    return 
Plugin_Stop;




All times are GMT -4. The time now is 00:58.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.