how to randowm spawn a one car
#1

how to spawn random one car etc : id 562 i want to this car spawn is difrent location i do this

Quote:

public OnPlayerSpawn( playerid )
{
new
Rand = random( 4 ),
Float:RandCoords[ 4 ][ 4 ] =
{
{ 1023.79,-976.95,43.14 },
{ 1197.05,-1001.90,32.88},
{ 1250.04,-904.73,42.53 },
{ 1284.84,-994.44,38.5 }
};

SetPlayerPos( playerid, RandCoords[ Rand ][ 0 ], RandCoords[ Rand ][ 1 ], RandCoords[ Rand ][ 2 ] );
SetPlayerFacingAngle( playerid, RandCoords[ Rand ][ 3 ] );
return 1;
}

but its work only for player not a veh

then i do this and its not change


Quote:

public OnPlayerSpawn(playerid)
{
new
Rand = random( 4 ),
Float:RandCoords[ 4 ][ 4 ] =
{
{ 1023.79,-976.95,43.14 },
{ 1197.05,-1001.90,32.88},
{ 1250.04,-904.73,42.53 },
{ 1284.84,-994.44,38.5 }
};
AddStaticVehicleEx(562,RandCoords[ Rand ][ 0 ], RandCoords[ Rand ][ 1 ], RandCoords[ Rand ][ 2 ] ,1,6,6,600000);



return 1;

}

or this

public OnVehicleSpawn(vehicleid)
{
new
Rand = random( 4 ),
Float:RandCoords[ 4 ][ 4 ] =
{
{ 1023.79,-976.95,43.14 },
{ 1197.05,-1001.90,32.88},
{ 1250.04,-904.73,42.53 },
{ 1284.84,-994.44,38.5 }
};
SetVehiclePos( 562, RandCoords[ Rand ][ 3 ], RandCoords[ Rand ][ 2], RandCoords[ Rand ][ 1 ] );



return 1;
}

Reply
#2

Hey, thanks for posting this topic, here's a quick fix and I hope it works as it's untested.

First, place this at the top of your script anywhere under #include <a_samp>

pawn Код:
new Float:RandCoords[4][6] = {
{1023.79,-976.95,43.14}, // 1
{1197.05,-1001.90,32.88}, // 2
{1250.04,-904.73,42.53} // 3
{1284.84,-994.44,38.5) // 4
};
Next, add this under OnGameModeInit:

pawn Код:
Public OnGameModeInit()
{
    new Rand = random( 4 ),
    AddStaticVehicle(562,RandCoords[Rand][3],RandCoords[Rand][2],RandCoords[Rand][1],0,0,0,1,1);
    return 1;
}
Reply
#3

Quote:
Originally Posted by Shadow™
Посмотреть сообщение
pawn Код:
.....

    AddStaticVehicle(562,RandCoords[Rand][3],RandCoords[Rand][2],RandCoords[Rand][1],0,0,0,1,1);
....
In the way I see this the coordinates are messed up. X contains <incorrect variable>, Y contains Z and Z contains Y

@the topic creator
In your first piece of code (for player spawning) you set the player angle with an invalid variable, ...[Rand][3] doesn't exist
Reply
#4

Yeah... I just noticed that, sorry... I copied it from his first post, just forgot to change it... Anyway, you're right...

pawn Код:
AddStaticVehicle(562,RandCoords[Rand][0], RandCoords[Rand][1], RandCoords[Rand][2],0,0,0,1,1); // White
Reply
#5

Quote:
Originally Posted by Shadow™
Посмотреть сообщение
Hey, thanks for posting this topic, here's a quick fix and I hope it works as it's untested.

First, place this at the top of your script anywhere under #include <a_samp>

pawn Код:
new Float:RandCoords[4][6] = {
{1023.79,-976.95,43.14}, // 1
{1197.05,-1001.90,32.88}, // 2
{1250.04,-904.73,42.53} // 3
{1284.84,-994.44,38.5) // 4
};
Next, add this under OnGameModeInit:

pawn Код:
Public OnGameModeInit()
{
    new Rand = random( 4 ),
    AddStaticVehicle(562,RandCoords[Rand][3],RandCoords[Rand][2],RandCoords[Rand][1],0,0,0,1,1);
    return 1;
}

Quote:
Originally Posted by Shadow™
Посмотреть сообщение
Yeah... I just noticed that, sorry... I copied it from his first post, just forgot to change it... Anyway, you're right...

pawn Код:
AddStaticVehicle(562,RandCoords[Rand][0], RandCoords[Rand][1], RandCoords[Rand][2],0,0,0,1,1); // White
Too much are parameter.
Код:
warning 202: number of arguments does not match definition
warning 202: number of arguments does not match definition
pawn Код:
AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2);
Try:
pawn Код:
#include <a_samp>

new
    Float:RandCoords[4][4] =
{
//      0       1       2       3
//      X       Y       Z       Angle
    { 1023.79, -976.95, 43.14, 270.0 }, // 0
    { 1197.05, -1001.90, 32.88, 270.0}, // 1
    { 1250.04, -904.73, 42.53, 270.0 }, // 2
    { 1284.84, -994.44, 38.5, 270.0  }  // 3
};

public
    OnGameModeInit()
{
    new
        Rand = random(4); // 0 1 2 3
//  AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2);
    AddStaticVehicle(562, RandCoords[Rand][0], RandCoords[Rand][1], RandCoords[Rand][2], RandCoords[Rand][3], -1, -1);
    return 1;
}
Reply
#6

Meh... Was thinking of Objects lol, anyway... I suppose that'll work.
Reply
#7

Quote:
Originally Posted by smeti
Посмотреть сообщение



Too much are parameter.
Код:
warning 202: number of arguments does not match definition
warning 202: number of arguments does not match definition
pawn Код:
AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2);
Try:
pawn Код:
#include <a_samp>

new
    Float:RandCoords[4][4] =
{
//      0       1       2       3
//      X       Y       Z       Angle
    { 1023.79, -976.95, 43.14, 270.0 }, // 0
    { 1197.05, -1001.90, 32.88, 270.0}, // 1
    { 1250.04, -904.73, 42.53, 270.0 }, // 2
    { 1284.84, -994.44, 38.5, 270.0  }  // 3
};

public
    OnGameModeInit()
{
    new
        Rand = random(3); // 0 1 2 3
//  AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2);
    AddStaticVehicle(562, RandCoords[Rand][0], RandCoords[Rand][1], RandCoords[Rand][2], RandCoords[Rand][3], -1, -1);
    return 1;
}
its worked but only when the player is relog then spawn loc will change for the player not when car is sxplode and it now change the loction only for that case its will change
Reply
#8

pawn Код:
#include <a_samp>

new Float:RandCoords[4][4] = {
//      0       1       2       3
//      X       Y       Z       Angle
    {1023.79, -976.95, 43.14, 270.0}, // 0
    {1197.05, -1001.90, 32.88, 270.0}, // 1
    {1250.04, -904.73, 42.53, 270.0}, // 2
    {1284.84, -994.44, 38.5, 270.0}  // 3
};

public OnVehicleSpawn(vehicleid)
{
    if(GetVehicleModel(vehicleid) == 562) {
        new Rand = random(4);
        SetVehiclePos(vehicleid, RandCoords[Rand][0], RandCoords[Rand][1], RandCoords[Rand][2]);
        SetVehicleZAngle(vehicleid, RandCoords[Rand][3]);
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
#include <a_samp>

new Float:RandCoords[4][4] = {
//      0       1       2       3
//      X       Y       Z       Angle
    {1023.79, -976.95, 43.14, 270.0}, // 0
    {1197.05, -1001.90, 32.88, 270.0}, // 1
    {1250.04, -904.73, 42.53, 270.0}, // 2
    {1284.84, -994.44, 38.5, 270.0}  // 3
};

public OnVehicleSpawn(vehicleid)
{
    if(GetVehicleModel(vehicleid) == 562) {
        new Rand = random(4);
        SetVehiclePos(vehicleid, RandCoords[Rand][0], RandCoords[Rand][1], RandCoords[Rand][2]);
        SetVehicleZAngle(vehicleid, RandCoords[Rand][3]);
    }
    return 1;
}
THANK YOU jeff
YOU THE BEST
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)