Jump to content

Can you delete RPC handlers? I reached a limit


Recommended Posts

It took me a long time to figure out why the player's controls would stop working after respawning a few times.

In my mod, each character is given a set of RPC keyhandlers. And I have a function commonly used in other mods where players can be de-spawned and taken back to the character select screen to pick a new character with "TheWorld:PushEvent("ms_playerdespawnanddelete", inst)"

And every time they do, they need to have their RPC keys re-attached to them. It works fine until respawning for the second time, where only half of their keyhandlers are applied, and the rest only show up in the client log as "Error encoding lua RPC code" when pressed.

I didn't realize there was a limit, but this mod has a lot of RPC key events. roughly 25 per player, in fact. Is there any way to "delete" old RPC events for the de-spawning players? 

 

Link to comment
Share on other sites

I'm sorry, but I don't understand really what these stuff mean, but I want to try to help you since you helped me so I wanna just give an example of how my keyhandler things is then maybe you can get ideas or something :)!

So, my character also has many, many actions that happen when you press keys, but then he started having so many keys to do different things that it would be annoying reaching all over the keyboard to preform the action I wanted.. So, I made all my character's keyhandler actions happen with a combination of 4 different buttons being pressed which allows for a total of 16 different actions! Like this

mycharacter.lua

Spoiler

local function OnKeyPressed(inst, data)
  if data.inst == ThePlayer then
    if data.key == KEY_UP then
      if TheWorld.ismastersim then
      BufferedAction(inst, inst, ACTIONS.UP):Do()
      else
      SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.UP.code, inst, ACTIONS.UP.mod_name)
      end 
	  
	  elseif data.key == KEY_DOWN then
      if TheWorld.ismastersim then
      BufferedAction(inst, inst, ACTIONS.DOWN):Do()
      else
      SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.DOWN.code, inst, ACTIONS.DOWN.mod_name)
      end
	  
	  elseif data.key == KEY_RIGHT then
      if TheWorld.ismastersim then
      BufferedAction(inst, inst, ACTIONS.RIGHT):Do()
      else
      SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.RIGHT.code, inst, ACTIONS.RIGHT.mod_name)
      end
	  
	  elseif data.key == KEY_LEFT then
      if TheWorld.ismastersim then
      BufferedAction(inst, inst, ACTIONS.LEFT):Do()
      else
      SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.LEFT.code, inst, ACTIONS.LEFT.mod_name)
      end
	  
    end
  end
end

local function common_postinit(inst)
	inst:AddComponent("keyhandler_adam")
	inst:ListenForEvent("keypressed", OnKeyPressed)
end

 

modmain.lua

Spoiler

-- Player wants to preform a left action.
local LEFT = GLOBAL.Action()
LEFT.str = "Left"
LEFT.id = "LEFT"
LEFT.fn = function(act)

   if act.target:HasTag("playerghost") then
      return
   end
   ---------------------------------------------

   if act.target.can_do_left_action == true then
	  activate_gelid(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_down_action == true then
      activate_wathgrithr(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_right_action == true then
      activate_lord(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_up_action == true then
      bat_veil(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_left_action == nil then
      act.target.can_do_left_action = true
      act.target:DoTaskInTime(.5, function() act.target.can_do_left_action = nil end)
   end
end
AddAction(LEFT)


-- Player wants to preform a right action.
local RIGHT = GLOBAL.Action()
RIGHT.str = "Right"
RIGHT.id = "RIGHT"
RIGHT.fn = function(act)

   if act.target:HasTag("playerghost") then
      return
   end
   ---------------------------------------------

   if act.target.can_do_left_action == true then
	  activate_chef(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_down_action == true then
      activate_demon(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_right_action == true then
      activate_psycho(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_up_action == true then
      evade(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_right_action == nil then
      act.target.can_do_right_action = true
      act.target:DoTaskInTime(.5, function() act.target.can_do_right_action = nil end)
   end
end
AddAction(RIGHT)


-- Player wants to preform a down action.
local DOWN = GLOBAL.Action()
DOWN.str = "Down"
DOWN.id = "DOWN"
DOWN.fn = function(act)

   if act.target:HasTag("playerghost") then
      return
   end
   ---------------------------------------------

   if act.target.can_do_left_action == true then
	  activate_succubi(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_down_action == true then
      activate_angelic(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_right_action == true then
      activate_fitness(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_up_action == true then
      parry(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_down_action == nil then
      act.target.can_do_down_action = true
      act.target:DoTaskInTime(.5, function() act.target.can_do_down_action = nil end)
   end
end
AddAction(DOWN)


-- Player wants to preform a up action.
local UP = GLOBAL.Action()
UP.str = "Up"
UP.id = "UP"
UP.fn = function(act)

   if act.target:HasTag("playerghost") then
      return
   end
   ---------------------------------------------

   if act.target.can_do_left_action == true then
	  activate_grue(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_down_action == true then
      activate_wx78(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_right_action == true then
      activate_pirate(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_up_action == true then
      destroy_item(act)
   end
   ---------------------------------------------
   
   if act.target.can_do_up_action == nil then
      act.target.can_do_up_action = true
      act.target:DoTaskInTime(.5, function() act.target.can_do_up_action = nil end)
   end
end
AddAction(UP)

 

& when my char die I never saw him lose the ability to call upon any of these actions, so I guess it's good? 

The only problem with doing something like this is having to remember what every key combination does..but that isn't a big problem. (At least when you play fighting games like me & everything boils down to muscle memory, hahaha)

EDIT: Also, to my understanding if RPC means the keyhandler actions that means with something like this which gives 16 possible actions with only 4 RPCs that means if you make another set of 4 buttons do something like this then you'll have 32 actions at the cost of 8 RPCs & your limit problem would be solved :D!! (I think!)

Also, I'm very sorry if my reply wasn't what your problem is asking about... English isn't my first language & I don't understand all these coding thingies is names & stuff, hahaha...so then I'm sorry :D!!!!!

Edited by SuperDavid
Link to comment
Share on other sites

Yea, but with normal respawning, the player isn't actually deleted, I think. Right? I don't actually know. But I'm using  ms_playerdespawnanddelete instead of the typical respawning method

But the problem here is that every time the are despawned and deleted, the new character has to have their RPCs re-added. So, supposedly, no matter how few RPC handlers I have, if the player is despawned and deleted enough times, the mod will still eventually run out of RPC handlers to use.

I'm wondering if there is a way to make room for more RPCs by possibly deleting old ones off of the unused player character before they despawn or something

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...