azerothcore / mod-eluna

Eluna Lua Engine © for WoW Emulators
https://elunaluaengine.github.io/
GNU General Public License v3.0
96 stars 126 forks source link

Is there any function in Lua that can cast spells for players? #179

Closed xengine-qyt closed 2 months ago

xengine-qyt commented 2 months ago

there is my script:

local function BuffCommand(event, player, command)
    local nTimeBuff = 60 * 60 * 1000 * 3
    if command == "buff" then
        local buffs = {23766, 23767, 23768, 23769,
                       49284, 49281,                      
                       47440, 47436                         
                       }                               
        for i, buffId in ipairs(buffs) do
            local aura = player:AddAura(buffId, player)
            -- local aura = player:CastSpell(player, buffId, true)
            if aura then
                aura:SetDuration(nTimeBuff) 
            end
        end
        player:SendBroadcastMessage("add buffs!")
        return false
    end
end

RegisterPlayerEvent(42, BuffCommand)

This buff command should perform certain checks, such as only allowing one type of Knight's Blessing or Warrior's Roar to be cast at a time. However, according to the game rules, multiple Knight's Blessings can be cast on a player as long as they are different types of blessings. What method should I use to implement this? I tried CastSpell, but the effect is always the same, and I can't set the buff duration. Can Lua implement the functionality I mentioned?

kissingers commented 2 months ago

I give up and use this way

local function ChangMapGiveBuff(event, player) local pGuid = player:GetGUIDLow() if PlayerJF[pGuid] and PlayerJF[pGuid][bufftime] and PlayerJF[pGuid][bufftime] > os.time() then player:AddAura(72221, player) player:AddAura(25392, player) player:AddAura(32999, player) player:AddAura(26991, player) player:AddAura(27127, player) player:AddAura(25898, player)

    local PRangeList = player:GetPlayersInRange(40)
    for _, v in ipairs(player:GetCreaturesInRange(40)) do
        table.insert(PRangeList, v)
    end
    if PRangeList then
        for k, menber in pairs(PRangeList) do
            if not player:HasAura(27141) or player:GetAura(27141):GetDuration() < 900000 then
                menber:CastCustomSpell(player, 27141, true, nil, nil, nil, nil, menber:GetGUID())
            elseif not player:HasAura(27143) or player:GetAura(27143):GetDuration() < 900000 then
                menber:CastCustomSpell(player, 27143, true, nil, nil, nil, nil, menber:GetGUID())
            else
                break
            end
        end
    end
end

end

xengine-qyt commented 2 months ago

Is this using nearby NPCs to cast spells on oneself? What if there are not enough nearby NPCs... expand the range?

kissingers commented 2 months ago

Is this using nearby NPCs to cast spells on oneself? What if there are not enough nearby NPCs... expand the range?

30 min normaly in group enough. this problem can not do by eluna self, becasue of AZ self buff limit. or use 2 can both can add to self buff, so it will double if other buff him, more than one same effect buff...