SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 31/08/2012, 02:26 PM   #1
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: Wigan, England
Posts: 3,012
Reputation: 231
Default Race System

Hello, i've scripted my own race system. Everything seems work apart from the last two checkpoints. The second to last checkpoint shows but doesn't function meaning the last one wont show at all.

OnPlayerEnterDynamicCheckpoint
pawn Code:
public OnPlayerEnterDynamicRaceCP(playerid, checkpointid) {
    if(checkpointid == CheckpointIDRace[playerid] && IsRaceOn == true && IsPlayerInRace(playerid)) {
        new string[128];
        DestroyDynamicRaceCP(CheckpointIDRace[playerid]);
        PlayerCheckpoint[playerid]++;
        CheckpointIDRace[playerid] = CreateDynamicRaceCP(OtherRaceInfo[ChosenRace][MarkerType], AroundTheCountry[PlayerCheckpoint[playerid]][X], AroundTheCountry[PlayerCheckpoint[playerid]][Y], AroundTheCountry[PlayerCheckpoint[playerid]][Z], AroundTheCountry[PlayerCheckpoint[playerid]+1][X], AroundTheCountry[PlayerCheckpoint[playerid]+1][Y], AroundTheCountry[PlayerCheckpoint[playerid]+1][Z], OtherRaceInfo[ChosenRace][CheckpointSize], -1, -1, playerid, 500.0);
        PlayerBestLap[playerid] = gettime() - RaceStartTime;
        new
            seconds = PlayerBestLap[playerid] % 60,
            minutes = (PlayerBestLap[playerid] - seconds) / 60,

        format(string, sizeof string, "~n~~n~~n~~n~~n~~n~~n~~n~~b~%s~n~~r~Checkpoints Remaining: ~w~%d/%d~n~Time: %02d:%02d", OtherRaceInfo[ChosenRace][Name], PlayerCheckpoint[playerid], OtherRaceInfo[ChosenRace][TotalCheckpoints], minutes, seconds);
        GameTextForPlayer(playerid, string, 28000000, 3);
        if(PlayerCheckpoint[playerid] >= OtherRaceInfo[ChosenRace][TotalCheckpoints]) {
            IsRaceOn = false;
            //PlayerCheckpoint[playerid] = -1;
            ChosenRace = 0;
            DestroyDynamicRaceCP(CheckpointIDRace[playerid]);
            format(string, sizeof string, "RACE: {FFFFFF}The race is now over. {FF0000}%s {FFFFF}has won!", GetPlayerNameEx(playerid));
            SendClientMessageToAll(COLOR_PURPLE, string);
            GameTextForAll(" ", 100, 3);
            StopAudioStreamForPlayer(playerid);
            DestroyVehicle(GetPlayerVehicleID(playerid));
        }
    }
    return 1;
}

My OtherRaceInfo Var
pawn Code:
enum raceInfo1 {
    ID,
    MarkerType,
    Name[100],
    Float:CheckpointSize,
    TotalCheckpoints,
    RaceMusic[250],
    CarID,
};
new OtherRaceInfo[][raceInfo1] = {
    {0, 0, "Around the Country", 6.5, 18, "http://media.soundcloud.com/stream/gY5IsvLMrLgR?stream_token=9iHHs", 541}

};

Kind Regards, Luis.
__________________

CITY LIFE ROLE PLAY
COMING SOON
---------------------------------
YouTube
YouTube | Twitter
On a break from YouTube.

Luis- is offline   Reply With Quote
Old 31/08/2012, 02:37 PM   #2
XGh0stz
Huge Clucker
 
XGh0stz's Avatar
 
Join Date: Nov 2007
Location: Florida
Posts: 418
Reputation: 17
Default Re: Race System

Actually about to get off and get to bed, but decided to quickly respond before I do, anyways:

Code:
if(PlayerCheckpoint[playerid] >= OtherRaceInfo[ChosenRace][TotalCheckpoints])
Off the top of my head, I'd say this is the problem, try raising your TotalCheckpoints for whatever race by 1 so that it allows that last checkpoint to function etc. (I think your TotalCheckpoints was just set too low)
__________________
Please respect the SA-MP Development Team
XGh0stz is offline   Reply With Quote
Old 31/08/2012, 02:40 PM   #3
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: Wigan, England
Posts: 3,012
Reputation: 231
Default Re: Race System

The total checkpoints is set to how many checkpoints there are which is 18 but i'll try setting it to 19 now.
__________________

CITY LIFE ROLE PLAY
COMING SOON
---------------------------------
YouTube
YouTube | Twitter
On a break from YouTube.

Luis- is offline   Reply With Quote
Old 31/08/2012, 02:44 PM   #4
HuSs3n
Guest
 
Posts: n/a
Default Re: Race System

idk if that will work , but you should try
because i have made a similar system before


pawn Code:
//Check if the player in (second to last checkpoint)
if(PlayerCheckpoint[playerid] == OtherRaceInfo[ChosenRace][TotalCheckpoints]-1)
{
CheckpointIDRace[playerid] = CreateDynamicRaceCP(OtherRaceInfo[ChosenRace][MarkerType], AroundTheCountry[PlayerCheckpoint[playerid]][X], AroundTheCountry[PlayerCheckpoint[playerid]][Y], AroundTheCountry[PlayerCheckpoint[playerid]][Z], 0.0,0.0, 0.0, OtherRaceInfo[ChosenRace][CheckpointSize], -1, -1, playerid, 500.0);
}
//Player In Last CP
else if(PlayerCheckpoint[playerid] >= OtherRaceInfo[ChosenRace][TotalCheckpoints])
{
}
else
{
}
  Reply With Quote
Old 31/08/2012, 03:06 PM   #5
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: Wigan, England
Posts: 3,012
Reputation: 231
Default Re: Race System

None of the above is working unfortunately. I'm really confused about this seeing at the other checkpoints work but the last two don't :S
__________________

CITY LIFE ROLE PLAY
COMING SOON
---------------------------------
YouTube
YouTube | Twitter
On a break from YouTube.

Luis- is offline   Reply With Quote
Old 31/08/2012, 06:15 PM   #6
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: Wigan, England
Posts: 3,012
Reputation: 231
Default Re: Race System

Can someone help me with this, as I need it being fixed as soon as possible. Thank you.
__________________

CITY LIFE ROLE PLAY
COMING SOON
---------------------------------
YouTube
YouTube | Twitter
On a break from YouTube.

Luis- is offline   Reply With Quote
Old 31/08/2012, 08:04 PM   #7
XGh0stz
Huge Clucker
 
XGh0stz's Avatar
 
Join Date: Nov 2007
Location: Florida
Posts: 418
Reputation: 17
Exclamation Re: Race System

In order to pinpoint a problem, print statements are highly recommended to be placed everywhere (Usually at every turn in the code such as an IF or an ELSE). However, it may be easier to just use client messages instead if you're testing within the server, so I'll include both:

Code:
public OnPlayerEnterDynamicRaceCP(playerid, checkpointid) {    if(checkpointid == CheckpointIDRace[playerid] && IsRaceOn == true && IsPlayerInRace(playerid)) {        new string[128];        DestroyDynamicRaceCP(CheckpointIDRace[playerid]);        PlayerCheckpoint[playerid]++;        CheckpointIDRace[playerid] = CreateDynamicRaceCP(OtherRaceInfo[ChosenRace][MarkerType], AroundTheCountry[PlayerCheckpoint[playerid]][X], AroundTheCountry[PlayerCheckpoint[playerid]][Y], AroundTheCountry[PlayerCheckpoint[playerid]][Z], AroundTheCountry[PlayerCheckpoint[playerid]+1][X], AroundTheCountry[PlayerCheckpoint[playerid]+1][Y], AroundTheCountry[PlayerCheckpoint[playerid]+1][Z], OtherRaceInfo[ChosenRace][CheckpointSize], -1, -1, playerid, 500.0);        PlayerBestLap[playerid] = gettime() - RaceStartTime;        new            seconds = PlayerBestLap[playerid] % 60,            minutes = (PlayerBestLap[playerid] - seconds) / 60,        format(string, sizeof string, "~n~~n~~n~~n~~n~~n~~n~~n~~b~%s~n~~r~Checkpoints Remaining: ~w~%d/%d~n~Time: %02d:%02d", OtherRaceInfo[ChosenRace][Name], PlayerCheckpoint[playerid], OtherRaceInfo[ChosenRace][TotalCheckpoints], minutes, seconds);        GameTextForPlayer(playerid, string, 28000000, 3);        if(PlayerCheckpoint[playerid] >= OtherRaceInfo[ChosenRace][TotalCheckpoints]) {            IsRaceOn = false;            //PlayerCheckpoint[playerid] = -1;            ChosenRace = 0;            DestroyDynamicRaceCP(CheckpointIDRace[playerid]);            format(string, sizeof string, "RACE: {FFFFFF}The race is now over. {FF0000}%s {FFFFF}has won!", GetPlayerNameEx(playerid));            SendClientMessageToAll(COLOR_PURPLE, string);            GameTextForAll(" ", 100, 3);            StopAudioStreamForPlayer(playerid);            DestroyVehicle(GetPlayerVehicleID(playerid));        }    }    return 1;}
Well, the above fails.. So new approach that requires more work on your behalf :P

There are only 2 IFs in the code you've displayed for us, so after each of those IFs, throw in a print(); or you may throw in a SendClientMessageToAll() or even both depending on your testing conditions. The messages used should be diffirent for each section (Point A for example, then Point B etc.)

Next, when you reach that 2nd to last checkpoint, make sure both of those prints/messages were called to ensure the script at least ran. If you're missing a print/message, then you'll at least know what IF failed and have an idea of where exactly to start looking in the code for your problem. Not only will this help you locate this problem, but also help with future problems by using this method

Once you've figured out which one of these IFs isnt being triggered when its suppose to be, we can examine that IF and start locating the source of the problem...

CreateDynamicRaceCP() or DestroyDynamicRaceCP() might be where the problem is as well, but isn't displayed here

UPDATE:
if(checkpointid == CheckpointIDRace[playerid] && IsRaceOn == true && IsPlayerInRace(playerid))
This line of code is what I'm guessing is failing to pass when called on the 2nd to last checkpoint,
so look into CheckpointIDRace[playerid], IsRaceOn and IsPlayerInRace. Something must have changed these values in your script somewhere down the line...
__________________
Please respect the SA-MP Development Team
XGh0stz is offline   Reply With Quote
Old 31/08/2012, 09:35 PM   #8
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: Wigan, England
Posts: 3,012
Reputation: 231
Default Re: Race System

I've done some more snooping on this and i've set the total checkpoints to 5 for a small test and everything works, it ends the race and what not. But if the total checkpoints are 18 it wont work correctly.
__________________

CITY LIFE ROLE PLAY
COMING SOON
---------------------------------
YouTube
YouTube | Twitter
On a break from YouTube.

Luis- is offline   Reply With Quote
Old 01/09/2012, 01:33 AM   #9
XGh0stz
Huge Clucker
 
XGh0stz's Avatar
 
Join Date: Nov 2007
Location: Florida
Posts: 418
Reputation: 17
Question Re: Race System

Well that's just interesting... (I assume you meant finishes the race early at the 4th,5th or 6th CP)

In that case, try lowering the total checkpoints instead of raising if you haven't already...
You started off with 18, then you tried 19, have you yet tried 17?
__________________
Please respect the SA-MP Development Team
XGh0stz is offline   Reply With Quote
Old 03/09/2012, 07:10 PM   #10
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: Wigan, England
Posts: 3,012
Reputation: 231
Default Re: Race System

I've been working on this and it's now not working with the last checkpoint which would be the finish.

Updated code
pawn Code:
if(checkpointid == CheckpointIDRace[playerid] && IsRaceOn == true && IsPlayerInRace(playerid) && IsValidDynamicRaceCP(CheckpointIDRace[playerid])) {
        new
            string[128],
            seconds = PlayerBestLap[playerid] % 60,
            minutes = (PlayerBestLap[playerid] - seconds) / 60
        ;

        if(PlayerCheckpoint[playerid] < OtherRaceInfo[ChosenRace][TotalCheckpoints]) {
            PlayerBestLap[playerid] = gettime() - RaceStartTime;
            format(string, sizeof string, "~n~~n~~n~~n~~n~~n~~n~~n~~b~%s~n~~r~Checkpoints Remaining: ~w~%d/%d~n~~r~Time: ~g~%02d:%02d", OtherRaceInfo[ChosenRace][Name], PlayerCheckpoint[playerid], OtherRaceInfo[ChosenRace][TotalCheckpoints], minutes, seconds);
            GameTextForPlayer(playerid, string, 28000000, 3);

            DestroyDynamicRaceCP(CheckpointIDRace[playerid]);
            CheckpointIDRace[playerid] = CreateDynamicRaceCP(OtherRaceInfo[ChosenRace][MarkerType], AroundTheCountry[PlayerCheckpoint[playerid]][X], AroundTheCountry[PlayerCheckpoint[playerid]][Y], AroundTheCountry[PlayerCheckpoint[playerid]][Z], AroundTheCountry[PlayerCheckpoint[playerid]+1][X], AroundTheCountry[PlayerCheckpoint[playerid]+1][Y], AroundTheCountry[PlayerCheckpoint[playerid]+1][Z], OtherRaceInfo[ChosenRace][CheckpointSize], -1, -1, playerid, 500.0);
            PlayerCheckpoint[playerid]++;
        }
        else if(PlayerCheckpoint[playerid] == OtherRaceInfo[ChosenRace][TotalCheckpoints] - 1) {
            IsRaceOn = false;
            PlayerCheckpoint[playerid] = -1;
            ChosenRace = 0;
            DestroyDynamicRaceCP(CheckpointIDRace[playerid]);
            GameTextForAll(" ", 100, 3);
            StopAudioStreamForPlayer(playerid);
            DestroyVehicle(GetPlayerVehicleID(playerid));
            new query[150], formattedtime[8];
            format(formattedtime, sizeof formattedtime, "%02d:%02d", minutes, seconds);
            if(formattedtime[0] > LoadedRaceInfo[ChosenRace][BestLap]) {
                format(query, sizeof query, "UPDATE `racetimes` SET `RaceName`='%s',`Time`='%s',`Name`='%s' WHERE `ID` = %d", OtherRaceInfo[ChosenRace][Name], formattedtime, GetPlayerNameEx(playerid), ChosenRace);
                mysql_function_query(dbHandle, query, false, "", "");
                format(string, sizeof string, "RACE: {FFFFFF}The race is now over. {FF0000}%s {FFFFFF}has won and has set a new best time, %s!", GetPlayerNameEx(playerid), formattedtime);
            }
            else {
                format(string, sizeof string, "RACE: {FFFFFF}The race is now over. {FF0000}%s {FFFFFF}has won!", GetPlayerNameEx(playerid));
            }
            SendClientMessageToAll(COLOR_PURPLE, string);
            RaceCountDown = MAX_RACETIME;
        }
    }
__________________

CITY LIFE ROLE PLAY
COMING SOON
---------------------------------
YouTube
YouTube | Twitter
On a break from YouTube.

Luis- 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
Race system P<3TS Server Support 0 04/08/2012 04:10 PM
Looking for Race System. petrolhead General 6 18/03/2012 07:15 AM
Race system wumpyc Scripting Help 6 26/10/2011 02:19 PM
Race system AzTeCaS Help Archive 4 03/12/2010 05:08 PM
about race system xExpressx Help Archive 1 20/10/2010 05:28 AM


All times are GMT. The time now is 11:20 PM.


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