Clientcmd and scope
by John Coyne · in Torque Game Engine · 08/18/2005 (4:03 am) · 7 replies
Is there a way to access player methods from a clientCmd?
So far the only way i've found goes like this:
commandToClient(%client,'FuncName',%client);
........
function clientCmdFuncName(%recipient)
{
%recipient.dump());
}
..............
Is there a better way to do this, I'd have thought that sending client once would have meant it would have access through %this or something.
So far the only way i've found goes like this:
commandToClient(%client,'FuncName',%client);
........
function clientCmdFuncName(%recipient)
{
%recipient.dump());
}
..............
Is there a better way to do this, I'd have thought that sending client once would have meant it would have access through %this or something.
About the author
#2
So far I'm planning on making both devices an item in the players inventory using whats in the FPS kit to start with.
in the case of the emp weapon, a command gets sent to the server to loop all the clients and call a clientCmd which then
checks the cloaked status of the player.
uncloaks the player if they need uncloaking.
Problem is i'm not sure how to get to the player methods to check and set the cloaked status.
08/18/2005 (3:24 pm)
I'm trying to make a cloaking device and an EMP device to shut them all down.So far I'm planning on making both devices an item in the players inventory using whats in the FPS kit to start with.
in the case of the emp weapon, a command gets sent to the server to loop all the clients and call a clientCmd which then
checks the cloaked status of the player.
uncloaks the player if they need uncloaking.
Problem is i'm not sure how to get to the player methods to check and set the cloaked status.
#3
08/18/2005 (3:39 pm)
Here's the problem though...the client should never in any way be "telling" the server anything authoritative. Instead of having the server send a command to client asking "what is your cloak status", the server should be taking care of all that information itself, and only sending client commands if it makes sense...and in the issue you describe, it doesn't. All of this checking should be done server side only, and most probably use the ghosting system to transmit the states to each appropriate client.
#4
I'm not sure I made myself clear, but I do think youve put me on the right track.
08/18/2005 (3:48 pm)
Ah, thanks for that.I'm not sure I made myself clear, but I do think youve put me on the right track.
#5
in default.bind.cs
moveMap.bindCmd(keyboard, "t", "commandToServer('use',\"EMP\");", "");
.......
in tools.cs:
datablock ItemData(EMP)
{
category = "Tools";
// Basic Item properties
shapeFile = "~/data/shapes/items/healthKit.dts"; //change this later
mass = 1;
friction = 1;
elasticity = 0.3;
pickupName = "EMP weapon";
};
function EMP::onUse(%this)
{
commandToServer('EmpEveryone');
}
..........................
and in commands.cs
function serverCmdEmpEveryone(%client)
{
//drain energy from the player for firing up the emp weapon
%client.player.setEnergyLevel(%client.player.getEnergyLevel() - (10)); //hardcoded for now
//loop all the players and EMP them if cloaked
%count = ClientGroup.getCount();
for(%i = 0; %i < %count; %i++)
{
%client = ClientGroup.getObject(%i);
if(%client.player.isCloaked())
{
//uncloak the player and drain some energy off them
%client.player.setCloaked(0);
%client.setEnergyLevel(%client.player.getEnergyLevel() - (15)); //hardcoded for now
//reset the recharge rate to a positive value
%client.player.setRechargeRate(%client.player.getDatablock().rechargeRate);
}
}
}
.....................
The cloaking code is very much the same structure, is this a better way to do things?
08/26/2005 (4:55 pm)
Ok. now i have:in default.bind.cs
moveMap.bindCmd(keyboard, "t", "commandToServer('use',\"EMP\");", "");
.......
in tools.cs:
datablock ItemData(EMP)
{
category = "Tools";
// Basic Item properties
shapeFile = "~/data/shapes/items/healthKit.dts"; //change this later
mass = 1;
friction = 1;
elasticity = 0.3;
pickupName = "EMP weapon";
};
function EMP::onUse(%this)
{
commandToServer('EmpEveryone');
}
..........................
and in commands.cs
function serverCmdEmpEveryone(%client)
{
//drain energy from the player for firing up the emp weapon
%client.player.setEnergyLevel(%client.player.getEnergyLevel() - (10)); //hardcoded for now
//loop all the players and EMP them if cloaked
%count = ClientGroup.getCount();
for(%i = 0; %i < %count; %i++)
{
%client = ClientGroup.getObject(%i);
if(%client.player.isCloaked())
{
//uncloak the player and drain some energy off them
%client.player.setCloaked(0);
%client.setEnergyLevel(%client.player.getEnergyLevel() - (15)); //hardcoded for now
//reset the recharge rate to a positive value
%client.player.setRechargeRate(%client.player.getDatablock().rechargeRate);
}
}
}
.....................
The cloaking code is very much the same structure, is this a better way to do things?
#6
Of course, there are always additional ways to skin a cat...this could be done in source code as well, but in my personal opinion the above implementation should be fine. The -only- issue I really see is if you have like 200+ clients logged in, then that loop might tie up just a bit of cycle time.
There is one design "flaw" (not really, but you need to think about it) however--you are basically letting the client send a forced command to the server--and never do any checks to see if the player using the EMP actually has an EMP, or the energy to use it if energy is required.
The reason I say that is because a server should -never- trust a client to send "game safe" information--in your serverCmdEmpEveryone you probably want to put in some checks for:
A) Does the guy really have an EMP in his inventory?
B) Does he have enough energy to use it?
This will keep "smart" hackers from doing things like opening up the console and sending the command directly, thereby spamming the server with emp hits, etc.
08/27/2005 (4:45 pm)
That actually looks like a pretty good implementation (assuming you want it to EMP -everyone-, and not just a certain radius). Implementation for that would be around a containerRadiusSearch--see the explosion of the crossbow bolt for that in the demo for an example.Of course, there are always additional ways to skin a cat...this could be done in source code as well, but in my personal opinion the above implementation should be fine. The -only- issue I really see is if you have like 200+ clients logged in, then that loop might tie up just a bit of cycle time.
There is one design "flaw" (not really, but you need to think about it) however--you are basically letting the client send a forced command to the server--and never do any checks to see if the player using the EMP actually has an EMP, or the energy to use it if energy is required.
The reason I say that is because a server should -never- trust a client to send "game safe" information--in your serverCmdEmpEveryone you probably want to put in some checks for:
A) Does the guy really have an EMP in his inventory?
B) Does he have enough energy to use it?
This will keep "smart" hackers from doing things like opening up the console and sending the command directly, thereby spamming the server with emp hits, etc.
#7
Checking the energy is something i forgot so i'll have to look at that *oops* :)
ps. I might look into using a radius, and maybe even draining a certain amount of energy for each player affected by the weapon. Maybe once i'm done i'll bundle it all into a resource :D
08/28/2005 (5:40 am)
Thanks, i was a bit concerned about people cheating. The game design is such that everyone starts off with an EMP weapon anyway and never looses it which is why i'm not checking there.Checking the energy is something i forgot so i'll have to look at that *oops* :)
ps. I might look into using a radius, and maybe even draining a certain amount of energy for each player affected by the weapon. Maybe once i'm done i'll bundle it all into a resource :D
Associate Kyle Carter