• Print

Author Topic: Introducing... ULib.clientRPC! Execute any function, any parameter, any size!  (Read 5497 times)

0 Members and 1 Guest are viewing this topic.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Execute functions on client in a snap, without worrying about what you're sending them! I've got this fully working, I'll be pushing it to SVN later today (probably). Here's the docs for this new function:
Code: Lua
  1. --[[
  2.         Function: clientRPC
  3.  
  4.         Think of this function as if you're calling a client function directly from the server. You state who should run it, what the name of
  5.         the function is, and then a list of parameters to pass to that function on the client. ULib handles the rest. Parameters can be any
  6.         data type that's allowed on the network and of any size. Send huge tables or strings, it's all the same, and it all works.
  7.  
  8.         Parameters:
  9.  
  10.                 filter - The Player object or RecipientFilter object for who you want to send this to, nil sends to everyone. Passed directly to umsg.Start.
  11.                 fn - A string of the function to run on the client. Does *not* need to be in the global namespace, "myTable.myFunction" works too.
  12.                 ... - *Optional* The parameters to pass to the function.
  13.                
  14.         Revisions:
  15.        
  16.                 v2.31 - Initial
  17. ]]

Here's some examples of some valid ways to use this function:
Code: Lua
  1. ULib.clientRPC( _, "print", "Hello, World!", 1, 3.14159, -999999, Entity( 1 ) ) -- Prints this list of arguments in all players' consoles
  2. ULib.clientRPC( _, "print", file.Read( "ulx_motd.txt" ) ) -- Prints the ulx motd in the console of all connected players
  3. ULib.clientRPC( Entity( 1 ), "PrintTable", { "bob", "barker", "was here!", { like="omg!", { file.Read( "../ulx_motd.txt" ) } } } ) -- Prints a crazy huge multi-level table in the console of the first player

I'm excited to start using this function, myself. :D

This fulfills feature #153 on Mantis -- http://ulyssesmod.net/bugs/view.php?id=153
« Last Edit: August 16, 2009, 12:03:51 pm by Megiddo »
Experiencing God's grace one day at a time.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Another mouth-watering example that I'm using in real code. It's calling a hook on all clients when a certain event on the server happens:
Code: Lua
  1. ULib.clientRPC( _, "hook.Call", "MyHook", _, ply ) -- Call hook on client
Experiencing God's grace one day at a time.

  • Print