🚢
Airship
  • Getting Started
    • Welcome to Airship
    • Installing Airship
  • TypeScript
    • Overview
    • AirshipBehaviour
      • Adding Inspector Properties
      • AirshipSingleton
      • Using Component Decorators
      • Accessing Other Components
  • Publishing
    • Publish Game
    • Developer Console
  • Networking
    • Multiplayer
    • Local Server Mode
    • Network Signals
    • Network Functions
    • Network Identity
    • Network Transform
  • Input
    • User Input
      • Actions
      • Keyboard
      • Mouse
    • Proximity Prompts
  • Core Package
    • What is the Core Package?
    • Chat Commands
    • Inventory
    • Spawning Characters
    • Enable / Disable Core Features
  • Physics
    • Physics Settings
    • Physics Layers
  • Platform Services
    • Data Store
      • Locking
    • Cache Store
    • Leaderboards
    • Platform Inventory
    • Server Management
    • Server List
    • Server Transfers
    • Users
    • Parties
    • Matchmaking
    • External Services
  • CHARACTERS
    • Quick Configuration
    • Character Movement System
      • Character Movement Data
      • Character Movement Events
    • Character Camera
      • First Person Camera
      • Simple Usage
      • Camera Structure
      • Default Camera Modes
      • Disabling the Camera System
    • Character Animations
      • Character Blender Animations
      • Character Ragdoll
  • Accessories
    • Accessories Intro
    • Creating Accessories
    • Using Accessories
  • ANIMATIONS
    • Animation Events
  • Optimization
    • Live Game Profiler
    • Reducing Bundle Size
  • Game Settings
    • Game Visibility
  • Other
    • Project Status
    • FAQ
    • DataType Math
    • JS to Luau
    • Tags
    • Terrain
    • AirshipNetworkBehaviour
      • Lifecycle Events
      • ServerRpc
      • ObserversRpc
      • TargetRpc
    • VoxelWorld
      • Voxel World Getting Started
      • Voxel World Tips
      • Prefab Voxels
      • QuarterBlocks
    • Easy Helper Utils
      • Easy Motion
      • Easy Grid Align
      • Easy Look At
      • Easy Shake
      • Easy Destroy
Powered by GitBook
On this page
  • Chat Command Structure
  • Create your own Chat Command
  • The Full Script
  1. Core Package

Chat Commands

Quickly run code from the chat window

Setting up a chat command lets you link code to keywords. Type the keyword in chat on your client and the code will be run on the Server.

Chat Command Structure

All commands are run with the / character followed by the command keyword, then parameters separated by spaces:

/mycommand 12 secondParam

You can use the / key to open the chat window with the / character already entered

Create your own Chat Command

  1. Create a new TS file and name MyCommand.ts

  2. Create a class that extends "ChatCommand"

export class MyCommand extends ChatCommand {
  1. Setup the core variables in the constructor

constructor() {
	super("mycommand", ["c"], "[string] (optional)", "Print a message");
}
  1. Implement the Execute function which fires on the server when a client types the command

//Player that sent the command and the variables passed through as string arguments
public Execute(player: Player, args: string[]): void {

	//Get the parameter if it was sent
	let firstParameter = ""
	if(args.size() > 0){
		firstParameter = args[0];
	}
	
	//Create a log message
	const logMessage = "Client sent message: " + firstParameter;

	//Log to console on server
	print(logMessage);

	//Send the results to every clients chat window
	Airship.Chat.BroadcastMessage(logMessage);
}
  1. Register the command somewhere in your games code through Airship.Chat

Airship.Chat.RegisterCommand(new MyCommand());
  1. You can now run your command in the chat by typing

/mycommand hello

The Full Script

import { Airship } from "@Easy/Core/Shared/Airship";
import { ChatCommand } from "@Easy/Core/Shared/Commands/ChatCommand";
import { Player } from "@Easy/Core/Shared/Player/Player";


export class MyCommand extends ChatCommand {
	constructor() {
		super("mycommand", ["c"], "[string] (optional)", "Print a message");
	}

	//Player that sent the command and the variables passed through as string arguments
	public Execute(player: Player, args: string[]): void {

		//Get the parameter if it was sent
		let firstParameter = ""
		if(args.size() > 0){
			firstParameter = args[0];
		}
		
		//Create a log message
		const logMessage = "Client sent message: " + firstParameter;

		//Log to console on server
		print(logMessage);

		//Send the results to every clients chat window
		Airship.Chat.BroadcastMessage(logMessage);
	}
}

PreviousWhat is the Core Package?NextInventory

Last updated 8 months ago