Race problem kinda wierd -
kalanerik99 - 06.06.2017
Hello guys
I have a problem
When I am alone on the server the race works perfectry fine
But when there are 2 or more players the race wont start.
It just doesnt show the second checkpoint( it does the count down and everything but when the countdown it just calls the LEAVE_RACE callback for all the racers(players)
PHP код:
function CountDownForAll(times)
{
foreach(new i : Player)
{
new raceid = GetPVarInt(i,"raceID");
if(times)
{
if(IsPlayerInRaceCheckpoint(i) && (GetVehicleModel(GetPlayerVehicleID(i)) == RaceInfo[raceid][racevehicle]))
{
GameTextForPlayer(i, CDTxt[times], 1500, 3);
PlayerPlaySound(i, 1056, 0, 0, 0);
}
SetTimerEx("CountDownForAll",1000,false,"i",times-1);
}
else
{
if(IsPlayerInRaceCheckpoint(i) && (GetVehicleModel(GetPlayerVehicleID(i)) == RaceInfo[raceid][racevehicle]))
{
GameTextForPlayer(i, CDTxt[times], 1000, 3);
PlayerPlaySound(i, 1057, 0, 0, 0);
SetPlayerRaceCheckpoint(i, 0, RaceInfo[raceid][checkpointx][1], RaceInfo[raceid][checkpointy][1], RaceInfo[raceid][checkpointz][1], RaceInfo[raceid][checkpointx][2], RaceInfo[raceid][checkpointy][2], RaceInfo[raceid][checkpointz][2], CP_SIZE);
RaceCheckpoint[i] = 2;
RaceInfo[raceid][originalcount] ++;
RaceInfo[raceid][racecount] ++;
if(RaceInfo[raceid][originalcount] == 0) return 1;
RaceInfo[raceid][racetimer] = SetTimerEx("RaceTime", 10, true, "dd", raceid,i);
RaceInfo[raceid][racerunning] = true;
new string[512];
format(string, sizeof(string),"%s~n~Time:%s~n~Checkpoints:%d/%d",RaceInfo[raceid][racename],ReturnTime(RaceInfo[raceid][racetime]),RaceCheckpoint[i]-2,RaceInfo[raceid][cpnum] - 1);
PlayerTextDrawSetString(i,RaceTextDraw[i][0],string);
PlayerTextDrawShow(i, RaceTextDraw[i][0]);
RaceInfo[raceid][raceticktime] = GetTickCount();
}
else
{
LeaveRace(i, raceid);
}
}
}
return 1;
}
Re: Race problem -
Loinal - 06.06.2017
PHP код:
if(IsPlayerInRaceCheckpoint(i) && (GetVehicleModel(GetPlayerVehicleID(i)) == RaceInfo[raceid][racevehicle]))
You didn't check if the player in the race or not also your code is not understandable for me
Re: Race problem -
JasonRiggs - 06.06.2017
Код:
foreach(new i : Player)
Not sure but shouldn't it be
Код:
for(new i = 0; i < MAX_PLAYERS; i++);
so it will work for all players?
Re: Race problem -
kalanerik99 - 06.06.2017
@Loinal This function only gets called when player joins the race.
He cannot leave without a special command....
@JasonRiggs Foreach is a special include you should check it out it's quite useful
Re: Race problem -
kalanerik99 - 07.06.2017
bump
Re: Race problem -
Jefff - 07.06.2017
pawn Код:
function CountDownForAll(times)
{
new raceid;
if(times)
{
foreach(new i : Player)
{
raceid = GetPVarInt(i,"raceID"); // should be global variable not per player
if(IsPlayerInRaceCheckpoint(i) && (GetVehicleModel(GetPlayerVehicleID(i)) == RaceInfo[raceid][racevehicle]))
{
GameTextForPlayer(i, CDTxt[times], 1500, 3);
PlayerPlaySound(i, 1056, 0, 0, 0);
}
}
SetTimerEx("CountDownForAll",1000,false,"i",times-1);
}
else
{
new string[512];
foreach(new i : Player)
{
raceid = GetPVarInt(i,"raceID"); // should be global variable not per player
if(IsPlayerInRaceCheckpoint(i) && (GetVehicleModel(GetPlayerVehicleID(i)) == RaceInfo[raceid][racevehicle]))
{
GameTextForPlayer(i, CDTxt[0], 1000, 3);
PlayerPlaySound(i, 1057, 0, 0, 0);
SetPlayerRaceCheckpoint(i, 0, RaceInfo[raceid][checkpointx][1], RaceInfo[raceid][checkpointy][1], RaceInfo[raceid][checkpointz][1], RaceInfo[raceid][checkpointx][2], RaceInfo[raceid][checkpointy][2], RaceInfo[raceid][checkpointz][2], CP_SIZE);
RaceCheckpoint[i] = 2;
RaceInfo[raceid][originalcount] ++;
RaceInfo[raceid][racecount] ++;
//if(RaceInfo[raceid][originalcount] == 0) return 1;
KillTimer(RaceInfo[raceid][racetimer]);
RaceInfo[raceid][racetimer] = SetTimerEx("RaceTime", 250, true, "dd", raceid,i); // wrong timer & variable RaceInfo[raceid][racetimer], all racers have 'raceid' the same
RaceInfo[raceid][racerunning] = true;
format(string, sizeof(string),"%s~n~Time:%s~n~Checkpoints:%d/%d",RaceInfo[raceid][racename],ReturnTime(RaceInfo[raceid][racetime]),RaceCheckpoint[i]-2,RaceInfo[raceid][cpnum] - 1);
PlayerTextDrawSetString(i,RaceTextDraw[i][0],string);
PlayerTextDrawShow(i, RaceTextDraw[i][0]);
RaceInfo[raceid][raceticktime] = GetTickCount();
}
else
{
LeaveRace(i, raceid);
}
}
}
return 1;
}
Re: Race problem -
kalanerik99 - 07.06.2017
I am using this for updating the textdraw so I need the id (or maybe I could LOOP for who is in the "raceid")
Код:
function RaceTime(raceid,playerid)
{
RaceInfo[raceid][racetime] ++;
new time = GetTickCount() - RaceInfo[raceid][raceticktime];
if(floatround((RaceInfo[raceid][racetime] / 10), floatround_floor) >= RaceInfo[raceid][racetimeout]) StopRace(raceid);
new string[512], minutes, seconds, miliseconds,hours;
ms_to_time(time, hours, minutes, seconds, miliseconds);
format(string, sizeof(string),"%s~n~Time:%d:%d:%d~n~Checkpoints:%d/%d",RaceInfo[raceid][racename],minutes,seconds,miliseconds,RaceCheckpoint[playerid]-2,RaceInfo[raceid][cpnum] - 1);
PlayerTextDrawSetString(playerid,RaceTextDraw[playerid][0],string);
return 1;
}
How do you mean it should be global variable ?
Код:
function StartRace(raceid)
{
RaceInfo[raceid][racejoinable] = false;
foreach(new i : Player)
{
if(InRace[i] != raceid) continue;
if(IsPlayerInRaceCheckpoint(i) && (GetVehicleModel(GetPlayerVehicleID(i)) == RaceInfo[raceid][racevehicle]))
{
SetPVarInt(i,"raceID",raceid);
CountDownForAll(sizeof(CDTxt)-1);
}
else
{
SendClientMessage(i, COLOR_RED, "You weren't in start checkpoint or you didn't have the right vehicle!");
RaceCheckpoint[i] = -1;
InRace[i] = -1;
RaceInfo[raceid][raceticktime] = 0;
DisablePlayerRaceCheckpoint(i);
new vehicleid = GetPlayerVehicleID(i);
SetVehicleVirtualWorld(vehicleid, 0);
SetPlayerVirtualWorld(i, 0);
PutPlayerInVehicle(i, vehicleid, 0);
}
}
return 1;
}
Re: Race problem -
Jefff - 07.06.2017
You can have few races in one time?
Re: Race problem -
kalanerik99 - 07.06.2017
yes multiple player choses what race he wanna join
Re: Race problem -
Jefff - 07.06.2017
So use only timer for raceid and inside add foreach for PlayerTextDrawSetString in RaceTime
RaceInfo[raceid][racetimer] = SetTimerEx("RaceTime", 250, true, "d", raceid);