pickleplayer Posted July 23, 2017 Share Posted July 23, 2017 (edited) Right now, I'm trying to match the control setup from my single-player version of this mod, but I've run into some issues. The first problem I ran into is that getting input from clients via the keyboard couldn't work the same way, as "TheInput:IsKeyDown(key)" couldnt return the value from the client. I got around this by simply using RPC handlers to send key-press events to the server, and just threw tags on the events like "keyup" and "keydown" that let me check if the key was being held or not. And I did the same thing for controllers, which also worked well. They looked something like this (though this is a generalized example) local function special1(player) if not player:HasTag("spc_key_dwn") then --DO THE STUFF player:AddTag("spc_key_dwn") else player:RemoveTag("spc_key_dwn") end end AddModRPCHandler(TUNING.MODNAME, "special1erc", special1) GLOBAL.TheInput:AddControlHandler(specialc, function() SendModRPCToServer(MOD_RPC[TUNING.MODNAME]["special1erc"]) end) And that works fine for getting button-down values from clients. HOWEVER; now I'm trying to get the analog values of controller thumbsticks, and I'm a little stumped on how I would go about doing that. Analog values can be gotten with "TheInput:GetAnalogControlValue(CONTROL_MOVE_RIGHT)" which returns a value from 0.0 to 1.0 depending on how far you are holding the thumbstick to the right, where 0 would be centered, 0.5 would be halfway to the right, and 1 would be all the way to the right. But unlike keys and buttons, there are not events for specific events for analog values being reached. (Well, technically there are, but it's built in, and it's no different than a button-press event that is pushed when the analog value reaches 0.5 or something like that) But I'm looking to get specific analog values from the client, other than 0.5. SHORT VERSION; I'm trying to find a way for the server to get a client's analog control value. I have tried throwing print("Analog value", TheInput:GetAnalogControlValue(CONTROL_MOVE_RIGHT)) into that rpc keypress function, but it still always returns as 0 on the dedicated server. Edited July 23, 2017 by pickleplayer Link to comment Share on other sites More sharing options...
ZupaleX Posted July 23, 2017 Share Posted July 23, 2017 (edited) Putting in the RPC TheInput:GetAnalogControlValue(CONTROL_MOVE_RIGHT) cannot work as the RPC is executed on the server side and you want the client value. Why don't you pass the analog value as an argument in your RPC and then inside the RPC check if it matches what you want to have. If it does then perform the action, if not then do nothing? Edited July 23, 2017 by ZupaleX Link to comment Share on other sites More sharing options...
pickleplayer Posted July 24, 2017 Author Share Posted July 24, 2017 4 hours ago, ZupaleX said: Putting in the RPC TheInput:GetAnalogControlValue(CONTROL_MOVE_RIGHT) cannot work as the RPC is executed on the server side and you want the client value. Why don't you pass the analog value as an argument in your RPC and then inside the RPC check if it matches what you want to have. If it does then perform the action, if not then do nothing? Oh!! For some reason, I have always been under the impression that you couldn't pass anything else in RPCs besides "player" which is automatically passed in. (I think I read that somewhere on the forums, but I could have read it wrong) But this changes everything!! I think this actually solves more than just one of my problems! So now I can just throw the AnalogControlValue on to the end like this to pass it into the function GLOBAL.TheInput:AddControlHandler(right, function() SendModRPCToServer(MOD_RPC[modname]["right1c"], GLOBAL.TheInput:GetAnalogControlValue(GLOBAL.CONTROL_MOVE_RIGHT)) end) And it works like a charm! Thanks again! Link to comment Share on other sites More sharing options...
ZupaleX Posted July 24, 2017 Share Posted July 24, 2017 You can pass as many arguments you want to the function called by the RPC. Just slam them at the end. If you look inside the lua scripts where these functions to call the RCP and whatnot are defined, you will see them defined with ... as the arguments at the end. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now