Jump to content

Switching player DataBlock with a Keybind


michael roberts 13
 Share

Recommended Posts

Switching the datablock would mean you'd need to call from the client to the server to let the server know it needs to be changed.


So you'd have your keybind function for it, and that would have a commandToServer call in it that calls to a function on the server side. This function would call the client's player object to play an animation, and then, maybe with a schedule for a delay, switch the datablocks.


That function would look something like this then:

 

function serverCmdChangePlayer(%client)
{
   //the variables you would have to set up yourself, whereever you feel is best organized.
   //They can be stored in the client object,
   //%client.changeAnimationLength
   //Or as a global if it's going to happen a lot
   //$changeAnimationLength
 
   schedule(%changeAnimationLength, 0, "finishedChangePlayerAnim", %client);
 
   %client.player.playThread(%changeAnimation);
}
 
//Our animation should be finished now
function finishedChangePlayerAnim(%client)
{
   %client.player.datablock = myNewDatablock;
}
Link to comment
Share on other sites

I was trying to help on the other forum and was just trying to get the datablock switch to occur on key press.


I set up a new GideonPlayerData with Gideon's animations and dts and tried in a fresh 3.7


in scripts/server/commands.cs, I put at the bottom.

function serverCmdChangePlayer(%client)  
{  
   %client.player.setDatablock(GideonPlayerData);  
   echo("you are gideon");      
}

 

and tried to do :

moveMap.bindCmd(keyboard, "p","commandToServer(\'changePlayer'\);", "");

 

in default.bind.cs, but it just doesn't work. I made sure that "p" is removed from all other commands.




When I place:

moveMap.bindCmd(keyboard, "p","commandToServer(\'changePlayer'\);", "");

 

in config.cs manually it then works.




Any idea why it won't work in default.bind.cs?

Link to comment
Share on other sites

It works really well for me when I put the


moveMap.bindCmd(keyboard, "p","commandToServer(\'changePlayer'\);", "");


in the default.bind_AFX.cs file.


Did you make sure that the default.bind.cs has been executed?


Are you using the Torque 3D AFX 2.0 engine? In that case you should place the mapping in the the file I placed it in. As far as I remember then the default.bind is not executed in the AFX engine as it uses the AFX version instead.


Just some thoughts. Of course I cannot say anything for certain when I have not looked into your scripts and setup :)


Happy script hunting!


PS: Did you execute the Gideon datablock? I guess you did.

Link to comment
Share on other sites

If you have used the in-game Options dialog to change key settings you must remember to remove the game/scripts/client/config.cs file or those settings will override your changes. Just as a reminder - I forget this one occasionally...


Also, not sure if it's a direct cut/paste or a typo - look at the difference between first (original) and second (corrected) lines:

// hint - in this line the second ' is not escaped correctly
moveMap.bindCmd(keyboard, "p","commandToServer(\'changePlayer'\);", "");
// in this line it is correct
moveMap.bindCmd(keyboard, "p","commandToServer(\'changePlayer\');", "");

The default.bind.cs vehicle flip command for reference:

// The key command for flipping the car
vehicleMap.bindCmd(keyboard, "ctrl x", "commandToServer(\'flipCar\');", "");
Edited by rlranft
Link to comment
Share on other sites

FYI the config.cs file is auto-generated when you run the engine if it doesn't exist - but if it DOES exist then it's sometimes used in preference to default.bind.cs, which is annoying. It stores any changes you've made to keybinds in the options GUI.

I have deleted this file long time ago in my project(s).... I suddenly realize why :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...