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

Lais Prad

Disgusting Scammer
Joined
Apr 12, 2017
Messages
153
Solutions
6
Reaction score
15
This npc give item ever, if player spam "yes" at final mission, how to fix?
tfs 1.3

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

-- Promotion
local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
    node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})

-- Justice For All
local missionKeyword = keywordHandler:addKeyword({'nokmir'}, StdModule.say, {npcHandler = npcHandler, text = 'Oh well, I liked Nokmir. He used to be a good dwarf until that day on which he stole the ring from Rerun.'}, function(player) return player:getStorageValue(Storage.hiddenCityOfBeregar.JusticeForAll) == 1 end)
    missionKeyword:addChildKeyword({'grombur'}, StdModule.say, {npcHandler = npcHandler, text = 'He\'s very ambitious and always volunteers for the long shifts.'}, nil, function(player) player:setStorageValue(Storage.hiddenCityOfBeregar.JusticeForAll, 2) end)

keywordHandler:addKeyword({'nokmir'}, StdModule.say, {npcHandler = npcHandler,
    text = {
        "Interesting. The fact that you have the ring means that Nokmir can't have stolen it. Combined with the information Grombur gave you, the case appears in a completely different light. ...",
        "Let there be justice for all. Nokmir is innocent and acquitted from all charges! And Rerun... I want him in prison for this malicious act!"
    }},
    function(player) return player:getStorageValue(Storage.hiddenCityOfBeregar.JusticeForAll) == 4 and player:removeItem(14348, 1) end,
    function(player) player:setStorageValue(Storage.hiddenCityOfBeregar.JusticeForAll, 5) end
)

-- Royal Rescue
local missionKeyword = keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, text = 'As you have proven yourself trustworthy I\'m going to assign you a special mission. Are you interested?'},
        function(player) return player:getStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue) < 1 end--and player:getStorageValue(Storage.hiddenCityOfBeregar.JusticeForAll) == 5
    )

    missionKeyword:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler,
        text = {
            "Splendid! My son Rehon set off on an expedition to the deeper mines. He and a group of dwarfs were to search for new veins of crystal. Unfortunately they have been missing for 2 weeks now. ...",
            "Find my son and if he's alive bring him back. You will find a reactivated ore wagon tunnel at the entrance of the great citadel which leades to the deeper mines. If you encounter problems within the tunnel go ask Xorlosh, he can help you."
        }}, nil, function(player) player:setStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue, 1) end
    )

local missionKeyword = keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, text = 'My son was captured by trolls? Doesn\'t sound like him, but if you say so. Now you want a reward, huh? ...'}, function(player) return player:getStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue) == 5 end)
    missionKeyword:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, text = 'Look at these dwarven legs. They were forged years ago by a dwarf who was rather tall for our kind. I want you to have them. Thank you for rescuing my son |PLAYERNAME|.'},
        nil, function(player) player:setStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue, 6) end player:addItem(2504, 1) end
    )

npcHandler:addModule(FocusModule:new())

player:addItem(2504, 1)
 
The keyword end is used to close out a metatable, loop, control structure or function/metamethod. You seem to have added an extra one when you added player:addItem(2504, 1)
Lua:
local missionKeyword = keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, text = 'My son was captured by trolls? Doesn\'t sound like him, but if you say so. Now you want a reward, huh? ...'}, function(player) return player:getStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue) == 5 end)
    missionKeyword:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, text = 'Look at these dwarven legs. They were forged years ago by a dwarf who was rather tall for our kind. I want you to have them. Thank you for rescuing my son |PLAYERNAME|.'},
        nil, function(player) player:setStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue, 6) player:addItem(2504, 1) end)
 
The keyword end is used to close out a metatable, loop, control structure or function/metamethod. You seem to have added an extra one when you added player:addItem(2504, 1)
Lua:
local missionKeyword = keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, text = 'My son was captured by trolls? Doesn\'t sound like him, but if you say so. Now you want a reward, huh? ...'}, function(player) return player:getStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue) == 5 end)
    missionKeyword:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, text = 'Look at these dwarven legs. They were forged years ago by a dwarf who was rather tall for our kind. I want you to have them. Thank you for rescuing my son |PLAYERNAME|.'},
        nil, function(player) player:setStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue, 6) player:addItem(2504, 1) end)

Same problem, The problem is that he does not stop giving the item, if we say yes, yes, yes. I could have a way to close the conversation as soon as the npc gave the item.
 
Well then you need to set/check for a storage value to see if they received the item, if they haven't received the item give them the item and set the storage so they don't get the item again.
 
Well then you need to set/check for a storage value to see if they received the item, if they haven't received the item give them the item and set the storage so they don't get the item again.
You think I have not tried? XD
I need a function to close the conversation when npc give the item
 
Well right away I can think of 2 things, first is to use talk states / topics insted, it works pretty good and is in my opinion probbly the best and easiest to read.
The other is to use a function called releaseFocus.
 
Well right away I can think of 2 things, first is to use talk states / topics insted, it works pretty good and is in my opinion probbly the best and easiest to read.
The other is to use a function called releaseFocus.
I tried too this function releaseFocus, but dont work, look what I was tried:

Lua:
local missionKeyword = keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, text = 'My son was captured by trolls? Doesn\'t sound like him, but if you say so. Now you want a reward, huh? ...'}, function(player) return player:getStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue) == 5 end)
    missionKeyword:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, text = 'Look at these dwarven legs. They were forged years ago by a dwarf who was rather tall for our kind. I want you to have them. Thank you for rescuing my son |PLAYERNAME|, go to nort and take your reward.'},
        nil, function(player) player:setStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue, 6) end player:addItem(2504, 1) npcHandler:releaseFocus(cid) end
    )

Lua:
reset = true
works
 
I tried too this function releaseFocus, but dont work, look what I was tried:

Lua:
local missionKeyword = keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, text = 'My son was captured by trolls? Doesn\'t sound like him, but if you say so. Now you want a reward, huh? ...'}, function(player) return player:getStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue) == 5 end)
    missionKeyword:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, text = 'Look at these dwarven legs. They were forged years ago by a dwarf who was rather tall for our kind. I want you to have them. Thank you for rescuing my son |PLAYERNAME|, go to nort and take your reward.'},
        nil, function(player) player:setStorageValue(Storage.hiddenCityOfBeregar.RoyalRescue, 6) end player:addItem(2504, 1) npcHandler:releaseFocus(cid) end
    )

Lua:
reset = true
works

Not even sure what the variable reset does, it's a global variable so you might be setting a value to something else, normally in the npc libs you got NpcHandler.variable or function to avoid changing scripts written by noobs :p

If the releaseFocus didn't work then go with states / topics ex; server/Rashid.lua at master · orts/server · GitHub
 
Back
Top