Skip to main content

Utilities and Commands

Helper functions for logging, messages, commands, effects, and more.

Logging

-- Basic console log
LogPrint("Message")

-- Colored logs
LogColor(3, "[MyPlugin] Loaded!") -- Blue
LogColor(1, "[ERROR] Something failed!") -- Red
LogColor(2, "[OK] Success!") -- Green

Player Messages

-- Message to one player
NoticeSend(aIndex, 1, "Hello!")

// Message to all players
NoticeSendToAll(1, "Server maintenance in 10 minutes!")

-- Message to region
NoticeRegionSend(1, "Event starting!")

-- Message globally (all servers)
NoticeGlobalSend(1, "World boss spawned!")

Commands

Register Commands

MyCmd = {}
MyCmd.Code = Toolkit:getUniqueIndex()

BridgeFunction:push("OnReadScript", function()
CommandAddInfo("/mycommand", MyCmd.Code)
end)

BridgeFunction:push("OnCommandManager", function(aIndex, code, args)
if code == MyCmd.Code then
-- Check permission
if not CommandCheckGameMasterLevel(aIndex, 1) then
NoticeSend(aIndex, 1, "No permission!")
return 1
end

-- Get arguments
local playerName = CommandGetArgString(args, 0)
local value = CommandGetArgNumber(args, 1)

-- Execute command
NoticeSend(aIndex, 1, "Command executed!")
return 1
end
return 0
end)

Command Arguments

-- Get string argument
local playerName = CommandGetArgString(args, 0) -- First arg

-- Get number argument
local amount = CommandGetArgNumber(args, 1) -- Second arg

-- Check GM level
if CommandCheckGameMasterLevel(aIndex, 1) then
-- Has GM permission (level 1+)
end

Effects and Buffs

-- Add effect
EffectAdd(aIndex, 3, 0, 0, 0, 0, 0, 60) -- Buff for 60 seconds

-- Remove effect
EffectDel(aIndex, 3)

-- Check if has effect
if EffectCheck(aIndex, 3) then
print("Has buff")
end

-- Clear all effects
EffectClear(aIndex)

Party and Guild

-- Party
local partyNum = GetObjectPartyNumber(aIndex)
if partyNum ~= -1 then
local memberCount = PartyGetMemberCount(partyNum)

for i = 0, memberCount - 1 do
local memberIndex = PartyGetMemberIndex(partyNum, i)
if memberIndex ~= -1 then
local memberName = GetObjectName(memberIndex)
print("Member: " .. memberName)
end
end
end

-- Guild
local guildNum = GetObjectGuildNumber(aIndex)
local guildName = GetObjectGuildName(aIndex)
local guildStatus = GetObjectGuildStatus(aIndex)
-- 0=member, 1=master, 2=assistant

Visual Effects

-- Level up animation
LevelUpSend(aIndex)

-- Master level up animation
MasterLevelUpSend(aIndex)

-- Fireworks
FireworksSend(aIndex, 0, 0)

-- Timer on client
TimerStartSend(aIndex, 0, 10, 0) -- 10 seconds

Player Control

-- Disconnect player
UserDisconnect(aIndex)

// Force logout
UserGameLogout(aIndex, 0)

// Recalculate stats (after changing attributes)
UserCalcAttribute(aIndex)

// Update client info
UserInfoSend(aIndex)

-- Update viewport (objects visible)
UserUpdateViewport(aIndex)

Random Numbers

// Random integer (0 to max-1)
local random = RandomGetNumber(100) -- 0-99

-- Random float (0.0 to max)
local randomFloat = RandomGetSingle(1.0) -- 0.0-1.0

Memory Storage

Temporary storage during server runtime:

-- Store number
MemorySetNumber("plugin:counter", 0)

-- Get number
local counter = MemoryGetNumber("plugin:counter")

-- Increment and return old value
local oldValue = MemoryAddNumber("plugin:counter", 1)

-- Decrement
MemoryDecNumber("plugin:counter", 1)

-- Store string
MemorySetString("plugin:status", "active")

-- Get string
local status = MemoryGetString("plugin:status")

-- Remove key
MemoryRemoveKey("plugin:counter")

Example - Global Kill Counter

BridgeFunction:push("OnLoadScript", function()
MemorySetNumber("global:kills", 0)
end)

BridgeFunction:push("OnMonsterDie", function(aIndex, bIndex)
local kills = MemoryAddNumber("global:kills", 1) + 1
if kills % 1000 == 0 then
NoticeSendToAll(1, string.format("%d monsters killed!", kills))
end
end)

Server Info

local serverName = GetGameServerName()
local onlinePlayers = GetGameServerCurUser()
local serverCode = GetGameServerCode()

LogPrint(string.format("Server: %s - Online: %d",
serverName, onlinePlayers))

Complete Example - VIP Buff System

VIPBuff = {}
VIPBuff.Code = Toolkit:getUniqueIndex()

BridgeFunction:push("OnReadScript", function()
CommandAddInfo("/vipbuff", VIPBuff.Code)
end)

BridgeFunction:push("OnCommandManager", function(aIndex, code, args)
if code == VIPBuff.Code then
VIPBuff:applyBuff(aIndex)
return 1
end
return 0
end)

function VIPBuff:applyBuff(aIndex)
local vipLevel = GetObjectAccountLevel(aIndex)

if vipLevel < 1 then
NoticeSend(aIndex, 1, "Need VIP to use this!")
return
end

-- Check cooldown (1 hour)
local lastUse = MemoryGetNumber("vipbuff:" .. GetObjectName(aIndex))
local currentTime = os.time()

if lastUse > 0 and (currentTime - lastUse) < 3600 then
local remaining = 3600 - (currentTime - lastUse)
local minutes = math.floor(remaining / 60)
NoticeSend(aIndex, 1, string.format("Wait %d minutes!", minutes))
return
end

-- Apply buffs based on VIP level
if vipLevel >= 1 then
EffectAdd(aIndex, 3, 0, 0, 0, 0, 0, 600) -- 10 min buff
SetObjectLife(aIndex, GetObjectMaxLife(aIndex))
SetObjectMana(aIndex, GetObjectMaxMana(aIndex))
NoticeSend(aIndex, 1, "VIP buff applied!")
end

if vipLevel >= 2 then
local zen = GetObjectMoney(aIndex)
SetObjectMoney(aIndex, zen + 1000000)
MoneySend(aIndex, GetObjectMoney(aIndex))
NoticeSend(aIndex, 1, "+1kk Zen bonus!")
end

if vipLevel >= 3 then
ItemGiveEx(aIndex, 14, 13, 0, 1, 0, 0, 0, 0, 0, 0,0,0,0,0,0)
NoticeSend(aIndex, 1, "+1 Jewel of Bless!")
end

-- Save cooldown
MemorySetNumber("vipbuff:" .. GetObjectName(aIndex), currentTime)

UserInfoSend(aIndex)
LevelUpSend(aIndex)
FireworksSend(aIndex, 0, 0)
end

Best Practices

  1. Use LogColor for important logs - Makes console easier to read
  2. Check GM level before executing admin commands
  3. Validate arguments - Check if strings are empty, numbers are valid
  4. Use Memory for temporary data - No database needed for runtime counters
  5. Give visual feedback - Effects, sounds, notifications
  6. Recalculate after stat changes - Always use UserCalcAttribute() and UserInfoSend()

Quick Reference

-- Logging
LogPrint("Message")
LogColor(2, "[OK] Success!")

-- Messages
NoticeSend(aIndex, 1, "Message")
NoticeSendToAll(1, "Broadcast")

-- Commands
CommandAddInfo("/cmd", code)
CommandCheckGameMasterLevel(aIndex, 1)
CommandGetArgString(args, 0)
CommandGetArgNumber(args, 1)

-- Effects
EffectAdd(aIndex, 3, 0,0,0,0,0, 60)
EffectCheck(aIndex, 3)
EffectDel(aIndex, 3)

-- Visual
LevelUpSend(aIndex)
FireworksSend(aIndex, 0, 0)

-- Control
UserCalcAttribute(aIndex)
UserInfoSend(aIndex)

-- Memory
MemorySetNumber("key", value)
MemoryGetNumber("key")

// Random
RandomGetNumber(100)

That's everything! You now have all the tools to build complete server-side plugins. Happy coding! 🚀