Detecting race start slots - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Detecting race start slots (
/showthread.php?tid=414085)
Detecting race start slots -
jibileu - 08.02.2013
Hello samp members.
I'm creating a race system and I've a problem. I want to detect which spots are occupied and the beggining of the race.
There are 6 spots and I want to know which ones are occupied so people don't steal each other places.
For example, a race starts and Player 1 joins and takes first spot, then Player 2 joins and takes spot number two, 3rd Player joins and takes spot number 3.
I've found a way to create vehicles and detect if they are occupied, but I want people to use their own vehicles.
Thank you.
Re: Detecting race start slots -
Vexus - 08.02.2013
At the top of your script:
Код:
//Otherwise, you will get warnings that "RaceSlot1, RaceSlot2, etc..." aren't defined!
new RaceSlot1[MAX_PLAYERS];
new RaceSlot2[MAX_PLAYERS];
new RaceSlot3[MAX_PLAYERS];
new RaceSlot4[MAX_PLAYERS];
new RaceSlot5[MAX_PLAYERS];
new RaceSlot6[MAX_PLAYERS];
Код:
forward RacingSlotsFilled(playerid);
public RacingSlotsFilled(playerid)
{
if(RaceSlot1[playerid] == 1 && RaceSlot2[playerid] == 1 && RaceSlot3[playerid] == 1 && RaceSlot4[playerid] == 1 && RaceSlot5[playerid] == 1 && RaceSlot6[playerid] == 1)
{//If all the slots are filled, it will tell them all the slots are filled, and they won't be able to join!
return 0;
}
}
Under "OnGameModeInit"
Код:
//When you start the server up, the racing slots will be empty, until you start the event!
RaceSlot1[playerid] = 0;
RaceSlot2[playerid] = 0;
RaceSlot3[playerid] = 0;
RaceSlot4[playerid] = 0;
RaceSlot5[playerid] = 0;
RaceSlot6[playerid] = 0;
Under your race event... you could do this:
Код:
if(RacingSlotsFilled)
{ //Asking if all the racing slots are filled.
SendClientMessage(playerid, 0xFF0000, "All Slots in the race event are filled! Please try another time!");
return 1;
}
else if(RaceSlot1[playerid] == 0)
{
//Your details, probably a SetPlayerPos, and maybe a PutPlayerInVehicle command.
SendClientMessage(playerid, 0x00FF00, "Welcome to the race! You've been placed in Slot 1!");
RaceSlot1 = 1;
}
else if(RaceSlot2[playerid] == 0)
{
//Your details, probably a SetPlayerPos, and maybe a PutPlayerInVehicle command.
SendClientMessage(playerid, 0x00FF00, "Welcome to the race! You've been placed in Slot 2!");
RaceSlot2 = 1;
}
else if(RaceSlot3[playerid] == 0)
{
//Your details, probably a SetPlayerPos, and maybe a PutPlayerInVehicle command.
SendClientMessage(playerid, 0x00FF00, "Welcome to the race! You've been placed in Slot 3!");
RaceSlot3 = 1;
}
else if(RaceSlot4[playerid] == 0)
{
//Your details, probably a SetPlayerPos, and maybe a PutPlayerInVehicle command.
SendClientMessage(playerid, 0x00FF00, "Welcome to the race! You've been placed in Slot 4!");
RaceSlot4 = 1;
}
else if(RaceSlot5[playerid] == 0)
{
//Your details, probably a SetPlayerPos, and maybe a PutPlayerInVehicle command.
SendClientMessage(playerid, 0x00FF00, "Welcome to the race! You've been placed in Slot 5!");
RaceSlot5 = 1;
}
else if(RaceSlot6[playerid] == 0)
{
//Your details, probably a SetPlayerPos, and maybe a PutPlayerInVehicle command.
SendClientMessage(playerid, 0x00FF00, "Welcome to the race! You've been placed in Slot 6!");
RaceSlot6 = 1;
}
Not sure if this is what you were looking for, and it may need some editting, but that's the basis of what I'd do personally for a racing system! Hope you can make sense of it!
Re: Detecting race start slots -
RajatPawar - 08.02.2013
pawn Код:
enum info
{
pRace
}
new PlayerInfo[MAX_PLAYERS][info];
CMD:joinrace(playerid)
{
//Your IsPlayerInHisOwnVehicle
//Other conditions
new temp=0;
for(new i;i<MAX_PLAYERS;i++)
{
if(PlayerInfo[i][pRace]==1
if(temp==6) temp = -1;
else temp++;
}
switch(temp)
{
case 1..5:
{//Teleport him to race and watever
PlayerInfo[playerid][pRace]=1;
}
case -1: //Sorry, race's full.
}
return 1;
}
Something like this, if you use an enum!