Timers Help
#1

I have 3 total timers on my server and ever since the recent addition of a timer for the weather, Everything else has been screwed up.

Here are the first timers i added:
Код:
public OnPlayerSpawn(playerid)
{
SetTimerEx("LooseHunger", 150000, true, "i", playerid);
}

public LooseHunger(playerid)
{
	if(PlayerInfo[playerid][Hunger] == 0 || PlayerInfo[playerid][Hunger] < 0)
	{
 		SetTimerEx("LooseHealth", 6000, false, "i", playerid);
       	if(PlayerInfo[playerid][Hunger] < 0)
		{
		PlayerInfo[playerid][Hunger] = 0;
		}
		
	}
	else
	{
		UpdateDodHunger(playerid, -5);
  		PlayerPlaySound(playerid, 1190, 0.0, 0.0, 0.0);
	}
return 1;
}

public LooseHealth(playerid)
{
	new Float:health;
    GetPlayerHealth(playerid,health);
	if(PlayerInfo[playerid][Hunger] < 1)
	{
	    SetTimerEx("LoseHealth", 6000, false, "i", playerid);
		SetPlayerHealth(playerid, health - 10);
		PlayerPlaySound(playerid, 1095, 0.0, 0.0, 0.0);
		if(health < 0)
		{
		SetPlayerHealth(playerid, 0);
		}
	}
return 1;
}
Here is what i recently added which SEEMED to cause all of the problems:
Код:
public OnGameModeInit()
{
/// World Time(Day/Night)
WorldTime = 12;
SetWorldTime(12);
print("Starting Day/Night Timer");
    SetTimer("WorldTimer", 60000, true);
}

public WorldTimer()
{
	if(WorldTime == 25)
	{
		WorldTime = 0;
	}
	else
	{
		WorldTime += 1;
	}
	SetWorldTime(WorldTime);
return 1;
}
also is 24 the max world time?

Thank You
Reply
#2

also can someone help me with the weather?
Reply
#3

I guess it's the part where you added the time as 25. The max world time is not even 24,if you notice in single player, after the time 23:59, it becomes 00:00 right? since it uses 24 hours clock format,change that 25 to 0
Reply
#4

pawn Код:
public OnPlayerSpawn(playerid)
{
    SetTimerEx("LooseHunger", 150000, false, "i", playerid);
}

public LooseHunger(playerid)
{
    if(!PlayerInfo[playerid][Hunger])
    {
        SetTimerEx("LooseHealth", 6000, false, "i", playerid);
        PlayerInfo[playerid][Hunger] = 0;
    }
    else
    {
        UpdateDodHunger(playerid, -5);
        PlayerPlaySound(playerid, 1190, 0.0, 0.0, 0.0);
        SetTimerEx("LooseHunger", 150000, false, "i", playerid);
    }
    return 1;
}

public LooseHealth(playerid)
{
    if(!PlayerInfo[playerid][Hunger])
    {
        new Float:health;
        GetPlayerHealth(playerid, health);
        SetTimerEx("LoseHealth", 6000, false, "i", playerid);
        SetPlayerHealth(playerid, health - 10);
        PlayerPlaySound(playerid, 1095, 0.0, 0.0, 0.0);
    }
    return 1;
}

public OnGameModeInit()
{
    SetWorldTime(WorldTime = 12);
    print("Starting Day/Night Timer");
    SetTimer("WorldTimer", 60000, true);
}

public WorldTimer()
{
    WorldTime += 1;
    if(WorldTime >= 24) WorldTime = 0
    SetWorldTime(WorldTime);
    return 1;
}
The maximum time is 23:59, and after that it goes back to 00:00. As 24:00 == 00:00, because there are 24 hours in a day. As for weather, something like this would work:

pawn Код:
public OnGameModeInit()
{
    SetTimer("ChangeWeather", 60000, false);
    return 1;
}

forward ChangeWeather();
public ChangeWeather() return SetWeather(random(21));
Reply
#5

thanks, im going to test it later and see, this has to be the fix. i think it was setting the world tie to 24 +.
Reply
#6

Quote:
Originally Posted by jeffery30162
Посмотреть сообщение
thanks, im going to test it later and see, this has to be the fix. i think it was setting the world tie to 24 +.
No setting it to 24 will not show any effect, you have use 0 instead or the problem will keep reoccurring.
Reply
#7

No, it will still work if you do 24. It just finds the time after 24 hours. So 29:00 would be 07:00. Works like this:

pawn Код:
while(number >= 24)
{
    number -= 24;
    hour++;
}
SetWorldTime(hour);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)