As the title says, whenever I get attacked the player attack sound alarm doesn't seem to work, every other alarms works properly.
Here is my alarms.lua
And here is my alarms.otui
I hope someone can help me to get it to work.
Here is my alarms.lua
Code:
alarmsPanelName = "alarms"
local ui = setupUI([[
Panel
height: 19
BotSwitch
id: title
anchors.top: parent.top
anchors.left: parent.left
text-align: center
width: 130
!text: tr('Alarms')
Button
id: alerts
anchors.top: prev.top
anchors.left: prev.right
anchors.right: parent.right
margin-left: 3
height: 17
text: Edit
]])
ui:setId(alarmsPanelName)
if not storage[alarmsPanelName] then
storage[alarmsPanelName] = {
enabled = false,
playerAttack = false,
playerDetected = false,
playerDetectedLogout = false,
creatureDetected = false,
healthBelow = false,
healthValue = 40,
manaBelow = false,
manaValue = 50,
privateMessage = false
}
end
ui.title:setOn(storage[alarmsPanelName].enabled)
ui.title.onClick = function(widget)
storage[alarmsPanelName].enabled = not storage[alarmsPanelName].enabled
widget:setOn(storage[alarmsPanelName].enabled)
end
rootWidget = g_ui.getRootWidget()
if rootWidget then
alarmsWindow = g_ui.createWidget('AlarmsWindow', rootWidget)
alarmsWindow:hide()
alarmsWindow.closeButton.onClick = function(widget)
alarmsWindow:hide()
end
alarmsWindow.playerAttack:setOn(storage[alarmsPanelName].playerAttack)
alarmsWindow.playerAttack.onClick = function(widget)
storage[alarmsPanelName].playerAttack = not storage[alarmsPanelName].playerAttack
widget:setOn(storage[alarmsPanelName].playerAttack)
end
alarmsWindow.playerDetected:setOn(storage[alarmsPanelName].playerDetected)
alarmsWindow.playerDetected.onClick = function(widget)
storage[alarmsPanelName].playerDetected = not storage[alarmsPanelName].playerDetected
widget:setOn(storage[alarmsPanelName].playerDetected)
end
alarmsWindow.playerDetectedLogout:setChecked(storage[alarmsPanelName].playerDetectedLogout)
alarmsWindow.playerDetectedLogout.onClick = function(widget)
storage[alarmsPanelName].playerDetectedLogout = not storage[alarmsPanelName].playerDetectedLogout
widget:setChecked(storage[alarmsPanelName].playerDetectedLogout)
end
alarmsWindow.creatureDetected:setOn(storage[alarmsPanelName].creatureDetected)
alarmsWindow.creatureDetected.onClick = function(widget)
storage[alarmsPanelName].creatureDetected = not storage[alarmsPanelName].creatureDetected
widget:setOn(storage[alarmsPanelName].creatureDetected)
end
alarmsWindow.healthBelow:setOn(storage[alarmsPanelName].healthBelow)
alarmsWindow.healthBelow.onClick = function(widget)
storage[alarmsPanelName].healthBelow = not storage[alarmsPanelName].healthBelow
widget:setOn(storage[alarmsPanelName].healthBelow)
end
alarmsWindow.healthValue.onValueChange = function(scroll, value)
storage[alarmsPanelName].healthValue = value
alarmsWindow.healthBelow:setText("Health < " .. storage[alarmsPanelName].healthValue .. "%")
end
alarmsWindow.healthValue:setValue(storage[alarmsPanelName].healthValue)
alarmsWindow.manaBelow:setOn(storage[alarmsPanelName].manaBelow)
alarmsWindow.manaBelow.onClick = function(widget)
storage[alarmsPanelName].manaBelow = not storage[alarmsPanelName].manaBelow
widget:setOn(storage[alarmsPanelName].manaBelow)
end
alarmsWindow.manaValue.onValueChange = function(scroll, value)
storage[alarmsPanelName].manaValue = value
alarmsWindow.manaBelow:setText("Mana < " .. storage[alarmsPanelName].manaValue .. "%")
end
alarmsWindow.manaValue:setValue(storage[alarmsPanelName].manaValue)
alarmsWindow.privateMessage:setOn(storage[alarmsPanelName].privateMessage)
alarmsWindow.privateMessage.onClick = function(widget)
storage[alarmsPanelName].privateMessage = not storage[alarmsPanelName].privateMessage
widget:setOn(storage[alarmsPanelName].privateMessage)
end
onTextMessage(function(mode, text)
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
playSound("/sounds/Player_Attack.ogg")
end
end)
macro(100, function()
if not storage[alarmsPanelName].enabled then
return
end
if storage[alarmsPanelName].playerDetected then
for _, spec in ipairs(getSpectators()) do
if spec:isPlayer() and spec:getName() ~= name() then
specPos = spec:getPosition()
if math.max(math.abs(posx()-specPos.x), math.abs(posy()-specPos.y)) <= 8 then
playSound("/sounds/Player_Detected.ogg")
delay(1500)
if storage[alarmsPanelName].playerDetectedLogout then
modules.game_interface.tryLogout(false)
end
return
end
end
end
end
if storage[alarmsPanelName].creatureDetected then
for _, spec in ipairs(getSpectators()) do
if not spec:isPlayer()then
specPos = spec:getPosition()
if math.max(math.abs(posx()-specPos.x), math.abs(posy()-specPos.y)) <= 8 then
playSound("/sounds/Creature_Detected.ogg")
delay(1500)
return
end
end
end
end
if storage[alarmsPanelName].healthBelow then
if hppercent() <= storage[alarmsPanelName].healthValue then
playSound("/sounds/Low_Health.ogg")
delay(1500)
return
end
end
if storage[alarmsPanelName].manaBelow then
if manapercent() <= storage[alarmsPanelName].manaValue then
playSound("/sounds/Low_Mana.ogg")
delay(1500)
return
end
end
end)
onTalk(function(name, level, mode, text, channelId, pos)
if mode == 4 and storage[alarmsPanelName].enabled and storage[alarmsPanelName].privateMessage then
playSound("/sounds/Private_Message.ogg")
return
end
end)
end
ui.alerts.onClick = function(widget)
alarmsWindow:show()
alarmsWindow:raise()
alarmsWindow:focus()
end
And here is my alarms.otui
Code:
AlarmsWindow < MainWindow
!text: tr('Alarms')
size: 270 200
@onEscape: self:hide()
BotSwitch
id: playerAttack
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
text-align: center
text: Player Attack
BotSwitch
id: playerDetected
anchors.left: parent.left
anchors.right: parent.horizontalCenter
anchors.top: prev.bottom
margin-top: 4
text-align: center
text: Player Detected
CheckBox
id: playerDetectedLogout
anchors.top: playerDetected.top
anchors.left: parent.horizontalCenter
anchors.right: parent.right
margin-top: 3
margin-left: 4
text: Logout
BotSwitch
id: creatureDetected
anchors.left: parent.left
anchors.right: parent.right
anchors.top: playerDetected.bottom
margin-top: 4
text-align: center
text: Creature Detected
BotSwitch
id: healthBelow
anchors.left: parent.left
anchors.top: prev.bottom
anchors.right: parent.horizontalCenter
text-align: center
margin-top: 4
text: Health < 50%
HorizontalScrollBar
id: healthValue
anchors.left: parent.horizontalCenter
anchors.right: parent.right
anchors.top: healthBelow.top
margin-left: 3
margin-top: 2
minimum: 1
maximum: 100
step: 1
BotSwitch
id: manaBelow
anchors.left: parent.left
anchors.top: healthBelow.bottom
anchors.right: parent.horizontalCenter
text-align: center
margin-top: 4
text: Mana < 50%
HorizontalScrollBar
id: manaValue
anchors.left: parent.horizontalCenter
anchors.right: parent.right
anchors.top: manaBelow.top
margin-left: 3
margin-top: 2
minimum: 1
maximum: 100
step: 1
BotSwitch
id: privateMessage
anchors.left: parent.left
anchors.top: manaBelow.bottom
anchors.right: parent.right
text-align: center
margin-top: 4
text: Private Message
HorizontalSeparator
id: separator
anchors.right: parent.right
anchors.left: parent.left
anchors.bottom: closeButton.top
margin-bottom: 8
Button
id: closeButton
!text: tr('Close')
font: cipsoftFont
anchors.right: parent.right
anchors.bottom: parent.bottom
size: 45 21
margin-top: 15
margin-right: 5
I hope someone can help me to get it to work.