ULX

Author Topic: Running clientside code on ULX  (Read 286 times)

0 Members and 1 Guest are viewing this topic.

Offline Blizzard098

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Running clientside code on ULX
« on: July 05, 2019, 09:54:46 PM »
Hey guys,

I'm trying to run some Derma through a ULX command. I've done an "if CLIENT then" statement but that didn't seem to work. It's a very small piece of derma so I don't feel like making a separate file. Any thoughts?

Offline Timmy

  • Ulysses Team Member
  • Full Member
  • *****
  • Posts: 218
  • Karma: 161
  • Code monkey
    • ULX Unofficial Documentation
Re: Running clientside code on ULX
« Reply #1 on: July 06, 2019, 08:47:11 AM »
The callback function of a ULX command always runs on the server-side.

ULX commonly uses ULib.clientRPC to make players run client-side code. While ULX separates these client-side functions into a different file, it is not strictly required.

The example below uses ULib.clientRPC to call ulx.rcvNotify on the client-side - all in one file.
Code: Lua
  1. -- lua/ulx/modules/sh/my_command.lua
  2.  
  3. function ulx.rcvNotify( message )
  4.     notification.AddLegacy( message, NOTIFY_GENERIC, 3 )
  5.     surface.PlaySound( "buttons/button14.wav" )
  6. end
  7.  
  8. function ulx.notify( calling_ply, target_plys, message )
  9.     ULib.clientRPC( target_plys, "ulx.rcvNotify", message )
  10.     ulx.fancyLogAdmin( calling_ply, "#A sent a notification to #P", target_plys )
  11. end
  12. local notify = ulx.command( "Example", "ulx notify", ulx.notify, "!notify" )
  13. notify:addParam{ type=ULib.cmds.PlayersArg }
  14. notify:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
  15. notify:defaultAccess( ULib.ACCESS_ADMIN )
  16. notify:help( "Send notification to target(s)." )
“When given the choice between being right or being kind, choose kind.”  —Dr. Wayne Dyer