• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua How to shorten this script?

Moj mistrz

Monster Creator
Joined
Feb 1, 2008
Messages
932
Solutions
10
Reaction score
295
Location
Poland
Hello, yes it's again me. I need little help in shortening this script. Thanks for any help.
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_NONE)

function onCastSpell(creature, var)
    local msg = "<the welter devours his spawn and heals himself>"
    local spectators, spectator = Game.getSpectators(creature:getPosition(), false, false, 10, 10, 10, 10)
    for i = 1, #spectators do
        spectator = spectators[i]
        if spectator:isMonster() and spectator:getName() == "Egg" then
            spectator:getPosition():sendMagicEffect(CONST_ME_HITBYPOISON)
            spectator:remove()
            creature:say(msg, TALKTYPE_ORANGE_1)
            creature:addHealth(25000)
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        elseif spectator:isMonster() and spectator:getName() == "Spawn Of The Welter" then
            spectator:getPosition():sendMagicEffect(CONST_ME_DRAWBLOOD)
            spectator:remove()
            creature:say(msg, TALKTYPE_ORANGE_1)
            creature:addHealth(25000)
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        end
    end
    return combat:execute(creature, var)
end
 
That's fine.. Why make it shorter?
Cause of twice used:
Code:
            spectator:remove()
            creature:say(msg, TALKTYPE_ORANGE_1)
            creature:addHealth(25000)
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
And my monster removes all of the eggs at once while this spell is executed. Lel
 
Just do if egg then effect = poison elseif spawn~ then effect = drawblood and then simply put
sendmagiceffect(effect)

If you didn't get it then ask again and I'll explain further
 
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_NONE)

function onCastSpell(creature, var)
    local msg = "<the welter devours his spawn and heals himself>"
    local spectators, spectator = Game.getSpectators(creature:getPosition(), false, false, 10, 10, 10, 10)
    for i = 1, #spectators do
        spectator = spectators[i]
        if spectator:isMonster() then
            if spectator:getName() == "Egg" then
                spectator:getPosition():sendMagicEffect(CONST_ME_HITBYPOISON)
            elseif spectator:getName() == "Spawn Of The Welter" then
                spectator:getPosition():sendMagicEffect(CONST_ME_DRAWBLOOD)
            end
            spectator:remove()
            creature:say(msg, TALKTYPE_ORANGE_1)
            creature:addHealth(25000)
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        end
    end
    return combat:execute(creature, var)
end
 
Back
Top