Still a problem using checkpoints...
#1

Hello

I got another problem :/
So I'm trying to make races, and the first checkpoint of all races should be shown to mark a race start there however nothing works as planned...

Here's the code:
pawn Код:
enum RaceInfo
{
    Name,  //Name
    Tele,
    ID,    //The race ID
    Float:RX,   //The Tele cords
    Float:RY,
    Float:RZ,
    Float:CPX[MAX_CHECKPOINTS],   //The CP cords
    Float:CPY[MAX_CHECKPOINTS],
    Float:CPZ[MAX_CHECKPOINTS],
    Timeout,  //Time untill race ends
    CheckPoints,    //Amount of CP's
    Running,    //Race is busy
    Joining,   //you can still enter
    Count,  //Amount players still in the race
    StartCount, //Amount of players that joined in the first place
    rRaceTimer,
    rRaceTime,
}
new RInfo[MAX_RACES][RaceInfo];

public OnGameModeInit()
{
    new string[256];
    for( new i = 0; i < MAX_RACES; i++ )
    {
        RaceCP[i] = CreateDynamicRaceCP(2, RInfo[ i ][ CPX ][ 0 ], RInfo[ i ][ CPY ][ 0 ], RInfo[ i ][ CPZ ][ 0 ], 0, 0, 0, 10.0, -1, -1, -1, 100.0);
        format (string, sizeof string, "RACE: \"%s\" type /join to enter", RInfo[i][Name]);
        CreateDynamic3DTextLabel(string, COLOR_GREEN_LABEL, RInfo[ i ][ CPX ][ 0 ], RInfo[ i ][ CPY ][ 0 ], RInfo[ i ][ CPZ ][ 0 ] + 5, 100.0,INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 100.0);
    }
    return 1;
}

stock AddCheckpointToRace(RaceID, CheckPointID, Float:CheckPointX, Float:CheckPointY, Float:CheckPointZ)
{
    RInfo[RaceID][CPX][CheckPointID] = CheckPointX;
    RInfo[RaceID][CPY][CheckPointID] = CheckPointY;
    RInfo[RaceID][CPZ][CheckPointID] = CheckPointZ;
    return 1;

}

stock CreateRace(RaceID,RaceName[], RaceTimeout, Float:TeleX,Float:TeleY,Float:TeleZ,cps)
{
    format(RInfo[RaceID][Name], 100, "%s", RaceName);
    RInfo[RaceID][Timeout] = RaceTimeout;

    RInfo[RaceID][Running] = 0;
    RInfo[RaceID][Joining] = 0;
   
    RInfo[RaceID][RX] = TeleX;
    RInfo[RaceID][RY] = TeleY;
    RInfo[RaceID][RZ] = TeleZ;
   
    RInfo[RaceID][ID] = RaceID;
    RInfo[RaceID][CheckPoints] = cps;   //Amount of CPS in the race
    return 1;
}

CMD:join(playerid,params[])
{
    if(PRInfo[playerid][RacingRace] == -1) //Player is not in any race
    {
        for(new i = 0; i < MAX_RACES; i++)
        {
            if (IsPlayerInDynamicRaceCP(playerid, RaceCP[i]))
            {
                new raceid;
                raceid = i;

                if(RInfo[raceid][Running] == 1 && RInfo[raceid][Joining] == 0)
                    SendClientMessage(playerid,COLOR_LIGHT_RED, "This race hasn't ended yet");
                if(RInfo[raceid][Running] == 0 && RInfo[raceid][Joining] == 1)
                    JoinRace(playerid,raceid);
                if(RInfo[raceid][Running] == 0 && RInfo[raceid][Joining] == 0)
                    StartRace(playerid,raceid);
                break;
            }
            else
            {
                SendClientMessage(playerid,COLOR_LIGHT_RED, "You are not near any race starting point");
                break;
            }
        }
    }
    else
        SendClientMessage(playerid,COLOR_LIGHT_RED, "You are still racing, please finish it first");
       
    return 1;
}
SO no errors but it doesn't do what wanted...
So it should create a dynamic RaceCP on every first checkpoint of all the races, first of all it only creates a checkpoint at point 0,0,0 (race 2, the farm race) and not at the other race (the test race)
also there are 3D text labels created however they do not contain the wanted information, and there are multiple 3d text labels at one spot (the farm race) but none on the test race..

Also when I type /join and I'm in the Checkpoint, it does not call the wanted functions...
any help?
Thanks in advance
Reply
#2

Hold on, I was confused at the last part about the race2, the farm race, the test race.. Anyways, from the code below:

pawn Код:
public OnGameModeInit()
{
    new string[256];
    for( new i = 0; i < MAX_RACES; i++ )
    {
        RaceCP[i] = CreateDynamicRaceCP(2, RInfo[ i ][ CPX ][ 0 ], RInfo[ i ][ CPY ][ 0 ], RInfo[ i ][ CPZ ][ 0 ], 0, 0, 0, 10.0, -1, -1, -1, 100.0);
        format (string, sizeof string, "RACE: \"%s\" type /join to enter", RInfo[i][Name]);
        CreateDynamic3DTextLabel(string, COLOR_GREEN_LABEL, RInfo[ i ][ CPX ][ 0 ], RInfo[ i ][ CPY ][ 0 ], RInfo[ i ][ CPZ ][ 0 ] + 5, 100.0,INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 100.0);
    }
    return 1;
}
I see that you set the X, Y, Z for the race checkpoint but those:
pawn Код:
RInfo[ i ][ CPX ][ 0 ], RInfo[ i ][ CPY ][ 0 ], RInfo[ i ][ CPZ ][ 0 ]
are 0.0

Nothing has been assigned before on them. RInfo[i][Name] as well, it should be null.
Reply
#3

I'm sorry I forgot to give you some code: under OnGameModeInit there's this aswell: (Before the CheckPoints and Text is created, so therefor are assigned before I create the cp's and texts)
pawn Код:
public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
   
    AddCheckpointToRace(1, 0, 2378.034423, -1256.948120, 23.392478);
    CreateRace(1,"TestRace", 50, 0,0,0,1);
   
    AddCheckpointToRace(2, 0, 0, 0, 0);
    CreateRace(2,"Race Farm", 50, 0,0,0,1);
   
    SInfo[Chat] = 1;
   
    new string[256];
    for( new i = 0; i < MAX_RACES; i++ )
    {
        RaceCP[i] = CreateDynamicRaceCP(2, RInfo[ i ][ CPX ][ 0 ], RInfo[ i ][ CPY ][ 0 ], RInfo[ i ][ CPZ ][ 0 ], 0, 0, 0, 10.0, -1, -1, -1, 100.0);
        format (string, sizeof string, "RACE: \"%s\" type /join to enter", RInfo[i][Name]);
        CreateDynamic3DTextLabel(string, COLOR_GREEN_LABEL, RInfo[ i ][ CPX ][ 0 ], RInfo[ i ][ CPY ][ 0 ], RInfo[ i ][ CPZ ][ 0 ] + 5, 100.0,INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 100.0);
    }
    return 1;
}
that's the full gamemodeinit callback
but this doesn't seem to work
Reply
#4

pawn Код:
AddCheckpointToRace(1, 0, 2378.034423, -1256.948120, 23.392478);
    CreateRace(1,"TestRace", 50, 0,0,0,1);
   
    AddCheckpointToRace(2, 0, 0, 0, 0);
    CreateRace(2,"Race Farm", 50, 0,0,0,1);
The first raceid should be 0 instead of 1.

Moreover, you will need to know the races exist because if MAX_RACES is let's say 50, it will create 48 3D labels at 0.0 coordinates.
Reply
#5

Hmm I see thank you,
And how can I check if the raceid is valid?
Reply
#6

You can add on the enum a boolean that checks if a raceid is valid or not. Whenever you add a checkpoint on it, set it to true. If none of the checkpoints has been set, the race is invalid.

Also, you enter the races manually, so declaring a global variable and assigning how many the loaded races are would be good.

For example:
pawn Код:
new
    Loaded_Races
;
// Global variable


// OnGameModeInit
AddCheckpointToRace(0, 0, 2378.034423, -1256.948120, 23.392478);
CreateRace(0,"TestRace", 50, 0,0,0,1);
   
AddCheckpointToRace(1, 0, 0, 0, 0);
CreateRace(1,"Race Farm", 50, 0,0,0,1);

Loaded_Races = 2;


// Somewhere else;
for( new i = 0; i < Loaded_Races; i++ )
By the way, it'd be better to save/load the races instead of entering manually. I mean, that if a race has 50 checkpoints, you will need to add them by hand (kinda boring!). Anyways, you know.
Reply
#7

Yes I'm planning to do that, but I'm first going to write the racing thing entirely and then maybe adjust some stuff...
I find this definately the hardest code of a stunt server tbh...
And i have never succeeded in finishing a race system
Reply
#8

Good, well.. it will be easier for you in the future, that's why I said it.

Honestly, it is not. There are things that are more difficult to create them!

No worries! When I started making that type of racing system (you know which one ), I failed the first 2 times. I said to myself, one more attempt and hopefully I made it. Okay, it may took me 2 weeks to complete it entirely (until everything worked like I wanted) but it was worth!

Anyways, I'll be glad to help you with any of your problems about it (if any) and test it sometime in the near future!
Reply
#9

Thanks man I appreciate it
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)