• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Hallow's End Treat

Status
Not open for further replies.

Render1982

Emulation Addict
I have been working on my very first LUA script to fix the Hallow's End Candy where it will give you a random buff.

Code:
 local ITEM_ID = 20557

function PumpkinTreat(event, player, item, target)
local caster = spell:GetCaster()
        if player:IsInCombat() == true then
                player:SendBroadcastMessage("|cFFFF0000You are in combat!|r")
        else
        local ItemCount = player:GetItemCount(ITEM_ID)
				caster:AddAura(24708)
            player:RemoveItem(ITEM_ID, 1)
        end                    
end
 
RegisterItemEvent(ITEM_ID, 2, PumpkinTreat)

It seems like every time I use it nothing happens nor an error shows.
Any Ideas?
 

Tommy

Founder
Code:
local caster = [COLOR="brick"]spell[/COLOR]:GetCaster()

Where are you getting the "spell" variable from? It doesn't exist. You should check for script errors after the server loads because that's one of them and calling "caster" is another since the variable is invalid.

Code:
local ItemCount = player:GetItemCount(ITEM_ID)

You aren't using this variable anywhere so why declare it?

If you want to give the player a buff you can do:

Code:
local ITEM_ID = 20557

function PumpkinTreat(event, player, item, target)
    if player:IsInCombat() then
        player:SendBroadcastMessage("|cFFFF0000You are in combat!|r")
    else
	player:AddAura(24708)
        player:RemoveItem(ITEM_ID, 1)
    end                    
end
 
RegisterItemEvent(ITEM_ID, 2, PumpkinTreat)

Where does the "random" part comes in at? You mentioned it gives you a random buff but you aren't randomizing anything.
 

Render1982

Emulation Addict
Yeah, I'm almost a complete idiot when it comes to LUA. I was going to add in the randomization after I got the script working so that will add the aura of the first spell. Thing is I have no idea even what I typed in for this script. I have a C++ Script from like 2011 that I used as reference and I see that LUA will take a while of getting used to. I take no credits for the C++ it comes from one of my custom scripts that I added a long time ago.

Code:
class item_pumpkin_treat : public ItemScript
{
    public:

        item_pumpkin_treat() : ItemScript("item_pumpkin_treat") { }



        bool OnUse(Player* player, Item* /*item*/, SpellCastTargets const& /*targets*/)
        {

            if (player->HasAura(SPELL_PIRATE) || player->HasAura(24709) || player->HasAura(24708))
            {
                player->RemoveAura(24709);
                player->RemoveAura(24708);
                player->RemoveAura(SPELL_PIRATE);
            }

            if (player->HasAura(SPELL_GHOST))
                player->RemoveAura(SPELL_GHOST);

            if (player->HasAura(SPELL_ORANGE_GIANT))
                player->RemoveAura(SPELL_ORANGE_GIANT);

            if (player->HasAura(SPELL_SKELETON))
                player->RemoveAura(SPELL_SKELETON);

            switch (urand(0, 3))
            {
                case 0:
                    player->CastSpell(player, SPELL_PIRATE, true);
                    break;
                case 1:
                    player->CastSpell(player, SPELL_GHOST, true);
                    break;
                case 2:
                    player->CastSpell(player, SPELL_ORANGE_GIANT, true);
                    break;
                case 3:
                    player->CastSpell(player, SPELL_SKELETON, true);
                    break;
                default:
                    break;
            }

           return false;
        }
};
 

Rochet2

Moderator / Eluna Dev
No errors showing?
Do you have Eluna.log?
Check that your worldserver.conf has the Eluna.log logging settings. If it doesnt, copy over the new worldserver.conf from the compilation folder.

Seems to me like the script you posted in first post should always make an error at local caster = spell:GetCaster() like tommy said.
Either you dont have the log settings as I said above or then your item never runs the function, which means your item doesnt have a spell on use or something.
 

Foereaper

Founder
Here, this would probably be the best way to handle this script in Lua. Simply replace the values in the Spells table (1, 2, 3) with the correct spell values. Haven't tested it so it may or may not work as intended.

Code:
local PumpkinTreat = {
    Entry = 20557,
    Spells = {1, 2, 3}, -- Define all the pumpkin spells here
}

function PumpkinTreat.OnUse(event, player, item, target)
    local t = PumpkinTreat["Spells"] -- Shorten the subtable to t
    
    for _, v in ipairs(t) do -- Loop through the spell table to see if the player has any of the spells applied
        if(player:HasAura(v)) then
            player:RemoveAura(v)
        end
    end
    
    player:CastSpell(player, t[math.random(#t)], true) -- Cast random spell on the player
end

RegisterItemEvent(PumpkinTreat.Entry, 2, PumpkinTreat.OnUse)
 

Render1982

Emulation Addict
Sweet works great Foereaper, I will certainly use this script as a base for making my own scripts. (Just thought about making a Instant Suicide Item Script) :thoughtful:
And thanks to the rest who at least took time to reply! :rockon:
 
Last edited:

Foereaper

Founder
Would appreciate if you'd fill in the correct values, test that everything works and release it in the release section for others to use :)
 
Status
Not open for further replies.
Top