Unusual Weapon
by Luke Griffin · in Torque 3D Professional · 03/04/2011 (10:24 am) · 3 replies
Hi
I am trying to make a bit of a strange weapon at the moment and I've hit a brick wall. First I will describe what I'm doing. First off I'm using the Game Mechanics pack for its usable items, such as doors and switches. I have duplicated the usable scripts and have successfully created a duplicate use function that I would like to use on my weapon item. I would like to make a pda that can use the item in front of you "using my alternate use function", a weapon that basically uses any usable item that I create in the level editor. I have gone through the weapon code for the rocketlauncher and blastergun ect, and I have no idea how I can get it to run my use function on fire. For now I would like to try and get it opening a basic door like a remote control using the stock use function and then worry about getting mine working with it later. Bit of a strange problem but if anyone has any ideas, it would really help.
I am trying to make a bit of a strange weapon at the moment and I've hit a brick wall. First I will describe what I'm doing. First off I'm using the Game Mechanics pack for its usable items, such as doors and switches. I have duplicated the usable scripts and have successfully created a duplicate use function that I would like to use on my weapon item. I would like to make a pda that can use the item in front of you "using my alternate use function", a weapon that basically uses any usable item that I create in the level editor. I have gone through the weapon code for the rocketlauncher and blastergun ect, and I have no idea how I can get it to run my use function on fire. For now I would like to try and get it opening a basic door like a remote control using the stock use function and then worry about getting mine working with it later. Bit of a strange problem but if anyone has any ideas, it would really help.
#2
scripts\server\logickingMechanics\Player.cs
------------------------------------------------------------------------
function Player::checkObjectsForPDAUse(%this)
{
%eyeVectri = %this.getEyeVector();
%startPos = VectorAdd(%this.getEyePoint(), VectorScale(%eyeVectri, 0.2));
%endPos = VectorAdd(%startPos, VectorScale(%eyeVectri, $Player::useTraceDist));
%this.PDAUseTarget = ContainerRayCast(%startPos, %endPos, $TypeMasks::ShapeBaseObjectType, %this);
%this.PDAUseTarget = getWord(%this.PDAUseTarget, 0);
//Make usable Icon on gui visible or not visible
if(%this.PDAUseTarget != 0 && %this.PDAUseTarget.getFieldValue("PDAusable") == true)
{
commandToClient(%this.client, 'updatePDAUseIcon', true);
return %this.PDAUseTarget;
}
else
{
commandToClient(%this.client, 'updatePDAUseIcon', false);
}
}
function serverCmdPDAUseObj(%client, %buttonState, %additional)
{
%player = %client.player;
// doing an additional ray cast check on the server to prevent possibility of cheating
%target = %player.checkObjectsForPDAUse();
if(isObject(%target))
{
%target.use(%player, %buttonState, %additional);
}
}
scripts\client\logickingMechanics\init.cs
------------------------------------------------------------------------
function PDAUseObject(%flg)
{
commandToServer('PDAUseObj', %flg);
}
function clientCmdUpdatePDAUseIcon(%isPDAUsable)
{
if(%isPDAUsable)
{
crossHair.setVisible(false);
PDAuseCrossHair.setVisible(true);
}
else
{
crossHair.setVisible(true);
PDAuseCrossHair.setVisible(false);
}
}
scripts\client\config.cs
------------------------------------------------------------------------
moveMap.bind(keyboard, "]", PDAUseObject);
------------------------------------------------------------------------
Ive attempted putting the "commandToServer('PDAUseObj', %flg);" in the weapons onfire callback, but that didnt work.
03/04/2011 (12:34 pm)
At the moment I already have the raycast set up and the function working using a key binding:scripts\server\logickingMechanics\Player.cs
------------------------------------------------------------------------
function Player::checkObjectsForPDAUse(%this)
{
%eyeVectri = %this.getEyeVector();
%startPos = VectorAdd(%this.getEyePoint(), VectorScale(%eyeVectri, 0.2));
%endPos = VectorAdd(%startPos, VectorScale(%eyeVectri, $Player::useTraceDist));
%this.PDAUseTarget = ContainerRayCast(%startPos, %endPos, $TypeMasks::ShapeBaseObjectType, %this);
%this.PDAUseTarget = getWord(%this.PDAUseTarget, 0);
//Make usable Icon on gui visible or not visible
if(%this.PDAUseTarget != 0 && %this.PDAUseTarget.getFieldValue("PDAusable") == true)
{
commandToClient(%this.client, 'updatePDAUseIcon', true);
return %this.PDAUseTarget;
}
else
{
commandToClient(%this.client, 'updatePDAUseIcon', false);
}
}
function serverCmdPDAUseObj(%client, %buttonState, %additional)
{
%player = %client.player;
// doing an additional ray cast check on the server to prevent possibility of cheating
%target = %player.checkObjectsForPDAUse();
if(isObject(%target))
{
%target.use(%player, %buttonState, %additional);
}
}
scripts\client\logickingMechanics\init.cs
------------------------------------------------------------------------
function PDAUseObject(%flg)
{
commandToServer('PDAUseObj', %flg);
}
function clientCmdUpdatePDAUseIcon(%isPDAUsable)
{
if(%isPDAUsable)
{
crossHair.setVisible(false);
PDAuseCrossHair.setVisible(true);
}
else
{
crossHair.setVisible(true);
PDAuseCrossHair.setVisible(false);
}
}
scripts\client\config.cs
------------------------------------------------------------------------
moveMap.bind(keyboard, "]", PDAUseObject);
------------------------------------------------------------------------
Ive attempted putting the "commandToServer('PDAUseObj', %flg);" in the weapons onfire callback, but that didnt work.
#3
03/06/2011 (4:54 am)
OK after playing around with it, I managed to get it to work. I tried to duplicate only the function WeaponImage::onFire insted of all the WeaponImage functions. Its working now.
Associate Michael Hall
Distracted...