Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: MEGAMIND on Aug 11, 2018, 12:12 PM

Title: how to spawn a random vehicle
Post by: MEGAMIND on Aug 11, 2018, 12: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)
Title: Re: how to spawn a random vehicle
Post by: Magneto 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 ?
Title: Re: how to spawn a random vehicle
Post by: MEGAMIND on Aug 11, 2018, 12:27 PM
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
Title: Re: how to spawn a random vehicle
Post by: Shadow on Aug 11, 2018, 01:43 PM
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
Title: Re: how to spawn a random vehicle
Post by: MEGAMIND on Aug 11, 2018, 02:08 PM
Anyother ...?
Title: Re: how to spawn a random vehicle
Post by: Shadow on Aug 11, 2018, 02:14 PM
what is the issue..?
Title: Re: how to spawn a random vehicle
Post by: MEGAMIND on Aug 11, 2018, 02:22 PM
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
Title: Re: how to spawn a random vehicle
Post by: ! on Aug 11, 2018, 02:35 PM
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 ];
}
Title: Re: how to spawn a random vehicle
Post by: MEGAMIND on Aug 11, 2018, 02: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 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 ..
Title: Re: how to spawn a random vehicle
Post by: ! on Aug 11, 2018, 02:43 PM
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 (https://forum.vc-mp.org/?topic=6157.msg42419#msg42419)
Title: Re: how to spawn a random vehicle
Post by: MEGAMIND on Aug 11, 2018, 02:45 PM
Thnx dude i havent tried it yet but does it really deletes the old spawned vehicle??
Title: Re: how to spawn a random vehicle
Post by: ! on Aug 11, 2018, 02:49 PM
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;