modding – How do I add custom logic to a World of Warcraft internal LUA event using an addon?

I’m trying to show a bit of custom text directly after mount names in the World of Warcraft Mount Journal. I’ve exported the Blizzard API code from the World of Warcraft client, found the method I want to override, copied it to my addon and attempted to register it as a replacement script using MountJournal.ListScrollFrame:SetScript(). However, this doesn’t appear to be working.

I’ve done some investigating, and apparently I need to some magic involving frames and registering events? I’m not sure.

My addon source code can be found at https://github.com/nzall/WarcraftTransportAcquisitionRating/blob/master/warcraftTransportAcquisitionRating.lua. The relevant part that I’m fairly sure is broken can be found below. I’m using Ace to simplify development.

function wTAR:OnEnable()
    MountJournal.ListScrollFrame:SetScript("OnUpdate", MountJournal_UpdateMountList);    
end

What is the proper way to do what I’m trying to do? Or otherwise, if I’m trying to do the wrong thing, how should I do it instead?

Hide World of Warcraft UI elements with Lua

I want to create a very simple WoW addon that hides the grips on both sides of the main menu bar and the micro buttons at the bottom right. The addon has a Lua script, main.lua:

-- main.lua
MainMenuBarArtFrame.LeftEndCap:Hide()
MainMenuBarArtFrame.RightEndCap:Hide()
MicroButtonAndBagsBar:Hide()
CharacterMicroButton:Hide()
SpellbookMicroButton:Hide()
TalentMicroButton:Hide()A
chievementMicroButton:Hide()
QuestLogMicroButton:Hide()
GuildMicroButton:Hide()
LFDMicroButton:Hide()
CollectionsMicroButton:Hide()
StoreMicroButton:Hide()
EJMicroButton:Hide()
MainMenuMicroButton:Hide()

This works perfectly, except that the grips don't go away and neither does the micro button for the store. In the game when I enter /run MainMenuBarArtFrame.LeftEndCap:Hide(), /run MainMenuBarArtFrame.RightEndCap:Hide(), or /run StoreMicroButton:Hide() The respective UI frame is hidden in the chat. Why doesn't the script hide these elements? How can I fix it? Thanks a lot!

lua – Integration of Moonsharp in Unity for Nintendo Switch

Thank you for your response to Game Development Stack Exchange!

  • Please be sure answer the question. Provide details and share your research!

But avoid

  • Ask for help, clarify, or respond to other answers.
  • Make statements based on opinions; Support them with references or personal experiences.

Use MathJax to format equations. MathJax reference.

For more information, see our tips on writing great answers.

lua – galera como eu paro o Audio-Depois que fecho o ImageButton or melhor dizendo quando toggled = false ja tentei usar codeblock mais gera em erros

– se caso eu adicionar “ `lua o roblox me pede pra identificar o '` `' eu definivamente erkeit como fazer isso

local toggled = false

– Roblox services
local ReplicatedStorage = game: GetService ("ReplicatedStorage")

– Module required
local AudioPlayerModule = require (ReplicatedStorage: WaitForChild ("AudioPlayer"))

– preload sounds
AudioPlayerModule.preloadAudio ({
("OOF") = 4468825557
})

– Reference to the button
local ImageButton = script.Parent

– The function is activated when the button is pressed

local function onButtonActivated ()
if toggled == false then

ImageButton.Image = "rbxgameasset: // Images / melhor"

AudioPlayerModule.playAudio ("OOF") – Play audio
local object = script.Parent
object.AnchorPoint = Vector2.new (0.5, 0.5)
object.Position = UDim2.new (0.1, 0, 0.5, 0)
wait (2)
game.StarterGui: SetCore ("SendNotification", {
Title = "HARDWARE",
Text = "U BAGUIU É DOIDO MEMO",
Duration = 6})
ImageButton.Image = "rbxgameasset: // Images / bom2"

Object: TweenPosition (UDim2.new (0.5, 0, 0.5, 0))
Object: TweenSize (UDim2.new (0.4,0,0.4,0))

wait (6)
Object: TweenSize (UDim2.new (0.9,0,0.9,0))

switched = true
otherwise

ImageButton.Image = "rbxgameasset: // Images / melhor"
local object = script.Parent
object.AnchorPoint = Vector2.new (0.0)
Object: TweenPosition (UDim2.new (0,0,0,0))
Object: TweenSize (UDim2.new (0,100,0,100))

    toggled = false -- quando o ImageButton é fechado

The End
The End

ImageButton.Activated: Connect (onButtonActivated)

Lua: Workaround for Boolean conversion of a class variable in parentheses

In the following code, can someone explain why t1: print () works, but (t1): print fails. I'm trying to do something like (t1 * 3): print () works without using an intermediate variable.

function classTestTable(members)
  members = members or {}
  local mt = {
    __metatable = members;
    __index     = members;
  }

  function mt.print(self)
    print("something")
  end
  return mt
end

TestTable = {}
TestTable_mt = ClassTestTable(TestTable)

function TestTable:new()
   return setmetatable({targ1 = 1}, TestTable_mt )
end

TestTable t1 = TestTable:new()

t1:print() -- works fine. 
(t1):print()  -- fails with error "attempt to call a boolean value"

lua – Improve the code design of a simple game mode for better teamwork

I developed this module in Lua as a mod for Project Zomboid.
In the future I will develop my mods in a small team (2-4 programmers).
At the moment, I have no experience with teamwork because I've been programming alone most of the time.

My question is:
1) What are my main mistakes (in terms of the code architecture)?
2) How can I improve this code so I can easily develop it in the future (with my team)?

local SKIP_FRAMES = 100;


local function round(x)
    return math.floor(x + 0.5)
end


local function DropItem(item)
    if item:isFavorite() then
        item:setFavorite(false)
    end
    local act = ISInventoryTransferAction:new(getPlayer(), item, item:getContainer(), getPlayerLoot(getPlayer():getPlayerNum()).inventory)
    act:transferItem(item)
end

local IGNORE_BOTTLE_ONCE = {
    --PopEmpty=1,
    WineEmpty=1, WhiskeyEmpty=1, WaterBottleEmpty=1, WineEmpty2=1, PopBottleEmpty=1,
}

local BIG_ITEM_WEIGHT_TRESHOLD = 1950 -- граммы
local MEDIUM_ITEM_WEIGHT_TRESHOLD = 550

local MAX_SMALL_ITEMS_WEIGHT = 1000
local MAX_MEDIUM_ITEMS = 3
local MAX_BIG_ITEMS = 1

local BIG_SLOT_TYPES = {
    BigWeapon=1,BigBlade=1,Shovel=1,
    GuitarAcoustic=1,PickAxeHandleSpiked=1,
    Rifle=1,
}
local MEDIUM_SLOT_TYPES = {
    Nightstick=1,Wrench=1,PipeWrench=1,
    Pistol=1,Pistol2=1,Pistol3=1,
}
local SMALL_SLOT_TYPES = {
    Drumstick=1, -- 3kg? why?
}

--Check if item is big. Depends on weight and size (properties)
local function isBigItem(rec)
    local slot_type = rec.item:getAttachmentType()
    if slot_type and BIG_SLOT_TYPES(slot_type) or rec.item:isTwoHandWeapon() then
        return true
    end
end

local function getItemSize(rec)
    if rec.slot then
        if BIG_SLOT_TYPES(rec.slot) then
            return 'big'
        elseif MEDIUM_SLOT_TYPES(rec.slot) then
            return 'medium'
        elseif SMALL_SLOT_TYPES(rec.slot) then
            return 'small'
        end
    end
    if rec.wep then
        if rec.item:isTwoHandWeapon() then
            return 'big'
        end
    end
    if rec.weight > BIG_ITEM_WEIGHT_TRESHOLD then
        return 'big'
    elseif rec.weight > MEDIUM_ITEM_WEIGHT_TRESHOLD then
        return 'medium'
    end
    return 'small'
end

local function prepareRecord(item)
    local rec = {
        item = item,
        name = item:getType(),
        weight = round(item:getWeight()*1000),
        actual = round(item:getActualWeight()*1000),
        wep = item:IsWeapon(),
        slot = item:getAttachmentType(),
        cat = item:getCategory()
    }
    if rec.wep then
        rec.damage = (item:getMinDamage() + item:getMaxDamage()) * 0.5
    end
    if rec.cat == 'Clothing' then
        rec.def = item:getBiteDefense()
    end
    rec.size = getItemSize(rec)
    return rec
end

local GUN_CLIPS = {
    ('556Clip')=1,('223Clip')=1,('308Clip')=1,('44Clip')=1,('45Clip')=1,('9mmClip')=1,
}

local IGNORE_ITEMS = { -- Zero weight
    ('223Bullets')=1,('308Bullets')=1,Bullets38=1,Bullets44=1,Bullets45=1,('556Bullets')=1,Bullets9mm=1, --bullets
    Nails=1,
    Cigarettes=1,
}

function DropItems()
    local player = getPlayer()
    if player:isNearVehicle() then
        return --packing and repairing a car is allowed
    end
    local inv = player:getInventory()
    local items = {}
    local count_big = 0
    local count_medium = 0
    for i=1,inv:getItems():size() do
        local item = inv:getItems():get(i-1)
        if item and (item:getAttachedSlot() == -1)
            and (not item:isEquipped()) and item:getJobDelta() == 0 and not IGNORE_ITEMS(item:getType())
        then
            local rec = prepareRecord(item)
            table.insert(items, rec)
            if rec.size == 'big' then
                count_big = count_big + 1
            elseif rec.size == 'medium' then
                count_medium = count_medium + 1
            end
        end
    end
    --print((#items - count_big - count_medium) .. ' / ' .. count_medium .. ' / ' .. count_big)

    -- Sorting items by their weights
    table.sort(items, function(a,b)
        local fav_a, fav_b = a.item:isFavorite(), b.item:isFavorite()
        if fav_a ~= fav_b then
            return fav_a
        end
        if a.wep ~= b.wep then
            return a.wep
        end
        if a.wep and b.wep then
            return a.damage > b.damage
        end
        if GUN_CLIPS(a.name) ~= GUN_CLIPS(b.name) then
            return GUN_CLIPS(a.name) ~= nil
        end
        if a.cat == 'Clothing' then
            if b.cat == 'Clothing' then
                if a.def ~= b.def then
                    return a.def > b.def
                end
            else
                return false
            end
        elseif b.cat == 'Clothing' then
            return true -- We prefer to drop clothes rather than other items
        end
        return a.actual < b.actual
    end)

    --for _, item in ipairs(items) do
    --  print(item.weight)
    --end

    local added_big = 0
    local smallItemsWeight = 0 --sum of weight of all kept items
    local was_battle = false
    local added_small = 0
    local added_medium = 0

    local MAX_ADD_SMALL = nil
    if count_big > 0 and count_medium > 0 then -- first found type is winner
        local found = nil
        for _, rec in ipairs(items) do  
            if rec.size == 'big' or rec.size == 'medium' then
                found = rec.size
                break
            end
        end
        if found then -- always true!
            MAX_ADD_SMALL = found == 'big' and MAX_BIG_ITEMS - count_big or MAX_MEDIUM_ITEMS - count_medium
        end
    end
    if not MAX_ADD_SMALL then
        MAX_ADD_SMALL = count_big > 0 and MAX_BIG_ITEMS - count_big or MAX_MEDIUM_ITEMS - count_medium
    end

    for _, rec in ipairs(items) do  
        local item = rec.item
        if not was_battle and IGNORE_BOTTLE_ONCE(rec.name) then
            was_battle = true
        else
            if rec.size == 'medium' then -- Medium Items
                if added_big > 0 then
                    DropItem(item) -- drop all medium items!
                elseif added_medium >= MAX_MEDIUM_ITEMS then
                    DropItem(item)
                else
                    added_medium = added_medium + 1
                end
            elseif rec.size == 'big' then -- Big Items
                if added_medium > 0 then
                    DropItem(item)
                elseif added_big >= MAX_BIG_ITEMS then
                    DropItem(item)
                else
                    added_big = added_big + 1
                end
            else -- Small Items
                if smallItemsWeight + rec.actual > MAX_SMALL_ITEMS_WEIGHT then
                    if added_small < MAX_ADD_SMALL then
                        added_small = added_small + 1
                    else
                        DropItem(item)  
                    end
                else
                    smallItemsWeight = smallItemsWeight + rec.actual --sum of weight of all kept items
                end
            end
        end
    end
    --print('ADDED_SMALL: ',added_small)
end


local frame = 0;
function DropItemsOnPlayerMove()
    frame = frame + 1;
    if frame >= SKIP_FRAMES then
        frame = 0
    end

    if frame == 0 then
        if getPlayerLoot(getPlayer():getPlayerNum()).inventory:getType()=="floor" then
            DropItems()      
        end
        --print("Dropping Items")
    end
end


Events.OnPlayerMove.Add(DropItemsOnPlayerMove);


----------Patch tooltips---------


local old_draw_fn = ISInventoryPane.drawItemDetails
function ISInventoryPane:drawItemDetails(item, y, xoff, yoff, red, ...)
    old_draw_fn(self, item, y, xoff, yoff, red, ...)
    --Add size info of the item
    --ISUIElement:drawText(str, x, y, r, g, b, a, font)
    --self:drawText
end

local cache_render_item = nil
local cache_render_size = nil
local cache_render_text = nil

local old_render = ISToolTipInv.render
function ISToolTipInv:render()
    if self.item ~= cache_render_item then
        cache_render_item = self.item
        local rec = prepareRecord(cache_render_item)
        cache_render_size = rec.size
        cache_render_text = rec.size == 'big' and getText('IGUI_RI_BIG_ITEM') or (rec.size == 'medium' and getText('IGUI_RI_MEDIUM_ITEM'))
    end
    if not cache_render_text then --small item (or error?)
        return old_render(self)
    end
    -- Ninja double injection in injection!
    local stage = 1
    local save_th = 0
    local old_setHeight = self.setHeight
    self.setHeight = function(self, num, ...)
        if stage == 1 then
            stage = 2
            save_th = num
            num = num + 25
        else 
            stage = -1 --error
        end
        return old_setHeight(self, num, ...)
    end
    local old_drawRectBorder = self.drawRectBorder
    self.drawRectBorder = function(self, ...)
        if stage == 2 then
            local r,g,b=1,1,1
            if cache_render_size == 'big' then
                r,g,b = 1,0.7,0.3
            elseif cache_render_size == 'medium' then
                r,g,b = 0.8,1,0
            end
            self.tooltip:DrawText(UIFont.Small, cache_render_text, 5, save_th, r, g, b, 1);
            stage = 3
        else
            stage = -1 --error
        end
        return old_drawRectBorder(self, ...)
    end
    old_render(self)
    self.setHeight = old_setHeight
    self.drawRectBorder = old_drawRectBorder
end

--Events.OnRefreshInventoryWindowContainers.Add(onUpdateInventory)
```

Press the JS logic in LUA

var s = 6;
var x = (s / 3) | 0;

console.log(x);

How could I write this in lua to have the same effect (the "|"Part)?

Edit: forgot to mention in on Lua 5.1.4

Edit: I tried

local s = 7
local x = bit32.bor(s/3, 0)

print(x)

But it fails because there can only be integers, and even decimals

Problems Analyzing JSON in Lua

Problem:

Need help loading a JSON file into a spreadsheet array in Lua for Corona SDK development?

My goal:

Use key-value pairs to call specific data from the JSON file into my application.

Current application behavior

The Corona Simulator Console returns only a table ID such as -> table: 114AF7D8

Expected behavior

Returns the name "Smith" when I print (DialogsTable.name2)

A reference to the Lua Code:

Enter image description here

A reference to the JSON file:

Enter image description here

text – Need help reading structured JSON / XML files in the Lua language for Corona SDK

I tried to read a json / xml or simple lua language text file for the Corona SDK, but I did not succeed. In all the tutorials I've followed, people basically wrote a file and then read it. In this way, the created file does not end up in the Corona sandbox and the developer can not access the file to my knowledge.

What I wanted to achieve was to put an externally created file somewhere in the root directory and read my Lua code and put the text elements into my game instead of hard-coding texts.

If anyone has any knowledge or experience regarding this species, please clarify me as I have been stuck here for a few days now.

Thank you for taking the time to read this.

Greetings.