Enemy Kill Message
by Stephen · in Torque 3D Beginner · 03/14/2014 (9:25 pm) · 8 replies
I would like to add a message for the player to let them know they have killed an enemy like in current FPS genre. Here's a Battlefield 4 example screenshot.
I'm not sure where to start. Any help would be great.
I'm not sure where to start. Any help would be great.
#2
03/14/2014 (9:39 pm)
I understand what you are talking about but I'm not sure how to go about the script. I have added the GuiMLTextCtrl to the playGui.gui but that's it.
#3
Anyways, do you happen to know how to use the commandToClient function in TorqueScript? It allows you to send a remote reliable data command to a specific client.
When the client receives it, it parses it with adding the prefix clientCmd to the function. Here's what I'm talking about, sometimes showing code helps explain it (sorry I'm a terrible explainer!)
Server code:
This will have to be added where the player is killed. What you will have to determine (as i do not know how the scripts work) is what client actually killed the enemy. %client is the client object that is part of the gameconnection class.
client code:
03/14/2014 (9:49 pm)
I don't know how the fps scripts work exactly, as my game is not a fps game that I've been developing, so I kinda just stripped them from my game hehe.Anyways, do you happen to know how to use the commandToClient function in TorqueScript? It allows you to send a remote reliable data command to a specific client.
When the client receives it, it parses it with adding the prefix clientCmd to the function. Here's what I'm talking about, sometimes showing code helps explain it (sorry I'm a terrible explainer!)
Server code:
This will have to be added where the player is killed. What you will have to determine (as i do not know how the scripts work) is what client actually killed the enemy. %client is the client object that is part of the gameconnection class.
commandToClient(%client, 'PlayerKilled', "Enemy Killed 100.");
client code:
function clientCmdPlayerKilled(%message) {
// set text and make it appear on the canvas
%gui_control.setText(%message);
%gui_control.setVisible(1);
// hide message in 1 second
cancel($killMessageSched);
$killMessageSched = %gui_control.schedule(1000, setVisible, false);
}
#4
I'm not sure where to place the "commandToClient" at. So I placed it in "function GameCore::incKills" but I'm getting these console errors.
03/14/2014 (10:14 pm)
So I have placed this function in "scripts/client/client.cs".function clientCmdPlayerKilled(%message) {
// set text and make it appear on the canvas
%gui_control.setText(%message);
%gui_control.setVisible(1);
// hide message in 1 second
cancel($killMessageSched);
$killMessageSched = %gui_control.schedule(1000, setVisible, false);
}I'm not sure where to place the "commandToClient" at. So I placed it in "function GameCore::incKills" but I'm getting these console errors.
scripts/client/client.cs (351): Unable to find object: '' attempting to call function 'setText' scripts/client/client.cs (352): Unable to find object: '' attempting to call function 'setVisible' scripts/client/client.cs (356): Unable to find object: '' attempting to call function 'schedule'
#5
03/14/2014 (11:51 pm)
Have a search for 'BottomPrint' in the scripts. Pretty sure the core/ scripts have functions for printing a timed message to the screen. You'd just need to make it look pretty.
#6
It displays the message but sadly it displays it for everyone. How to make it show for only the player who got the kill?
03/15/2014 (12:07 am)
So I added this to the "GameCore::incKills"bottomPrintAll("Enemy Killed", 1, 1);It displays the message but sadly it displays it for everyone. How to make it show for only the player who got the kill?
#7
You shouldn't need what Dan was saying as long as you use a new GUI control in playGUI which you said you already have. + the bottom print is ugly as heck. I think he was pointing you in the direction of functionality, correct me if I am wrong Dan as I do not want to put words in your mouth :P
The errors you are getting, is because %gui_control was a placeholder that I put there. Replace that with your GUI control's name in playGUI. Sorry If i didn't make that clear Stephen.
Post back if you have any more problems :)
It is necessary to understand how the remote commands in TS work for multiplayer, if anything is unclear about that post back too, I can try to explain it.
Jeff
03/15/2014 (8:06 am)
GameConnection::incScore() should be fine for the commandToClient, looked at the code.You shouldn't need what Dan was saying as long as you use a new GUI control in playGUI which you said you already have. + the bottom print is ugly as heck. I think he was pointing you in the direction of functionality, correct me if I am wrong Dan as I do not want to put words in your mouth :P
The errors you are getting, is because %gui_control was a placeholder that I put there. Replace that with your GUI control's name in playGUI. Sorry If i didn't make that clear Stephen.
Post back if you have any more problems :)
It is necessary to understand how the remote commands in TS work for multiplayer, if anything is unclear about that post back too, I can try to explain it.
Jeff
#8
Perhaps start here and experiment to find different ways of doing this.
03/15/2014 (9:11 am)
Call bottomPrint() - then it sends the message to the specified client:function bottomPrint( %client, %message, %time, %lines )
{
if( %lines $= "" || ((%lines > 3) || (%lines < 1)) )
%lines = 1;
commandToClient( %client, 'BottomPrint', %message, %time, %lines );
}It's in core/scripts/server/centerprint.cs - you can use it "out of the box."Perhaps start here and experiment to find different ways of doing this.
Torque 3D Owner JeffH
A quick and easy way to do this would be to create a GuiMLTextCtrl so that you can format the text, make it's visible property to 0 by default. Then, when a kill is registered on the server, do a commandToClient and pass the text to be rendered or a flag of some sort so the game knows what to display. Then, set the text and display the gui control. To hide the Gui control, use the schedule method like this inside of your commandToClient's clientCMD function:
The reason why we cancel the schedule before we schedule, is to prevent a "race condition" with the script. For example, lets say you have your time delay set to 1000 ms. Say within 200ms after getting a kill, you get another one. What will happen is that 2 commands would be sent across the network.
So, it would schedule *both* of them, causing it to hide prematurely.