Last race checkpoint. -
CREED115 - 21.01.2016
Maybe somebody, can see problem.
Код:
#include <a_samp>
#define winner_money 10000
new Float:CheckPoints[10][3] =
{
{-2127.3611,-81.2161,35.1019},
{-2167.1638,-71.8486,34.9774},
{-2256.0537,-191.7249,34.9743},
{-2204.0200,-466.3755,49.3204},
{-2226.0217,-740.3702,64.3937},
{-2312.0801,-782.2291,90.6318},
{-2422.8140,-609.5429,132.3662},
{-2628.3250,-494.8151,69.9621},
{-2355.0166,-460.1673,80.0940},
{-2790.6455,-483.1252,7.1875}
};
new Player_CheckPoint[MAX_PLAYERS];
new bool:IsRaceRunning = false;
new WinnerName[MAX_PLAYER_NAME];
new stringwin[64];
public OnPlayerSpawn(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
Player_CheckPoint[i] = 0;
SetPlayerRaceCheckpoint(i,0,CheckPoints[0][0],CheckPoints[0][1],CheckPoints[0][2],CheckPoints[1][0],CheckPoints[1][1],CheckPoints[1][2],9.7);
IsRaceRunning = true;
}
}
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
if(IsRaceRunning == true) { Player_CheckPoint[playerid]++; }
if(Player_CheckPoint[playerid] < 9 && IsRaceRunning == true)
{
DisablePlayerRaceCheckpoint(playerid);
SetPlayerRaceCheckpoint(playerid,0,CheckPoints[Player_CheckPoint[playerid]][0],CheckPoints[Player_CheckPoint[playerid]][1],CheckPoints[Player_CheckPoint[playerid]][2],CheckPoints[Player_CheckPoint[playerid]+1][0],CheckPoints[Player_CheckPoint[playerid]+1][1],CheckPoints[Player_CheckPoint[playerid]+1][2],9.7);
return 1;
}
if(Player_CheckPoint[playerid] == 9 && IsRaceRunning == true)
{
DisablePlayerRaceCheckpoint(playerid);
SetPlayerRaceCheckpoint(playerid,0,CheckPoints[Player_CheckPoint[playerid]][0],CheckPoints[Player_CheckPoint[playerid]][1],CheckPoints[Player_CheckPoint[playerid]][2],CheckPoints[Player_CheckPoint[playerid]+1][0],CheckPoints[Player_CheckPoint[playerid]+1][1],CheckPoints[Player_CheckPoint[playerid]+1][2],9.7);
return 1;
}
if(Player_CheckPoint[playerid] == 10 && IsRaceRunning == true)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
DisablePlayerRaceCheckpoint(i);
}
GetPlayerName(playerid,WinnerName,sizeof(WinnerName));
format(stringwin,sizeof(stringwin),"[RACE] The race is over, %s has won and achieved $%d!",WinnerName,winner_money);
SendClientMessageToAll(0xFF0000FF,stringwin);
GivePlayerMoney(playerid,winner_money);
IsRaceRunning = false;
return 1;
}
return 1;
}
Last checkpoint wont show up, why?
Re: Last race checkpoint. -
Vince - 21.01.2016
Chances are the last checkpoint is 9, not 10. But it hurts my brain to think this through. You should use sizeof, anyway. If you decide to add or remove a checkpoint later the code will instantly break.
Re: Last race checkpoint. -
yvoms - 21.01.2016
Код:
0 {-2127.3611,-81.2161,35.1019},
1 {-2167.1638,-71.8486,34.9774},
2 {-2256.0537,-191.7249,34.9743},
3 {-2204.0200,-466.3755,49.3204},
4 {-2226.0217,-740.3702,64.3937},
5 {-2312.0801,-782.2291,90.6318},
6 {-2422.8140,-609.5429,132.3662},
7 {-2628.3250,-494.8151,69.9621},
8 {-2355.0166,-460.1673,80.0940},
9 {-2790.6455,-483.1252,7.1875}
It starts at 0, Vince is right.
So set
Код:
new Float:CheckPoints[10][3] =
To
Код:
new Float:CheckPoints[9][3] =
And Change the checkpoint ID's.
Re: Last race checkpoint. -
CREED115 - 21.01.2016
Hmm i finnaly fix this just removed +1] @ last "SetPlayerRaceCheckpoint", all works.
Код:
new Float:CheckPoints[10][3] =
{
{-2127.3611,-81.2161,35.1019},
{-2167.1638,-71.8486,34.9774},
{-2256.0537,-191.7249,34.9743},
{-2204.0200,-466.3755,49.3204},
{-2226.0217,-740.3702,64.3937},
{-2312.0801,-782.2291,90.6318},
{-2422.8140,-609.5429,132.3662},
{-2628.3250,-494.8151,69.9621},
{-2355.0166,-460.1673,80.0940},
{-2790.6455,-483.1252,7.1875}
};
public OnPlayerSpawn(playerid)
{
new Random = random(sizeof(RandomSpawns));
new Clover = CreateVehicle(521,RandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2],0.0000,149,149,-1);// Nosakām {X,Y,Z,-},
PutPlayerInVehicle(playerid, Clover, 0); // Ieliekam spēlētāju maљīnā, kā vadītāju
TogglePlayerControllable(playerid,0); // Sasaldējam dalībnieku
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
Player_CheckPoint[i] = 0;
SetPlayerRaceCheckpoint(i,0,CheckPoints[0][0],CheckPoints[0][1],CheckPoints[0][2],CheckPoints[1][0],CheckPoints[1][1],CheckPoints[1][2],9.7);
IsRaceRunning = true;
}
}
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
if(IsRaceRunning == true) { Player_CheckPoint[playerid]++; }
if(Player_CheckPoint[playerid] < 9 && IsRaceRunning == true)
{
DisablePlayerRaceCheckpoint(playerid);
SetPlayerRaceCheckpoint(playerid,0,CheckPoints[Player_CheckPoint[playerid]][0],CheckPoints[Player_CheckPoint[playerid]][1],CheckPoints[Player_CheckPoint[playerid]][2],CheckPoints[Player_CheckPoint[playerid]+1][0],CheckPoints[Player_CheckPoint[playerid]+1][1],CheckPoints[Player_CheckPoint[playerid]+1][2],9.7);
return 1;
}
if(Player_CheckPoint[playerid] == 9 && IsRaceRunning == true)
{
DisablePlayerRaceCheckpoint(playerid);
SetPlayerRaceCheckpoint(playerid,1,CheckPoints[Player_CheckPoint[playerid]][0],CheckPoints[Player_CheckPoint[playerid]][1],CheckPoints[Player_CheckPoint[playerid]][2],CheckPoints[Player_CheckPoint[playerid]][0],CheckPoints[Player_CheckPoint[playerid]][1],CheckPoints[Player_CheckPoint[playerid]][2],9.7);
return 1;
}
if(Player_CheckPoint[playerid] == 10 && IsRaceRunning == true)
{
for(new i = 10; i < MAX_PLAYERS; i++)
{
DisablePlayerRaceCheckpoint(playerid);
}
GetPlayerName(playerid,WinnerName,sizeof(WinnerName));
format(stringwin,sizeof(stringwin),"[RACE] The race is over, %s has won and achieved $%d!",WinnerName,winner_money);
SendClientMessageToAll(0xFF0000FF,stringwin);
GivePlayerMoney(playerid,winner_money);
IsRaceRunning = false;
new currentveh;
currentveh = GetPlayerVehicleID(playerid);
DestroyVehicle(currentveh);
return 1;
}
return 1;
}