Skip to content

Commit 5628f7a

Browse files
committed
version 1.0, initial release
1 parent 9207b10 commit 5628f7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+13146
-2
lines changed

.gitattributes

Lines changed: 0 additions & 2 deletions
This file was deleted.

0_AAmain.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- main tab
2+
UI.Label("vBot 1.0 \n \n Scripting Service: \n Vithrax#5814")
3+
4+
UI.Separator()

0_BotSever.lua

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
setDefaultTab("Main")
2+
3+
BotPanelName = "BOTserver"
4+
local ui = setupUI([[
5+
Panel
6+
height: 18
7+
8+
Button
9+
id: botServer
10+
anchors.left: parent.left
11+
anchors.right: parent.right
12+
text-align: center
13+
height: 18
14+
!text: tr('BotServer')
15+
]])
16+
ui:setId(BotPanelName)
17+
18+
if not storage[BotPanelName] then
19+
storage[BotPanelName] = {
20+
manaInfo = true,
21+
mwallInfo = true
22+
}
23+
end
24+
25+
if not storage.BotServerChannel then
26+
storage.BotServerChannel = tostring(math.random(1000000000000,9999999999999))
27+
end
28+
29+
local channel = tostring(storage.BotServerChannel)
30+
BotServer.init(name(), channel)
31+
32+
rootWidget = g_ui.getRootWidget()
33+
if rootWidget then
34+
botServerWindow = g_ui.createWidget('BotServerWindow', rootWidget)
35+
botServerWindow:hide()
36+
37+
38+
botServerWindow.Data.Channel:setText(storage.BotServerChannel)
39+
botServerWindow.Data.Channel.onTextChange = function(widget, text)
40+
storage.BotServerChannel = text
41+
end
42+
43+
botServerWindow.Data.Random.onClick = function(widget)
44+
storage.BotServerChannel = tostring(math.random(1000000000000,9999999999999))
45+
botServerWindow.Data.Channel:setText(storage.BotServerChannel)
46+
end
47+
48+
botServerWindow.Features.Feature1:setOn(storage[BotPanelName].manaInfo)
49+
botServerWindow.Features.Feature1.onClick = function(widget)
50+
storage[BotPanelName].manaInfo = not storage[BotPanelName].manaInfo
51+
widget:setOn(storage[BotPanelName].manaInfo)
52+
end
53+
54+
botServerWindow.Features.Feature2:setOn(storage[BotPanelName].mwallInfo)
55+
botServerWindow.Features.Feature2.onClick = function(widget)
56+
storage[BotPanelName].mwallInfo = not storage[BotPanelName].mwallInfo
57+
widget:setOn(storage[BotPanelName].mwallInfo)
58+
end
59+
end
60+
61+
function updateStatusText()
62+
if BotServer._websocket then
63+
botServerWindow.Data.ServerStatus:setText("CONNECTED")
64+
if serverCount then
65+
botServerWindow.Data.Participants:setText(#serverCount)
66+
end
67+
else
68+
botServerWindow.Data.ServerStatus:setText("DISCONNECTED")
69+
botServerWindow.Data.Participants:setText("-")
70+
end
71+
end
72+
73+
macro(2000, function()
74+
if BotServer._websocket then
75+
BotServer.send("list")
76+
end
77+
updateStatusText()
78+
end)
79+
80+
local regex = [["(.*?)"]]
81+
BotServer.listen("list", function(name, data)
82+
serverCount = regexMatch(json.encode(data), regex)
83+
storage.serverMembers = json.encode(data)
84+
end)
85+
86+
ui.botServer.onClick = function(widget)
87+
botServerWindow:show()
88+
botServerWindow:raise()
89+
botServerWindow:focus()
90+
end
91+
92+
botServerWindow.closeButton.onClick = function(widget)
93+
botServerWindow:hide()
94+
end
95+
96+
97+
-- scripts
98+
99+
storage[BotPanelName].mwalls = {}
100+
BotServer.listen("mwall", function(name, message)
101+
if storage[BotPanelName].mwallInfo then
102+
if not storage[BotPanelName].mwalls[message["pos"]] or storage[BotPanelName].mwalls[message["pos"]] < now then
103+
storage[BotPanelName].mwalls[message["pos"]] = now + message["duration"] - 150 -- 150 is latency correction
104+
end
105+
end
106+
end)
107+
108+
BotServer.listen("mana", function(name, message)
109+
if storage[BotPanelName].manaInfo then
110+
local creature = getPlayerByName(name)
111+
if creature then
112+
creature:setManaPercent(message["mana"])
113+
end
114+
end
115+
end)
116+
117+
onAddThing(function(tile, thing)
118+
if storage[BotPanelName].mwallInfo then
119+
if thing:isItem() and thing:getId() == 2129 then
120+
local pos = tile:getPosition().x .. "," .. tile:getPosition().y .. "," .. tile:getPosition().z
121+
if not storage[BotPanelName].mwalls[pos] or storage[BotPanelName].mwalls[pos] < now then
122+
storage[BotPanelName].mwalls[pos] = now + 20000
123+
BotServer.send("mwall", {pos=pos, duration=20000})
124+
end
125+
tile:setTimer(storage[BotPanelName].mwalls[pos] - now)
126+
end
127+
end
128+
end)
129+
130+
local lastMana = 0
131+
macro(100, function()
132+
if storage[BotPanelName].manaInfo then
133+
if manapercent() ~= lastMana then
134+
lastMana = manapercent()
135+
BotServer.send("mana", {mana=lastMana})
136+
end
137+
end
138+
end)
139+
140+
141+
142+
143+
144+
145+
146+
147+
addSeparator()

1_alarms.lua

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
alarmsPanelName = "alarms"
2+
local ui = setupUI([[
3+
Panel
4+
height: 19
5+
6+
BotSwitch
7+
id: title
8+
anchors.top: parent.top
9+
anchors.left: parent.left
10+
text-align: center
11+
width: 130
12+
!text: tr('Alarms')
13+
14+
Button
15+
id: alerts
16+
anchors.top: prev.top
17+
anchors.left: prev.right
18+
anchors.right: parent.right
19+
margin-left: 3
20+
height: 17
21+
text: Edit
22+
23+
]])
24+
ui:setId(alarmsPanelName)
25+
26+
if not storage[alarmsPanelName] then
27+
storage[alarmsPanelName] = {
28+
enabled = false,
29+
playerAttack = false,
30+
playerDetected = false,
31+
playerDetectedLogout = false,
32+
creatureDetected = false,
33+
healthBelow = false,
34+
healthValue = 40,
35+
manaBelow = false,
36+
manaValue = 50,
37+
privateMessage = false
38+
}
39+
end
40+
41+
ui.title:setOn(storage[alarmsPanelName].enabled)
42+
ui.title.onClick = function(widget)
43+
storage[alarmsPanelName].enabled = not storage[alarmsPanelName].enabled
44+
widget:setOn(storage[alarmsPanelName].enabled)
45+
end
46+
47+
rootWidget = g_ui.getRootWidget()
48+
if rootWidget then
49+
alarmsWindow = g_ui.createWidget('AlarmsWindow', rootWidget)
50+
alarmsWindow:hide()
51+
52+
alarmsWindow.closeButton.onClick = function(widget)
53+
alarmsWindow:hide()
54+
end
55+
56+
alarmsWindow.playerAttack:setOn(storage[alarmsPanelName].playerAttack)
57+
alarmsWindow.playerAttack.onClick = function(widget)
58+
storage[alarmsPanelName].playerAttack = not storage[alarmsPanelName].playerAttack
59+
widget:setOn(storage[alarmsPanelName].playerAttack)
60+
end
61+
62+
alarmsWindow.playerDetected:setOn(storage[alarmsPanelName].playerDetected)
63+
alarmsWindow.playerDetected.onClick = function(widget)
64+
storage[alarmsPanelName].playerDetected = not storage[alarmsPanelName].playerDetected
65+
widget:setOn(storage[alarmsPanelName].playerDetected)
66+
end
67+
68+
alarmsWindow.playerDetectedLogout:setChecked(storage[alarmsPanelName].playerDetectedLogout)
69+
alarmsWindow.playerDetectedLogout.onClick = function(widget)
70+
storage[alarmsPanelName].playerDetectedLogout = not storage[alarmsPanelName].playerDetectedLogout
71+
widget:setChecked(storage[alarmsPanelName].playerDetectedLogout)
72+
end
73+
74+
alarmsWindow.creatureDetected:setOn(storage[alarmsPanelName].creatureDetected)
75+
alarmsWindow.creatureDetected.onClick = function(widget)
76+
storage[alarmsPanelName].creatureDetected = not storage[alarmsPanelName].creatureDetected
77+
widget:setOn(storage[alarmsPanelName].creatureDetected)
78+
end
79+
80+
alarmsWindow.healthBelow:setOn(storage[alarmsPanelName].healthBelow)
81+
alarmsWindow.healthBelow.onClick = function(widget)
82+
storage[alarmsPanelName].healthBelow = not storage[alarmsPanelName].healthBelow
83+
widget:setOn(storage[alarmsPanelName].healthBelow)
84+
end
85+
86+
alarmsWindow.healthValue.onValueChange = function(scroll, value)
87+
storage[alarmsPanelName].healthValue = value
88+
alarmsWindow.healthBelow:setText("Health < " .. storage[alarmsPanelName].healthValue .. "%")
89+
end
90+
alarmsWindow.healthValue:setValue(storage[alarmsPanelName].healthValue)
91+
92+
alarmsWindow.manaBelow:setOn(storage[alarmsPanelName].manaBelow)
93+
alarmsWindow.manaBelow.onClick = function(widget)
94+
storage[alarmsPanelName].manaBelow = not storage[alarmsPanelName].manaBelow
95+
widget:setOn(storage[alarmsPanelName].manaBelow)
96+
end
97+
98+
alarmsWindow.manaValue.onValueChange = function(scroll, value)
99+
storage[alarmsPanelName].manaValue = value
100+
alarmsWindow.manaBelow:setText("Mana < " .. storage[alarmsPanelName].manaValue .. "%")
101+
end
102+
alarmsWindow.manaValue:setValue(storage[alarmsPanelName].manaValue)
103+
104+
alarmsWindow.privateMessage:setOn(storage[alarmsPanelName].privateMessage)
105+
alarmsWindow.privateMessage.onClick = function(widget)
106+
storage[alarmsPanelName].privateMessage = not storage[alarmsPanelName].privateMessage
107+
widget:setOn(storage[alarmsPanelName].privateMessage)
108+
end
109+
110+
onTextMessage(function(mode, text)
111+
if storage[alarmsPanelName].enabled and storage[alarmsPanelName].playerAttack and mode == 16 and string.match(text, "hitpoints due to an attack") and not string.match(text, "hitpoints due to an attack by a ") then
112+
playSound("/sounds/Player_Attack.ogg")
113+
end
114+
end)
115+
116+
macro(100, function()
117+
if not storage[alarmsPanelName].enabled then
118+
return
119+
end
120+
if storage[alarmsPanelName].playerDetected then
121+
for _, spec in ipairs(getSpectators()) do
122+
if spec:isPlayer() and spec:getName() ~= name() then
123+
specPos = spec:getPosition()
124+
if math.max(math.abs(posx()-specPos.x), math.abs(posy()-specPos.y)) <= 8 then
125+
playSound("/sounds/Player_Detected.ogg")
126+
delay(1500)
127+
if storage[alarmsPanelName].playerDetectedLogout then
128+
modules.game_interface.tryLogout(false)
129+
end
130+
return
131+
end
132+
end
133+
end
134+
end
135+
136+
if storage[alarmsPanelName].creatureDetected then
137+
for _, spec in ipairs(getSpectators()) do
138+
if not spec:isPlayer()then
139+
specPos = spec:getPosition()
140+
if math.max(math.abs(posx()-specPos.x), math.abs(posy()-specPos.y)) <= 8 then
141+
playSound("/sounds/Creature_Detected.ogg")
142+
delay(1500)
143+
return
144+
end
145+
end
146+
end
147+
end
148+
149+
if storage[alarmsPanelName].healthBelow then
150+
if hppercent() <= storage[alarmsPanelName].healthValue then
151+
playSound("/sounds/Low_Health.ogg")
152+
delay(1500)
153+
return
154+
end
155+
end
156+
157+
if storage[alarmsPanelName].manaBelow then
158+
if manapercent() <= storage[alarmsPanelName].manaValue then
159+
playSound("/sounds/Low_Mana.ogg")
160+
delay(1500)
161+
return
162+
end
163+
end
164+
end)
165+
166+
onTalk(function(name, level, mode, text, channelId, pos)
167+
if mode == 4 and storage[alarmsPanelName].enabled and storage[alarmsPanelName].privateMessage then
168+
playSound("/sounds/Private_Message.ogg")
169+
return
170+
end
171+
end)
172+
end
173+
174+
ui.alerts.onClick = function(widget)
175+
alarmsWindow:show()
176+
alarmsWindow:raise()
177+
alarmsWindow:focus()
178+
end

0 commit comments

Comments
 (0)