Random car spawn
#1

Sooo I have this code, and there are six posibilites of spawning in random areas. But I want it: If the place is already taken, you can't spawn there.. Any help :> ?

PHP код:
public OnPlayerSpawn(playerid)
{
    if(
pInfo[playerid][pVIP] == 1SetPlayerColor(playerid,0xFF0000);
    new 
Float:RandomSpawn[][3] =
    {
        {
3782.6897,-1919.2844,2.2270},
        {
3770.6841,-1912.3002,2.2271},
        {
3777.3240,-1914.1091,2.2271},
        {
3782.6748,-1913.8456,2.2271},
        {
3788.4456,-1914.4016,2.2271},
        {
3794.0837,-1914.7858,2.2271}
    };
    new 
rand random(sizeof(RandomSpawn));
    new 
Car CreateVehicle(411,RandomSpawn[rand][0],RandomSpawn[rand][1],RandomSpawn[rand][2],0,0,0,0);
    
PutPlayerInVehicle(playerid,Car,0);
    
SetPlayerInterior(playerid0);
    new 
pveh;
    new 
PlayerIn[MAX_PLAYER_NAME];
    for(new 
i=0;i<MAX_VEHICLES;i++)
    {
    if(
PlayerIn[i] == 0)
        {
            
pveh i;
            break;
        }
    }
    
PutPlayerInVehicle(playerid,pveh,0);
    
PlayerIn[pveh] = 1;
    return 
1;

Reply
#2

What do you mean with "If the place is already taken, you can't spawn there".

Also,

this makes no sense
pawn Код:
new PlayerIn[MAX_PLAYER_NAME];
    for(new i=0;i<MAX_VEHICLES;i++)
    {
    if(PlayerIn[i] == 0)
        {
            pveh = i;
            break;
        }
    }
PutPlayerInVehicle(playerid,pveh,0);
    PlayerIn[pveh] = 1;
You are creating an array within a function (so when the function is done, it's content is gone).

You define it's size to MAX_PLAYER_NAME(20, I believe) and then loop trough it up to index MAX_VEHICLES(2000, I believe).
This will give an error.

Then you put player in vehicle pveh(which always is 0) since you've set it in the loop.
VehicleID 0 is never in use anyways so this doesn't make sense eighter.




Off-topic:
Spelling correction in your signiture ammount is with one m
Reply
#3

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
What do you mean with "If the place is already taken, you can't spawn there".

Also,

this makes no sense
pawn Код:
new PlayerIn[MAX_PLAYER_NAME];
    for(new i=0;i<MAX_VEHICLES;i++)
    {
    if(PlayerIn[i] == 0)
        {
            pveh = i;
            break;
        }
    }
PutPlayerInVehicle(playerid,pveh,0);
    PlayerIn[pveh] = 1;
You are creating an array within a function (so when the function is done, it's content is gone).

You define it's size to MAX_PLAYER_NAME(20, I believe) and then loop trough it up to index MAX_VEHICLES(2000, I believe).
This will give an error.

Then you put player in vehicle pveh(which always is 0) since you've set it in the loop.
VehicleID 0 is never in use anyways so this doesn't make sense eighter.




Off-topic:
Spelling correction in your signiture ammount is with one m
Meh I deleted it, thanks for it !

I mean, if someone spawned at, lets say X1,Y1,Z1
Someone else can't spawn at that location, the script will give him another place. (Ex: X2,Y2,Z2)

Off-topic:
Spelling correction in your Off-topic message, you spell it signature not "signiture"
Reply
#4

When do you want the spawn to be 'available' again?

Off-topic:
Reply
#5

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
When do you want the spawn to be 'available' again?

Off-topic:
5 minutes
Reply
#6

pawn Код:
enum e_spawns
{
    Float:spawnPos[3],
    spawnUsed
}
new spawns[][e_spawns] =
{
        {{3782.6897,-1919.2844,2.2270},0},
        {{3770.6841,-1912.3002,2.2271},0},
        {{3777.3240,-1914.1091,2.2271},0},
        {{3782.6748,-1913.8456,2.2271},0},
        {{3788.4456,-1914.4016,2.2271},0},
        {{3794.0837,-1914.7858,2.2271},0}
};
forward spawnAvailable(spawn);
public spawnAvailable(spawn)
{
    spawns[spawn][spawnUsed] = 0;
}
public OnPlayerSpawn(playerid)
{
    if(pInfo[playerid][pVIP] == 1) SetPlayerColor(playerid,0xFF0000);

    new rand = random(sizeof(spawns));
    while(spawns[rand][spawnUsed])
        rand = random(sizeof(spawns));
    new Car = CreateVehicle(411,spawns[rand][spawnPos][0],spawns[rand][spawnPos][1],spawns[rand][spawnPos][2],0,0,0,0);
    PutPlayerInVehicle(playerid,Car,0);
    SetPlayerInterior(playerid, 0);

    spawns[rand][spawnUsed] = 1;
    SetTimerEx("spawnAvailable", 300000, 0, "d", rand);
    return 1;
}
UNTESTED.

Notice you need a couple more spawns than slots, or your server crashes when everyone spawns.
And than still, when everyone dies a couple of times within 5 minutes, your server freezes due to the random loop.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)