-
Notifications
You must be signed in to change notification settings - Fork 0
Creating a gamemode
First, you need to create a folder for your gamemode. The folder name must be the same as the gamemode name. For example, if you want to create a gamemode called "My Gamemode", you need to create a folder called "My Gamemode" in the gamemodes
folder.
Then you need to create two files in the gamemode folder. The first file is the gamemode file. The gamemode file must be called "gamemode.js". The second file is the gamemode config file. The gamemode config file must be called "gamemode.json". In the config file, you need to add the following code:
{
"name":"My Gamemode",
"description":"Your gamemode description",
"version":1,
"versionString": "v1.0",
"hasTeams": true, //if this is true, there will be a teams button in the GUI
"hasSettings": true, //if this is true, there will be a settings button in the GUI
"settings": { //define settings here (only needed if hasSettings is true)
"your-setting":{
"name":"Your Setting", //the name of the setting
"type":"number", //the type of the setting (number / boolean)
"default": 0, //the default value of the setting
"unit": "sec" //the unit of the setting (only needed if type is number)
},
"your-second-setting":{
"name":"Your Second Setting",
"type":"boolean",
"default": false
}
}
}
To add the gamemode to the gamemode list, you need to add this code to the gamemodes.json
file in the gamemodes
folder:
"your-gamemode-name": {
"path":"your-gamemode-folder-name/gamemode.js",
"info":"your-gamemode-folder-name/gamemode.json"
}
This is needed to load the gamemode when the server starts. The path
is the path to the gamemode file. The info
is the path to the gamemode config file.
First, you need to create a class called game
. This class must contain the following functions, also export the class at the end of the file:
class game {
constructor(devices, link) {
// This function is called when the game class is created
// devices is an object containing the devices
// link is the link object
}
init() {
// This function is called when the gamemode is loaded
}
start() {
// This function is called when the gamemode is started
}
stop() {
// This function is called when the gamemode is stopped
}
tick() {
// This function is called every 0.5s
}
hit(player, target) {
// This function is called when a player hits another player
// player is the player who hit the target
// target is the player who was hit
}
setTeams(teams) {
// This function is only needed if the gamemode has teams (hasTeams is true in the config file)
// This function is called when the teams are set using the GUI
// Teams is an object containing the player id as the key and the team id as the value
}
setSettings(settings) {
// This function is only needed if the gamemode has settings (hasSettings is true in the config file)
// This function is called when the settings are set using the GUI
// settings is an object containing the setting name as the key and the setting value as the value
}
}
module.exports = game; // This is needed to export the class
You need to create the following variables in the constructor:
this.values = {}; //stores the values of the devices
this.teams = []; //stores the teams
this.players = []; //it is a list containing the ids of all participating players
this.link = link; //the link object
Object.entries(devices).forEach(([key, value]) => { //adds all players to the players list and sets the values of the devices
if(value.type == "gun"){
this.values[key] = { //stores the values of the devices (you can change the standard values, and also add more if you want)
HP: 100, //the health of the player
MHP: 100, //the max health of the player
SP: 100, //the shield of the player
MSP: 100, //the max shield of the player
ATK: 10, //the attack of the player
MATK: 10, //the max attack of the player
RT: 10, //the reload time of the player (not used in the gun code yet)
PTS: 0, //the points of the player
KILL: 0 //the kills of the player
}; //these values are send to the guns, so they are needed
this.players.push(key); //adds the player to the players list
}
});
this.colors = [ //not needed, but it is useful, because the game uses these color ids
{name:"Red", rgb:[255,0,0]},
{name:"Green", rgb:[0,255,0]},
{name:"Blue", rgb:[0,0,255]},
{name:"Yellow",rgb:[255,255,0]},
{name:"Purple",rgb:[255,0,255]},
{name:"Cyan",rgb:[0,255,255]},
{name:"Orange",rgb:[255,128,0]}
];
The link object is used to send data to the guns. The link object has the following functions:
Link.setColor(colorArray: int[], id: int): boolean
This function is used to set the color of the guns. The colorArray is an array containing the rgb values of the color. The id is the id of the gun. The function returns true if it executed successfully, otherwise it returns false.
Link.setGamestate(gamestate: int, id: int): boolean
This function is used to set the gamestate of the guns. The gamestate is an integer. The id is the id of the gun. The function returns true if it executed successfully, otherwise it returns false.
The gamestates are used to tell the guns what to do. The gamestates are:
- 0: Game is stopped
- 1: Game is waiting to start
- 2: Game is running
Link.setValues(values: object, id: int): boolean
This function is used to set the values of the guns. The values is an object containing the values. The id is the id of the gun. The function returns true if it executed successfully, otherwise it returns false. Required values:
-
int
HP: Health of the player -
int
MHP: Max health of the player -
int
SP: Shield of the player -
int
MSP: Max shield of the player -
int
ATK: Attack of the player -
int
RT: Reload time of the player -
int
PTS: Points of the player -
int
KILL: Kills of the player
LoeweTag is licensed under the MIT LICENSE | © Loewe_111