Jump to content

Race werkt niet


Recommended Posts

Geplaatst: (bewerkt)

ik heb geprobeert een race te maken maar er zijn allemaal dingen die niet werken. en de race werkt alleen bij de player die als laatste joint.

weeten jullie waarom het niet werkt?

code:

#include <a_samp>
#define winner_money 10000

new CheckPoints[9][3] =
{
{307,3012,1},
{633,3012,1},
{784,3054,1},
{643,3102,1},
{518,3191,1},
{354,3257,1},
{104,3149,1},
{307,3011,1},
{307,3011,1}
};

new Player_CheckPoint[MAX_PLAYERS];
new bool:IsRaceRunning[MAX_PLAYERS] = false;
new bool:joinedracetrack[MAX_PLAYERS] = false;
new bool:IsRacetrackRunning = false;
new bool:IsRacetrackRunningjoin = false;
new WinnerName[MAX_PLAYER_NAME];
new stringwin[64];

forward IsPlayerInRangeOfRace();
forward One(playerid);
forward Two(playerid);
forward Three(playerid);
forward Four(playerid);
forward Five(playerid);
forward GoGoGo(playerid);
forward StartRacetrack(playerid);
forward RacetrackStarted(playerid);

public OnGameModeInit()
{
SetTimer("IsPlayerInRangeOfRace",5000,true);
   return 1;
}

public IsPlayerInRangeOfRace()
{
   for(new i=0;i<MAX_PLAYERS;i++)
{
	if(IsRaceRunning[i] == false)
	{
		if(IsPlayerInRangeOfPoint(i, 150.0, 307,3012,2))
		{
				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],25.0);
           }
		if(IsPlayerInRangeOfPoint(i, 20.0, 307,3012,2))
		{
			if(IsRacetrackRunning == false)
			{
    				GameTextForPlayer(i, "~g~racetrack type /join to join.",6000,3);
			}
			if(IsRacetrackRunning == true)
			{
    				GameTextForPlayer(i, "~g~racetrack is already running, pleas wait.",6000,3);
			}
           }
	}
}
return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/join", cmdtext, true, 10) == 0)
{
   	//for(new i=0;i<MAX_PLAYERS;i++)
	//{
		if(IsRaceRunning[playerid] == false)
		{
			if(IsPlayerInRangeOfPoint(playerid, 21.0, 307,3012,2))
			{
					if(IsRacetrackRunning == false)
					{
						IsRacetrackRunning = true;
						format(stringwin,sizeof(stringwin),"[RACE - /racetrack] Will start in 30 seconds.");
						SendClientMessageToAll(0xFF0000FF,stringwin);
						SetTimer("StartRacetrack",24000,false);
						GameTextForPlayer(playerid, "~g~racetrack will start in 30 seconds.",5000,3);
					}
					IsRaceRunning[playerid] = true;
					joinedracetrack[playerid] = true;
 						return 1;
 					}
		} else {
       		GameTextForPlayer(playerid, "~g~your already in a race.",5000,3);
       	}
       //}
}
return 0;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
	if(IsRaceRunning[playerid] == true)
	{
		Player_CheckPoint[playerid]++;
	}
	if(Player_CheckPoint[playerid] < 7 && IsRacetrackRunning == true)
	{
		DisablePlayerRaceCheckpoint(playerid);
		PlayerPlaySound(playerid, 1056, 0.0, 0.0, 10.0);
		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],25.0);
		return 1;
	}
	if(Player_CheckPoint[playerid] == 7 && IsRacetrackRunning == true)
	{
		DisablePlayerRaceCheckpoint(playerid);
		PlayerPlaySound(playerid, 1056, 0.0, 0.0, 10.0);
		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],25.0);
		return 1;
	}
	if(Player_CheckPoint[playerid] == 8 && IsRacetrackRunning == true)
	{
		for(new i = 0; i < MAX_PLAYERS; i++)
		{
			DisablePlayerRaceCheckpoint(i);
			PlayerPlaySound(i, 1056, 0.0, 0.0, 10.0);
			IsRaceRunning[i] = false;
			joinedracetrack[i] = false;
		}
		GetPlayerName(playerid,WinnerName,sizeof(WinnerName));
		format(stringwin,sizeof(stringwin),"[RACE - /racetrack] The race is over, %s has won!",WinnerName);
		SendClientMessageToAll(0xFF0000FF,stringwin);
		GivePlayerMoney(playerid,winner_money);
		IsRacetrackRunning = false;
		IsRacetrackRunningjoin = false;
		return 1;
	}
return 1;
}

public StartRacetrack(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
	if(joinedracetrack[i] == true)
	{
		IsRacetrackRunningjoin = true;
		SetTimer("Five", 1000, false);
		SetTimer("Four", 2000, false);
		SetTimer("Three", 3000, false);
		SetTimer("Two", 4000, false);
		SetTimer("One", 5000, false);
		SetTimer("GoGoGo", 6000, false);
		SetTimer("RacetrackStarted", 6000, false);
       }
}
return 1;
}

public RacetrackStarted(playerid)
{
	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],19.7);
return 1;
}

public One(playerid)
{
GameTextForPlayer(playerid, "~r~1",2000,3);
PlayerPlaySound(playerid, 1056, 0.0, 0.0, 10.0);
return 1;
}

public Two(playerid)
{
GameTextForPlayer(playerid, "~p~2",2000,3);
PlayerPlaySound(playerid, 1056, 0.0, 0.0, 10.0);
return 1;
}

public Three(playerid)
{
GameTextForPlayer(playerid, "~y~3",2000,3);
PlayerPlaySound(playerid, 1056, 0.0, 0.0, 10.0);
return 1;
}

public Four(playerid)
{
GameTextForPlayer(playerid, "~b~4",2000,3);
PlayerPlaySound(playerid, 1056, 0.0, 0.0, 10.0);
return 1;
}

public Five(playerid)
{
	GameTextForPlayer(playerid, "~w~5",2000,3);
	PlayerPlaySound(playerid, 1056, 0.0, 0.0, 10.0);
TogglePlayerControllable(playerid,0);
	return 1;
}

public GoGoGo(playerid)
{
GameTextForPlayer(playerid, "~g~GO GO GO!",3000,3);
PlayerPlaySound(playerid, 1057, 0.0, 0.0, 10.0);
TogglePlayerControllable(playerid,1);
return 1;
}

Bewerkt: door ted80
Geplaatst: (bewerkt)

Om het probleem met dat er maar 1 speler in de race kan op te lossen:

public StartRacetrack() // playerid arg is hier niet nodig
{
       for(new i = 0; i < MAX_PLAYERS; i++)
       {
               if(joinedracetrack[i] == true)
               {
                       IsRacetrackRunningjoin = true;
                       SetTimerEx("Five", 1000, false,"i",i); // gebruik SetTimerEx
                       SetTimerEx("Four", 2000, false,"i",i);
                       SetTimerEx("Three", 3000, false,"i",i);
                       SetTimerEx("Two", 4000, false,"i",i);
                       SetTimerEx("One", 5000, false,"i",i);
                       SetTimerEx("GoGoGo", 6000, false,"i",i);
                       SetTimerEx("RacetrackStarted", 6000, false,"i",i);
       }
       }
       return 1;
}

En ik zou in plaats van voor elk getal een functie maken eerder iets doen met die switch functie. :puh:

EDIT:

Zo iets als:

new int=6;

public Count(playerid)
{
  int--;
  switch(int) 
  {
     case 5: GameTextForPlayer(playerid, "~p~5",2000,3);
     case 4: GameTextForPlayer(playerid, "~p~4",2000,3);
     // etc...
     case 0: GameTextForPlayer(playerid, "~p~GO GO GO",2000,3);
     case -1: int=6;

  }
  if(!int == 6)SetTimerEx("Count", 1000, false,"i",i);;
  PlayerPlaySound(playerid, 1056, 0.0, 0.0, 10.0);

}

Bewerkt: door GTAguillaume

Een reactie plaatsen

Je kan nu een reactie plaatsen en pas achteraf registreren. Als je al lid bent, log eerst in om met je eigen account een reactie te plaatsen.

Gast
Op dit onderwerp reageren...

×   Je hebt text geplaatst met opmaak.   Opmaak verwijderen

  Only 75 emoji are allowed.

×   Je link is automatisch ingevoegd.   In plaats daarvan weergeven als link

×   Je vorige bewerkingen zijn hersteld.   Alles verwijderen

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent actief   0 leden

    • Er zijn hier geen geregistreerde gebruikers aanwezig.
×
×
  • Create New...