This function is not working like it should...
#1

Hello.

pawn Код:
forward OneSecondUpdate(playerid);
public OneSecondUpdate(playerid)
{
    if(PlayerInfo[playerid][pSeconds] == 59)
    {
        PlayerInfo[playerid][pSeconds] = 0;
        if(PlayerInfo[playerid][pMinutes] == 59)
        {
            PlayerInfo[playerid][pMinutes] = 0;
            if(PlayerInfo[playerid][pHours] == 23)
            {
                PlayerInfo[playerid][pHours] = 0;
                PlayerInfo[playerid][pDays]++;
            }
            else PlayerInfo[playerid][pHours]++;
        }
        else PlayerInfo[playerid][pMinutes]++;
    }
    else PlayerInfo[playerid][pSeconds]++;
    return 1;
}
This function works, after some time however, the numbers start skipping and does not function like it should.
What I'm trying to do is use this function to display the amount of time people have been logged in the server, therefore the reason why I added the variables, in which can be then seen in the stats command.

It works, but like I said, after a while, they start going crazy..

pawn Код:
OnPlayerConnect(playerid);
{
    OneSecondUpdatetimer = SetTimerEx("OneSecondUpdate",1000,true,"iiii",playerid);
   return 1;
}
The timer is active once the player connects..

pawn Код:
OnPlayerDisconect(playerid);
{
KillTimer(OneSecondUpdatetimer);
return 1;
}
The timer is destroyed, to avoid any lapses..
Reply
#2

I realized that my function returned a 1, I removed it, thinking that would fix the problem and it hasn't..
Reply
#3

First..
pawn Код:
new OneSecondUpdateTimer[MAX_PLAYERS];
public OnPlayerConnect(playerid);
{
    OneSecondUpdatetimer[playerid] = SetTimerEx("OneSecondUpdate", 1000, true, "i", playerid);
    return 1;
}
You should do that timer like this:
pawn Код:
forward OneSecondUpdate(playerid);
public OneSecondUpdate(playerid)
{
    PlayerInfo[playerid][pSeconds] ++;
    if(PlayerInfo[playerid][pSeconds] == 60)
    {
        PlayerInfo[playerid][pSeconds] = 0;
        PlayerInfo[playerid][pMinutes] ++;
        if(PlayerInfo[playerid][pMinutes] == 60)
        {
            PlayerInfo[playerid][pMinutes] = 0;
            PlayerInfo[playerid][pHours] ++;
            if(PlayerInfo[playerid][pHours] == 4)
            {
                PlayerInfo[playerid][pHours] = 0;
                PlayerInfo[playerid][pDays]++;
            }
        }
    }
    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid)
{
    KillTimer(OneSecondUpdateTimer[playerid]);
    return 1;
}
Reply
#4

KillTimer(OneSecondUpdateTimer[playerid]);

gave me errors

Код:
C:\Users\Steven Tacle\Desktop\New folder\gamemodes\WCGF.pwn(3079) : error 028: invalid subscript (not an array or too many subscripts): "OneSecondUpdatetimer"
C:\Users\Steven Tacle\Desktop\New folder\gamemodes\WCGF.pwn(3079) : warning 215: expression has no effect
C:\Users\Steven Tacle\Desktop\New folder\gamemodes\WCGF.pwn(3079) : error 001: expected token: ";", but found "]"
C:\Users\Steven Tacle\Desktop\New folder\gamemodes\WCGF.pwn(3079) : error 029: invalid expression, assumed zero
C:\Users\Steven Tacle\Desktop\New folder\gamemodes\WCGF.pwn(3079) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#5

Sorry.. letter wrong..
pawn Код:
KillTimer(OneSecondUpdatetimer[playerid]);
Reply
#6

Thanks!
Reply
#7

You must replace
pawn Код:
new OneSecondUpdatetimer;
with
pawn Код:
new OneSecondUpdatetimer[MAX_PLAYERS];
Reply
#8

Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)