Vehicle mounting problems
by Ronald J Nelson · in Torque Game Engine · 01/03/2006 (5:06 pm) · 3 replies
I am trying to make a system that allows more than one player to mount a vehicle. Different seats of course. Everytime someone tries to get into an already mounted vehicle, it crashes the server. Here is my code, any help would be appreciated.
function serverCmdMountVehicle(%client)
{
%testMnted = %client.getControlObject();
//Determine how far should the picking ray extend into the world?
%selectRange = 3;
// Only search for vehicles
%searchMasks = $TypeMasks::vehicleObjectType;
%pos = %client.player.getEyePoint();
// Start with the shape's eye vector...
%eye = %client.player.getEyeVector();
%eye = vectorNormalize(%eye);
%vec = vectorScale(%eye, %selectRange);
%end = vectorAdd(%vec, %pos);
%scanTarg = ContainerRayCast (%pos, %end, %searchMasks);
// a target in range was found so select it
if (%scanTarg && %testMnted != %client.vehicle)
{
%targetObject = firstWord(%scanTarg);
%col = %targetObject;
%obj = %client.getControlObject();
echo("Found a vehicle: " @ %targetObject);
// Mount vehicles
%this = %col.getDataBlock();
// Only mount drivers for now.
//%node = 0;
%node = findEmptySeat(%col, %this);
if(%node >= 0)
{
%col.mountObject(%obj,%node);
%obj.mVehicle = %col;
%obj.client.setcontrolobject(%col);
%curVehicle8 = %client.getControlObject();
%curVehicle8.parkingBrake = false;
}
}
else
{
echo("No object found/Try dismount");
if (!%scanTarg)
{
%curVehicle = %client.getControlObject();
%curVehicle.parkingBrake = true;
%curVehicle.setGear(0);
commandToClient(%client,'getOut',%client);
%client.setControlObject(%client.player);
}
}
}
function findEmptySeat(%vehicle, %vehicleblock)
{
for (%i = 0; %i < %vehicleblock.numMountPoints; %i++)
{
%node = %vehicle.getMountNodeObject(%i);
if (%node == 0)
{
return %i;
}
}
return -1;
}
#2
Helicopter Resource
Avg. Rating (of 13) 4.9
Basic Information
Author: Tim Heldna & Frank Skilton <<
May be worth looking at.
01/04/2006 (8:41 am)
I would say have a look at www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9263 . This is a chopper resource, How ever it as the ability to mount in 2 seats using the Q button to switch between the seats while mounted , It may give you some more idea on it. With in the resource My self and Denis Linardic are hosting the full zip file for the chopper, If you also look in the resource you'll see i have also posted a full tutorial on adding the files with coding in side the tut. Helicopter Resource
Avg. Rating (of 13) 4.9
Basic Information
Author: Tim Heldna & Frank Skilton <<
May be worth looking at.
#3
01/04/2006 (4:25 pm)
Have you looked at the Torque Vehicle Resource?
Torque Owner Kirby Webber
if (%node >= 0) { %col.mountObject(%obj, %node); %obj.mVehicle = %col [b]%obj.client.setControlObject(%col);[/b] %curVehicle8 = %client.getControlObject(); %curVehic;e8.parkingBrake = false; }Now, correct me if I'm wrong, but doesn't this try to give every player who mounts the vehicle control over it?
Maybe something like this:
if (%node >= 0) { %col.mountObject(%obj, %node); %obj.mVehicle = %col if (%node $= 0) %obj.client.setControlObject(%col); %curVehicle8 = %client.getControlObject(); %curVehic;e8.parkingBrake = false; }~Worth a try. =)