AlliedModders

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

uurbyrkdr 06-15-2015 17:39

Timer problems
 
PHP Code:

public Action:Event_Round_Start(Handle:event, const String:name[], bool:dontBroadcast
{
    
iTime GetTime();
    
CreateTimer(60.0GodOff);
    for(new 
1i<=MaxClients;i++)
    {
        if(
IsClientInGame(i) && IsPlayerAlive(i))
            
SetEntProp(iProp_Data"m_takedamage"01);
    }
}

public 
Action:GodOff(Handle:timer)
{
    
int iRoundTime GetTime() - iTime;
    if(
iRoundTime == 60// Checking again time for bugs
    
{
        for(new 
1i<=MaxClients;i++)
        {
            
SetEntProp(iProp_Data"m_takedamage"21);
        }
        
CreateTimer(90.0GiveBeacon);
    }
}

public 
Action:GiveBeacon(Handle:timer)
{
    
int iRoundTime GetTime() - iTime;
    if(
iRoundTime == 150)
    {
        
ServerCommand("sm_beacon @all");
        
CreateTimer(90.0blabla...);
    }
}

... 

How can I optimize this code?
I know, i'm really a poor coder :D

uurbyrkdr 06-15-2015 19:14

Re: Timer problems
 
i used OnGameFrame, with this i got better stability.
Now works correctly..

Drixevel 06-16-2015 07:37

Re: Timer problems
 
Code:

public Action:Event_Round_Start(Handle:event, const String:name[], bool:dontBroadcast)
{
        for (new i = 1; i <= MaxClients; i++)
        {
                if(IsClientInGame(i) && IsPlayerAlive(i))
                {
                        SetEntProp(i, Prop_Data, "m_takedamage", 0, 1);
                }
        }
       
        CreateTimer(60.0, GodOff);
}

public Action:GodOff(Handle:timer)
{
        for(new i = 1; i <= MaxClients; i++)
        {
                SetEntProp(i, Prop_Data, "m_takedamage", 2, 1);
        }
       
        CreateTimer(90.0, GiveBeacon);
}

public Action:GiveBeacon(Handle:timer)
{
        ServerCommand("sm_beacon @all");
       
        CreateTimer(90.0, blabla...);
}

Not sure what you're trying to do but that's what I see.

TnTSCS 06-16-2015 09:14

Re: Timer problems
 
Here's another example of working with timers you want to execute only if certain conditions apply... like resetting every round_start event

code


All times are GMT -4. The time now is 18:20.

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