Server Script

  • Server scripts must exist in the project folder or under the "Scripts" directory with file names like Hello.lua to be read properly.

Script
Description

Server.onJoinPlayer(unit)

A new player connects.

Server.onLeavePlayer(unit)

A specific user leaves the game.

Server.SendCenterLabel(text)

Display a label on the screen.

Server.SendSay(text, color)

Display a message in the chat window.

ScriptEventPublisher Server.GetTopic(topic)

Register a specific topic to send and receive messages with the client.

Server.FireEvent(topic, args…)

Send a message to the client with a specific topic.

Server.players

Retrieve a list of players.

Server.fields

Retrieve the entire map list.

Server.CreateEventUnit(name, imageID)

Create an event user.

Server.GetField(dataID)

Retrieve the map of a specific ID.

ScriptUnit

Monsters are objects similar to players.

Server.playerLeavePartyCallback(scriptRoomPlayer,scriptParty)

Triggered when a player leaves the party.

Server.playerJoinPartyCallback(scriptRoomPlayer,scriptParty)

Triggered when a player joins the party.

Server.onAddItem(scriptUnit,titem)

Triggered when a user acquires an item.

Server.onRemoveItem(scriptUnit,titem)

Triggered when a user removes or uses an item.

Retrieve the class the user belongs to.

Retrieve color information.

  • unit.type = (0=player, 1=event, 2=monster)

Example: Server Script - Display a Message Upon Player Level-Up and Grant an Item at a Specific Level

Example: Server Script - Broadcast a Message to All Players and Grant Rewards for PVP Kills

Example: Using onJoinField - Display Player Name Upon Entering a Specific Map and Send a Server-Wide Message

onLeaveField - Handle actions when leaving a specific map

map - ScriptField

unit - ScriptUnit

File: Script Example for a Specific Map Usage Example: Decreasing the Value of a World Variable by 1 When Leaving the Map

Examples of Events Triggered During Specific Actions:

  • onUseItem: Triggered when an item is used.

  • onBuyGameMoneyItem: Triggered when an item is purchased with in-game currency.

  • onSellGameMoneyItem: Triggered when an item is sold for in-game currency.

Examples: Adding, Removing, and Modifying Item Options (Refer to ScriptUtility)

  • Please test the code by removing the applied comments (--). The script below was executed via a touch event - triggered through the script.

Example: Event Triggered Upon Joining a Party (playerJoinPartyCallback)

Example: Event Triggered Upon Leaving a Party (playerLeavePartyCallback)

Example: Event Triggered Upon Item Acquisition (onAddItem)

Example: Event Triggered Upon Item Removal (onRemoveItem)

Example: Event Triggered When Damage is Applied (damageCallback)

Example: Event Triggered Upon Completion of a Trade (onTradeDone)

Last updated