michael roberts 13 Posted August 1, 2015 Share Posted August 1, 2015 Hey Everyone, Michael here and I've got a question for you.How do I implement a key bind to Switch the player from one data block to another while in game.I also wanted to know if i could play an animation before the data block switch to create a more dramatic effect 8-) thanks in advance,Michael Roberts ;) Quote Link to comment Share on other sites More sharing options...
JeffR Posted August 6, 2015 Share Posted August 6, 2015 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; } Quote Link to comment Share on other sites More sharing options...
Jason Campbell Posted August 7, 2015 Share Posted August 7, 2015 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.7in 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? Quote Link to comment Share on other sites More sharing options...
rlranft Posted August 8, 2015 Share Posted August 8, 2015 (edited) 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 August 10, 2015 by rlranft Quote Link to comment Share on other sites More sharing options...
buckmaster Posted August 10, 2015 Share Posted August 10, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.