Jump to content

To trigger a Client Event: Client RPC's vs Netvar's


Recommended Posts

Hello good people of the morning forums, I've got a question for ya.

I've be taking advantage of Client RPC's in my mod to trigger any events that for some reason won't trigger normally on clients. My question is this though,

If I need to trigger an event with no specific variables, what's the advantage to using a netvars opposed to a client RPC? I've noticed a lot of mods use netvars for this kindof thing, and I never understood it. I understand it's a thing you CAN do, but RPC's seem more robust to me on the surface for events.

Link to comment
Share on other sites

Netvars should be less networking intensive, but yeah I feel you on that one.  I like the RPC interface much more than the setup of netvars.  Simpler, more robust, and can be easily changed to support more things later if need be.

Link to comment
Share on other sites

I'm not sure if I get your question

Like, RPC is used to send data from the client to the server (and later the server choose what to do with this data)
Netvars are the opposite, used to send data from server to client

I think it is not a question of "advantage", it is more like "the information is coming from the server of being send to the server"

Link to comment
Share on other sites

2 minutes ago, Gleenus said:

I'm not sure if I get your question

Like, RPC is used to send data from the client to the server (and later the server choose what to do with this data)
Netvars are the opposite, used to send data from server to client

I think it is not a question of "advantage", it is more like "the information is coming from the server of being send to the server"

RPC's are traditionally used to send client to server, but in this post, Zarklord outlines how to use Client RPC's, which send data from server to client like netvars. My question is here, which ones should be used for triggering events then? RPC's seem more robust but then why does everyone use netvars?

I should clarify, that I use RPC's in my own mod for the purpose I've outlined, they work fine.

Edited by TheSkylarr
Link to comment
Share on other sites

1 minute ago, TheSkylarr said:

RPC's are traditionally used to send client to server, but in this post, Zarklord outlines how to use Client RPC's, which send data from server to client like netvars. My question is here, which ones should be used for triggering events then? RPC's seem more robust but then why does everyone use netvars?

I should clarify, that I use RPC's in my own mod for the purpose I've outlined, they work fine.

I didn't know that was possible
But about if you only wants to trigger an event, I would use a net_event or a net_bool and change its value, since in this case would have less data being transferred

  • Thanks 1
Link to comment
Share on other sites

4 minutes ago, Gleenus said:

I didn't know that was possible
But about if you only wants to trigger an event, I would use a net_event or a net_bool and change its value, since in this case would have less data being transferred

That makes a lot of sense to prevent network load, but netvars seem like they are heavier on the server itself than RPC's.

Link to comment
Share on other sites

51 minutes ago, TheSkylarr said:

That makes a lot of sense to prevent network load, but netvars seem like they are heavier on the server itself than RPC's.

why they seem heavier?

I never notice anything like that
And one bool var is like nothing, the smallest computational amount possible for computers

Link to comment
Share on other sites

5 hours ago, Gleenus said:

why they seem heavier?

I never notice anything like that
And one bool var is like nothing, the smallest computational amount possible for computers

It seems heavier to me due to all the extra functions you have to set up in order to get them working, though maybe that's down to my lack of understanding of them.

Link to comment
Share on other sites

While the general purpose of the two are the same (providing data to clients), they have some details that give them different use cases.

A few details:

RPCs are good for transferring large amounts of data, while doing so on a netvar can cause serialization failure.

Netvars remove the need to monitor clients' version of data, while RPCs will force you to implement additional code for dealing with remembering data (and will require more network overhead).

RPCs let you pass in a bunch of arguments in a single call and specify recipients, while netvars only let you send one specific data type per netvar, on all clients that have that entity.

Netvars implicitly give you a better form of organization for data bound to entities, while using RPCs means you have to deal with more generalization of data.

Edited by penguin0616
  • Like 1
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...