The ClientAPI (custom content)

Since sending dll's mod to clients would represent a security risk we've made a small client api that allows you to interact with the clients and load custom content. It is pretty basic but it can already allow for a TON of stuff. Only your imagination is your limit. The ClientAPI works by using paths from the hierarchy for non-networked objects. It is not 100% safe as if a client hierarchy get out of sync it could stop working. However things like buildings, map, ATM's etc.. that are static should not be impacted by this if you follow the general rules.

The ClientAPI offers mostly extension methods to GameObjects ending by Clientside. Most of the methods sends a network message to the client to tell him to move an object, rotate it, disable it, call a method on it etc. For most things it is saved for new players such as position, rotation, destroying, disabling etc. Which means that if when your plugin starts you remove the police office, new players will get that removal action when they connect.

The ClientAPI also works with NetworkObjects (Players, Vehicles etc) And is more stable than the hierarchy path approach (It'll internally detect when its a NetworkObject or child of one).

This sets the position of the object you pass. There is also SetLocalPositionClientside for changing the position relative to the gameobject parent.

void SetPositionClientside(this GameObject gameObject, Vector3 position, bool local = false)
void SetLocalPositionClientside(this GameObject gameObject, Vector3 position)

This sets the rotation of the object you pass. There is also SetLocalRotationClientside for changing the rotation relative to the gameobject parent.

void SetRotationClientside(this GameObject gameObject, Quaternion rotation, bool local = false)
void SetLocalRotationClientside(this GameObject gameObject, Quaternion rotation)

This allows you to disable objects, simple call it with either true or false to set the object as active (true) or inactive (false).

void SetActiveClientside(this GameObject gameObject, bool active)

This allows you to set a gameobject parent.

void SetParentClientside(this GameObject gameObject, GameObject parent)

This allows you to create a copy of a gameobject. (Not working with network objects) It returns the cloned object so you can then use for example SetPositionClientside on it.

GameObject CloneClientside(this GameObject gameObject, Vector3 position = default, Vector3 rotation = default)

Allows you enable or disable specific components. You can use it to disable game scripts, renderers or parts of an object.

void SetComponentActiveClientside(this Component component, bool active)

This is probably one of the most powerful methods of the API yet. It allows to invoke any method on any object with any parameters.

void InvokeMethodClientside(this Component component, string methodName, params object[] args)

This is also one of the most powerful methods as it allows you to set any variables on any game object.

void SetVariableClientside(this Component component, string variableName, object value)

This allows you to destroy objects on the client.

Last updated