Defining a Message
Let's start with defining our first message.
In order to do that we need to create a custom method that is going to be a basis for our message.
Let's make a simple custom method that calls a print
function.
- TypeScript
- Luau
attack.ts
import { Skill, SkillDecorator } from "@rbxts/wcs";
@SkillDecorator
export class Attack extends Skill {
protected printSomething(a: number, b: string) {
print(a,b);
}
}
attack.lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WCS = require(ReplicatedStorage.WCS)
local Attack = WCS.RegisterSkill("Attack")
function Attack:printSomething(a,b)
print(a,b)
end
return Attack
We defined our custom method called printSomething
. Now, all we need to do is call WCS.DefineMessage
on that specific function:
- TypeScript
- Luau
note
To define a message in TypeScript
you need to use @Message()
decorator factory.
attack.ts
import { Skill, SkillDecorator } from "@rbxts/wcs";
@SkillDecorator
export class Attack extends Skill {
@Message({
Type: "Event",
Destination: "Client",
})
protected printSomething(a: number, b: string) {
print(a,b);
}
}
attack.lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WCS = require(ReplicatedStorage.WCS)
local Attack = WCS.RegisterSkill("Attack")
function Attack:printSomething(a,b)
print(a,b)
end
WCS.DefineMessage(Attack.printSomething, {
Type = "Event",
Destination = "Client",
})
return Attack
From now, if we call printSomething()
on server, it will be passed to a remote event and invoked on client.
The following method will be invoked on client:
- TypeScript
- Luau
attack.ts
import { Skill, SkillDecorator } from "@rbxts/wcs";
@SkillDecorator
export class Attack extends Skill {
//...TRUNCATED...
public OnStartServer() {
this.printSomething(1, "hi")
}
}
attack.lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WCS = require(ReplicatedStorage.WCS)
local Attack = WCS.RegisterSkill("Attack")
-- ...TRUNCATED...
function Attack:OnStartServer()
self:printSomething(1, "hi")
end
return Attack