Race position problem
#1

Hello everyone, i have problem with race positions. I making mini race system for my server and i have problem. I can't make that when play types: /race he will be spawned in position, secon player in second position, third player...About 20 players and 20 positions. I don't want that player will be spawned in same position, and i no need random spawns. So maybe someone knows how to do that?

My script who doesn't work...:

Код:
new Float:StartPositions[20][3] =
{
    {-1418.0464,-667.8558,1058.8853},
    {-1417.5392,-666.5084,1058.8463},
    {-1417.3503,-665.3151,1058.8364},
    {-1417.2483,-663.8860,1058.8359},
    {-1417.2594,-662.3469,1058.8485},
    {-1417.2816,-660.4011,1058.8645},
    {-1413.5150,-668.1015,1058.4664},
    {-1413.2587,-666.8832,1058.4520},
    {-1413.2622,-665.5123,1058.4636},
    {-1412.9541,-663.9665,1058.4440},
    {-1412.9523,-662.5579,1058.4547},
    {-1412.8295,-660.3596,1058.4595},
    {-1409.5519,-667.6078,1058.1082},
    {-1409.2167,-666.0783,1058.0879},
    {-1409.0236,-664.5811,1058.0840},
    {-1409.0116,-662.9490,1058.0924},
    {-1408.7771,-661.2306,1058.0844},
    {-1405.8873,-666.8409,1057.7815},
    {-1405.4391,-665.3012,1057.7515},
    {-1405.0856,-662.0101,1057.7426}
};
Код:
	SetVehiclePos(playerid,SpawnPos[playerid][0],SpawnPos[playerid][1],SpawnPos[playerid][2]);
Thank you for help ;]
Reply
#2

make a counter;

pawn Код:
new pCounter = 0; // ontop of your script.

// in the callback.
if( pCounter > sizeof( StartPositions[ ] ) ) return SendClientMessage( playerid, -1, "no more slots available" ); // checking if there's still a slot available in the array, if not, it won't spawn the player at the race because it could crash the server / spawn the player at coords 0,0,0( the farm ), or some memory failures could occur.
SetVehiclePos(GetPlayerVehicleID( playerid ),SpawnPos[pCounter][0],SpawnPos[pCounter][1],SpawnPos[pCounter][2]); // setting the player's vehicle to the right pos.
pCounter++; // updating the counter.
this will update the counter when a player has spawned in the race.

the first player to join the race, spawns at the first row of the array ( -1418.0464,-667.8558,1058.8853 ).

the counter updates, it becomes 1.

second player spawns at the coordinates of row 1.

although I prefer using random positions, even though players could spawn ontop of eachother, it'll happen rarely aslong as you've got enough rows in your array.
Reply
#3

Ou My God, It perfectly works! Thanks for help Smileys! +rep ;]
Reply
#4

Quote:
Originally Posted by Zaec
Посмотреть сообщение
Ou My God, It perfectly works! Thanks for help Smileys! +rep ;]
no problem

ps: don't forget to reset the variable to 0, when it starts a new race, or it could bug.

like

pawn Код:
pCounter = 0; // somewhere in the code where it starts a new race.
Reply
#5

Ofcourse, thanks for advice. I have another quesion.

Quote:

SetVehiclePos(GetPlayerVehicleID( playerid ),SpawnPos[pCounter][0],SpawnPos[pCounter][1],SpawnPos[pCounter][2]); // setting the player's vehicle to the right pos.

In this line can spawn 4 player, then i make more, example: SpawnPos[pCounter][3] and ... It says "out of bounds" its to long line? How can i make 20 positions for 20 players? And how to make that cars spawn with Z angle cordinates?
Reply
#6

you've got a 2 dimensional array.

to make it look more understandable for humans:

pawn Код:
new Float:StartPositions[20][3] =
{
    // first dimension, the [20] part. means it can hold 20 rows with data.
    { // second dimension, first row of dimension 1( the [20] );
        -1418.0464, // the 0 index.
        -667.8558, // the 1 index.
        1058.8853 // the 2 index.
        // to make a 3th index, simply add one more line here, also don't forget to put a ',' behind the last coordinate, the one above this one.
    },
    {-1417.5392,-666.5084,1058.8463},
    {-1417.3503,-665.3151,1058.8364},
    {-1417.2483,-663.8860,1058.8359},
    {-1417.2594,-662.3469,1058.8485},
    {-1417.2816,-660.4011,1058.8645},
    {-1413.5150,-668.1015,1058.4664},
    {-1413.2587,-666.8832,1058.4520},
    {-1413.2622,-665.5123,1058.4636},
    {-1412.9541,-663.9665,1058.4440},
    {-1412.9523,-662.5579,1058.4547},
    {-1412.8295,-660.3596,1058.4595},
    {-1409.5519,-667.6078,1058.1082},
    {-1409.2167,-666.0783,1058.0879},
    {-1409.0236,-664.5811,1058.0840},
    {-1409.0116,-662.9490,1058.0924},
    {-1408.7771,-661.2306,1058.0844},
    {-1405.8873,-666.8409,1057.7815},
    {-1405.4391,-665.3012,1057.7515},
    {-1405.0856,-662.0101,1057.7426}
};

// so something like:
new Float:StartPositions[20][4] =
{
    {
        -1418.0464,
        -667.8558,
        1058.8853,
        180.0// add coordinate 4 here, with index nr 3. I assume this will be the facing angle coordinate?
    },
    {-1417.5392,-666.5084,1058.8463},
    {-1417.3503,-665.3151,1058.8364},
    {-1417.2483,-663.8860,1058.8359},
    {-1417.2594,-662.3469,1058.8485},
    {-1417.2816,-660.4011,1058.8645},
    {-1413.5150,-668.1015,1058.4664},
    {-1413.2587,-666.8832,1058.4520},
    {-1413.2622,-665.5123,1058.4636},
    {-1412.9541,-663.9665,1058.4440},
    {-1412.9523,-662.5579,1058.4547},
    {-1412.8295,-660.3596,1058.4595},
    {-1409.5519,-667.6078,1058.1082},
    {-1409.2167,-666.0783,1058.0879},
    {-1409.0236,-664.5811,1058.0840},
    {-1409.0116,-662.9490,1058.0924},
    {-1408.7771,-661.2306,1058.0844},
    {-1405.8873,-666.8409,1057.7815},
    {-1405.4391,-665.3012,1057.7515},
    {-1405.0856,-662.0101,1057.7426}
};

//then do
SetVehicleFacingAngle( GetPlayerVehicleID( playerid ), StartPositions[ pCounter ][ 3 ] );
you can easily pack those 5/6 lines back into 1 line, it's all the same to pawno, but for humans it might be better to understand.

for more information about multi-dimensional arrays, check this out:

https://sampforum.blast.hk/showthread.php?tid=318212
Reply
#7

Nothink understandable for me here, but i will try Thanks a lot for you ;]
Reply
#8

So i have to do somethink like this with all 20 position cordinates?
Код:
new Float:StartPositions[20][3] =
{
    {
        -1418.0464,
        -667.8558,
        1058.8853,
        180.0// add coordinate 4 here, with index nr 3. I assume this will be the facing angle coordinate?
        -1417.5392,
       -666.5084,
       1058.8463,
       Angle cordinate,
// seconds position cordinates
  },
And then change this part to "20" ?

Код:
StartPositions[ pCounter ][ 3 ]
Reply
#9

There are currently 3 index:
index 0 -> x position
index 1 -> y position
index 2 -> z position

If you want to add angle, you'll need one more index:
pawn Код:
new Float:StartPositions[][4] =
Now you can use 4 indexes, it starts from 0 and ends at 3. Any other number will give error about out of bounds.
Reply
#10

Oh, i get it, thanks. But what abou this lines?

Quote:

// so something like:
new Float:StartPositions[20][4] =
{
{
-1418.0464,
-667.8558,
1058.8853,
84.6126// add coordinate 4 here, with index nr 3. I assume this will be the facing angle coordinate?
},

{
-1417.5392,
-666.5084,
1058.8853,
83.6136// add coordinate 4 here, with index nr 3. I assume this will be the facing angle coordinate?
},


{-1417.5392,-666.5084,1058.8463},
{-1417.3503,-665.3151,1058.8364},
{-1417.2483,-663.8860,1058.8359},
{-1417.2594,-662.3469,1058.8485},
{-1417.2816,-660.4011,1058.8645},
{-1413.5150,-668.1015,1058.4664},
{-1413.2587,-666.8832,1058.4520},
{-1413.2622,-665.5123,1058.4636},
{-1412.9541,-663.9665,1058.4440},
{-1412.9523,-662.5579,1058.4547},
{-1412.8295,-660.3596,1058.4595},
{-1409.5519,-667.6078,1058.1082},
{-1409.2167,-666.0783,1058.0879},
{-1409.0236,-664.5811,1058.0840},
{-1409.0116,-662.9490,1058.0924},
{-1408.7771,-661.2306,1058.0844},
{-1405.8873,-666.8409,1057.7815},
{-1405.4391,-665.3012,1057.7515},
{-1405.0856,-662.0101,1057.7426}
};

C:\Users\User\Desktop\Free-Roam\gamemodes\freeroam.pwn(87) : error 018: initialization data exceeds declared size
Quote:

C:\Users\User\Desktop\Free-Roam\gamemodes\freeroam.pwn(89) : error 010: invalid function or declaration
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.

How to do what can be 20 players positions without "out of bounds" ?
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)