SA-MP Forums Archive
How to create this. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to create this. (/showthread.php?tid=178333)



How to create this. - Seven. - 21.09.2010

I have a race script, but want to make something like, when a person finishes it will set a local record.

When the gamemode starts it will say.

Race record time set by: Name at. Minutes:Seconds.

When someone else finishes and beats the others name it will set him to best time.

I've searched on the forums and could not find anything..


Re: How to create this. - Conroy - 21.09.2010

pawn Код:
forward StartRace();
forward FinishRace(winnerid);

new seconds, minutes;

/*
When the race is started, you might want to use this:
new message[128];
format(message, sizeof(message), "The current record for this race is: %02d:%02d", dini_Int("racerecord.ini", "minutes"), dini_Int("racerecord.ini", "seconds"));
for(...) //Fine all the participants
SendClientMessage(i, COLOR_GREEN, message);
*/


//Called when race has started (racetimer = SetTimer("StartRace", 1000, true);)
StartRace()
{
    if(!dini_Exists("racerecord.ini")) dini_Create("racerecord.ini"), dini_IntSet("racerecord.ini", "minutes", "00"), dini_IntSet("racerecord.ini", "seconds", "00");
    seconds++;
    if(seconds == 60) minutes++, seconds = 0;
    return 1;
}

//Called when race is finished (also kill timer, KillTimer(racetimer);)
FinishRace(winnerid)
{
    if(minutes < dini_Int("racerecord.ini", "minutes") return 1;
    if(minutes == dini_Int("racerecord.ini", "minutes")) if(seconds < dini_Int("racerecord.ini", "seconds")) return 1;
    dini_IntSet("racerecord.ini", "minutes", minutes);
    dini_IntSet("racerecord.ini", "seconds", seconds);
    new winnername[MAX_PLAYER_NAME], message[128];
    GetPlayerName(winnerid, winnername, sizeof(winnername));
    format(message, sizeof(message), "%s has set a new race record of: %02d:%02d", winnername, minutes, seconds);
    SendClientMessageToAll(COLOR_GREEN, message);
    minutes = 0;
    seconds = 0;
    return 1;
}