Timer is not working
#1

So yeah.

OnGameModeInit
Code:
    // Timers
    SetTimer("KillUpdate", 1000, true); //this one doesn't give me problems
    SetTimer("OnServerUpdate", 1, true); //this one either
    SetTimer("GMX", 10000, true); //This one won't work. I'm using 10 secs just to see if it works but it's meant to be 15 mins
Code:
public KillUpdate()
{
        new string[128];
        format(string, sizeof(string), "Army: %d", T1Kills);
        TextDrawSetString(Kill1, string);
        format(string, sizeof(string), "Rebels: %d", T2Kills);
        TextDrawSetString(Kill2, string);

        GameSec--;
	if(GameSec<=-1)
	{
	    GameMin--;
	    GameSec=59;
	}
		return 1;
}

forward OnServerUpdate();
public OnServerUpdate()
{
	new String[1000];
    format(String,sizeof(String),"%02d:%02d",GameMin, GameSec);
    TextDrawSetString(Watch,String);

}

public GMX()
{
	        print("Hello World!");
            SetTimer("GMX2", 10000, false);
            TextDrawDestroy(Watch);
            if(T1Kills > T2Kills)

                {
                        for(new i=0;i<MAX_PLAYERS;i++)
                        {
                                if(gTeam[i] == T1)
                                {
                                GameTextForPlayer(i, "You Won! When is the party?", 4000, 3);
                                        SetPlayerScore(i, GetPlayerScore(i) + 1);
                                        GivePlayerMoney(i, 2000);

                                }
                                else
                                {
                                GameTextForPlayer(i, "You brought Disgrace!You LOST!", 4000, 3);
                                }
                        }
                }
                else if(T2Kills > T1Kills)
                {
                        for(new i=0;i<MAX_PLAYERS;i++)
                        {
                        if(gTeam[i] == T2)
                        {
                                GameTextForPlayer(i, "You Won! When is the party?", 4000, 3);
                                SetPlayerScore(i, GetPlayerScore(i) + 1);
                                GivePlayerMoney(i, 2000);
                                }
                                else
                                {
                                GameTextForPlayer(i, "You brought Disgrace!You LOST!", 4000, 3);
                                }
                        }
                }
                else if(T1Kills == T2Kills)
                {
                        GameTextForAll("Round Draw!", 4000, 3);
                }

                  return 1;
}

forward GMX2();
public GMX2()
{
     SendRconCommand("gmx");
	 return 1;
}
What could be wrong?
Reply
#2

This is just a random quick idea I am having at 7 in the morning but did you forward GMX?
Reply
#3

I'm trying to learn.
Would you explain me what's so wrong with that?
this gamemode is not supposed to last more than 15 minutes, but I'm trying to do this with 10 seconds. Anyways is not working.
Reply
#4

Well, did you do the following somewhere in your code:

pawn Code:
forward GMX();
I am actually pretty sure it gives an error if you don't so I feel pretty dumb for even asking, but I've re-read that code several times and I don't see any issues. Have you tried renaming GMX? Try the following:

pawn Code:
forward GMXTest();
public GMXTest()
and the timer

pawn Code:
SetTimer("GMXTest", 10000, true);
Also for best practice purposes it might be a good idea to store the timers and kill them, but I am pretty sure it does that on its own once the gamemode dies. But yeah, the idea is that maybe the name is conflicting?

EDIT:

Here is a better indented version of GMX for the next readers:

pawn Code:
public GMX()
{
    print("Hello World!");
    SetTimer("GMX2", 10000, false);
    TextDrawDestroy(Watch);
    if(T1Kills > T2Kills)
    {
        for(new i=0;i<MAX_PLAYERS;i++)
    {
            if(gTeam[i] == T1)
        {
            GameTextForPlayer(i, "You Won! When is the party?", 4000, 3);
            SetPlayerScore(i, GetPlayerScore(i) + 1);
        GivePlayerMoney(i, 2000);
            }
        else
        {
        GameTextForPlayer(i, "You brought Disgrace!You LOST!", 4000, 3);
        }
    }
    }
    else if(T2Kills > T1Kills)
    {
    for(new i=0;i<MAX_PLAYERS;i++)
        {
        if(gTeam[i] == T2)
            {
        GameTextForPlayer(i, "You Won! When is the party?", 4000, 3);
                SetPlayerScore(i, GetPlayerScore(i) + 1);
                GivePlayerMoney(i, 2000);
            }
            else
            {
        GameTextForPlayer(i, "You brought Disgrace!You LOST!", 4000, 3);
            }
        }
    }
    else if(T1Kills == T2Kills)
    {
    GameTextForAll("Round Draw!", 4000, 3);
    }
    return 1;
}
Reply
#5

What do you expect when you put this right before it;
Code:
SetTimer("OnServerUpdate", 1, true);
This is 1 millisecond. For comparison, the blink of an eye is 300 milliseconds. There's just not enough time to do anything else.
Reply
#6

Quote:
Originally Posted by Vince
View Post
What do you expect when you put this right before it;
Code:
SetTimer("OnServerUpdate", 1, true);
This is 1 millisecond. For comparison, the blink of an eye is 300 milliseconds. There's just not enough time to do anything else.
That still leaves the question why the KillUpdate works? It's based on the exact same timer system/framework.
Reply
#7

Quote:
Originally Posted by Vince
View Post
What do you expect when you put this right before it;
Code:
SetTimer("OnServerUpdate", 1, true);
This is 1 millisecond. For comparison, the blink of an eye is 300 milliseconds. There's just not enough time to do anything else.
I'll see what happens.
As far as I know, it shouldn't be a problem.

That was the problem, I think I'll just mix some timers and look for more intelligent ways to use them.
Thank you good sir.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)