• 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!

TFS 1.X+ Mana rune with level req

joncis

Hostopia.hopto.org
Joined
Nov 29, 2012
Messages
234
Reaction score
91
Location
Lithuania
Wanted to make that my mana rune has level ,magic req...




Code:
local cfg = {
    level = 16, -- minimum level to use item
    magic = 16, -- minimum magic level to use item
    vocation = {1,6,8} -- {1, 2, 3} -- vocations that can use item
}

    function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- check vocation
    if not isInArray(cfg.vocation, getPlayerVocation(cid)) then
        doCreatureSay(cid, "You do not have the required vocation to use this item.", TALKTYPE_ORANGE_1)
        return true
    end
    
    -- check level
    local player_level = getPlayerLevel(cid)
    if player_level < cfg.level then
        doCreatureSay(cid, "You can't use this. Only players of level " .. cfg.level .. " or higher can use this item.", TALKTYPE_ORANGE_1)
        return true
    end
    
    -- check magic level
    local player_magic_level = getPlayerMagLevel(cid)
    if player_magic_level < cfg.magic then
        doCreatureSay(cid, "You can't use this. Only players with magic level " .. cfg.magic .. " or higher can use this item.", TALKTYPE_ORANGE_1)
        return true
    end
    
    -- check that item is being used on a creature.
    if not isCreature(itemEx.uid) then
        doCreatureSay(cid, "This rune can only be used on creatures.", TALKTYPE_ORANGE_1)
        return true
    end
    
     local level = player:getLevel()
    local magLevel = player:getMagicLevel()
    local min = (level * 0.2) + (magLevel * 2.5)
    local max = (level * 0.4) + (magLevel * 3)
    player:addMana(math.random(min, max))
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    player:say("Yeeaah...", TALKTYPE_MONSTER_SAY)
    return true
end
Post automatically merged:

Got it to work with level but it doesnt show any msg if used by lower lvl and vocations still missing :(
Code:
)


local cfg = {
    level = 16, -- minimum level to use item
    vocation = {1,6,8} -- {1, 2, 3} -- vocations that can use item
}

    function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    
     -- check level
    local level = player:getLevel()
    if level < cfg.level then
        doCreatureSay(cid, "You can't use this. Only players of level " .. cfg.level .. " or higher can use this item.", TALKTYPE_ORANGE_1)
        return true
    end
     local level = player:getLevel()
    local magLevel = player:getMagicLevel()
    local min = (level * 0.2) + (magLevel * 2.5)
    local max = (level * 0.4) + (magLevel * 3)
    player:addMana(math.random(min, max))
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    player:say("Yeeaah...", TALKTYPE_MONSTER_SAY)
    return true
end
 
Last edited:
Code:
local cfg = {
    level = 16, -- minimum level to use item
    vocation = {1,6,8} -- {1, 2, 3} -- vocations that can use item
}

    function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   
     -- check level
    local level = player:getLevel()
    if level < cfg.level then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You need level ".. cfg.level .." to use this rune.")
        return true
    end
     local level = player:getLevel()
    local magLevel = player:getMagicLevel()
    local min = (level * 0.2) + (magLevel * 2.5)
    local max = (level * 0.4) + (magLevel * 3)
    player:addMana(math.random(min, max))
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    player:say("Yeeaah...", TALKTYPE_MONSTER_SAY)
    return true
end
 
Back
Top