zarklord_klei

New Modding RPCs API

Recommended Posts

Cunning fox    788

Will client RPC work if the player is in the lobby?

EDIT: It won't work for players that are not in the world. Zark confirmed it.

Edited by Cunning fox

Share this post


Link to post
Share on other sites
Cunning fox    788
6 minutes ago, zarklord_klei said:

as long as you can get their userid, it should!

Why Klei haven't hired you sooner?? I made a while system that dynamically spawns classified prefabs only to send data to a certain player in lobby. This would make it SO MUCH easier

Edited by Cunning fox
  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
Tykvesh    660

For some reason, ShardRPC fails if sender_list is anything but nil (Invalid RPC sender list). And when it is nil, the rpc won't fire on the shard it's called from.

Also I wonder why tables aren't supported as valid arguments (Invalid RPC data type)?

Share this post


Link to post
Share on other sites
zarklord_klei    4016
2 hours ago, Tykvesh said:

For some reason, ShardRPC fails if sender_list is anything but nil (Invalid RPC sender list). And when it is nil, the rpc won't fire on the shard it's called from.

Also I wonder why tables aren't supported as valid arguments (Invalid RPC data type)?

tables have always been invalid data types, would you mind sharing the relevant code snippet?

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Tykvesh    660

This code sends a RPC with player's position each time they locomote. After that the RPC prints the received position:

Spoiler

AddShardModRPCHandler("test_namespace", "test_name", function(shardid, x, y, z)
	print("(Received from a ShardRPC)", x, y, z)
end)

local function OnLocomote(inst)
	local x, y, z = inst.Transform:GetWorldPosition()
	print("(Sending a ShardRPC)", x, y, z)	
	SendModRPCToShard(GetShardModRPC("test_namespace", "test_name"), nil, x, y, z)
end

AddComponentPostInit("playercontroller", function(self, inst)
	inst:ListenForEvent("locomote", OnLocomote)
end)

And here's how it appears in the logs:


From the shard from which the rpc was sent:
[00:10:14]: (Sending a ShardRPC)	355.60037231445	0	349.40600585938	
[00:10:14]: (Sending a ShardRPC)	355.72143554688	0	349.40570068359	
[00:10:15]: (Sending a ShardRPC)	355.72143554688	0	349.40570068359

From the other shard that received the rpc:
[00:10:14]: (Received from a ShardRPC)	355.60037231445	0	349.40600585938	
[00:10:15]: (Received from a ShardRPC)	355.72143554688	0	349.40570068359	
[00:10:15]: (Received from a ShardRPC)	355.72143554688	0	349.40570068359

 

 

  • Like 1

Share this post


Link to post
Share on other sites
Cunning fox    788

For some reason when I call ClientRPC, I always get 

[00:13:35]: Invalid RPC namespace: 	1	table: 0x40915618

My RPC:
 

AddClientModRPCHandler("HG", "TEAM_MSG", function(...)
    printwrap("", {...})
end)

How I call it
 

SendModRPCToClient(GetClientModRPC("HG", "TEAM_MSG"), nil)

Edit: Zarklord found a bug and this should be fixed in the next patch.

Edited by Cunning fox

Share this post


Link to post
Share on other sites
Monti18    382

I made a mod named Craftable Wormholes, where I added wormhole icon support in the last update. I use SendModRPCToClient to make the client delete the icons. This works if I use newly created wormholes, but if I try to do it when an original wormhole that was created with the world is connected to a new wormhole, nothing happens. I get no error in the client or server log, just nothing. If I only do it with the new wormholes, it works without problems.

I added prints to check if the RPC is indeed sent and they appear in the log.

The code in question:

Spoiler

local function onhammered(inst, worker)
    GLOBAL.TheWorld:PushEvent("wormhole_destroyed",{wormhole = inst})
    if GetModConfigData("ENABLED") then
    	if inst.components.teleporter.targetTeleporter ~= nil then
    		local userids = {}
			for i, player in ipairs(GLOBAL.AllPlayers) do
				table.insert(userids, player.userid)
			end
			SendModRPCToClient(GetClientModRPC("Wormhole_Crafter", "RemoveWormhole"),userids,inst,inst.components.teleporter.targetTeleporter)
    	end
    end
    inst:DoTaskInTime(0.3, function() inst:Remove() end)
end

local function RemoveWormhole(wormhole_removed,wormhole_still_here)
	local hole_removed = {inst=wormhole_removed,pos = wormhole_removed:GetPosition()}
	local hole_still_here = {inst=wormhole_still_here,pos = wormhole_still_here:GetPosition()}
	RemoveWormholePair(hole_removed,hole_still_here)
end

AddClientModRPCHandler("Wormhole_Crafter", "RemoveWormhole", RemoveWormhole)

 

Does someone have an idea why this doesn't work?

  • Like 1

Share this post


Link to post
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