Raised This Month: $ Target: $400
 0% 

Cumulative Timer


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-15-2022 , 10:20   Re: Cumulative Timer
Reply With Quote #6

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
 



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 00:58.


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