ChatChannel
There are many types of events for the ChatChannel interface, here is a list.
  • You create a ChatChannel script in data/chatchannels/scripts folder, but
  • You must register ChatChannel in data/chatchannels/chatchannels.xml, here is an example
1
<channel id="8" name="GodChannel" script="godchat.lua" />
Copied!
  • Alternatively you can use revscript method to register via lua, by saving a .lua file in data/scripts folder.
Please keep in mind you can name your script whatever you want as long as it ends in .lua, and its full name is in the xml, with script="scriptname.lua"

canJoin(player)

  • player -- 1st arg/parameter /userdata/ = The player who is trying to join the channel
canJoin is called whenever any player attempts to open the registered channel.
You can register your event in movement.xml like so:
1
<channel id="8" name="GodChannel" script="godchat.lua" />
Copied!
You can then call the event in a script like so:
Example: godchat.lua
1
function canJoin(player)
2
return player:getAccountType() > ACCOUNT_TYPE_GAMEMASTER -- if account type is higher access than a gamemaster returns true to allow joining, otherwise returns false and doesn't allow access
3
end
Copied!
Always remember to return true if you wish to allow player to join the channel, false if not!

onJoin(player)

  • player -- 1st arg/parameter /userdata/ = The player whom has just joined the channel
onJoin is called whenever any player joins the registered chatchannel
You can register your event in creaturescripts.xml like so:
1
<channel id="8" name="GodChannel" script="godchat.lua" />
Copied!
You can then call the event in a script like so:
Example: godchat.lua
1
function onJoin(player)
2
player:sendChannelMessage("System:", "Welcome to GodChat!", MESSAGE_STATUS_CONSOLE_RED, 8)
3
end
Copied!
onJoin will execute its logic everytime a player joins the channel, returns don't matter for this event!

onLeave(player)

  • player -- 1st arg/parameter /userdata/ = The player who has left the registered chatchannel
onLeave is called whenever a player leaves the registered chatchannel
You can register your event in creaturescripts.xml like so:
1
<channel id="8" name="GodChannel" script="godchat.lua" />
Copied!
You can then call the event in a script like so:
Example: godchat.lua
1
function onLeave(player)
2
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have left GodChat")
3
end
Copied!
onLeave will execute its logic everytime a player leaves the channel, returns don't matter for this event!

onSpeak(player, type, message)

  • player -- 1st arg/parameter /userdata/ = The player that is removing the item
  • type -- 2nd arg/parameter /integer/ = a constant value representing the TALK_TYPE
  • message -- 3rd arg/parameter /string/ = the text that player has sent
onSpeak runs everytime a player in the chatchannel sends a message.
You can register your event in creaturescripts.xml like so:
1
<channel id="8" name="GodChannel" script="godchat.lua" />
Copied!
You can then call the event in a script like so:
Example: godchat.lua
1
function onSpeak(player, type, message)
2
if player:getAccountType() == 10 then
3
if message == "hidehealth" then
4
player:setHiddenHealth(true)
5
end
6
if message == "showhealth" then
7
player:setHiddenHealth(false)
8
end
9
else
10
player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have appropriate account type to execute this channel command!")
11
end
12
end
Copied!
onSpeak executes everytime a player speaks in registered channel, returns don't matter here
Here is a complete example including all the events in one file
Example in xml:
1
<channel id="8" name="GodChannel" script="godchat.lua" />
Copied!
Example: godchat.lua
1
function canJoin(player)
2
return player:getAccountType() > ACCOUNT_TYPE_GAMEMASTER -- if account type is higher access than a gamemaster returns true to allow joining, otherwise returns false and doesn't allow access
3
end
4
5
function onJoin(player)
6
player:sendChannelMessage("System:", "Welcome to GodChat!", MESSAGE_STATUS_CONSOLE_RED, 8)
7
end
8
9
function onLeave(player)
10
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have left GodChat")
11
end
12
13
function onSpeak(player, type, message)
14
if player:getAccountType() == 10 then
15
if message == "hidehealth" then
16
player:setHiddenHealth(true)
17
end
18
if message == "showhealth" then
19
player:setHiddenHealth(false)
20
end
21
else
22
player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have appropriate account type to execute this channel command!")
23
end
24
end
Copied!
Last modified 2mo ago