• 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 [TFS 1.3] Spider Egg, help finishing/optimizing the script :D

  • Thread starter Thread starter Evil Puncker
  • Start date Start date
E

Evil Puncker

Guest
Hello everyone, here is another script that i'm trying to do to implement on our official repository, help me finishing it according to this (ignore the giant spider chance, it is not true), mostly the chances and anything else that I missed, thanks :D

LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chance = math.random(100)
    if chance >= 50 and chance < 83 then
        Game.createMonster("Spider", fromPosition)
    elseif chance >= 83 and chance < 97 then
        Game.createMonster("Poison Spider", fromPosition)
    elseif chance >= 97 and chance < 100 then
        Game.createMonster("Tarantula", fromPosition)
    end
    item:transform(7536)
    item:decay()
    item:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
end
 
Sarcophagus and dragon eggs are viable additions too:

LUA:
-- Sarcophagus South
7560,
7565

-- Sarcophagus East
7561,
7564

-- Dragon Egg
15501,
15502

But no, code is solid 👍
 
what you mean with optimizing? you can add stuff so then you can easily config but idk if thats optimizing, anyways here is my example

LUA:
local r = {
    ["50-83"] = "Spider",
    ["83-97"] = "Poison Spider",
    ["97-100"] = "Tarantula",
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local name
    local chance = math.random(100)
    for rand, mob in pairs(r) do
        rand = rand:split("-")
        if chance >= tonumber(rand[1]) and chance < tonumber(rand[2]) then
            name = mob
            break
        end
    end

    if name then
        Game.createMonster(name, fromPosition)
    end
    item:transform(7536)
    item:decay()
    item:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
end
 

Similar threads

Replies
3
Views
269
Back
Top