AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Cumulative Timer (https://forums.alliedmods.net/showthread.php?t=338590)

alasfourom 07-14-2022 15:15

Cumulative Timer
 
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*/



eyal282 07-14-2022 15:20

Re: Cumulative Timer
 
Quote:

Originally Posted by alasfourom (Post 2783769)
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 )

alasfourom 07-14-2022 15:24

Re: Cumulative Timer
 
if there is 2 Eyals life would be much easier

Thanks man

Marttt 07-14-2022 17:43

Re: Cumulative Timer
 
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

alasfourom 07-15-2022 02:03

Re: Cumulative Timer
 
What kind of disaster I'm doing here :oops: ?

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;



Marttt 07-15-2022 07:13

Re: Cumulative Timer
 
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.

alasfourom 07-15-2022 07:42

Re: Cumulative Timer
 
Awwww

Thanks Marttt, I will test it right now

eyal282 07-15-2022 10:20

Re: Cumulative Timer
 
Quote:

Originally Posted by alasfourom (Post 2783817)
What kind of disaster I'm doing here :oops: ?

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)]

alasfourom 07-15-2022 12:47

Re: Cumulative Timer
 
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


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

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