-
-
Notifications
You must be signed in to change notification settings - Fork 664
/
Copy pathzones.lua
103 lines (97 loc) · 3 KB
/
zones.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
local zones = TalkAction("/zones")
function zones.onSay(player, words, param)
local params = string.split(param, ",")
local cmd = params[1]
if not cmd then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Command not found.")
return true
end
if cmd == "list" then
local list = {}
local filter = params[2] and params[2]:trim()
for _, zone in ipairs(Zone.getAll()) do
if filter then
if not zone:getName():lower():find(filter:lower()) then
goto continue
end
end
table.insert(list, zone:getName())
::continue::
end
player:sendTextMessage(MESSAGE_HEALED, "Zones:\n" .. table.concat(list, "\n "))
return true
end
local function zoneFromParam()
local zoneName = params[2]:trim()
if not zoneName then
player:sendTextMessage(MESSAGE_HEALED, "Zone not found.")
return true
end
local zone = Zone.getByName(zoneName)
if not zone then
player:sendTextMessage(MESSAGE_HEALED, "Zone not found.")
return true
end
return zone
end
local commands = {
["goto"] = function(zone)
local pos = zone:randomPosition()
if not pos then
player:sendTextMessage(MESSAGE_HEALED, "No position found.")
return true
end
player:teleportTo(pos)
player:sendTextMessage(MESSAGE_HEALED, "You have been teleported to " .. zone:getName() .. ".")
end,
removeMonsters = function(zone)
zone:removeMonsters()
player:sendTextMessage(MESSAGE_HEALED, "Monsters removed from " .. zone:getName() .. ".")
end,
countMonsters = function(zone)
local monsters = zone:getMonsters()
player:sendTextMessage(MESSAGE_HEALED, "Zone " .. zone:getName() .. " monsters: " .. #monsters .. ".")
end,
removeNpcs = function(zone)
zone:removeNpcs()
player:sendTextMessage(MESSAGE_HEALED, "NPCs removed from " .. zone:getName() .. ".")
end,
countNpcs = function(zone)
local npcs = zone:getNpcs()
player:sendTextMessage(MESSAGE_HEALED, "Zone " .. zone:getName() .. " NPCs: " .. #npcs .. ".")
end,
kickPlayers = function(zone)
zone:removePlayers()
player:sendTextMessage(MESSAGE_HEALED, "Players kicked from " .. zone:getName() .. ".")
end,
listPlayers = function(zone)
local players = zone:getPlayers()
local list = {}
for _, player in ipairs(players) do
table.insert(list, player:getName())
end
player:sendTextMessage(MESSAGE_HEALED, "Zone " .. zone:getName() .. " players: " .. table.concat(list, ", ") .. ".")
end,
countPlayers = function(zone)
local players = zone:getPlayers()
player:sendTextMessage(MESSAGE_HEALED, "Zone " .. zone:getName() .. " players: " .. #players .. ".")
end,
size = function(zone)
local positions = zone:getPositions()
player:sendTextMessage(MESSAGE_HEALED, "Zone " .. zone:getName() .. " size: " .. #positions .. ".")
end,
}
local command = commands[cmd]
if not command then
player:sendTextMessage(MESSAGE_HEALED, "Command not found.")
return true
end
local zone = zoneFromParam()
if not zone then
return true
end
return command(zone)
end
zones:separator(" ")
zones:groupType("god")
zones:register()