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

Not sure how to add lvl requirement in action

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
873
Solutions
2
Reaction score
49
Hi so i made my second script which is on action so im having hard time with applying lvl requirement with action script, didnt had problems with npc's but now somehow i cant figure it out :D
So i came with something like this
Lua:
local config = { 
    minLevel = 250,
    destination = { x = 76, y = 129, z = 7 },
}


function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)

    if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not able to use teleport while in combat!")
    return false
    end
    doTeleportThing(cid, config.destination)
    if config.minLevel and config.minLevel > 0 and player:getLevel() < config.minLevel then
    -- not sure about this part because sendTextMessage do not support %s if im not wrong or im doing something wrong
    end
    return true
end
 
Solution
Hmm probably forgot to mention that it should not let to teleleport if level is <minlevel

in that case ...
here you go.

Lua:
local config = {
    minLevel = 250,
    destination = { x = 76, y = 129, z = 7 },
}


function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)

    if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not able to use teleport while in combat!")
        return false
    end
    

    if player:getLevel() < config.minLevel then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need to be atleast level " .. tostring(config.minLevel))
        return true    -- do not continue...
What's the problem ?

Are you not sure how to tell the user that they have to be level x ?

using tostring( )
Lua:
if player:getLevel() < config.minLevel then
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need to be atleast level " .. tostring(config.minLevel))
end

using string.format()
Lua:
if player:getLevel() < config.minLevel then
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("You need to be atleast level %d", config.minLevel) )
end

note: haven't tested.
 
What's the problem ?

Are you not sure how to tell the user that they have to be level x ?

using tostring( )
Lua:
if player:getLevel() < config.minLevel then
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need to be atleast level " .. tostring(config.minLevel))
end

using string.format()
Lua:
if player:getLevel() < config.minLevel then
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("You need to be atleast level %d", config.minLevel) )
end

note: haven't tested.
Hmm probably forgot to mention that it should not let to teleleport if level is <minlevel
 
Hmm probably forgot to mention that it should not let to teleleport if level is <minlevel
Try this one.
Lua:
local config = {
    minLevel = 250,
    destination = Position(76, 129, 7)
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not able to use teleport while in combat!")
        return false
    end
    if player:getLevel() < config.minLevel then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need level " .. config.minLevel .. " to use this teleport.")
        return false
    end

    player:teleportTo(destination)
    destination:sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
 
Hmm probably forgot to mention that it should not let to teleleport if level is <minlevel

in that case ...
here you go.

Lua:
local config = {
    minLevel = 250,
    destination = { x = 76, y = 129, z = 7 },
}


function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)

    if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not able to use teleport while in combat!")
        return false
    end
    

    if player:getLevel() < config.minLevel then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need to be atleast level " .. tostring(config.minLevel))
        return true    -- do not continue
    end
    
    -- if everything was, teleport the player to destination
    doTeleportThing(cid, config.destination)
    return true
end
 
Solution
Try this one.
Lua:
local config = {
    minLevel = 250,
    destination = Position(76, 129, 7)
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not able to use teleport while in combat!")
        return false
    end
    if player:getLevel() < config.minLevel then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need level " .. config.minLevel .. " to use this teleport.")
        return false
    end

    player:teleportTo(destination)
    destination:sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
Your code says attempt to index destination
player:teleportTo(config.destination)
in that case ...
here you go.

Lua:
local config = {
    minLevel = 250,
    destination = { x = 76, y = 129, z = 7 },
}


function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)

    if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not able to use teleport while in combat!")
        return false
    end
   

    if player:getLevel() < config.minLevel then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need to be atleast level " .. tostring(config.minLevel))
        return true    -- do not continue
    end
   
    -- if everything was, teleport the player to destination
    doTeleportThing(cid, config.destination)
    return true
end
Your code works just fine :D
 
Using tostring is useless in this case. String concatenation does it for you.
Yea i noticed that to so thats why i picked Apollos level requirement part
Lua:
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need level " .. config.minLevel .. " to use this teleport.")
 
Back
Top