Get damage value and school of magic incoming damage (WoW 1.13) - lua

How do I get damage value and school of incoming damage magic using api World Of WarCraft 1.13 in lua language? Damage caused to me by another player or mob.
This is necessary so that I can use
print("You received " .. damageValue .. " " .. damageSchool .. " damage")
So that I can get in the chat:
You received 100 Fire damage
You received 50 Physical damage
etc.

Classic combat log should be almost the same as retail
See https://wow.gamepedia.com/COMBAT_LOG_EVENT
local playerGUID = UnitGUID("player")
local MSG_PLAYER_DAMAGE = "You received %d %s damage"
local damageEvents = {
SWING_DAMAGE = true,
SPELL_DAMAGE = true,
}
local f = CreateFrame("Frame")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
f:SetScript("OnEvent", function(self, event)
self:OnEvent(event, CombatLogGetCurrentEventInfo())
end)
function f:OnEvent(event, ...)
local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = ...
local spellId, spellName, spellSchool
local amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing, isOffHand
if subevent == "SWING_DAMAGE" then
amount = select(12, ...)
elseif subevent == "SPELL_DAMAGE" then
spellId, spellName, spellSchool, amount = select(12, ...)
end
if damageEvents[subevent] and destGUID == playerGUID then
print(MSG_PLAYER_DAMAGE:format(amount, GetSchoolString(spellSchool or 0x1)))
end
end

Related

StarterGui:SetCore must be called from a local script

So... I am trying to explode everyone and send them a message but it is not working. Here is the code.
Serverside:
local gui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local pp = game:GetService("ProximityPromptService")
local phone = game:GetService("ReplicatedStorage")
local world = game.Workspace
local function pptrig (obj, ply)
for i,v in pairs(game.Players:GetChildren()) do
local player = world:FindFirstChild(v.Name)
local nuke = Instance.new("Explosion", world)
nuke.BlastRadius = 0.9
nuke.BlastPressure = 1000000
nuke.Position = player.HumanoidRootPart.Position
print("run")
phone.Exploded:FireClient(v, v.Name, ply.Name)
end
end
pp.PromptTriggered:Connect(pptrig)
Clientside:
local phone = game:GetService("ReplicatedStorage")
local gui = game:GetService("StarterGui")
gui:SetCore("test", {Text = "Ran"})
local function humiliation(me, ply)
gui:SetCore("test", {Text = "Ran"})
if ply ~= me then
gui:SetCore("Humiliation", {
Title = "Exploded!",
Text = "You have been exploded by "..ply..".",
Duration = 10,
})
elseif ply == me then
gui:SetCore("Humiliation", {
Title = "Exploded!",
Text = "You, "..me..", exploded yourself."
})
end
end
phone.Exploded.OnClientEvent:Connect(humiliation())
When I try to run it it gives me this:
StarterGui:SetCore must be called from a local script. (x2) - Studio
Players.GoldenRStar.PlayerGui.Script:19: attempt to concatenate nil with string - Server - Script:19
Exploded is a remote event and I wanted to Explode everyone and send them a message:
"You have been exploded by GuyThatPressesButtons." and
"You, GuyThatPressesButtons, exploded yourself."
this program tries to loop though every player, explodes them and sends them a fire from the remote event Exploded, then a client script catches it and processes it acordingly.
on the fire, it is sent the players name: v.Name and the player that pressed the button, on the client script both values are nil.

LUA unexpected symbol near ')' line local society =

RegisterServerEvent('esx_society:depositMoney')
AddEventHandler('esx_society:depositMoney', function(society, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local society = 'society_mechanic', function(society)
if amount > 0 and xPlayer.get('money') >= amount then
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
xPlayer.removeMoney(amount)
account.addMoney(amount)
end)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', amount))
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
end
end)
Hello, an error appears in my console when i use script.
Where can the error come from?
You have a syntax error with your function local society = 'society_mechanic', function(society) => end missing.
Correct your code like this :
RegisterServerEvent('esx_society:depositMoney')
AddEventHandler('esx_society:depositMoney', function(society, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local society = 'society_mechanic', function(society)
if amount > 0 and xPlayer.get('money') >= amount then
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
xPlayer.removeMoney(amount)
account.addMoney(amount)
end)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', amount))
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
end
end
end)
In your code is a end missing. You open a function in local society but doesn't close it.

Equation script for scaling rebirth cost not working

So basically I'm making a roblox clicker game where I have rebirths which have a cost and i made a menuOrganiser script that basically automatically makes rebirth buttons every time the value of players.upgrades.rebirthbuttons changes and I have added an equation that should scale the cost every time I rebirth but for someone it doesn't change the cost on the actual screen it says that the cost is 800 but when you try to rebirth with 800 clicks it doesn't work so it changes it but not the GUI and I'm wondering why.
This is the script with the equation for the rebirths. And I also get this error:
Players.kukata4321.PlayerGui.ScreenGui.RebirthMenu.ScrollingFrame.menuOrganiser:55: attempt to index number with 'Value'
...
rebirthButtons.Changed:Connect(function()
local amount = rebirthButtons.Value
for count = 1, amount do
if not scrollingframe:FindFirstChild(rebirthOptions[count]) then
local newButton = template:Clone()
local rebirthsAmount = rebirthOptions[count]
newButton.Name = rebirthsAmount
newButton.rebirthAmount.Text = rebirthsAmount.." Rebirths"
newButton.cost.Text = rebirthsAmount*800*((1)+((rebirths.Value)/10)).. " Clicks"
newButton.Parent = scrollingframe
end
end
end)
rebirths.Changed:Connect(function()
local rebirths = leaderstats:WaitForChild("Rebirths").Value
for _, child in pairs(scrollingframe:GetChildren()) do
if child:IsA("TextButton") then
local rebirthsAmount = tonumber(child.Name)
child.cost.Text = rebirthsAmount*800*((1)+((rebirths.Value)/10)).. " Clicks"
end
end
end)
So what your error means is that you defined a variable with an IntValue's value (which is a number) and then tried to get the "Value" of a number
Eg:
local rebirths = game.Players.leaderstats.Rebirths.Value -- returns a number
print(rebirths.Value) -- 12345.Value doesn't work
The simple solution is to remove .Value from when you define the variable
rebirths.Changed:Connect(function()
local rebirths = leaderstats:WaitForChild("Rebirths") -- Remove .Value
for _, child in pairs(scrollingframe:GetChildren()) do
if child:IsA("TextButton") then
local rebirthsAmount = tonumber(child.Name)
child.cost.Text = rebirthsAmount*800*((1)+((rebirths.Value)/10)).. " Clicks"
end
end

WoW Classic (1.13) addons events: COMBAT_TEXT_UPDATE. How to fix my code?

I just recently began to study LUA and add-ons for WoW. I want to display the school of magic and the amount of damage in the chat, but my code does not work. Please see what I'm doing wrong.
local Congrats_EventFrame = CreateFrame("Frame")
CombatTextSetActiveUnit("player")
Congrats_EventFrame:RegisterEvent("COMBAT_TEXT_UPDATE")
Congrats_EventFrame:SetScript("OnEvent",
function(arg1, arg2, arg3)
print(arg1 .. ' - ' .. arg2 .. ' - ' .. arg3)
end)
See the "amount" parameter for SPELL_DAMAGE under https://wow.gamepedia.com/COMBAT_LOG_EVENT
local playerGUID = UnitGUID("player")
local MSG_SPELL_DAMAGE = "Your %s (%s) hit %s for %d damage!"
local f = CreateFrame("Frame")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
f:SetScript("OnEvent", function(self, event)
self:OnEvent(event, CombatLogGetCurrentEventInfo())
end)
function f:OnEvent(event, ...)
local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = ...
local spellId, spellName, spellSchool
local amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing, isOffHand
if subevent == "SPELL_DAMAGE" then
spellId, spellName, spellSchool, amount = select(12, ...)
end
if amount and sourceGUID == playerGUID then
local spell = spellId and GetSpellLink(spellId)
print(MSG_SPELL_DAMAGE:format(spell, GetSchoolString(spellSchool), destName, amount))
end
end

Error in code. Lua on NodeMCU

I have a motorized roller blind project.
I am following this instructable: https://www.instructables.com/id/Motorized-WiFi-IKEA-Roller-Blind/ .
I am using the code in the instructable, but I suspect tha fault is in one of these codes:
config.lua
-- file : config.lua
local module = {}
module.SSID = {}
module.SSID["ssid"] = "password"
-- example for local MQTT
--module.MQHOST = "ohab.local"
--module.MQPORT = 1883
--module.MQID = node.chipid()
--module.MQUSR = ""
--module.MQPW = ""
-- example for cloud MQTT
module.MQHOST = "192.***.*.*"
module.MQPORT = 1883
module.MQID = node.chipid()
module.MQUSR = "username"
module.MQPW = "password"
module.MQTLS = 1 -- 0 = unsecured, 1 = TLS/SSL
module.ENDPOINT = "/house/masterbedroom/rollerblind/"
module.ID = "0"
--module.SUB = "set"
module.SUB = {[module.ENDPOINT .. module.ID .. "/set"]=0,[module.ENDPOINT .. "all"]=0}
module.POST = module.ENDPOINT .. module.ID .. "/status"
return module
wifi_setup
-- file: setup.lua
local module = {}
local function wifi_wait_ip()
if wifi.sta.getip()== nil then
print("IP unavailable, Waiting...")
else
tmr.stop(1)
gpio.write(pin_led,1) --off
print("\n================== ==================")
print("ESP8266 mode is: " .. wifi.getmode())
print("MAC address is: " .. wifi.ap.getmac())
print("IP is "..wifi.sta.getip())
print("====================================")
mq.start()
end
end
local function wifi_start(list_aps)
if list_aps then
gpio.write(pin_led,0) --on
for key,value in pairs(list_aps) do
if config.SSID and config.SSID[key] then
wifi.setmode(wifi.STATION);
wifi.sta.config(key,config.SSID[key])
wifi.sta.connect()
print("Connecting to " .. key .. " ...")
--config.SSID = nil -- can save memory
tmr.alarm(1, 2500, 1, wifi_wait_ip)
end
end
else
print("Error getting AP list")
end
end
function module.start()
print("Configuring Wifi ...")
wifi.setmode(wifi.STATION);
wifi.sta.getap(wifi_start)
end
return module
Sadly I cant manage to go beyond step 4. After I have tried to download the code to the ESP8266 I only get this error:
PANIC: unprotected error in call to Lua API (wifi_setup.lua:25: bad argument #1 to 'config' (config table not found!))
I have only changed the stuff the instructable told me to change, and I have tried to look for faults myself but I cant find any... It's the first time I am using Lua, so this is totally new for me.
Hope somebody here can offer some help. Been stuck on this for days...
THIS PART OF THE PROBLEM IS SOLVED. CHECK COMMENTS FOR SOLUTION
Sadly when one problem is solved, a new one rises...
The chip is now successfully connecting to the wifi and mqtt service, but when I try to do the dry run by putting in the command 'step_move(1000,FWD,2)' nothing happens. The motor should rotate...
Also when I press the button I get a new panic error as follows:
PANIC: unprotected error in call to Lua API (button.lua:23: attempt to perform arithmetic on upvalue '?' (a nil value))
button.lua
--file button4.lua
do
-- use pin 1 as the input pulse width counter
local pin=5
local debounce = 150 --ms
local longpress = 2000 --ms
local pulse1, pulse2, du, now, trig = 1, 0, 0, tmr.now, gpio.trig
local prev_int_time, int_time, up_time = 0
local cal_steps = 100000
local cal_steps_dn = 0
local cal_steps_up = 0
local cal_state = 0 -- 0 = not calibration, 1 = calibrating down, 2 = calibrating up
state = 0 -- state: 0 = up, 1 = transition, 2 = down
gpio.mode(pin,gpio.INT)
local function pin4cb(level)
int_time = now() / 1000
if ((int_time - prev_int_time) > debounce) then
if (level == 0) then
up_time = int_time
else
if((int_time - up_time) > longpress) then
print("calibrating")
cal_state = 1
--cur_step = 100000
step_move(cal_steps,FWD,2)
else -- short press
print("short", cal_state)
if (cal_state == 2) then -- calibrated up (done)
print("calibration done")
state = 0 -- up
cur_step = 0
tot_steps = cal_steps - step_stepsleft
print("cal_steps: " .. cal_steps)
print("step_stepsleft: " .. step_stepsleft)
print("tot_steps: " .. tot_steps)
step_stop()
pins_disable()
cal_state = 0
if file.open("cfg_tot_steps.lua", "w+") then
file.write("tot_steps=" .. tot_steps .. '\n')
file.close()
end
elseif (cal_state == 1) then -- calibrated dn (switch direction)
print("calibration low point")
print(cal_steps - step_stepsleft)
step_stop()
step_move(cal_steps,REV,2)
cal_state = 2
elseif (cal_state == 0) then
if (state == 0 and step_stepsleft == 0) then -- i am up, go dowm
rollerblind.down()
-- state = 2
elseif (state == 1) then -- i am moving, do nothing
-- do nothing
elseif (state == 2 and step_stepsleft == 0) then -- i am down, go up
rollerblind.up()
-- state = 0
end
end
end
end
--print (level)
prev_int_time = int_time
end
end
gpio.trig(pin, "both", pin4cb)
end
Here is the code for the stepper.lua:
-- stepper.lua
-- code from: http://www.esp8266.com/viewtopic.php?f=19&t=2326
-- simple stepper driver for controlling a stepper motor with a
-- l293d driver
-- nodemcu pins: 0 5 6 7
stepper_pins = {1,3,2,4} -- (A-)blue, (A+)pink, (B-)yellow, (B+)orange
--stepper_pins = {1,2,3,4}
-- half or full stepping
step_states4 = {
{1,0,0,1},
{1,1,0,0},
{0,1,1,0},
{0,0,1,1}
}
step_states8 = {
{1,0,0,0},
{1,1,0,0},
{0,1,0,0},
{0,1,1,0},
{0,0,1,0},
{0,0,1,1},
{0,0,0,1},
{1,0,0,1},
}
step_states = step_states4 -- choose stepping mode
step_numstates = 4 -- change to match number of rows in step_states
step_delay = 10 -- choose speed
step_state = 0 -- updated by step_take-function
step_direction = 1 -- choose step direction -1, 1
step_stepsleft = 0 -- number of steps to move, will de decremented
step_timerid = 4 -- which timer to use for the steps
status_timerid = 2 -- timer id for posing of status messages
-- setup pins
function pins_enable()
for i = 1, 4, 1 do
gpio.mode(stepper_pins[i],gpio.OUTPUT)
end
end
function pins_disable()
-- for i = 1, 4, 1 do -- no power, all pins
for i = 2, 4, 1 do -- no power, all pins except one (to keep it in place)
gpio.mode(stepper_pins[i],gpio.INPUT)
end
end
-- turn off all pins to let motor rest
function step_stopstate()
for i = 1, 4, 1 do
gpio.write(stepper_pins[i], 0)
end
end
-- make stepper take one step
function step_take()
-- jump to the next state in the direction, wrap
step_state = step_state + step_direction
cur_step = cur_step + step_direction * FWD
if step_state > step_numstates then
step_state = 1;
elseif step_state < 1 then
step_state = step_numstates
end
-- write the current state to the pins
pins_enable()
for i = 1, 4, 1 do
gpio.write(stepper_pins[i], step_states[step_state][i])
end
-- might take another step after step_delay
step_stepsleft = step_stepsleft-1
if step_stepsleft > 0 then
-- if cur_step > 0 and cur_step < tot_steps and step_stepsleft > 0 then
tmr.alarm(step_timerid, 10, 0, step_take )
--tmr.alarm(step_timerid, 10, 0, step_take )
else
step_stopstate()
step_stop()
pins_disable()
mq.post_status()
if file.open("cfg_cur_step.lua", "w+") then
file.write("cur_step=" .. cur_step .. '\n')
file.close()
end
end
end
-- public method to start moving number of 'int steps' in 'int direction'
function step_move(steps, direction, delay)
tmr.stop(step_timerid)
step_stepsleft = steps
step_direction = direction
step_delay = delay
step_take()
end
function step_go_to(step, delay)
if step >= cur_step then
steps = step - cur_step
step_move(steps, FWD, delay)
end
if step <= cur_step then
steps = cur_step - step
step_move(steps, REV, delay)
end
end
function percent_go_to(percent, delay)
if(percent >= 0 and percent <= 100) then
step_stop()
tmr.register(status_timerid, 1000, tmr.ALARM_AUTO, function () mq.post_status() end)
tmr.start(status_timerid)
step = percent * tot_steps / 100
step_go_to(step, delay)
end
end
-- public method to cancel moving
function step_stop()
tmr.stop(step_timerid)
tmr.stop(status_timerid)
step_stepsleft = 0
step_stopstate()
end
Let's parse the error message one by one:
unprotected error in call to Lua API (wifi_setup.lua:25: bad argument #1 to 'config' (config table not found!))
Unprotected error means that you did a normal function call, as opposed to a protected call (aka pcall), which is a function call where you expect errors to occur and want to provide means to handle them. Since you did not do a protected call, Lua does not know how to handle the error and terminates right away (which is not a bad thing).
wifi_setup.lua:25 tells you the file and line at which the error occured.
bad argument #1 to 'config' means that the problem is due to the first argument passed to a function named config.
config table not found! is the error message provided by the implementer of that function.
So in summary, there is a problem with the function call wifi.sta.config(key,config.SSID[key]) as it expects a table as first argument, while you provided something different (ie. a string with the BSSID). Indeed checking with the NodeMCU docs shows that you need to pass a table to this function:
wifi.sta.config()
Sets the WiFi station configuration. [...]
Syntax
wifi.sta.config(station_config)
Parameters
station_config table containing configuration data for
station
The expected layout of the table is documented in detail on that page as well.
ComicSansMS provided a great answer the essence of which is that you need to replace
wifi.sta.config(key,config.SSID[key])
with
wifi.sta.config{ssid=key,pwd=config.SSID[key]}
Thus a standalone example could be like this:
--wifi.setmode(wifi.NULLMODE)
config = {}
config.SSID = {}
config.SSID["ssid"] = "password"
function wifi_wait_ip()
if wifi.sta.getip() == nil then
print("IP unavailable, Waiting...")
else
tmr.stop(1)
print("\n====================================")
print("ESP8266 mode is: " .. wifi.getmode())
print("MAC address is: " .. wifi.ap.getmac())
print("IP is " .. wifi.sta.getip())
print("====================================")
end
end
function wifi_start(list_aps)
if list_aps then
for key, value in pairs(list_aps) do
if config.SSID and config.SSID[key] then
wifi.setmode(wifi.STATION);
wifi.sta.config{ssid=key, pwd=config.SSID[key]}
-- wifi.sta.connect() not needed as config() uses auto-connect=true by default
print("Connecting to " .. key .. " ...")
tmr.alarm(1, 2500, 1, wifi_wait_ip)
end
end
else
print("Error getting AP list")
end
end
function start()
print("Configuring Wifi ...")
wifi.setmode(wifi.STATION)
wifi.sta.getap(wifi_start)
end
start()

Resources