How to make race spawns?
#1

Hello. I've been looking around the forums, and I can't seem to find anything to help me with this problem. I'm trying to make a very simple race. So when a player spawns, they'll spawn in a certain vehicle, and line up by one another. I don't want to just use
pawn Код:
SetPlayerPos
Because they'll spawn right ontop of each other. Would I need to do something like this?

pawn Код:
new Float:RandomSpawns[][] =
{
    {2788.5237,-1783.2423,39.4115}, // Randomspawn
    {2730.4958,-1813.5750,39.8603}, // Randomspawn
    {2689.3464,-1754.2125,40.9982}, // Randomspawn
    {2730.0369,-1705.9900,39.6468}, // Randomspawn
    {2757.5171,-1713.3196,40.4796} // Randomspawn
};
If I do, how would I put a player in a vehicle? I've tried PutPlayerInVehicle, but they never seem to spawn in it.

Any help would be greatly appreciated. This is my first attempt at making a race, thanks.
Reply
#2

pawn Код:
new Float:RandomSpawns[][] =
{
    {2788.5237,-1783.2423,39.4115}, // Randomspawn
    {2730.4958,-1813.5750,39.8603}, // Randomspawn
    {2689.3464,-1754.2125,40.9982}, // Randomspawn
    {2730.0369,-1705.9900,39.6468}, // Randomspawn
    {2757.5171,-1713.3196,40.4796} // Randomspawn
};
pawn Код:
new ran = random(sizeof(RandomSpawns));
    SetPlayerPos(playerid,RandomSpawns[ran][0],RandomSpawns[ran][1],RandomSpawns[ran][2]);
this is where ever the race will be. Maybe in the /race cmd
Reply
#3

Thanks for the reply. Would I do:
pawn Код:
SetPlayerPos(playerid,RandomSpawns[ran][0],RandomSpawns[ran][1],RandomSpawns[ran][2]);
But add more "RandomSpawns[ran][3]" and so on?

Also, how would I put the player in a vehicle? Because PutPlayerInVehicle doesn't work.
Reply
#4

pawn Код:
new veh[MAX_PLAYERS];
new ran = random(sizeof(RandomSpawns));
Veh[playerid] =  CreateVehicle(402,RandomSpawns[rana][0],RandomSpawns[ran][1],RandomSpawns[ran][2],0,0,0);
PutPlayerInVehicle(playerid,veh[playerid],0);
Hope this will help u.
Reply
#5

yeah. and
pawn Код:
new Float:RandomSpawns[][] =
theres a number that goes like
pawn Код:
new Float:RandomSpawns[][here] =
but im not sure what number to put.

pawn Код:
new vehid = GetPlayerVehicleID(playerid);
new ran = random(sizeof(RandomSpawns));
            SetPlayerPos(playerid,RandomSpawns[ran][0],RandomSpawns[ran][1],RandomSpawns[ran][2]);
            SetVehiclePos(vehid,RandomSpawns[ran][0],RandomSpawns[ran][1],RandomSpawns[ran][2]);
            PutPlayerInVehicle(playerid,vehid,0);
NOT TESTED

Or (not sure if i read it right) if you want a vehicle assigned do

pawn Код:
new ran = random(sizeof(RandomSpawns));
            SetPlayerPos(playerid,RandomSpawns[ran][0],RandomSpawns[ran][1],RandomSpawns[ran][2]);
            PutPlayerInVehicle(playerid,[vehicleid],0);
Reply
#6

Thank you guys. I'll start to make the Race, and see how it goes.
Reply
#7

I've scripted it somewhat, but I don't spawn in a vehicle.
pawn Код:
public OnPlayerSpawn(playerid)
{
    new RaceStarted;
    RaceStarted = 1;
    new vehid = GetPlayerVehicleID(playerid);
    new ran = random(sizeof(Race1Spawns));
    SetPlayerPos(playerid,Race1Spawns[ran][0],Race1Spawns[ran][1],Race1Spawns[ran][2]);
    SetVehiclePos(vehid,Race1Spawns[ran][0],Race1Spawns[ran][1],Race1Spawns[ran][2]);
    PutPlayerInVehicle(playerid,vehid,434);
    return 1;
}
How can I get it so all players spawn in the vehicle ID 434?
Reply
#8

make sure you create the vehicle OnGameModeInit

put the vehicles on the position you want then do this

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++) //replace this with PutPlayerInVehicle | Explanation: Loop through all players
{
    if(IsPlayerConnected(i)) //checks if the player is connected
    {
          PutPlayerInVehicle(i,vehid,434); //all players will be put at vehicle id 434
    }
}
Reply
#9

You got to be kidding me. There's not an easier way to do this? I have no idea what
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
is. It loops through all players? Why do I need that?...

And
pawn Код:
veh[playerid] =  CreateVehicle(402,Race1Spawns[rana][0],Race1Spawns[ran][1],Race1Spawns[ran][2],0,0,0);
Gives me errors, saying 'veh' is undefined.
I just want a simple race. Players spawn in a line, in a certain vehicle, a countdown starts, from 3, and then they go. They race through a few checkpoints until the finish, and at the end they are frozen at the last checkpoint.
Reply
#10

If you want the player to spawn in the car he is already in use

pawn Код:
PutPlayerInVehicle(playerid,vehid,0);
if you want to create the vehicle use
pawn Код:
PutPlayerInVehicle(playerid,(ID OF CAR),0);
you need that 0 because it means set the player as the driver
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)