Utilities

Has some useful server utilities

Summary
UtilitiesHas some useful server utilities
Functions
clientRPCThink of this function as if you’re calling a client function directly from the server.
play3DSoundPlays a 3D sound, the further away from the point the player is, the softer the sound will be.
getAllReadyPlayersSimilar to player.GetAll(), except it only returns players that have ULib ready to go.
replicatedWritableCvarThis function also creates a cvar on the client that can be modified and will be sent back to the server.

Functions

clientRPC

function ULib.clientRPC(plys,
fn,
...)

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 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 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.

Parameters

filterThe Player object, table of Player objects for who you want to send this to, nil sends to everyone.
fnA string of the function to run on the client.  Does not need to be in the global namespace, “myTable.myFunction” works too.
...Optional The parameters to pass to the function.

Revisions

v2.40Initial.

play3DSound

function ULib.play3DSound(sound,
vector,
volume,
pitch)

Plays a 3D sound, the further away from the point the player is, the softer the sound will be.

Parameters

soundThe sound to play, relative to the sound folder.
vectorThe point to play the sound at.
volume(Optional, defaults to 1) The volume to make the sound.
pitch(Optional, defaults to 1) The pitch to make the sound, 1 = normal.

getAllReadyPlayers

function ULib.getAllReadyPlayers()

Similar to player.GetAll(), except it only returns players that have ULib ready to go.

Revisions

2.40Initial

replicatedWritableCvar

function ULib.replicatedWritableCvar(sv_cvar,
cl_cvar,
default_value,
save,
notify,
access)

This function is mainly intended for use with the menus.  This function is very similar to creating a replicated cvar with one caveat

This function also creates a cvar on the client that can be modified and will be sent back to the server.

Parameters

sv_cvarThe string of server side cvar.
cl_cvarThe string of the client side cvar.  THIS MUST BE DIFFERENT FROM THE sv_cvar VALUE IF YOU’RE PIGGY BACKING AN EXISTING REPLICATED CVAR (like sv_gravity).
default_valueThe string of the default value for the cvar.
saveBoolean of whether or not the value is persistent across map changes.  This uses garry’s way, which has lots of issues.  We recommend you watch the cvar for changes and handle saving yourself.
notifyBoolean of whether or not value changes are announced on the server
accessThe string of the access required for a client to actually change the value.

Returns

The server-side cvar object.

Revisions

v2.40Initial.
v2.50Changed to not depend on the replicated cvars themselves due to Garry-breakage.
function ULib.clientRPC(plys,
fn,
...)
Think of this function as if you’re calling a client function directly from the server.
function ULib.play3DSound(sound,
vector,
volume,
pitch)
Plays a 3D sound, the further away from the point the player is, the softer the sound will be.
function ULib.getAllReadyPlayers()
Similar to player.GetAll(), except it only returns players that have ULib ready to go.
function ULib.replicatedWritableCvar(sv_cvar,
cl_cvar,
default_value,
save,
notify,
access)
This function also creates a cvar on the client that can be modified and will be sent back to the server.
Close