Raised This Month: $51 Target: $400
 12% 

Cumulative Timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 07-14-2022 , 15:15   Cumulative Timer
Reply With Quote #1

Hello guys

How is it possible to prolong timer if something is checked

For example, I'm trying to make a plugin if you killed someone, you will have some abilities and after a period of time, it will be turning off.

After killing someone you will have like 10 seconds of these abilities then it will go back to normal.

What I want to do is, if I killed more players, the time to rest to normal will be delayed, like killing 3 players simultaneously will give you 10 + 10 + 10 seconds before resetting instead of resetting earlier.

This is a script example - For Left 4 Dead 2:

PHP Code:
public void Event_InfectedDeath (Event event, const char[] namebool dontBroadcast)
{
    
int victim GetClientOfUserId (event.GetInt("userid")); if (IsClient (victim))
    {
        
int team GetClientTeam (victim); if (team == TEAM_INFECTED)
        {
            
int attacker GetClientOfUserId (event.GetInt("attacker"));
            
            if (
IsValidClient (attackerTEAM_SURVIVOR)) if (!IsFakeClient (attacker))
            
            
/*I'm doing some long stuff here, didnt want to bother*/
            /*bluh bluh bluh*/
            /*bluh bluh bluh*/

            /*I created timer to stop the abilities after 10 seconds*/
            
CreateTimer (10.0StopTimerattacker);
        }
    }
    return;



PHP Code:
public Action StopTimer (Handle timerany client)
{
    
/*I stopped everything here*/


Last edited by alasfourom; 07-15-2022 at 00:15.
alasfourom is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-14-2022 , 15:20   Re: Cumulative Timer
Reply With Quote #2

Quote:
Originally Posted by alasfourom View Post
Hello guys

How is it possible to prolong timer if something is checked

For example, I'm trying to make a plugin if you killed someone, you will have some abilities and after a period of time, it will be turning off.

After killing someone you will have like 10 seconds of these abilities then it will go back to normal.

What I want to do is, if I killed more players, the time to rest to normal will be increase, like killing 3 players simultaneously will give you 10 + 10 + 10 seconds before resetting.

This is a script example - For Left 4 Dead 2:

PHP Code:
public void Event_InfectedDeath (Event event, const char[] namebool dontBroadcast)
{
    
int victim GetClientOfUserId (event.GetInt("userid")); if (IsClient (victim))
    {
        
int team GetClientTeam (victim); if (team == TEAM_INFECTED)
        {
            
int attacker GetClientOfUserId (event.GetInt("attacker"));
            
            if (
IsValidClient (attackerTEAM_SURVIVOR)) if (!IsFakeClient (attacker))
            
            
/*I'm doing some long stuff here, didnt want to bother*/
            /*bluh bluh bluh*/
            /*bluh bluh bluh*/

            /*I created timer to stop the abilities after 10 seconds*/
            
CreateTimer (GetConVarFloat(10.0), StopTimerattacker);
        }
    }
    return;

Hello. I would do the following:

1. Because I want to let him know how much time is left at real time, I would make a 0.1 repeat timer to count down his time. Then the time left is a variable ( either set expiration by GetGameTime() or just make a time left var to 10 and decrease by 0.1 each time the timer arrives )

This allows you to both increment it whenever you like, and let the client track it.

Note that with the best way in L4D2 ( which I know you use ) you need to send an empty message or wait a bit, otherwise you will have bugs if you spam those hints ( PrintHintText )
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 07-14-2022 , 15:24   Re: Cumulative Timer
Reply With Quote #3

if there is 2 Eyals life would be much easier

Thanks man

Last edited by alasfourom; 07-15-2022 at 02:03.
alasfourom is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 07-14-2022 , 17:43   Re: Cumulative Timer
Reply With Quote #4

Create a player float array
Set the value with GetEngineTime() + 10.0
Create a 1.0 timer to check if any client has the value
if it has, resets
otherwise goes next
__________________
Marttt is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 07-15-2022 , 02:03   Re: Cumulative Timer
Reply With Quote #5

What kind of disaster I'm doing here ?

I created the float

PHP Code:
float f_AbilityStart [MAXPLAYERS+1]; 
The cumulative timer here

PHP Code:
public Action CumulativeEffect (int client)
{
    
f_AbilityStart[0] = GetEngineTime() + 10.0;
    
    if (
AbilityStart [client])
    {
        if (
f_AbilityStart [client])
        {
            
CreateTimer(0.1StopTimerclient);
        }
    }
    else 
AbilityStart [client] = true;
    return 
Plugin_Continue;

Timer Stop

PHP Code:
public Action StopTimer(Handle timerany client)
{
    
/*I stopped everything here*/
    
AbilityStart [client] = false;


Last edited by alasfourom; 07-15-2022 at 02:24.
alasfourom is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 07-15-2022 , 07:13   Re: Cumulative Timer
Reply With Quote #6

I would create a single timer of 1.0 seconds and do a loop through all clients where AbilityStart[client] = true

PHP Code:
if (f_AbilityStart[client] > 0.0 && GetGameTime() - f_AbilityStart[client] > 10.0)
    
AbilityStart[client] = false 
anyway, this is HOW I would do it, is not the most effective way but is easier to maintain.

also don't forget to reset on player death, round restart, etc

There are a lot of plugins with similar cooldown features, just need to search a bit and check their code.
__________________
Marttt is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 07-15-2022 , 07:42   Re: Cumulative Timer
Reply With Quote #7

Awwww

Thanks Marttt, I will test it right now
alasfourom is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-15-2022 , 10:20   Re: Cumulative Timer
Reply With Quote #8

Quote:
Originally Posted by alasfourom View Post
What kind of disaster I'm doing here ?

I created the float

PHP Code:
float f_AbilityStart [MAXPLAYERS+1]; 
The cumulative timer here

PHP Code:
public Action CumulativeEffect (int client)
{
    
f_AbilityStart[0] = GetEngineTime() + 10.0;
    
    if (
AbilityStart [client])
    {
        if (
f_AbilityStart [client])
        {
            
CreateTimer(0.1StopTimerclient);
        }
    }
    else 
AbilityStart [client] = true;
    return 
Plugin_Continue;

Timer Stop

PHP Code:
public Action StopTimer(Handle timerany client)
{
    
/*I stopped everything here*/
    
AbilityStart [client] = false;

For a start, AbilityStart is a lie. IsAbilityActive, bAbilityActive, AbilityActive are all acceptable names for the variable that asks If the ability is active

Second, f_AbilityStart[0] does absolutely nothing. If you were to try [1] by accident, it would work only for the first player that entered the server, and nobody else, so it's like every player in the server would contribute to the timer of the first player in the server, and nobody would get the ability except him.

When you do f_AbilityStart[x], where x is a constant number (1, 2, 3, 4, 5, 6, 7) you will assign that variable to a constant slot, which will ignore who did the action.

When you use f_AbilityStart[client] you are giving the client's "unique"* index the responsibility to hold his time, so it works.

* It's not totally unique if a client disconnects and another client joins, as client indexes can be stolen. User ID cannot be stolen, and therefore User ID is unlimited in size ( which is bad for programming if you tried something like:

float f_AbilityStart[32767] with f_AbilityStart[GetClientUserId(client)]
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 07-15-2022 , 12:47   Re: Cumulative Timer
Reply With Quote #9

Thank you Eyal, you will find multiple mistakes in the script obviously

I just started reading about scripts like 1 month ago, and trying to replicate some lines that I saw other ppl do

Its still getting me crazy tbh, its need a while to make it right and understand the timer concept you guys explaining

Thanks anyway, I will keep trying and testing
alasfourom is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:49.


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