Few questions
#1

I've questions

I'm looping players using foreach

and then i do

pawn Код:
if((i != playerid) && (pInfo[playerid][Admin] > pInfo[i][Admin]) && (RaceParticipant[playerid] < 0) && (GetPlayerState(i) != 1 && GetPlayerState(i) != 2 && GetPlayerState(i) != 3) && (pInfo[i][Jail] == 0) && (pInfo[i][Freeze] == 0))
How it comes it don't work?

let me explain.

Код:
if((i != playerid)
checks if loop player is playerid. (It work fine)

Код:
pInfo[playerid][Admin] < pInfo[i][Admin]
checks if loop player is higher admin than playerid (doesn't work)

Код:
GetPlayerState(blahblahblah)
Not sure if it works.

Another problem.

pawn Код:
public LoadRace(tmp[])
{
    new race_name[32],templine[512];
    format(CRaceName,sizeof(CRaceName), "%s",tmp);
    format(race_name,sizeof(race_name), "Stu4Lif/Races/%s.yr",tmp);
    if(!fexist(race_name)) return -1; // File doesn't exist
    CFile=race_name;
    LCurrentCheckpoint=-1; RLenght=0; RLenght=0;
    new File:f, i;
    f = fopen(race_name, io_read);
    fread(f,templine,sizeof(templine));
    if(templine[0] == 'Y') //Checking if the racefile is v0.2+
    {
        new fileversion;
        strtok(templine,i); // read off YRACE
        fileversion = strval(strtok(templine,i)); // read off the file version
        if(fileversion > RACEFILE_VERSION) return -2; // Check if the race is made with a newer version of the racefile format
        CBuilder=strtok(templine,i); // read off RACEBUILDER
        ORacemode = strval(strtok(templine,i)); // read off racemode
        ORacelaps = strval(strtok(templine,i)); // read off amount of laps
        if(fileversion > 1)
        {
            Airrace = strval(strtok(templine,i));   // read off airrace
            CPsize = floatstr(strtok(templine,i));    // read off CP size
        }
        else // v1 file format, set to default
        {
            Airrace = 0;
            CPsize = 8.0;
        }
        OAirrace = Airrace;
        OCPsize = CPsize;
        Racemode=ORacemode; Racelaps=ORacelaps; //Allows changing the modes, but disables highscores if they've been changed.
        fread(f,templine,sizeof(templine)); // read off best race times
        i=0;
        for(new j=0;j<5;j++)
        {
            TopRacers[j]=strtok(templine,i);
            TopRacerTimes[j]=strval(strtok(templine,i));
        }
        fread(f,templine,sizeof(templine)); // read off best lap times
        i=0;
        for(new j=0;j<5;j++)
        {
            TopLappers[j]=strtok(templine,i);
            TopLapTimes[j]=strval(strtok(templine,i));
        }
    }
    else //Otherwise add the lines as checkpoints, the file is made with v0.1 (or older) version of the script.
    {
        LCurrentCheckpoint++;
        RaceCheckpoints[LCurrentCheckpoint][0] = floatstr(strtok(templine,i));
        RaceCheckpoints[LCurrentCheckpoint][1] = floatstr(strtok(templine,i));
        RaceCheckpoints[LCurrentCheckpoint][2] = floatstr(strtok(templine,i));
        Racemode=0; ORacemode=0; Racelaps=0; ORacelaps=0;   //Enables converting old files to new versions
        CPsize = 8.0; Airrace = 0;              // v2 additions
        OCPsize = CPsize; OAirrace = Airrace;   // v2 additions
        CBuilder="UNKNOWN";
        for(new j;j<5;j++)
        {
            TopLappers[j]="A"; TopLapTimes[j]=0; TopRacers[j]="A"; TopRacerTimes[j]=0;
        }
    }
    while(fread(f,templine,sizeof(templine),false))
    {
        LCurrentCheckpoint++;
        i=0;
        RaceCheckpoints[LCurrentCheckpoint][0] = floatstr(strtok(templine,i));
        RaceCheckpoints[LCurrentCheckpoint][1] = floatstr(strtok(templine,i));
        RaceCheckpoints[LCurrentCheckpoint][2] = floatstr(strtok(templine,i));
        if(LCurrentCheckpoint >= 1)
        {
            RLenght+=Distance(RaceCheckpoints[LCurrentCheckpoint][0],RaceCheckpoints[LCurrentCheckpoint][1],
                                RaceCheckpoints[LCurrentCheckpoint][2],RaceCheckpoints[LCurrentCheckpoint-1][0],
                                RaceCheckpoints[LCurrentCheckpoint-1][1],RaceCheckpoints[LCurrentCheckpoint-1][2]);
        }
    }
    LLenght = RLenght + Distance(RaceCheckpoints[LCurrentCheckpoint][0],RaceCheckpoints[LCurrentCheckpoint][1],
                                RaceCheckpoints[LCurrentCheckpoint][2],RaceCheckpoints[0][0],RaceCheckpoints[0][1],
                                RaceCheckpoints[0][2]);
    fclose(f);
    return 1;
}
It doesn't work. When i load a valid race it saids "Invalid race" i'm using Yagu's race [FS].

Can someone help to fix it?
Reply
#2

First try debugging your code before asking for help. Have you printed the variables ect?

In the race code you posted - no-where does it have the text "invalid race" so i guess the problem isn't in the code you posted.
Reply
#3

Actually the loadrace i gave you is just a stock function.
Here is the real loadrace which has doesn't exist race message.

Anyways, The first problem has been fixed.
But the race problem is still not fixed.

pawn Код:
dcmd_loadrace(playerid, params[])
{
    if(RaceAdmin == 1 && IsNotAdmin(playerid)) return 1;
    Racemode = 0; Racelaps = 1;
    new tmp[128], idx, fback;
    tmp = strtok(params, idx);
    if(!strlen(tmp))
    {
        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /loadrace [name]");
        return 1;
    }
    if(RaceActive == 1)
    {
        SendClientMessage(playerid, COLOR_RED, "A race is already active!");
        return 1;
    }
    fback=LoadRace(tmp);
    if(Exist == -1) format(ystring,sizeof(ystring),"Race \'%s\' doesn't exist!",tmp);
    else if (fback == -2) format(ystring,sizeof(ystring),"Race \'%s\' is created with a newer version of YRACE, cannot load.",tmp);
    if(fback < 0)
    {
        SendClientMessage(playerid,COLOR_RED,ystring);
        return 1;
    }
    format(ystring,sizeof(ystring),"Race \'%s\' loaded, /startrace to start it. You can change laps and mode before that.",CRaceName);
    SendClientMessage(playerid,COLOR_GREEN,ystring);
    if(LCurrentCheckpoint<2 && Racemode == 2)
    {
        Racemode = 1; // Racemode 2 doesn't work well with only 2CPs, and mode 1 is just the same when playing with 2 CPs.
    }                 // Setting racemode 2 is prevented from racebuilder so this shouldn't happen anyways.
#if defined MENUSYSTEM
    if(!IsValidMenu(MRace)) CreateRaceMenus();
    if(Airrace == 0) SetMenuColumnHeader(MRace,0,"Air race: off");
    else SetMenuColumnHeader(MRace,0,"Air race: ON");
    TogglePlayerControllable(playerid,0);
    ShowMenuForPlayer(MRace,playerid);
#endif
    return 1;
}
Reply
#4

Bump.
Reply
#5

Well first off, having each if statement on one line, it can cause a bit of confusion with the && and || etc.

So you can try splitting it into different if statements and see if that works.

pawn Код:
if((i != playerid))
{
    if(pInfo[playerid][Admin] > pInfo[i][Admin])
    {
        if(RaceParticipant[playerid] < 0)
        {
            if(GetPlayerState(i) != 1 && GetPlayerState(i) != 2 && GetPlayerState(i) != 3)
            {
                if(pInfo[i][Jail] == 0)
                {
                    if(pInfo[i][Freeze] == 0)
                    {
                        //Code here
                    }
                }
            }
        }
    }
}
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)