Saving race time not working.
#1

Hello samp forum!
So i have this code:
pawn Код:
if(RaceMinutes[playerid] >= 1)
        {
            if(RaceSeconds[playerid] < pInfo[playerid][SultanSeconds])
            {
                pInfo[playerid][SultanMiliSeconds] = RaceMiliSeconds[playerid];
                pInfo[playerid][SultanSeconds] = RaceSeconds[playerid];
                pInfo[playerid][SultanMinutes] = RaceMinutes[playerid];
                SavePlayer(playerid);
                format(string, sizeof(string),"[Mission]: This is your new record: %d:%d:%d.",RaceMinutes[playerid], RaceSeconds[playerid], RaceMiliSeconds[playerid]);
                SendClientMessage(playerid, -1, string);
                RaceMinutes[playerid] = 0;
                RaceSeconds[playerid] = 0;
                RaceMiliSeconds[playerid] = 0;
            }
            else
            {
                format(string, sizeof(string),"[Mission]: Your best time is: %d:%d:%d.",pInfo[playerid][SultanMinutes], pInfo[playerid][SultanSeconds], pInfo[playerid][SultanMiliSeconds]);
                SendClientMessage(playerid, -1, string);
                RaceMinutes[playerid] = 0;
                RaceSeconds[playerid] = 0;
                RaceMiliSeconds[playerid] = 0;
            }
        }
        else
        {
            if(RaceSeconds[playerid] < pInfo[playerid][SultanSeconds])
            {
                pInfo[playerid][SultanMiliSeconds] = RaceMiliSeconds[playerid];
                pInfo[playerid][SultanSeconds] = RaceSeconds[playerid];
                pInfo[playerid][SultanMinutes] = RaceMinutes[playerid];
                SavePlayer(playerid);
                format(string, sizeof(string),"[Mission]: This is your new record: %d:%d:%d.",RaceMinutes[playerid], RaceSeconds[playerid], RaceMiliSeconds[playerid]);
                SendClientMessage(playerid, -1, string);
                RaceMinutes[playerid] = 0;
                RaceSeconds[playerid] = 0;
                RaceMiliSeconds[playerid] = 0;
            }
            else
            {
                format(string, sizeof(string),"[Mission]: Your best time is: %d:%d:%d.",pInfo[playerid][SultanMinutes], pInfo[playerid][SultanSeconds], pInfo[playerid][SultanMiliSeconds]);
                SendClientMessage(playerid, -1, string);
                RaceMinutes[playerid] = 0;
                RaceSeconds[playerid] = 0;
                RaceMiliSeconds[playerid] = 0;
            }
        }
I don't know is this the best code
But the problem is, when i end the race it tells me: "Your best time is: 0:0:0" And sometimes tell me "This is your new record: 0:0:0."
I don't understand where is the problem?
Reply
#2

Are the right values stored in the RaceMinutes/RaceSeconds/RaceMiliSeconds variables?
Reply
#3

Quote:
Originally Posted by Schneider
Посмотреть сообщение
Are the right values stored in the RaceMinutes/RaceSeconds/RaceMiliSeconds variables?
Yes.
Reply
#4

Well, if they are correctly saved, they shouldn't appear as zero's in the messages.. So somehow they are still '0'.

Are you also sure these variables are not reset in the SavePlayer(playerid); function?
Reply
#5

Quote:
Originally Posted by Schneider
Посмотреть сообщение
Well, if they are correctly saved, they shouldn't appear as zero's in the messages.. So somehow they are still '0'.

Are you also sure these variables are not reset in the SavePlayer(playerid); function?
This is my saving:
pawn Код:
stock SavePlayer(playerid)
{
        new INI:file = INI_Open(Path(playerid));
    INI_SetTag(file,"Player's Data");
    INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]);
    INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);
    INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
    INI_WriteInt(file,"Scores",GetPlayerScore(playerid));
    INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);
    INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);
    INI_WriteInt(file,"SultanMiliSeconds",pInfo[playerid][SultanMiliSeconds]);
    INI_WriteInt(file,"SultanSeconds",pInfo[playerid][SultanSeconds]);
    INI_WriteInt(file,"SultanMinutes",pInfo[playerid][SultanMinutes]);
    INI_Close(file);
}
I don't get it, where is the problem -.-
Reply
#6

Ok,
can you show us the piece of code where RaceMinutes/RaceSeconds/RaceMiliSeconds are set when the race is finished?
Reply
#7

Quote:
Originally Posted by Schneider
Посмотреть сообщение
Ok,
can you show us the piece of code where RaceMinutes/RaceSeconds/RaceMiliSeconds are set when the race is finished?
This is the timer:
pawn Код:
public RaceTimer(playerid)
{
    RaceMiliSeconds[playerid] += 100;
    if(RaceMiliSeconds[playerid] == 1000)
    {
        RaceSeconds[playerid]++;
        RaceMiliSeconds[playerid] = 0;
    }
    if(RaceSeconds[playerid] == 60)
    {
        RaceMinutes[playerid]++;
        RaceSeconds[playerid] = 0;
    }
    new string[16];
    format(string, 16, "%d:%d:%d", RaceMinutes[playerid], RaceSeconds[playerid], RaceMiliSeconds[playerid]);
    TextDrawSetString(Race[playerid], string);
}
And whole code when race ends:
pawn Код:
else if (CP[playerid] == 11)
    {
        new string[70];
        DisablePlayerCheckpoint(playerid);
        SendClientMessage(playerid, -1, "[Mission]: Sultan mission is completed! You get +$1200 ja +2 score!");
        GivePlayerCash(playerid, 1200);
        SetPlayerScore(playerid, GetPlayerScore(playerid) + 2);
        Missioonil[playerid] = 0;
        KillTimer(RaceT[playerid]);
        format(string, sizeof(string),"[Mission]: You ended Sultan missioni. Time:  %d:%d:%d.",RaceMinutes[playerid], RaceSeconds[playerid], RaceMiliSeconds[playerid]);
        SendClientMessage(playerid, -1, string);
        TextDrawHideForPlayer(playerid, Race[playerid]);
        if(RaceMinutes[playerid] >= 1)
        {
            if(RaceSeconds[playerid] < pInfo[playerid][SultanSeconds])
            {
                pInfo[playerid][SultanMiliSeconds] = RaceMiliSeconds[playerid];
                pInfo[playerid][SultanSeconds] = RaceSeconds[playerid];
                pInfo[playerid][SultanMinutes] = RaceMinutes[playerid];
                SavePlayer(playerid);
                format(string, sizeof(string),"[Mission]: This is your new record: %d:%d:%d.",RaceMinutes[playerid], RaceSeconds[playerid], RaceMiliSeconds[playerid]);
                SendClientMessage(playerid, -1, string);
                RaceMinutes[playerid] = 0;
                RaceSeconds[playerid] = 0;
                RaceMiliSeconds[playerid] = 0;
            }
            else
            {
                format(string, sizeof(string),"[Mission]: Your best time is: %d:%d:%d.",pInfo[playerid][SultanMinutes], pInfo[playerid][SultanSeconds], pInfo[playerid][SultanMiliSeconds]);
                SendClientMessage(playerid, -1, string);
                RaceMinutes[playerid] = 0;
                RaceSeconds[playerid] = 0;
                RaceMiliSeconds[playerid] = 0;
            }
        }
        else
        {
            if(RaceSeconds[playerid] < pInfo[playerid][SultanSeconds])
            {
                pInfo[playerid][SultanMiliSeconds] = RaceMiliSeconds[playerid];
                pInfo[playerid][SultanSeconds] = RaceSeconds[playerid];
                pInfo[playerid][SultanMinutes] = RaceMinutes[playerid];
                SavePlayer(playerid);
                format(string, sizeof(string),"[Mission]: This is your new record: %d:%d:%d.",RaceMinutes[playerid], RaceSeconds[playerid], RaceMiliSeconds[playerid]);
                SendClientMessage(playerid, -1, string);
                RaceMinutes[playerid] = 0;
                RaceSeconds[playerid] = 0;
                RaceMiliSeconds[playerid] = 0;
            }
            else
            {
                format(string, sizeof(string),"[Mission]: Your best time is: %d:%d:%d.",pInfo[playerid][SultanMinutes], pInfo[playerid][SultanSeconds], pInfo[playerid][SultanMiliSeconds]);
                SendClientMessage(playerid, -1, string);
                RaceMinutes[playerid] = 0;
                RaceSeconds[playerid] = 0;
                RaceMiliSeconds[playerid] = 0;
            }
        }
    }
Reply
#8

Does the textdraw show you the correct time at each timer-update?
Reply
#9

Quote:
Originally Posted by Schneider
Посмотреть сообщение
Does the textdraw show you the correct time at each timer-update?
Yes. And this also works:
pawn Код:
format(string, sizeof(string),"[Mission]: You ended Sultan missioni. Time: %d:%d:%d.",RaceMinutes[playerid], RaceSeconds[playerid], RaceMiliSeconds[playerid]);
        SendClientMessage(playerid, -1, string);
Reply
#10

-delete-
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)