Mario384 Posted June 10, 2015 Share Posted June 10, 2015 So basically, I have two buttons that make a player using a different stategraph sleep and wake up.local function OnKeySleep(inst, data) if data.inst == ThePlayer then if data.key == KEY_O then if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.SLEEP):Do() -- Since we are the server, do the action on the server. else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.SLEEP.code, inst, ACTIONS.SLEEP.mod_name) end end endendlocal function OnKeyWakeup(inst, data) if data.inst == ThePlayer then if data.key == KEY_P then if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.WAKEUP):Do() -- Since we are the server, do the action on the server. else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.WAKEUP.code, inst, ACTIONS.WAKEUP.mod_name) end end endendAnd this is in modmain:local SLEEP = GLOBAL.Action()SLEEP.str = "Sleep"SLEEP.id = "SLEEP"SLEEP.fn = function(act) if not act.target:HasTag("busy") or act.target:HasTag("leif") then act.target.sg:GoToState("sleep") act.target:AddComponent("healthRegen") else if act.target:HasTag("leif") then act.target.sg:GoToState("sleeping") act.target:AddComponent("healthRegen")endendendAddAction(SLEEP) local WAKEUP = GLOBAL.Action()WAKEUP.str = "Wakeup"WAKEUP.id = "WAKEUP"WAKEUP.fn = function(act) act.target.sg:GoToState("wake") act.target:RemoveComponent("healthRegen")endAddAction(WAKEUP)Now, if I'm the hoster, I can go to sleep and wake up with no issue. However, if I'm a client, I can't wake up, only go to sleep. How can I fix this? Link to comment Share on other sites More sharing options...
Seiai Posted June 10, 2015 Share Posted June 10, 2015 (edited) @Mario384,thats not how u use RPCs. u have to make a function that u want to call on the server, and add a handler, and then call that handler from the client. for your code, this would probably look like this:in your modmain:local function wakeup(player)GLOBAL.BufferedAction(player, player, GLOBAL.ACTIONS.WAKEUP):Do()endAddModRPCHandler(modname, "Wakeup", wakeup)the RPC call:SendModRPCToServer(MOD_RPC[modname]["Wakeup"])and dont change "modname", thats on purpose. also, this rpc works even if u are host, so u can remove that TheWorld.ismastersim part and just use the RPC.and look here for a full working example of a RPC: http://forums.kleientertainment.com/topic/54536-help-with-a-mod-spider-summoning/ Edited June 10, 2015 by Seiai Link to comment Share on other sites More sharing options...
DarkXero Posted June 10, 2015 Share Posted June 10, 2015 @Mario384, this is odd. Put aprint("Hi, I'm in wakeup!")inside the wakeup function andprint("I'm next to the SendRPC")Confirm the RPCs are being sent and received appropriately. Link to comment Share on other sites More sharing options...
Mario384 Posted June 10, 2015 Author Share Posted June 10, 2015 @Mario384, this is odd. Put aprint("Hi, I'm in wakeup!")inside the wakeup function andprint("I'm next to the SendRPC")Confirm the RPCs are being sent and received appropriately. It appears the RPC is sent, but the function isn't being run. Any idea? Link to comment Share on other sites More sharing options...
DarkXero Posted June 10, 2015 Share Posted June 10, 2015 @Mario384, the DoWidgetButtonAction, while handled, checksif playercontroller ~= nil and playercontroller:IsEnabled() and not player.sg:HasStateTag("busy") thenSo when playing as the host, you bypass these checks because you run the action wakeup directly.When being a client, you send the rpc when you are in the sleeping state (which has a busy state tag), so wakeup doesn't get processed. So you will want to take Seiai's approach:- in modmainlocal function wakeup(player) GLOBAL.BufferedAction(player, player, GLOBAL.ACTIONS.WAKEUP):Do()endAddModRPCHandler("leifworkaround", "Wakeup", wakeup)- replacing the DoWidgetButtonActionSendModRPCToServer(MOD_RPC["leifworkaround"]["Wakeup"]) Link to comment Share on other sites More sharing options...
Mario384 Posted June 10, 2015 Author Share Posted June 10, 2015 DarkXero, I never made anything named leifworkaround. I made leif work by changing his state name, so assumin leif doesnt ned anything specical, how would I do this? Link to comment Share on other sites More sharing options...
DarkXero Posted June 10, 2015 Share Posted June 10, 2015 @Mario384, "leifworkaround" is just a name. Only thing you need is to includelocal function wakeup(player) GLOBAL.BufferedAction(player, player, GLOBAL.ACTIONS.WAKEUP):Do()end AddModRPCHandler("leifworkaround", "Wakeup", wakeup)in modmain, as it is,andSendModRPCToServer(MOD_RPC["leifworkaround"]["Wakeup"])replacing yourSendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.WAKEUP.code, inst, ACTIONS.WAKEUP.mod_name) Link to comment Share on other sites More sharing options...
Mario384 Posted June 11, 2015 Author Share Posted June 11, 2015 Thanks DarkXero and Seiai, I understand this better now, and got it fixed. Link to comment Share on other sites More sharing options...
Seiai Posted June 11, 2015 Share Posted June 11, 2015 @DarkXero, so the RPCs are actually supposed to work like his first approach? Link to comment Share on other sites More sharing options...
DarkXero Posted June 11, 2015 Share Posted June 11, 2015 @Seiai, well, yes, they are legal. He has a keyhandler component in the common_postinit, so when clients press a key, events trigger client side, triggering functions like OnKeySleep, which send a RPC already defined, with the parameters it requires to function, that you can see in networkclientrpc.lua. Mario made other actions trigger the same way, but I saw that they mostly triggered coming from an idle state, so no busy tag was there, so they passed the checks of the RPC he used. 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