Jump to content

Switching player DataBlock with a Keybind

michael roberts 13

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,
   //Or as a global if it's going to happen a lot
   schedule(%changeAnimationLength, 0, "finishedChangePlayerAnim", %client);
//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)  
   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

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

Join the conversation

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

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.

  • Create New...