Solved.
#1

I'm making a script to put a player in a random vehicle on spawn, but I don't really have a clue how to do this...

pawn Код:
//I have this
new cars[87][1] = {
{400},{401},{402},{404},{405},{410},{411},{413},{415},{418},
{419},{421},{422},{424},{426},{429},{434},{436},{439},{442},
{445},{451},{458},{446},{467},{470},{474},{475},{477},{478},
{479},{480},{482},{483},{489},{491},{492},{495},{496},{500},
{505},{506},{507},{516},{517},{518},{525},{526},{527},{529},
{533},{534},{535},{536},{540},{541},{542},{543},{545},{546},
{547},{549},{550},{551},{554},{555},{558},{559},{560},{561},
{562},{565},{566},{567},{568},{575},{576},{579},{580},{585},
{587},{589},{600},{602},{603},{604},{605}
};
pawn Код:
// And this is my OnPlayerSpawn
public OnPlayerSpawn(playerid)
{
    PlayerVehicle[playerid] = CreateVehicle(560, -1253.9496,-193.6417,56.3562, 0.0, -1, -1, 60000);
    PutPlayerInVehicle(playerid, PlayerVehicle[playerid], 0);
    SetVehiclePos(PlayerVehicle[playerid], -1253.943848, -193.086182, 59.217461);
    Spawned[playerid] = 1;
    StartedPlaying[playerid] = 1;
    return 1;
}
As you can see I always get the same car model now, so how can I make it to pick a random car from the list?
Reply
#2

Try using a random function?
Reply
#3

Yea I had gotten that far :P
But I don't know how to use random for picking a modelid from the list I gave
Reply
#4

well

you dont need the second part

Код:
new cars[87] = {
400,401,402 ........
}
new carowned[MAX_PLAYERS];
ok thats that

Код:
OnPlayerSpawn(playerid){
new i;
i = random(sizeof(cars));
if(carowned[playerid] > 0){
SetVehiclePos(carowned[playerid], x, y, z);
PutPlayerInVehicle(playerid, carowned[playerid], 0);
}
else{
carowned[playerid] = CreateVehicle(cars[i], x, y, z);
SetVehiclePos(carowned[playerid], x, y, z);
PutPlayerInVehicle(playerid, carowned[playerid], 0);
}
its not complete but it should help
Reply
#5

There is no actual Createvehicle in your code, which is exactly the part that I need xD
I got this now:
pawn Код:
public OnPlayerSpawn(playerid)
{
    new rCar;
  rCar = random(sizeof(cars));
    PlayerVehicle[playerid] = CreateVehicle(rCar, -1253.9496,-193.6417,56.3562, 0.0, -1, -1, 60000);
    PutPlayerInVehicle(playerid, PlayerVehicle[playerid], 0);
    SetVehiclePos(PlayerVehicle[playerid], -1253.943848, -193.086182, 59.217461); //used for other stuff
    Spawned[playerid] = 1; //used for other stuff
    StartedPlaying[playerid] = 1; //used for other stuff
    return 1;
}
And I got this warning:
Код:
(363) : warning 203: symbol is never used: "cars"
But I used cars right?...
Reply
#6

indeed
Reply
#7

Soo, what do I do?
Reply
#8

pawn Код:
#include <a_samp>

new PlayerVehicle[MAX_PLAYERS] = {-1,...};
new cars[] = { 400,401,402,404,405,410,411,413,415,418,419,421,422,424,426,429,434,436,439,442,
        445,451,458,446,467,470,474,475,477,478,479,480,482,483,489,491,492,495,496,500,
        505,506,507,516,517,518,525,526,527,529,533,534,535,536,540,541,542,543,545,546,
        547,549,550,551,554,555,558,559,560,561,562,565,566,567,568,575,576,579,580,585,
        587,589,600,602,603,604,605 };

public OnPlayerSpawn(playerid)
{
    if(PlayerVehicle[playerid] != -1) { DestroyVehicle(PlayerVehicle[playerid]); } // Delete Old car
// Check player coordinate and angle
    new
      Float:x,
      Float:y,
      Float:z,
      Float:Angle;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, Angle);
//------------------------------------------
    PlayerVehicle[playerid] = CreateVehicle(vehicle[random(sizeof(vehicle))], x, y, z, Angle, -1, -1, 60000); // Create Vehicle player position
    PutPlayerInVehicle(playerid, PlayerVehicle[playerid], 0);          // Player set vehicle driver
    LinkVehicleToInterior(vehicle, GetPlayerInterior(playerid));        // Vehicle Set Interior PLayer Interior
    SetVehicleVirtualWorld(vehicle, GetPlayerVirtualWorld(playerid));      // Vehicle Set VW ID Player VW ID.
       
//  Spawned[playerid] = 1;
//  StartedPlaying[playerid] = 1;
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)