• 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 Help to make if statements nicer

E

Evil Puncker

Guest
Hi everyone, I tried to make a nail case script to tame a hellgrip, to include it on TFS, but I couldn't get the increment count part of the script to work, any help is appreciated:

this is what I've done:

Lua:
local nailCase = Action()

function nailCase.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target:isCreature() or not target:isMonster() or target:getMaster() then
        return false
    end
    if target:getMonster():getName():lower() ~= "the hellgrip" then
        return true
    end
    if player:hasMount(39) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already have the obedience of the hellgrip.")
        return true
    end

    if math.random(100) >= 50 then
        target:remove()
        player:say("You failed to manicure the nails of the sensitive gravedigger. Before you can make amends, the creature runs away in agony.", TALKTYPE_MONSTER_SAY)
        player:setStorageValue(1234, 0)
        return true
    else
        player:setStorageValue(1234, player:getStorageValue(1234) + 1)
        local count = player:getStorageValue(1234)
        if count == 1 then
            player:say("You carefully cut the nail of the gravedigger's thumb.", TALKTYPE_MONSTER_SAY)
            return true
        end
        else if count == 2 then
            player:say("You successfully manicured the forefinger of the gravedigger.", TALKTYPE_MONSTER_SAY)
            return true
        end
        else if count == 3 then
            player:say("You successfully manicured the middlefinger of the gravedigger.", TALKTYPE_MONSTER_SAY)
            return true
        end
        else if count == 4 then
            player:say("You actually manicured the ring finger of the gravedigger without a problem.", TALKTYPE_MONSTER_SAY)
            return true
        end
        -- else if count == 5 then
        player:say("You did it! A completely manicured gravedigger is ready to follow you as your own personal trusty mount until the bitter end!", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        target:remove()
        player:addMount(39)
    end
    return true
end

nailCase:id(21452)
nailCase:register()

as you guys can see, from line 22 onward everything is a mess because I lack the knowledge to do so, thanks in advance!
 
Lua:
local nailCase = Action()
local messages = {
    [1] = "You carefully cut the nail of the gravedigger's thumb.",
    [2] = "You successfully manicured the forefinger of the gravedigger.",
    [3] = "You successfully manicured the middlefinger of the gravedigger.",
    [4] = "You actually manicured the ring finger of the gravedigger without a problem.",
}

function nailCase.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target:isCreature() or not target:isMonster() or target:getMaster() then
        return false
    end

    if target:getMonster():getName():lower() ~= "the hellgrip" then
        return true
    end

    if player:hasMount(39) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already have the obedience of the hellgrip.")
        return true
    end

    if math.random(100) >= 50 then
        target:remove()
        player:say("You failed to manicure the nails of the sensitive gravedigger. Before you can make amends, the creature runs away in agony.", TALKTYPE_MONSTER_SAY)
        player:setStorageValue(1234, 0)
        return true
    end

    player:setStorageValue(1234, player:getStorageValue(1234) + 1)
    local count = player:getStorageValue(1234)
    local message = messages[count]
    if message then
        player:say(message, TALKTYPE_MONSTER_SAY)
        return true
    end
   
    player:say("You did it! A completely manicured gravedigger is ready to follow you as your own personal trusty mount until the bitter end!", TALKTYPE_MONSTER_SAY)
    item:remove(1)
    target:remove()
    player:addMount(39)
    return true
end

nailCase:id(21452)
nailCase:register()

thank you so much, perfect
 
Back
Top