This topic was marked solved by its starter, on August 11th, 03:55 PM
how to spawn a random vehicle

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 634
how to spawn a random vehicle
«  »Last edited
hello i want to spawn a random vehicle using a cmd

for example using /car i get any vehicle not using FindVehicle(anyidgoeshere)

like if my server even doesnt contain a packer so it spawn a packer for me

like also createvehicle(randomly)

Magneto

  • Newbie
  • LBR Member
  • Posts: 12

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 634
Re: how to spawn a random vehicle
« Reply #2,  »
Quote from Ninja on August 11th, 01:26 PM
Quote from MEGAMIND on August 11th, 01:12 PM
hello i want to spawn a random vehicle using a cmd

for example using /car i get any vehicle not using FindVehicle(anyidgoeshere)

like if my server even doesnt contain a packer so it spawn a packer for me

like also createvehicle(randomly)
Like this: http://wiki.vc-mp.org/wiki/Scripting/Squirrel/Functions/FindVehicle ?
i already said i dont want findvehicle(0

Shadow

  • LU Beta Tester
  • Posts: 176
Re: how to spawn a random vehicle
« Reply #3,  »Last edited
Code: [Select]
global_modelArray<- [];

function getRandomVehicle()
{
       srand(time()); // ?

       if(global_modelArray.size() != 0)
       {
             for( local i = 0; i < MAX_VEHICLES; ++i )
                        if( FindVehicle(i) )
                                  if( global_modelArray.find(FindVehicle(i).Model) == null )
                                            global_modelArray.push(FindVehicle(i).Model);
        }

        local index = LOWEST_MODEL_COUNT + rand() % (MAX_MODEL_COUNT - LOWEST_MODEL_COUNT);

        while(global_modelArray.find(index) != NULL) // infinite loop if you have every type of model
                  index = LOWEST_MODEL_COUNT + rand() % (MAX_MODEL_COUNT - LOWEST_MODEL_COUNT);

        return index;
}

not sure if it works or not but should be a good pseudocode
Quote
PS:is trash is ur home language??

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 634

Shadow

  • LU Beta Tester
  • Posts: 176
Quote
PS:is trash is ur home language??

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 634
Re: how to spawn a random vehicle
« Reply #6,  »
Code: [Select]
globalCount <- 0;
vehs <- [
CreateVehicle(141, 1, Vector(-54.2794, 986.151, 15.9403), -1.6069, 0, 0),
CreateVehicle(141, 1, Vector(X, Y, Z),A, 0, 0),
CreateVehicle(141, 1, Vector(X, Y, Z), A, 0, 0),
CreateVehicle(141, 1, Vector(X, Y, Z), A, 0, 0)
];
function onPlayerCommand( player, cmd, text )
{
if( cmd == "join" ) player.Vehicle = vehs[ globalCount++ ];
}
k now i wont be needing   random vehicles instead i found this usefull but if there r 4 vehicles.... Now when u do /join and repeat this 4 times u get to sit on those 4 vehicles for once the fifth time u do it u wont sit so can we loop it so that we can sit in those cars every time we do /join a hundred times + theres one more issue if i leave server and rejoin and do /join the vehicles get created again on the same vehicles which were created before... So any help regarding my issue ty

!

  • Sr. Member
  • Don't feel shy while zooming on h*r...
  • Posts: 369
Re: how to spawn a random vehicle
« Reply #7,  »Last edited
Quote from MEGAMIND on August 11th, 03:22 PM
Code: [Select]
globalCount <- 0;
vehs <- [
CreateVehicle(141, 1, Vector(-54.2794, 986.151, 15.9403), -1.6069, 0, 0),
CreateVehicle(141, 1, Vector(X, Y, Z),A, 0, 0),
CreateVehicle(141, 1, Vector(X, Y, Z), A, 0, 0),
CreateVehicle(141, 1, Vector(X, Y, Z), A, 0, 0)
];
function onPlayerCommand( player, cmd, text )
{
if( cmd == "join" ) player.Vehicle = vehs[ globalCount++ ];
}
k now i wont be needing   random vehicles instead i found this usefull but if there r 4 vehicles.... Now when u do /join and repeat this 4 times u get to sit on those 4 vehicles for once the fifth time u do it u wont sit so can we loop it so that we can sit in those cars every time we do /join a hundred times + theres one more issue if i leave server and rejoin and do /join the vehicles get created again on the same vehicles which were created before... So any help regarding my issue ty
Code: [Select]
pVehicle <- array( GetMaxPlayers(), null );
if( cmd == "join" ) {
if ( pVehicle[ player.ID ] == null ) {
pVehicle[ player.ID ] = CreateVehicle(141, 1, Vector(-54.2794, 986.151, 15.9403), -1.6069, 0, 0);
}
player.Vehicle = pVehicle[ player.ID ];
}

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 634
Re: how to spawn a random vehicle
« Reply #8,  »
Ok that was quick ut what if some noob really dpawn it a hundered time and which males the server lag (only that place where the noob spawned will be laged) so how to if u do that
Code: [Select]
if( cmd == "join" ) {
   local veh = CreateVehicle(141, 1, Vector(-54.2794, 986.151, 15.9403), -1.6069, 0, 0);
   player.Vehicle = veh;
}
Ok and everytime i do this it should delete the old vehicle ..

!

  • Sr. Member
  • Don't feel shy while zooming on h*r...
  • Posts: 369
Re: how to spawn a random vehicle
« Reply #9,  »
Quote from MEGAMIND on August 11th, 03:40 PM
Ok that was quick ut what if some noob really dpawn it a hundered time and which males the server lag (only that place where the noob spawned will be laged) so how to if u do that
Code: [Select]
if( cmd == "join" ) {
   local veh = CreateVehicle(141, 1, Vector(-54.2794, 986.151, 15.9403), -1.6069, 0, 0);
   player.Vehicle = veh;
}
Ok and everytime i do this it should delete the old vehicle ..
Edited check again

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 634

!

  • Sr. Member
  • Don't feel shy while zooming on h*r...
  • Posts: 369
Re: how to spawn a random vehicle
« Reply #11,  »
Quote from MEGAMIND on August 11th, 03:45 PM
Thnx dude i havent tried it yet but does it really deletes the old spawned vehicle??
No if you want to delete the old one use it in player part or if it is an event you can use it when player is leaving.
Code: [Select]
pVehicle[ player_ID ].Remove();
pVehicle[ player_ID ] = null;