how to spawn a random vehicle

Started by MEGAMIND, Aug 11, 2018, 12:12 PM

Previous topic - Next topic

MEGAMIND

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

Quote from: MEGAMIND on Aug 11, 2018, 12:12 PMhello 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 ?

MEGAMIND

Quote from: Ninja on Aug 11, 2018, 12:26 PM
Quote from: MEGAMIND on Aug 11, 2018, 12:12 PMhello 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

#3
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
QuotePS:is trash is ur home language??

MEGAMIND


Shadow

QuotePS:is trash is ur home language??

MEGAMIND

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

!

#7
Quote from: MEGAMIND on Aug 11, 2018, 02:22 PMglobalCount <- 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

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 ];
}

Discord: zeus#5155

MEGAMIND

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 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 ..

!

Quote from: MEGAMIND on Aug 11, 2018, 02:40 PMOk 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 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

Discord: zeus#5155

MEGAMIND

Thnx dude i havent tried it yet but does it really deletes the old spawned vehicle??

!

Quote from: MEGAMIND on Aug 11, 2018, 02:45 PMThnx 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.
pVehicle[ player_ID ].Remove();
pVehicle[ player_ID ] = null;

Discord: zeus#5155