Jump to content

Client RPC confusion

Recommended Posts

After following this guide on RPC's, I successfully managed to get traditional RPC's implemented in my mod, however I'm having trouble with Client RPC's. I need to have code that is only executed on the client. This is what I'm using to get it working so far, and I bet I did something wrong.

local function ClientPrintfn()
	print("CLIENT test")

AddClientModRPCHandler("hkr_RPC", "ClientPrint", ClientPrintfn)

local function SendTestRPC()
	local userids = {}
	for i, player in ipairs(AllPlayers) do
		table.insert(userids, player.userid)
	SendModRPCToClient(GetClientModRPC("hkr_RPC", "ClientPrint"), userids, nil)

GLOBAL.TheInput:AddKeyDownHandler(108, SendTestRPC)

This is contained in my modmain, and that keydown handler is just a way to debug it, it would normally get called from an event listener. My problem is that my code seems to be doing absolutely nothing, and i think it's occuring within SendTestRPC(), specifcally when trying to get all the players. Is that line outdated?

Edited by TheSkylarr
wasn't clear
Link to comment
Share on other sites

22 hours ago, zarklord_klei said:

Client RPCs go from the server to the client, the server doesn't know what keys your pressing, so it can't fire the key down event.

Really? I figured it worked so that the Client sent the keypress to the server, and that keypress fires it, thanks for clearing this up for me!

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

  • Create New...