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

Solved Addoner NPC issue/improvement [0.4]

Amiroslo

Excellent OT User
Joined
Jul 28, 2009
Messages
6,767
Solutions
5
Reaction score
769
Hello OTLanders,
I have an Addoner NPC, very simple script. The only issue is that the addoner doesnt know if you already have addons 1 and 2 or not. So you can keep buying them and he will keep taking money from you. Anyone knowledgeable enough who can adjust it so if someone already bought Addon 1/2 they wont be able to buy it again? Thank you

TFS 0.4, Tibia 8.6

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

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

function buyAddons(cid, message, keywords, parameters, node)
    --TODO: buyAddons function in modules.lua
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local addon = parameters.addon
    local cost = parameters.cost
    local premium = (parameters.premium ~= nil and parameters.premium)

    if isPlayerPremiumCallback == nil or (isPlayerPremiumCallback(cid) and premium) then
        if doPlayerRemoveMoney(cid, cost) then
            doPlayerAddAddons(cid, addon)
            npcHandler:say('There, you are now able to use all addons!', cid)
        else
            npcHandler:say('Sorry, you do not have enough money.', cid)
        end
    else
        npcHandler:say('I only serve customers with premium accounts.', cid)
    end

    keywordHandler:moveUp(1)
    return true
end

local node1 = keywordHandler:addKeyword({'first addon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the first addons set for 1 gold nugget?'})
    node1:addChildKeyword({'yes'}, buyAddons, {addon = 1, cost = 1000000, premium = true})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'Too expensive, eh?'})

local node2 = keywordHandler:addKeyword({'second addon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to buy the second addons set for 1 gold nugget?'})
    node2:addChildKeyword({'yes'}, buyAddons, {addon = 2, cost = 1000000, premium = true})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'Too expensive, eh?'})

keywordHandler:addKeyword({'addon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell the first addons set for 1 gold nugget and the second addons set for 1 gold nugget.'})

npcHandler:addModule(FocusModule:new())
 
Solution
Not sure if this is the way to call addons ids in this function but this should work.
Lua:
local keywordHandler = KeywordHandler:new()

local npcHandler = NpcHandler:new(keywordHandler)

NpcSystem.parseParameters(npcHandler)

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

function buyAddons(cid, message, keywords, parameters, node)
    --TODO: buyAddons function in modules.lua

    if (not npcHandler:isFocused(cid)) then
        return false
    end

    local addon = parameters.addon

    local...
You can check using this on your buyAddons function
Lua:
canPlayerWearOutfit(cid, currentLookType, 1, 2 or 3)
This function return true if player can wear a outfit with x addons, so if is true this mean player has it and then you can return with a message.
 
Last edited:
You can check using this on your buyAddons function
Lua:
canPlayerWearOutfit(cid, currentLookType, 1, 2 or 3)
This function return true if player can wear a outfit with x addons, so if is true this mean player has it and then you can return with a message.
Awesome, thank you
Does this look right? I tried doing it, line 28-32

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

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

function buyAddons(cid, message, keywords, parameters, node)
    --TODO: buyAddons function in modules.lua
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local addon = parameters.addon
    local cost = parameters.cost
    local premium = (parameters.premium ~= nil and parameters.premium)

    if isPlayerPremiumCallback == nil or (isPlayerPremiumCallback(cid) and premium) then
        if doPlayerRemoveMoney(cid, cost) then
            doPlayerAddAddons(cid, addon)
            npcHandler:say('There, you are now able to use all addons!', cid)
        else
            npcHandler:say('Sorry, you do not have enough money.', cid)
        end
        else
        if canPlayerWearOutfit(cid, currentLookType, 1) then
            npcHandler:say('You have addon 1 already', cid)
        elseif canPlayerWearOutfit(cid, currentLookType, 2) then
            npcHandler:say('You have addon 2 already', cid)
    end
    else
        npcHandler:say('I only serve customers with premium accounts.', cid)
    end

    keywordHandler:moveUp(1)
    return true
end

local node1 = keywordHandler:addKeyword({'first addon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the first addons set for 1 gold nugget?'})
    node1:addChildKeyword({'yes'}, buyAddons, {addon = 1, cost = 1000000, premium = true})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'Too expensive, eh?'})

local node2 = keywordHandler:addKeyword({'second addon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to buy the second addons set for 1 gold nugget?'})
    node2:addChildKeyword({'yes'}, buyAddons, {addon = 2, cost = 1000000, premium = true})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'Too expensive, eh?'})

keywordHandler:addKeyword({'addon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell the first addons set for 1 gold nugget and the second addons set for 1 gold nugget.'})

npcHandler:addModule(FocusModule:new())
 
Not sure if this is the way to call addons ids in this function but this should work.
Lua:
local keywordHandler = KeywordHandler:new()

local npcHandler = NpcHandler:new(keywordHandler)

NpcSystem.parseParameters(npcHandler)

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

function buyAddons(cid, message, keywords, parameters, node)
    --TODO: buyAddons function in modules.lua

    if (not npcHandler:isFocused(cid)) then
        return false
    end

    local addon = parameters.addon

    local cost = parameters.cost

    for i = 0, table.maxn(maleOutfits) do
        if canPlayerWearOutfit(cid, maleOutfits[i], addon) then
            npcHandler:say("You have " .. addon .. " already", cid)
            return true
        end
    end

    for i = 0, table.maxn(femaleOutfits) do
        if canPlayerWearOutfit(cid, femaleOutfits[i], addon) then
            npcHandler:say("You have " .. addon .. " already", cid)
            return true
        end
    end

    local premium = (parameters.premium ~= nil and parameters.premium)

    if isPlayerPremiumCallback == nil or (isPlayerPremiumCallback(cid) and premium) then
        if doPlayerRemoveMoney(cid, cost) then
            doPlayerAddAddons(cid, addon)

            npcHandler:say("There, you are now able to use all addons!", cid)
        else
            npcHandler:say("Sorry, you do not have enough money.", cid)
        end
    else
        npcHandler:say("I only serve customers with premium accounts.", cid)
    end

    keywordHandler:moveUp(1)

    return true
end

local node1 =
    keywordHandler:addKeyword(
    {"first addon"},
    StdModule.say,
    {npcHandler = npcHandler, onlyFocus = true, text = "Do you want to buy the first addons set for 1 gold nugget?"}
)

node1:addChildKeyword({"yes"}, buyAddons, {addon = 1, cost = 1000000, premium = true})

node1:addChildKeyword(
    {"no"},
    StdModule.say,
    {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = "Too expensive, eh?"}
)

local node2 =
    keywordHandler:addKeyword(
    {"second addon"},
    StdModule.say,
    {npcHandler = npcHandler, onlyFocus = true, text = "Would you like to buy the second addons set for 1 gold nugget?"}
)

node2:addChildKeyword({"yes"}, buyAddons, {addon = 2, cost = 1000000, premium = true})

node2:addChildKeyword(
    {"no"},
    StdModule.say,
    {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = "Too expensive, eh?"}
)

keywordHandler:addKeyword(
    {"addon"},
    StdModule.say,
    {
        npcHandler = npcHandler,
        onlyFocus = true,
        text = "I sell the first addons set for 1 gold nugget and the second addons set for 1 gold nugget."
    }
)

npcHandler:addModule(FocusModule:new())
 
Solution
Not sure if this is the way to call addons ids in this function but this should work.
Lua:
local keywordHandler = KeywordHandler:new()

local npcHandler = NpcHandler:new(keywordHandler)

NpcSystem.parseParameters(npcHandler)

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

function buyAddons(cid, message, keywords, parameters, node)
    --TODO: buyAddons function in modules.lua

    if (not npcHandler:isFocused(cid)) then
        return false
    end

    local addon = parameters.addon

    local cost = parameters.cost

    for i = 0, table.maxn(maleOutfits) do
        if canPlayerWearOutfit(cid, maleOutfits[i], addon) then
            npcHandler:say("You have " .. addon .. " already", cid)
            return true
        end
    end

    for i = 0, table.maxn(femaleOutfits) do
        if canPlayerWearOutfit(cid, femaleOutfits[i], addon) then
            npcHandler:say("You have " .. addon .. " already", cid)
            return true
        end
    end

    local premium = (parameters.premium ~= nil and parameters.premium)

    if isPlayerPremiumCallback == nil or (isPlayerPremiumCallback(cid) and premium) then
        if doPlayerRemoveMoney(cid, cost) then
            doPlayerAddAddons(cid, addon)

            npcHandler:say("There, you are now able to use all addons!", cid)
        else
            npcHandler:say("Sorry, you do not have enough money.", cid)
        end
    else
        npcHandler:say("I only serve customers with premium accounts.", cid)
    end

    keywordHandler:moveUp(1)

    return true
end

local node1 =
    keywordHandler:addKeyword(
    {"first addon"},
    StdModule.say,
    {npcHandler = npcHandler, onlyFocus = true, text = "Do you want to buy the first addons set for 1 gold nugget?"}
)

node1:addChildKeyword({"yes"}, buyAddons, {addon = 1, cost = 1000000, premium = true})

node1:addChildKeyword(
    {"no"},
    StdModule.say,
    {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = "Too expensive, eh?"}
)

local node2 =
    keywordHandler:addKeyword(
    {"second addon"},
    StdModule.say,
    {npcHandler = npcHandler, onlyFocus = true, text = "Would you like to buy the second addons set for 1 gold nugget?"}
)

node2:addChildKeyword({"yes"}, buyAddons, {addon = 2, cost = 1000000, premium = true})

node2:addChildKeyword(
    {"no"},
    StdModule.say,
    {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = "Too expensive, eh?"}
)

keywordHandler:addKeyword(
    {"addon"},
    StdModule.say,
    {
        npcHandler = npcHandler,
        onlyFocus = true,
        text = "I sell the first addons set for 1 gold nugget and the second addons set for 1 gold nugget."
    }
)

npcHandler:addModule(FocusModule:new())
Worked, cheers
 
Back
Top