Grenade throwing
by _____ · in Torque Game Engine · 09/19/2005 (8:25 am) · 34 replies
Hi i have this code binded to key g but when i press it i get this error in console can any help?
Mapping string : throwgrenade to index 3
servercmdthrowgrenadenow:unkonwcommand
and then
in defaultbinds.cs file
Mapping string : throwgrenade to index 3
servercmdthrowgrenadenow:unkonwcommand
// ============================================================
// Project : Torque scripts
// File : ..\..\..\torque\SDK\example\starter.fps\server\scripts\Grenades.cs
// Copyright : © 2005
// Author :
// Editor : TorqueDev 1.2.2085.14342
//
// Description :
// :
// :
// ============================================================
datablock ItemData(Grenade)
{
category = "Grenades";
shapeFile = "starter.fps/data/shapes/items/healthkit.dts";
mass = 0.7;
friction = 1;
elasticity = 0.3; //how much bounce 0.1 = none, 1 = funny
repairAmount = 50;
maxDamage = 0.2;
directDamage = 30;
damageRadius = 20;
radiusDamage = 20;
areaImpulse = 200;
dynamicType = $TypeMasks::DamagableItemObjectType;
explosion = CrossbowExplosion;
fadeIn = 0;
};
function Grenade::Explode(%dataBlock, %obj)
{
echo("Grenade::Explode called");
%obj.ExplodeEventID = 0;
%obj.setDamageState(Destroyed);
%obj.schedule(99, "delete");
}
function Grenade::Damage(%this,%obj,%sourceObject, %position, %damage, %damageType)
{
echo("Grenade::Damage called");
if (%obj.ExplodeEventID)
{
cancel(%obj.ExplodeEventID);
%obj.ExplodeEventID=0;
%obj.setDamageState(Destroyed);
%obj.schedule(99, "delete");
}
}
function Grenade::onDestroyed(%data,%obj)
{
echo("Grenade::onDestroyed called");
%pos = %obj.getPosition();
radiusDamage(%obj,%pos,%data.damageRadius,%data.radiusDamage,"Grenade",%data.area
impulse);
}
function ShapeBase::throwGrenadeDB(%this,%GrenadeTypeDB,%client,%DelayToExplode)
{
//%GrenadeTypeDB = the datablock type for this grenade
//%client = client object
//%time = time in milliseconds before explode
//Check time is not silly or negative
if (%DelayToExplode < 1)
%DelayToExplode = 500;
echo("ShapeBase::throwGrenade grenade, creating item");
%item = new Item()
{
dataBlock = %GrenadeTypeDB;
rotation = "1 0 0 " @ (getRandom() * 360);
sourceObject= %client.player;
client = %client;
ExplodeEventID=0;
};
//call the more general throwObject
%this.throwObject(%item);
//set detonantion delay
%item.ExplodeEventID = %GrenadeTypeDB.schedule(%DelayToExplode, "Explode",%item);
//make sure we tidy up :)
MissionCleanup.add(%item);
}
function ShapeBase::throwObject(%this,%obj){
// Throw the given object in the direction the shape is
// looking. The force values are hardcoded...
echo("ShapeBase::throwObject grenade, getting direction");
%eye = %this.getEyeVector();
%vec = vectorScale(%eye, 20);
// Add a vertical component to give the item a better arc
%dot = vectorDot("0 0 1",%eye);
if (%dot < 0)
%dot = -%dot;
%vec = vectorAdd(%vec,vectorScale("0 0 7",1 - %dot));
// Add the shapes velocity
%vec = vectorAdd(%vec,%this.getVelocity());
// Set the objects position and initial velocity
%pos = getBoxCenter(%this.getWorldBox());
%obj.setTransform(%pos);
echo("ShapeBase::throwObject grenade, Applying impulse");
// Since the object is thrown from the center of the
// shape, the object needs to avoid colliding with it's
// thrower.
%obj.setCollisionTimeout(%this);
%obj.applyImpulse(%pos,%vec);
}
moveMap.bindCmd(keyboard, "g", "commandToServer(\'throwGrenadeNow\');", "");and then
moveMap.bindCmd(keyboard, "g", "commandToServer(\'throwGrenadeNow\');", "");
in defaultbinds.cs file
About the author
#2
09/19/2005 (8:43 am)
Nope still thew same thanks any way
#3
?
09/19/2005 (8:49 am)
So you do have a function function serverCmdthrowGrenadeNow(%client)
{
//whatever you put in here to throw the grenade
}?
#4
09/19/2005 (9:47 am)
Repost..
#5
09/19/2005 (9:51 am)
No i do not
#6
its looking for this function on the server "servercmdthrowgrenadenow"
:)
09/19/2005 (9:52 am)
That is what its looking for... re-look at your error messageQuote:
Mapping string : throwgrenade to index 3
servercmdthrowgrenadenow:unkonwcommand
its looking for this function on the server "servercmdthrowgrenadenow"
:)
#7
Ok so you want to tell the server to run a command from a client machine... you do this with "commandToServer()" and pass it the function name and any values to pass into it...
in your case you did
Now when the server receives this (in a single palyer situation the same as the client machine) looks for a function with the name passed with a "ServerCmd" added to the front
so
"ServerCmd" + "throwGrenadeNow"
thats what its looking for, since you have no such function it gives you an error for uknown command and does nothing
09/19/2005 (10:16 am)
Heres a quick run down of using commandToServer();Ok so you want to tell the server to run a command from a client machine... you do this with "commandToServer()" and pass it the function name and any values to pass into it...
in your case you did
commandToServer('throwGrenadeNow');Now when the server receives this (in a single palyer situation the same as the client machine) looks for a function with the name passed with a "ServerCmd" added to the front
so
"ServerCmd" + "throwGrenadeNow"
funciton ServerCmdthrowGrenadeNow(%client)
{
}thats what its looking for, since you have no such function it gives you an error for uknown command and does nothing
#8
basiclly call another function with this fucntion?
09/19/2005 (10:33 am)
So could i say do thisfunciton ServerCmdthrowGrenadeNow(%client)
{
function ShapeBase::throwObject(%this,%obj,%client)
}basiclly call another function with this fucntion?
#9
basiclly call another function with this fucntion?
09/19/2005 (10:46 am)
So could i say do thisfunciton ServerCmdthrowGrenadeNow(%client)
{
function ShapeBase::throwObject(%this,%obj,%client)
}basiclly call another function with this fucntion?
#10
then you have to specify an object
09/19/2005 (10:49 am)
Almost... I'd say try thisfunciton ServerCmdthrowGrenadeNow(%client)
{
%client.player.throwObject(%obj);
}then you have to specify an object
#11
09/19/2005 (10:50 am)
Hmmm dude are you sure about what you saying to me? any back up what hes saying
#12
you creating a function within a function
it would be
ShapeBase.throwObject(%this,%obj,%client)
instead of
function ShapeBase::throwObject(%this,%obj,%client)
also you don't pass %this
"function ShapeBase::throwObject(%this, %obj)"
the %this is automatically passed as the object the function is attached to... in this case an instance of ShapeBase... not ShapeBase itself
so you need to take %this out of
(%this,%obj,%client)
otherwise %obj will be whatever you pass in %this
also throwObject doesn't take a third parameter ( a second for that matter either )
so in
(%this,%obj,%client)
%client is invalid
09/19/2005 (10:55 am)
Not posotive the above will work, seemingly it should though I haven't tested it... in your code snippet there are some major errors thoughfunction ServerCmdthrowGrenadeNow(%client)
{
function ShapeBase::throwObject(%this,%obj,%client)
}you creating a function within a function
it would be
ShapeBase.throwObject(%this,%obj,%client)
instead of
function ShapeBase::throwObject(%this,%obj,%client)
also you don't pass %this
"function ShapeBase::throwObject(%this, %obj)"
the %this is automatically passed as the object the function is attached to... in this case an instance of ShapeBase... not ShapeBase itself
so you need to take %this out of
(%this,%obj,%client)
otherwise %obj will be whatever you pass in %this
also throwObject doesn't take a third parameter ( a second for that matter either )
so in
(%this,%obj,%client)
%client is invalid
#13
09/19/2005 (11:04 am)
Wow,have to read this over a couple time more to totaly understand what you said but i think im getting that i cant have a function in a function and i cant use %this with A %obj bleh.....computer games they rock hehe thanks man lets just put the code in and see if it works hehe
#14
09/19/2005 (11:07 am)
Nope maybe this will help man www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7075
#15
That was posted by someone in there
which is very similar to what I was guessing would work :)
09/19/2005 (11:11 am)
Yeahfunction serverCmdthrowGrenadeNow(%client)
{
%client.player.throwGrenadeDB(Grenade,%client,5);
}That was posted by someone in there
which is very similar to what I was guessing would work :)
#16
(missed a ";")
though use the above function
09/19/2005 (11:11 am)
I had a typo in my code it should be (missed a ";")
funciton ServerCmdthrowGrenadeNow(%client)
{
%client.player.throwObject(%obj);
}though use the above function
#17
09/19/2005 (11:44 am)
Noooooooooo,this is getting frustrating
#18
09/19/2005 (1:28 pm)
Come on guys how do i get my character to throw a grenade? please tell me
#19
09/19/2005 (1:28 pm)
Lol :D
#20
09/19/2005 (1:52 pm)
Actually Matt you spelled "function" wrong in that last code block. :P
Torque 3D Owner Matthew Langley
Torque
After a -very- quick look it seems you might need that function call "throwGrenadeDB()"