Author Topic: Getting all the vehicles in a server  (Read 1620 times)

Is there any way to get all the vehicles?

I know getting all the clients is like this
Code: [Select]
for(%i=0;%i<clientGroup.getCount();,%i++)
{
    %client = clientGroup.getObject(%i);
    //docodewithclient
}

Is there any similar ways to get vehicles?

Use this code to make a vehicleGroup. Place it in its own file in your mod.

Code: [Select]
if(isObject(vehicleGroup))
return; //we don't want the code to be executed again if somebody else already created a vehicleGroup
else
new simSet(vehicleGroup);

package vehicleGroup
{
function fxDtsBrick::spawnVehicle(%this,%a)
{
%parent = parent::spawnVehicle(%this,%a);

%vehicle = %this.vehicle;
if(isObject(%vehicle))
vehicleGroup.add(%vehicle);

return %parent;
}
};
activatePackage(vehicleGroup);
« Last Edit: January 04, 2013, 11:22:20 AM by Greek2me »

Use this code to make a vehicleGroup. Place it in its own file in your mod.

Code: [Select]
if(isObject(vehicleGroup))
return; //we don't want the code to be executed again if somebody else already created a vehicleGroup
else
new simSet(vehicleGroup);

package vehicleGroup
{
function fxDtsBrick::spawnVehicle(%this,%a)
{
%parent = parent::spawnVehicle(%this,%a);

%vehicle = %this.vehicle;
if(isObject(%vehicle))
vehicleGroup.add(%vehicle);

return %parent;
}
};
activatePackage(vehicleGroup);
But that won't get all vehicles in the server. Only vehicles spawned by bricks.

But that won't get all vehicles in the server. Only vehicles spawned by bricks.

Lol.. How else would you be spawning them? If it is through code, then you shouldn't be asking this lol..

Anyways, i think you can also loop through the missionCleanup container object.
« Last Edit: January 04, 2013, 01:19:58 PM by elm »

Use this code to make a vehicleGroup. Place it in its own file in your mod.

Code: [Select]
if(isObject(vehicleGroup))
return; //we don't want the code to be executed again if somebody else already created a vehicleGroup
else
new simSet(vehicleGroup);

package vehicleGroup
{
function fxDtsBrick::spawnVehicle(%this,%a)
{
%parent = parent::spawnVehicle(%this,%a);

%vehicle = %this.vehicle;
if(isObject(%vehicle))
vehicleGroup.add(%vehicle);

return %parent;
}
};
activatePackage(vehicleGroup);
This breaks when I respawn the vehicle.
Should I change it to Wheeledvehicle::onAdd()?

Code: [Select]
package vehicleGroup
{
function vehicle::onAdd(%this)
{
if(!isObject(vehicleGroup))
new simSet(vehicleGroup);
vehicleGroup.add(%this);
parent::onAdd(%this);
}
function vehicle::onRemove(%this)
{
if(isObject(vehicleGroup))
vehicleGroup.remove(%this);
parent::onRemove(%this);
}
};
activatePackage(vehicleGroup);

Code: [Select]
package vehicleGroup
{
function vehicle::onAdd(%this)
{
if(!isObject(vehicleGroup))
new simSet(vehicleGroup);
vehicleGroup.add(%this);
parent::onAdd(%this);
}
function vehicle::onRemove(%this)
{
if(isObject(vehicleGroup))
vehicleGroup.remove(%this);
parent::onRemove(%this);
}
};
activatePackage(vehicleGroup);
Thank you

EDIT: um looks like wheeledvehicles don't have onAdd...
any alternatives?
« Last Edit: January 10, 2013, 05:34:52 PM by Aide33 »

Client sided
Code: [Select]
function GetVehicles()
{
%count = serverConnection.getCount();
for(%a=0;%a<%count;%a++)
{
%object = serverConnection.getObject(%a);
if(%object.getClassName() $= "WheeledVehicle")
echo(%object);
}
}

Plexious, why did you post that?

Plexious, why did you post that?
It's only 6 lines and applies to the thread.

It's only 6 lines and applies to the thread.
No, it's unrelated and inefficient.

EDIT: um looks like wheeledvehicles don't have onAdd...
any alternatives?
All objects have an onAdd function. It's an engine implemented constructor callback. It may be undefined for vehicle, in which case you may be able to fix that by removing my code from the package and removing the parent lines.

No, it's unrelated and inefficient.
It gets the vehicles in the server and is the easiest way to get vehicles client sided.

It gets the vehicles in the server and is the easiest way to get vehicles client sided.
OP clearly posted something server-sided, so he's probably looking for something server-sided.

Anyways, i think you can also loop through the missionCleanup container object.