Game Development Community

Changing player data block with a keybind

by Michael Roberts 13 · in Torque 3D Beginner · 07/27/2015 (10:53 am) · 10 replies

Hey everyone im back with another question.How do i change the player data block with a key bind instead of a trigger?
And also if it is possible to add an animation before the data block is switched

About the author

13 year old teen,n00b scriptor but skillful in 3d artists.Gamer 4 life


#1
07/27/2015 (1:07 pm)
Hi Master Roberts , hope you are doing well ,
Well , Id say , decide where you want to place the function , Id guess the player CS , decide where you want to place the keybind and whether it will be more temporary than permanent and may need to be binded/unbinded regularly . Then just use objectshandle.setDataBlock() . ?? maybe
In the playerCS you should be able to just use this.getcontrolobject() to get the ID if you need to . ?? maybe . Anyway Good Luck To You and hang in there . BTW sorry if its all completely wrong :)
#2
07/27/2015 (8:27 pm)
Hi Michael,

I copied Gideon and animation folders from the old FPS tutorial to the shape/actors folder.

I opened the datablock editor and created a new PlayerData and named it GideonPlayerData

In client/default.bind.cs, I added to the bottom.

function serverCmdChangePlayer(%client)
{
   %client.player.setDatablock(GideonPlayerData);
   echo("you are gideon");    
}
moveMap.bind( keyboard, p, changePlayer );

Make sure you edit out any other usage of 'p' in client/config.cs

Seems to work. You could use it to toggle or cycle through different datablocks with a little tinkering.

Hope that helps.
#3
07/28/2015 (9:40 am)
hehe THX Michael , that was actually pretty cool . I used it to change the playerDataBlock to a copy in which i only changed the shape file to that orc guy ! LOL
However , i did it the way that Mr Cambell has suggested . I was in a hurry to see it :) But , if you have that obj ID you can pass it to the function using the keymapCmd.bind , Ive only done that using a Global variable and passed it to a function in the playerCS , Im going to try a few more times to do this all within the player CS and just use local variables . Ah the freedom of piddling aroundness !:)

BACK ON TOPIC .
Of course youll probably need to change the name "playerkeymap" and the "L" key , Function name blahblahblah :)

//----control/client/config.CS---or--whatever--it--is--in--T3D----------
playerkeymap.bindCmd(keyboard, "l","CommandtoServer(\'switchDB\');","");
//----------------------------------------------------------------------

//----control/server/server.CS---or--whatever--it--is--in--T3D----------
function serverCmdswitchDB(%this)
{
echo("THIS = " @ %this);
%this.getcontrolobject().setdatablock(NewDBName);
}
//----------------------------------------------------------------------

I liked this Thx. And >I<...that means be careful) think there should be many a G'Zillion ways to actually implement its use . I had actually changed the wheelSpringDataBlocks but ,,, well it was pretty cool actually . Anyway , Cool . Good Luck and Have a Nice Day

#4
07/29/2015 (1:28 pm)
hey guys thanks for the help but i have one problem,i cant find my config.cs file!
#5
07/29/2015 (2:21 pm)
I think that's ok. Does it still work for you?
#6
07/29/2015 (2:29 pm)
no :(
#7
07/29/2015 (5:10 pm)
Master Roberts ,
be sure to backup your files . have subfolders in the folders where the files you are working on are and place copies in them .

remove the keybindCSDSO and configCSDSO files files from the folder (to back up folder). thats just to be safe and not permantly delete your dso then be stuck only with a messed up CS .

place an echo message inside the swithchDataBlock function to see if the keybind is working .
something like echo("server/serverCS- switchblock function- line xxx");
echo("key working");
retry the game .

be sure and check the log to see if your edited files have compiled and loaded .
Have a Nice Day !

#8
08/01/2015 (8:18 am)
is there any other way to implement this keybind so it works for me?
#9
08/01/2015 (11:45 am)
Master Roberts ,
May I ask how youd like for it to work for you ?
BTW dont expect much from me I am not very knowledgeable and just piddle around with TGE .

But i considered the different approaches to making the function of switching dataBlocks accessible , from an ingame perspective , interesting and gamey :) You can approach it a number of ways , I guess , depending on how your game is structured .

and for instance you can put keybinds and unbinds just about anywhere , inside other functions , and change keymaps when you change datablocks etc etc etc .

But , hold up a sec . Did things not work with the above suggestions ?
Are you familiar with T3D.org ? If not then check it out ASAP . I think that they are a little more active there with far more knowledgeable help than I can provide . I dont mind trying to help at all , but for your own good youll need better advice than mine .
Anyway , Have A Nice Day young Master Roberts .
#10
08/01/2015 (1:06 pm)
Thanks for the info james ill check it out