Server Scripting

Players who own a server can create customized game modes via editing the conditions/events in Settings rule file, without needing to know coding!

Everything inside of the settings file can be customized to create different game modes. Apart from current settings in the file, more ways to customize the private servers will be added soon.

Rule files in Tribals are written in JSON file format, including settings.json file.

Settings (settings.json) file structure

Game Mode

It defines which of the specified modeSetting will be set as the current game mode.

Mode Settings

modeSettings is the parent category of the game modes in your server. All of your game modes will be a child element of this element. You can share your modes with other players, and they can easily add them under their modeSettings area.

Mode Name

The name of your mode. Usually defines the general gameplay rules of your server. For example, official Tribals servers have PVP, PVE, and Test type of game modes. But you can name your script as anything! Make sure its name can only contain the letters in the English alphabet, and numbers.

Events

Events are the things that we listen if they triggered or not. When triggered, it brings back the information about the thing it triggered with. We can use the information to set an outcome of the triggered event. We can listen actors, set methods, and add scripts under the event we listen.

  • onInteract: When player interacts with it.

  • onSpawn: When player spawns.

  • onAttack: When player attacks to it.

  • onKill: When player kills it.

  • onDropItem: When player drops item.

  • onCraft: When player crafts a something

  • onBuild: When player builds something

Actors

The things that determines what triggered this event. We can prevent specific actors to trigger in any event, via onCancel method.

  • Building

  • Player

  • Animal

Methods

onCancel is the only method available for now. When specified, it will cancel the triggered event, based on the terms you specify. An error message can be set when event cancelled.

This effect can be overridden with bypass methods.

Also, the things listed after the onCancel method will also override the cancel.

Bypass Methods

Bypasses the onCancel method, based on the specified terms. The bypass methods are only for the building elements. More methods will be added soon.

It will bypass the event if:

  • isResource: The "building" is a resource

  • decaying: The building is decaying

  • isProtected: The building is protected

  • authorized: Player is authorized to the building

  • owner: The building is owned by the player

Scripts

Scripts are premade commands that does something. Can be use under events, actors, and in objects (item or building)

  • Clearall: clears the player inventory Usage: "script": ["clearall"]

  • Heal: fully heals the player health, hunger and thirst. Usage: "script": ["heal"]

  • Destroy: Destroys the object/building Usage: "script": ["destroy"]

  • Add Item: Adds the specified item and quantity. Usage: "script": ["addItem shit 1"]

  • Add Items: Used to add items to specific slots, with specified quantity. It should be used after "clearall" to avoid errors. Make sure the last item doesn't have a comma after it. Usage: "addItems": [ { "name": "Pistol", "amount": 1, "slot": 1 }, { "name": "PistolAmmo", "amount": 99, "slot": 2 } ]

  • Any of the script can be run at the same time. Usage: "script": ["heal", "clearall", "addItem shit 1", "destroy"]

Example Script:

Let's create a "PVE" game mode from settings.json file

  1. modeSettings is where you will write scripts for different modes. It's the parent category of your game modes.

  2. The next line is for the name of your script. It can include any letter in the English alphabet. In this case, we'll use "PvE".

  1. Next, you'll create the event you want to listen. In this example, we will use onInteract event. It will be triggered, when player "interacts" with this object.

  1. Under onInteract event, we will define exactly what this script is for; Building, Player, or Animal. In this example, I use Building:

  1. We want to cancel building, so we'll use onCancel event to prevent buildings from interacted. Before that, we can specify things that'll bypass the onCancel event. In this case the owner of the house, resources, and authorized players can be interacted with each other.

  2. If we want to add more building elements that will bypass onCancel event, we can list them under it. For this example, we should add the Toolbox to the items that can be interacted, so players can interact with toolbox to get authorized.

Last updated