zarklord_klei

New Modding RPCs API

Recommended Posts

Cunning fox    650

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    650
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    323

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    1498
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?

  • Thanks 1

Share this post


Link to post
Share on other sites
Tykvesh    323

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    650

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

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