NOTE: This is my first event add-on. The add-ons I've made before this was a playertype and a projectile and a vehicle that makes sound. I have very little experience.
So I'm making an output event that spawns a specified vehicle with a specified color, independent of a vehicle spawn brick. It's very early in the works so I haven't added any abuse checks or anything. Here's the code:
registerOutputEvent(fxDTSBrick,spawnVehicle,"dataBlock Vehicle" TAB "paintColor paintColor",1);
package spawnVehicleEvent
{
function fxDTSBrick::spawnVehicle(%this,%DataBlock,%paintColor)
{
%pos = %this.getWorldBoxCenter();
%vehicle = new WheeledVehicle()
{
position = %pos;
datablock = %DataBlock;
};
%vehicle.setColor(%paintColor);
}
};
activatepackage(SpawnVehicleEvent);
There are some issues with this tiny block of code:
- It breaks vehicle spawns (you can't spawn vehicles on vehicle bricks with the wrench)
- It can only spawn WheeledVehicleData types [I have solved this, but I would appreciate it if you could suggest methods other than an if-statement]
- /resetVehicles doesn't seem to work with non-physics vehicles such as the horse, meaning the only way to get rid of them is to kill them.
I know why it can only spawn WheeledVehicle types, because I've specified WheeledVehicle in this line:
%vehicle = new WheeledVehicle()
If I set it to FlyingVehicle it can spawn magic carpets. If I set it to Player it can spawn rowboats and horses. If I set it to Vehicle it crashes the game. What should I put in there so that it can spawn all 3 of these vehicle types?
I've tried making if statements like this:
if(%datablock.classname == WheeledVehicleData)
if(%datablock.classname == FlyingVehicleData)
if(%datablock.classname == Armor)
But it says that they "always evaluate to 0" and usually just executes all of them. Any help on this would be greatly appreciated.
As for why it's breaking the vehicle spawns: I have absolutely no idea. When I try to spawn something with the wrench on a vehiclespawn, it gives me this:
BackTrace: -> [BotHolePackage]serverCmdSetWrenchData -> serverCmdSetWrenchData -> fxDTXBrick::setVehicle -> [spawnVehicleEvent]fxtDTSBrick::spawnVehicle
I'm also not sure what to do about the /resetVehicles dilemma. Any suggestions would be appreciated.