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

error NPC sells outfit even if you have no money

chupaescadatri

Banned User
Joined
Jul 5, 2014
Messages
338
Reaction score
49
The NPC sells the outfit even if you have no money.
but if you have money it cashes.
which the error?

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() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local config = {
     itemNeeded = 2160,
     count = 100,
     addonName = "Beggar",
     outfitId = 14,
     storage = 3848,
}
                if (msgcontains(msg, config.addonName)) then
                if doPlayerRemoveItem(cid, config.itemNeeded, config.count) then else selfSay('Sorry, you need a '..config.count..' of '..getItemNameById(config.itemNeeded)..' for complet a my trade.', cid) end
                if getPlayerStorageValue(cid, config.storage) < 1 then else return selfSay('Sorry, you this have a addon of '..config.addonName..' Outfit.', cid) end
                         selfSay("Well I give you "..config.addonName..", the more you need to give me certain items do you accept this trade? ", cid)
                         talkState[talkUser] = 1
                elseif(msgcontains(msg, "yes")) and talkState[talkUser] == 1 then
                         selfSay("only rich people can buy my outfit.",cid)
                         talkState[talkUser] = 0
                         doPlayerAddOutfit(cid,config.outfitId, config.giveAddons)
                         setPlayerStorageValue(cid, config.storage, 1)
                end
                       
                        
return true
end

keywordHandler:addKeyword({'outfit'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell {Beggar} Outfit for 1k.'})
keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell {Beggar} Outfit for 1k.'})
keywordHandler:addKeyword({'task'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell {Beggar} Outfit for 1k.'})

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
The script you posted is abit incorrect, I fixed some for you.
You can see the results below.

But the script you've made removes the money before the player accepts the trade, so if the player walks away he needs to pay the fee again to gain the addon/outfit, thats not good imo.

Your version with some cleanups:

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() end

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

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    local config = {
        itemNeeded = 2160,
        count = 100,
        addonName = "Beggar",
        outfitId = 14,
        storage = 3848,
    }

    if (msgcontains(msg, config.addonName)) then
        if doPlayerRemoveItem(cid, config.itemNeeded, config.count) then
            if getPlayerStorageValue(cid, config.storage) < 1 then
                selfSay("Well I give you ".. config.addonName ..", the more you need to give me certain items do you accept this trade? ", cid)
                talkState[talkUser] = 1
            else
                selfSay('Sorry, you already have a addon of '.. config.addonName ..' Outfit.', cid)
            end
        else
            selfSay('Sorry, you need a '.. config.count ..' of '.. getItemNameById(config.itemNeeded) ..' for complet a my trade.', cid)
        end
    elseif(msgcontains(msg, "yes")) and talkState[talkUser] == 1 then
        selfSay("only rich people can buy my outfit.", cid)
        talkState[talkUser] = 0
        doPlayerAddOutfit(cid,config.outfitId, config.giveAddons)
        setPlayerStorageValue(cid, config.storage, 1)
    end           
    return true
end



Fixed version:
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() end

local config = {
    itemNeeded = 2160,
    count = 100,
    addonName = "Beggar",
    outfitId = 14,
    storage = 3848,
}

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, config.addonName)) then
        if getPlayerStorageValue(cid, config.storage) < 1 then
            selfSay("Well I give you ".. config.addonName ..", the more you need to give me certain items do you accept this trade? ", cid)
            talkState[talkUser] = 1
        else
            selfSay('Sorry, you already have a addon of '.. config.addonName ..' Outfit.', cid)
        end
    elseif (msgcontains(msg, "yes")) and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, config.itemNeeded, config.count) then
            selfSay("only rich people can buy my outfit.", cid)
            talkState[talkUser] = 0
            doPlayerAddOutfit(cid, config.outfitId, 0)
            setPlayerStorageValue(cid, config.storage, 1)
        else
            selfSay('Sorry, you need a '.. config.count ..' of '.. getItemNameById(config.itemNeeded) ..' for complet a my trade.', cid)
        end
    end             
    return true
end

keywordHandler:addKeyword({'outfit'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell {Beggar} Outfit for 1k.'})
keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell {Beggar} Outfit for 1k.'})
keywordHandler:addKeyword({'task'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell {Beggar} Outfit for 1k.'})

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

You need to correct the english in the chat messages, they are incorrect.
 
There is no value for config.giveAddons

Also using:
Code:
if canPlayerWearOutfit(cid, outfit, addons) == false then

would be better then:
Code:
if getPlayerStorageValue(cid, storage) < 1 then
 
Back
Top