KeyMap setting for each player type after spawn
by Demolishun · in Torque Game Engine · 07/23/2006 (4:11 pm) · 4 replies
I am trying to change the keymap for a player after they spawn as a player type. For instance, I have two player types with different keymaps because one will have a turret. What is the best place to do this? This is what I have tried so far:
I call this from game.cs on the server side inside of the createPlayer function:
The engine acts as though this is too soon. Is there a better place to do this? It gets the message, but does not change the keymap.
function clientCmdSetMechaMap(%val)
{
error("clientCmdSetMechaMap: "@%val);
if(%val)
{
mechaMap.push();
$pref::Input::mechaMap = true;
}
else
{
mechaMap.pop();
$pref::Input::mechaMap = false;
}
}I call this from game.cs on the server side inside of the createPlayer function:
// Notify player of client type to change keymap
if(%ptype $= "mechaplayer") // rott
commandToClient(%this,'SetMechaMap', 1);
else
commandToClient(%this,'SetMechaMap', 0);The engine acts as though this is too soon. Is there a better place to do this? It gets the message, but does not change the keymap.
About the author
I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67
#2
Maybe you could remove the code from onMissionDownloadComplete and just put it into cmdSetPlayerType()
something like this:
edit: Forgot to mention, createPlayer is the function that gets called only after we know everything is 'up'
07/23/2006 (11:33 pm)
I think this is a just ever-so-slightly backwards approach. As far as my understanding, onMissionDownloadComplete() gets called sometime BEFORE gameConnection::createPlayer().Maybe you could remove the code from onMissionDownloadComplete and just put it into cmdSetPlayerType()
something like this:
function clientCmdSetPlayerType(%val)
{
error("clientCmdSetPlayerType: "@%val);
$pref::Input::playerType = %val;
if($pref::Input::playerType $= "mechaplayer")
{
mechaMap.push();
$pref::Input::mechaMap = true;
}
else
{
mechaMap.pop();
$pref::Input::mechaMap = false;
}
}edit: Forgot to mention, createPlayer is the function that gets called only after we know everything is 'up'
#3
07/25/2006 (6:54 pm)
That is what I did the first time and it did not work either. Another thing is the function described in the second post gets the info and has to be happening after createPlayer in the game.cs script on the server. Maybe we are talking about a different createPlayer?
#4
Inside PlayGui::onWake function after moveMap.push:
Inside PlayGui::onSleep after Canvas.popDialog:
Ummm, it kind of makes sense to place it where the standard moveMap is getting set. Doh! I mean, I knew that.
07/25/2006 (8:04 pm)
Alright, found what I was looking for in starter.fps/client/scripts/playGui.cs.Inside PlayGui::onWake function after moveMap.push:
// just update the action map here
moveMap.push();
// try putting keymap stuff here
error("PlayGui::onWake: "@$pref::Input::playerType);
if($pref::Input::playerType $= "mechaplayer")
{
mechaMap.push();
$pref::Input::mechaMap = true;
}
else
{
mechaMap.pop();
$pref::Input::mechaMap = false;
}Inside PlayGui::onSleep after Canvas.popDialog:
Canvas.popDialog( MainChatHud );
// pop mecha keymap if used
if($pref::Input::mechaMap)
{
mechaMap.pop();
$pref::Input::mechaMap = false;
} Ummm, it kind of makes sense to place it where the standard moveMap is getting set. Doh! I mean, I knew that.
Torque Owner Demolishun
DemolishunConsulting Rocks!
function onMissionDownloadComplete() { // Client will shortly be dropped into the game, so this is // good place for any last minute gui cleanup. // try putting keymap stuff here error("onMissionDownloadComplete: "@$pref::Input::playerType); if($pref::Input::playerType $= "mechaplayer") { mechaMap.push(); $pref::Input::mechaMap = true; } else { mechaMap.pop(); $pref::Input::mechaMap = false; } }I see the error call, but the keymap is unchanged.
I just went in a ran onMIssionDownloadComplete and it switches the keymap. So this getting called and it does work, but the timing is still wrong.
Oh yeah, this is getting called here:
function clientCmdSetPlayerType(%val) { error("clientCmdSetPlayerType: "@%val); $pref::Input::playerType = %val; }This is called by this on the server when the server creates the client object:
Just so you know I think I am keeping the client/server interface clean.
All I can think to do now is schedule the event, but that seems to be a hack. Ins't there any functions called when we "know" everthing is "up"?