• 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 Sell promotion if premdays is greater than or equal to x number

chupaescadatri

Banned User
Joined
Jul 5, 2014
Messages
338
Reaction score
49
Modifying this script, so that it is the sale promotion premium of days is equal to or greater than five days?
Code:
-- This is an example NPC script that can be used on Jiddo's NPC system

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                          npcHandler:onThink() end
-- OTServ event handling functions end

local node1 = keywordHandler:addKeyword({'promotion'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to be promoted in your vocation for 20000 gold?'})
    node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, promotion = 1, cost = 20000,  premium = false, level = 20, text = 'Congratulations! You are now promoted.'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Allright then. Come back when you are ready.', reset = true})

npcHandler:addModule(FocusModule:new())
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)            npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)            npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                    npcHandler:onThink()

-- vocations to be promoted to
local promotions = {
    5, -- master sorcerer
    6, -- elder druid
    7, -- royal paladin
    8  -- elite knight
}
-- cost of the promotion
local cost = 20000
-- level required to be promoted
local levelReq = 20
-- amount of days required to buy a promotion
local premDays = 5

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if(msgcontains(msg, 'promo') or msgcontains(msg, 'promotion')) then
        selfSay('Do you want to be promoted in your vocation for '.. cost ..' gold?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if getPlayerPremiumDays(cid) >= premDays then
            if getPlayerLevel(cid) >= levelReq then
                if promotions[getPlayerVocation(cid)] ~= nil then
                    if(doPlayerRemoveMoney(cid, cost)) then
                        setPlayerPromotionLevel(promotions[getPlayerVocation(cid)])
                        selfSay('Congratulations! You are now promoted.', cid)
                    else
                        selfSay('Sorry, you don\'t have enough gold.', cid)
                    end
                else
                    selfSay('You have already been promoted.', cid)
                end
            else
                selfSay('Sorry, you need to be level '.. levelReq ..' to be promoted.', cid)
            end
        else
            selfSay('Sorry, you need to have '.. premDays ..' or more premium days on your account to buy a promotion.', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        talkState[talkUser] = 0
        selfSay('Allright then. Come back when you are ready.', cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
what server r u using?
tfs 0.3.0
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)            npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)            npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                    npcHandler:onThink()

-- vocations to be promoted to
local promotions = {
    5, -- master sorcerer
    6, -- elder druid
    7, -- royal paladin
    8  -- elite knight
}
-- cost of the promotion
local cost = 20000
-- level required to be promoted
local levelReq = 20
-- amount of days required to buy a promotion
local premDays = 5

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if(msgcontains(msg, 'promo') or msgcontains(msg, 'promotion')) then
        selfSay('Do you want to be promoted in your vocation for '.. cost ..' gold?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if getPlayerPremiumDays(cid) >= premDays then
            if getPlayerLevel(cid) >= levelReq then
                if promotions[getPlayerVocation(cid)] ~= nil then
                    if(doPlayerRemoveMoney(cid, cost)) then
                        setPlayerPromotionLevel(promotions[getPlayerVocation(cid)])
                        selfSay('Congratulations! You are now promoted.', cid)
                    else
                        selfSay('Sorry, you don\'t have enough gold.', cid)
                    end
                else
                    selfSay('You have already been promoted.', cid)
                end
            else
                selfSay('Sorry, you need to be level '.. levelReq ..' to be promoted.', cid)
            end
        else
            selfSay('Sorry, you need to have '.. premDays ..' or more premium days on your account to buy a promotion.', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        talkState[talkUser] = 0
        selfSay('Allright then. Come back when you are ready.', cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Thank you! I'll try !
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)            npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)            npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                    npcHandler:onThink()

-- vocations to be promoted to
local promotions = {
    5, -- master sorcerer
    6, -- elder druid
    7, -- royal paladin
    8  -- elite knight
}
-- cost of the promotion
local cost = 20000
-- level required to be promoted
local levelReq = 20
-- amount of days required to buy a promotion
local premDays = 5

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if(msgcontains(msg, 'promo') or msgcontains(msg, 'promotion')) then
        selfSay('Do you want to be promoted in your vocation for '.. cost ..' gold?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if getPlayerPremiumDays(cid) >= premDays then
            if getPlayerLevel(cid) >= levelReq then
                if promotions[getPlayerVocation(cid)] ~= nil then
                    if(doPlayerRemoveMoney(cid, cost)) then
                        setPlayerPromotionLevel(promotions[getPlayerVocation(cid)])
                        selfSay('Congratulations! You are now promoted.', cid)
                    else
                        selfSay('Sorry, you don\'t have enough gold.', cid)
                    end
                else
                    selfSay('You have already been promoted.', cid)
                end
            else
                selfSay('Sorry, you need to be level '.. levelReq ..' to be promoted.', cid)
            end
        else
            selfSay('Sorry, you need to have '.. premDays ..' or more premium days on your account to buy a promotion.', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        talkState[talkUser] = 0
        selfSay('Allright then. Come back when you are ready.', cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
error.jpg

error =(
 
Back
Top