Getting control object server side
by Lukas Joergensen · in Torque Game Engine · 04/08/2009 (2:03 am) · 1 replies
I am trying to create a projectile with this code:
It obviously have something to do with the %client
So heres the default bind.cs code and server cmd code
In default.bind.cs
In spellcommands.cs
In dospellserver.cs
in dospellclient.cs
So what i really wanna know is how do i get the %client.getControlObject(); to work server side and have i done anything wrong?
//From dospellclient.cs
//PROJECTILE
%clientplayer = %client.getcontrolobject();
if(getWord.castrayfromplayer = "setlifetime")
{
%setlifetime = true;
}
else{
%wordcount = getWordCount(castrayfromplayer(%client));
%start = getWords(castrayfromplayer(%client), 4, 6);
%point = getWords(castrayfromplayer(%client), 0, 3);
}
%bullet = new Projectile() {
dataBlock = SampleSpellProjectile;
//initialVelocity = %muzzleVelocity;
initialPosition = %start;
//sourceObject = %client.player;
//sourceSlot = mount0;
//client = %client;
};but getting this errorQuote:And in my SpellExplosion.cs
GameOne/client/dospellclient.cs (8): Unable to find object: '' attempting to call function 'getTransform'
GameOne/client/dospellclient.cs (16): Unable to find object: '' attempting to call function 'getEyeVector'
GameOne/client/dospellclient.cs (46): Unable to find object: '' attempting to call function 'getControlObject'
//A lot of Datablocks and then this
%player = %client.player;
%start = %client.player.getEyePoint();
%rayLength = 1000;
%rayDirection = VectorScale(%player.getEyeVector(), %rayLength);
%end = VectorAdd(%start, %rayDirection);
$TypeMasks::ShapeBaseObjectType;
%rayInfo = ContainerRayCast(%start, %end, $TypeMask::StaticObjectType |
$TypeMask::InteriorObjectType |
$TypeMask::WaterObjectType |
$TypeMask::ShapeBaseObjectType |
$TypeMask::StaticShapeObjectType |
$TypeMask::ItemObjectType |
$TypeMask::TerrainObjectType |
$TypeMask::StaticTSObjectType , %player);
if (getWordCount(%rayInfo))
{
%object = getWord(%rayInfo, 0);
%point = getWords(%rayInfo, 1, 3);
%normal = getWords(%rayInfo, 4, 6);
%return = %point + %start;
return %return;
}
else
{
return "setlifetime";
}Quote:
GameOne/server/SpellExplosion.cs (216): Unable to find object: '' attempting to call function 'getEyePoint'
GameOne/server/SpellExplosion.cs (219): Unable to find object: '' attempting to call function 'getEyeVector'
GameOne/client/dospellclient.cs (65): Register object failed for object (null) of class Projectile
It obviously have something to do with the %client
So heres the default bind.cs code and server cmd code
In default.bind.cs
//------------------------------------------------------------------------------
// Spell Functions
//------------------------------------------------------------------------------
//samplespell
function castSpell(%val)
{
if(%val)
{
commandToServer('DoSpell');
}
}
//------------------------------------------------------------------------------
// Spell Bindings
//------------------------------------------------------------------------------
moveMap.bind(keyboard, "ctrl s", castSpell);In spellcommands.cs
// Call the DoSpell function
function serverCmdDoSpell(%this,%client)
{
tellclientsdoSpell("50",%client,3);
}In dospellserver.cs
//Execute doSpell on all clients
function tellclientsdoSpell( %radius , %client , %type )
{
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
{
%someClient = ClientGroup.getObject(%clientIndex);
commandToClient( %someClient , 'DoSpell' , %radius , %client , %type );
}
}in dospellclient.cs
function clientCmdDoSpell(%radius,%client,%type)
{
%radiusDamage = 8.0;
%pos = %client.player.getTransform();
%x = getWord(%pos, 0);
%y = getWord(%pos, 1);
%z = getWord(%pos, 2);
// adjust z value a bit...
%z += 2.0;
%finalPos = %x SPC %y SPC %z;
%eye = %client.player.getEyeVector();
%vec = vectorScale(%eye, 20);
%finalPos = vectorAdd(%finalPos, %vec);
switch$(%type)
{
case1:
//some code
case2:
//some code
case3:
//Look at top //PROJECTILE code
default:
//some code
}So what i really wanna know is how do i get the %client.getControlObject(); to work server side and have i done anything wrong?
About the author
IPS Bundle available at: https://www.winterleafentertainment.com/Products/IPS.aspx
Torque Owner Lukas Joergensen
WinterLeaf Entertainment
Solved the problem
I just solved this problem: servercmd function didn't take %this as first argument so the code should look like this:// Call the DoSpell function function serverCmdDoSpell(%client) { tellclientsdoSpell("50",%client,3); }