RaceSpawn.
#1

I've added the collision for players who spawn in race. I want all people who join the race spawn in one position. This code with set the racer 2 next to racer 1 and racer 3 behind the race 1 and etc...


Code:
function SetupRaceForPlayer(playerid)
{
    DisableRemoteVehicleCollisions(playerid, 1);
    SetCameraBehindPlayer(playerid);
	CPProgess[playerid] = 0;
	TogglePlayerControllable(playerid, false);
	CPCoords[playerid][3] = 0;
	SetCP(playerid, CPProgess[playerid], CPProgess[playerid]+1, TotalCP, RaceType);

	SetPlayerVirtualWorld( playerid, 6969  );

	if(IsOdd(playerid)) Index = 1;
	    else Index = 0;

	switch(Index)
	{
		case 0:
		{
		    if(PlayersCount[0] == 1)
		    {
				RaceVehCoords[0][0] -= (6 * floatsin(-RaceVehCoords[0][3], degrees));
		 		RaceVehCoords[0][1] -= (6 * floatcos(-RaceVehCoords[0][3], degrees));
		   		CreatedRaceVeh[playerid] = CreateVehicle(RaceVehicle, RaceVehCoords[0][0], RaceVehCoords[0][1], RaceVehCoords[0][2]+2, RaceVehCoords[0][3], random(126), random(126), (60 * 60));
				SetPlayerPos(playerid, RaceVehCoords[0][0], RaceVehCoords[0][1], RaceVehCoords[0][2]+2);
				SetPlayerFacingAngle(playerid, RaceVehCoords[0][3]);
				SetVehicleVirtualWorld( CreatedRaceVeh[ playerid ], 6969  );
				PutPlayerInVehicle(playerid, CreatedRaceVeh[playerid], 0);
			}
		}
		case 1:
 		{
 		    if(PlayersCount[1] == 1)
 		    {
				RaceVehCoords[1][0] -= (6 * floatsin(-RaceVehCoords[1][3], degrees));
		 		RaceVehCoords[1][1] -= (6 * floatcos(-RaceVehCoords[1][3], degrees));
		   		CreatedRaceVeh[playerid] = CreateVehicle(RaceVehicle, RaceVehCoords[1][0], RaceVehCoords[1][1], RaceVehCoords[1][2]+2, RaceVehCoords[1][3], random(126), random(126), (60 * 60));
				SetPlayerPos(playerid, RaceVehCoords[1][0], RaceVehCoords[1][1], RaceVehCoords[1][2]+2);
				SetPlayerFacingAngle(playerid, RaceVehCoords[1][3]);
				SetVehicleVirtualWorld( CreatedRaceVeh[ playerid ], 6969  );
				PutPlayerInVehicle(playerid, CreatedRaceVeh[playerid], 0);
    		}
 		}
	}
	switch(Index)
	{
	    case 0:
		{
			if(PlayersCount[0] != 1)
			{
		   		CreatedRaceVeh[playerid] = CreateVehicle(RaceVehicle, RaceVehCoords[0][0], RaceVehCoords[0][1], RaceVehCoords[0][2]+2, RaceVehCoords[0][3], random(126), random(126), (60 * 60));
				SetPlayerPos(playerid, RaceVehCoords[0][0], RaceVehCoords[0][1], RaceVehCoords[0][2]+2);
				SetPlayerFacingAngle(playerid, RaceVehCoords[0][3]);
				SetVehicleVirtualWorld( CreatedRaceVeh[ playerid ], 6969  );
				PutPlayerInVehicle(playerid, CreatedRaceVeh[playerid], 0);
			    PlayersCount[0] = 1;
		    }
	    }
	    case 1:
	    {
			if(PlayersCount[1] != 1)
			{
		   		CreatedRaceVeh[playerid] = CreateVehicle(RaceVehicle, RaceVehCoords[1][0], RaceVehCoords[1][1], RaceVehCoords[1][2]+2, RaceVehCoords[1][3], random(126), random(126), (60 * 60));
				SetPlayerPos(playerid, RaceVehCoords[1][0], RaceVehCoords[1][1], RaceVehCoords[1][2]+2);
				SetPlayerFacingAngle(playerid, RaceVehCoords[1][3]);
				SetVehicleVirtualWorld( CreatedRaceVeh[ playerid ], 6969  );
				PutPlayerInVehicle(playerid, CreatedRaceVeh[playerid], 0);
				PlayersCount[1] = 1;
		    }
   		}
	}
	InfoTimer[playerid] = SetTimerEx("TextInfo", 500, 1, "e", playerid);
	JoinCount++;
	return 1;
}
Reply
#2

Avoid spaghetti code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)