• 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+ npc problem

Landera

Veteran OT User
Joined
Nov 24, 2011
Messages
909
Solutions
1
Reaction score
319
Hello all,

Hope somebody could help me with this one.

I've been editing an npc script that basically make you collect 1500 berries in total.

1st time collecting 500 berries you get base outfit
2nd time you collect 500 berries gets you addon 1
3rd time cou collect 500 berries you get the last addon.

but i have no idea how i could make this happen at this point, beware the script can look messy after I did edit it :p

PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local rtnt = {}
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

npcHandler:setMessage(MESSAGE_GREET, "Greetings, |PLAYERNAME| like to help me with some{ farming}?")

addoninfo = {
['help'] = {cost = 0, items = {{2677,500}}, outfit_female = 1246, outfit_male = 1245, addon = 0, storageID = 10042},
['help'] = {cost = 0, items = {{2677,500}}, outfit_female = 1246, outfit_male = 1245, addon = 1, storageID = 10043},
['help'] = {cost = 0, items = {{2677,500}}, outfit_female = 1246, outfit_male = 1245, addon = 2, storageID = 10044}
-- next storage 10045
}

function creatureSayCallback(cid, type, msg)
local talkUser = cid

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

        if addoninfo[msg] ~= nil then
                if (getPlayerStorageValue(cid, addoninfo[msg].storageID) ~= -1) then
                                npcHandler:say('You already have helped me enough, thank you.', cid)
                                npcHandler:resetNpc()
                else
                local itemsTable = addoninfo[msg].items
                local items_list = ''
                        if table.maxn(itemsTable) > 0 then
                                for i = 1, table.maxn(itemsTable) do
                                        local item = itemsTable[i]
                                        items_list = items_list .. item[2] .. ' ' .. ItemType(item[1]):getName()
                                        if i ~= table.maxn(itemsTable) then
                                                items_list = items_list .. ', '
                                        end
                                end
                        end
                local text = ''
                        if (addoninfo[msg].cost > 0) then
                                text = addoninfo[msg].cost .. ' gp'
                        elseif table.maxn(addoninfo[msg].items) then
                                text = items_list
                        elseif (addoninfo[msg].cost > 0) and table.maxn(addoninfo[msg].items) then
                                text = items_list .. ' and ' .. addoninfo[msg].cost .. ' gp'
                        end
                        npcHandler:say('Thank you for helping me please bring me ' .. text .. '. Did you farm enough blueberry?', cid)
                        rtnt[talkUser] = msg
                        talkState[talkUser] = addoninfo[msg].storageID
                        return true
                end
        elseif msgcontains(msg, "yes") then
                if (talkState[talkUser] > 10010 and talkState[talkUser] < 10100) then
                        local items_number = 0
                        if table.maxn(addoninfo[rtnt[talkUser]].items) > 0 then
                                for i = 1, table.maxn(addoninfo[rtnt[talkUser]].items) do
                                        local item = addoninfo[rtnt[talkUser]].items[i]
                                        if (getPlayerItemCount(cid,item[1]) >= item[2]) then
                                                items_number = items_number + 1
                                        end
                                end
                        end
                        if(getPlayerMoney(cid) >= addoninfo[rtnt[talkUser]].cost) and (items_number == table.maxn(addoninfo[rtnt[talkUser]].items)) then
                                doPlayerRemoveMoney(cid, addoninfo[rtnt[talkUser]].cost)
                                if table.maxn(addoninfo[rtnt[talkUser]].items) > 0 then
                                        for i = 1, table.maxn(addoninfo[rtnt[talkUser]].items) do
                                                local item = addoninfo[rtnt[talkUser]].items[i]
                                                doPlayerRemoveItem(cid,item[1],item[2])
                                        end
                                end
                                doPlayerAddOutfit(cid, addoninfo[rtnt[talkUser]].outfit_male, addoninfo[rtnt[talkUser]].addon)
                                doPlayerAddOutfit(cid, addoninfo[rtnt[talkUser]].outfit_female, addoninfo[rtnt[talkUser]].addon)
                                setPlayerStorageValue(cid,addoninfo[rtnt[talkUser]].storageID,1)
                                npcHandler:say('Here, a little present for helping me.', cid)
                        else
                                npcHandler:say('You do not farmed enough yet.', cid)
                        end
                        rtnt[talkUser] = nil
                        talkState[talkUser] = 0
                        npcHandler:resetNpc()
                        return true
                end
        elseif msgcontains(msg, "farming") then
                npcHandler:say('Ah yea, Id could use some {help}', cid)
                rtnt[talkUser] = nil
                talkState[talkUser] = 0
                npcHandler:resetNpc()
                return true
        else
                if talkState[talkUser] ~= nil then
                        if talkState[talkUser] > 0 then
                        npcHandler:say('Please come back if you have enough.', cid)
                        rtnt[talkUser] = nil
                        talkState[talkUser] = 0
                        npcHandler:resetNpc()
                        return true
                        end
                end
        end
        return true
end

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

It is an edit of an addon npc

PS im using TFS1.3
 
You only need 1 storage value for this.

You can convert it to 1.3 yourself.
I'm only going to show you what it should look like
Lua:
function creatureSayCallback(cid, type, msg)
    local talkUser = cid
    
    if not npcHandler:isFocused(cid) then
        return false
    end
    
    
    if msgcontains(msg, "help") then
    
        local cur_storage = getPlayerStorageValue(cid, 45001)
        
        -- obtaining outfit.
        if cur_storage < 0 then
            npcHandler:say("Want to help me?", cid)
        elseif cur_storage == 1 then
            npcHandler:say("You have 500 blueberries?", cid)
            
        -- obtaining 1st addon.
        elseif cur_storage == 2 then
            npcHandler:say("Want to help me again?", cid)
        elseif cur_storage == 3 then
            npcHandler:say("You have 500 blueberries again?", cid)
            
        -- obtaining 2nd addon.
        elseif cur_storage == 4 then
            npcHandler:say("Want to help me again?", cid)
        elseif cur_storage == 5 then
            npcHandler:say("You have 500 blueberries again?", cid)
            
        -- no more missions available.
        else
            npcHandler:say("I have enough blueberries for now. Maybe another time.", cid)
            talkState[talkUser] = 0
            return true
            
        end
        
        talkState[talkUser] = 1 -- allows for player to answer yes.
        return true            
            
    elseif talkState[talkUser] == 1 and msgcontains(msg, "yes") then
    
        local cur_storage = getPlayerStorageValue(cid, 45001)
        
        -- obtaining outfit.
        if cur_storage < 0 then
            npcHandler:say("Great. Go get me 500 blueberries.", cid)
            setPlayerStorageValue(cid, 45001, 1)
        elseif cur_storage == 1 then
            npcHandler:say("Great. Here's an outfit. Come again if you want to help me.", cid)
            setPlayerStorageValue(cid, 45001, 2)
            
        -- obtaining 1st addon.
        elseif cur_storage == 2 then
            npcHandler:say("Great. Go get me 500 blueberries again.", cid)
            setPlayerStorageValue(cid, 45001, 3)
        elseif cur_storage == 3 then
            npcHandler:say("Great. Here's an addon. Come again if you want to help me.", cid)
            setPlayerStorageValue(cid, 45001, 4)
        
        -- obtaining 2nd addon.
        elseif cur_storage == 4 then
            npcHandler:say("Great. Go get me 500 blueberries again.", cid)
            setPlayerStorageValue(cid, 45001, 5)
        elseif cur_storage == 5 then
            npcHandler:say("Great. Here's an addon. Come again if you want to help me.", cid)
            setPlayerStorageValue(cid, 45001, 6)
            
        end
        
        talkState[talkUser] = 0 -- disallows the player to use the keyword 'yes'
        return true
        
    end
    
    return true
end
 
Back
Top