• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Calling client/server functions (mutator)

-=THOR=-

Grizzled Veteran
Sep 20, 2011
1,050
50
Hi,

When someone calls Mutate MyMutatorName in the console, it calls the function Mutate on the server. I want the server to trigger a mutator function call on each client. Inside that function, the client must trigger a function call on the server, with a struct as parameter. So basically, there are 3 functions, mutate(...), ClientFunction(), and ServerFunction(param).

So for example, the following execution scenario could happen:
1. Client 1 types Mutate MyMutatorName
2. Server calls Mutate(...)
3. In the Mutate function, the server triggers a mutator function call on each client.
4. ClientFunction called on client 1, and triggers a server function call.
5. ClientFunction called on client 2, and triggers a server function call.
6. ServerFunction("Ack from 1") called on the server
7. ClientFunction called on client 3, and triggers a server function call.
8. ServerFunction("Ack from 2") called on the server
9. ServerFunction("Ack from 3") called on the server

What is the simplest solution to "route" these function calls? What is the syntax required?

Thanks
 
Last edited:
The documentation: http://udn.epicgames.com/Three/FunctionReplication.html

The short version: you need to make an object that exists on both client and server, owned by the client's playercontroller on both sides, before the function calls will replicate both ways. After that, it's fairly straight-forward, you just route the calls through that object. The clients call a method of that object that's flagged with the server keyword, and the server calls a method flagged with the client keyword, and they work just like any other function call.
 
Upvote 0
Include a replication block for small variables. You can also have a repnotify event block to detect when those variables are changed. You generally want to only pass through ints/floats (same size in memory), and bytes/bools (same size in memory) and you want to limit the amount you pass through as best as you can.

A lot of objects, including the Pawn, exist twice: one for the player, one for the server. Variables, such as Location, have to be declared as needing to be replicated. If the client value is different than the server, then the server will change the client value using the replication block. When a variable is changed, you can use the repnotify block to detect that.

The server handles such things as the functionality behind weapons, projectiles, players (not input), collision, triggers, game (game is never run on the client).
 
Upvote 0