SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 19/02/2015, 06:00 AM   #1
Dex007HLH
Big Clucker
 
Dex007HLH's Avatar
 
Join Date: Nov 2010
Location: Somewhere infront of a computer.
Posts: 121
Reputation: 2
Default Timer is not working

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?
__________________
This signature was made in 5.706 seconds
Dex007HLH is offline   Reply With Quote
Old 19/02/2015, 06:20 AM   #2
Extremo
Gangsta
 
Extremo's Avatar
 
Join Date: Jul 2008
Posts: 717
Reputation: 90
Default Re: Timer is not working

This is just a random quick idea I am having at 7 in the morning but did you forward GMX?
__________________
Extremo is offline   Reply With Quote
Old 19/02/2015, 06:23 AM   #3
Dex007HLH
Big Clucker
 
Dex007HLH's Avatar
 
Join Date: Nov 2010
Location: Somewhere infront of a computer.
Posts: 121
Reputation: 2
Default Re: Timer is not working

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.
__________________
This signature was made in 5.706 seconds
Dex007HLH is offline   Reply With Quote
Old 19/02/2015, 06:27 AM   #4
Extremo
Gangsta
 
Extremo's Avatar
 
Join Date: Jul 2008
Posts: 717
Reputation: 90
Default Re: Timer is not working

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;
}
__________________
Extremo is offline   Reply With Quote
Old 19/02/2015, 06:45 AM   #5
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,067
Reputation: 2660
Default Re: Timer is not working

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.
__________________
Vince is offline   Reply With Quote
Old 19/02/2015, 06:58 AM   #6
Extremo
Gangsta
 
Extremo's Avatar
 
Join Date: Jul 2008
Posts: 717
Reputation: 90
Default Re: Timer is not working

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.
__________________
Extremo is offline   Reply With Quote
Old 19/02/2015, 04:45 PM   #7
Dex007HLH
Big Clucker
 
Dex007HLH's Avatar
 
Join Date: Nov 2010
Location: Somewhere infront of a computer.
Posts: 121
Reputation: 2
Default Re: Timer is not working

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.
__________________
This signature was made in 5.706 seconds
Dex007HLH is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Timer Not Working NoahF Scripting Help 12 23/06/2013 12:54 PM
Not working, timer KingyKings Scripting Help 9 22/11/2012 07:49 PM
Timer not working? +REP! Gooday Scripting Help 3 14/03/2012 04:21 PM
Timer Not Working acade Scripting Help 2 09/03/2012 08:24 AM
Timer Not working. Alex_Obando Help Archive 5 13/08/2011 03:15 AM


All times are GMT. The time now is 03:22 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.