• 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 0.X is it possible to make an npc answer just one person at a time?

Lurk

Active Member
Joined
Dec 4, 2017
Messages
336
Reaction score
48
I have this reset npc but when he answers 2 guys at a time, 1 of them gets the reset storage, the new health/mana but their level stays the same. I could work around this adding a storage to that player that would be checked on login but still, would be nice to make this npc answer just one guy a time
npc script:
Lua:
local config = {
    minlevel = 100000, --- level inical para resetar
    price = 0, --- preço inicial para resetar
    newlevel = 15000, --- level após reset
    priceByReset = 0, --- preço acrescentado por reset
    percent = 37, ---- porcentagem da vida/mana que você terá ao resetar (em relação à sua antiga vida total)
    maxresets = 20,
    newcap = 200000, -- NOVA CAP
    levelbyreset = 12000 --- quanto de level vai precisar a mais no próximo reset
}
--- end config

function getResets(cid)
resets = getPlayerStorageValue(cid,378378)
if getPlayerStorageValue(cid,378378) < 0 then
resets = 0
end
return resets
end

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

    function addReset(cid)
        if(npcHandler:isFocused(cid)) then
            npcHandler:releaseFocus(cid)
        end
        
        talkState[talkUser] = 0
        resets = getPlayerStorageValue(cid,378378)
        
        if (getPlayerStorageValue(cid,378378)<1) then
            setPlayerStorageValue(cid,378378,1)
        else
            setPlayerStorageValue(cid,378378,resets+1)
        end
        
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        local hp = getCreatureMaxHealth(cid)
        local resethp = hp*(config.percent/100)
        setCreatureMaxHealth(cid, resethp)
        local differencehp = (hp - resethp)
        doCreatureAddHealth(cid, -differencehp)
        local mana = getCreatureMaxMana(cid)
        local resetmana = mana*(config.percent/100)
        setCreatureMaxMana(cid, resetmana)
        local differencemana = (mana - resetmana)
        doCreatureAddMana(cid, -differencemana)
        doRemoveCreature(cid)       
        db.executeQuery("UPDATE [ICODE]players[/ICODE] SET [ICODE]level[/ICODE]="..config.newlevel..",[ICODE]experience[/ICODE]= 0 WHERE [ICODE]players[/ICODE].[ICODE]id[/ICODE]= ".. playerid .."")
        db.query("UPDATE [ICODE]players[/ICODE] SET [ICODE]cap[/ICODE]="..config.newcap.." WHERE [ICODE]players[/ICODE].[ICODE]id[/ICODE]= ".. playerid .."")
        return true
    end
    
    local newPrice = config.price + (getResets(cid) * config.priceByReset)
    local newminlevel = config.minlevel + (getResets(cid) * config.levelbyreset)

    if msgcontains(msg, 'reset') then
        if getResets(cid) < config.maxresets then
            selfSay('You want to reset your character? It will cost '..newPrice..' gp\'s!', cid)
            talkState[talkUser] = 1
        else
            selfSay('You already reached the maximum reset level!', cid)
        end
        
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if getPlayerMoney(cid) < newPrice then
            selfSay('Its necessary to have at least '..newPrice..' gp\'s for reseting!', cid)
        elseif getPlayerLevel(cid) < newminlevel then
            selfSay('The minimum level for reseting is '..newminlevel..'!', cid)
        else
            doPlayerRemoveMoney(cid,newPrice)
            playerid = getPlayerGUID(cid)
            addEvent(function()
                if isPlayer(cid) then
                    addReset(cid)
                end
            end, 3000)
            local number = getPlayerStorageValue(cid,378378)+1
            local msg ="---[Reset: "..number.."]-- You have reseted!  You'll be disconnected in 3 seconds."
            doPlayerPopupFYI(cid, msg)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no')) and isInArray({1}, talkState[talkUser]) == TRUE then
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)
        selfSay('Ok.', cid)
    elseif msgcontains(msg, 'quantity') then
        selfSay('You have a total of '..getPlayerStorageValue(cid,378378)..' reset(s).', cid)
        talkState[talkUser] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Use global storage.
If npc answer to first player then storage set to 1.
If 1 then return false or dialog that npc is bussy for second player.
If npc end talking with first player set global storage to 0
Use global storage.
If npc answer to first player then storage set to 1.
If 1 then return false or dialog that npc is bussy for second player.
If npc end talking with first player set global storage to 0
 
Solution
good idea, worked perfectly. ty
edit: nvm, found a problem. I'm setting the storage when the players says "reset" since tha stuff when he says hi and bye is a xml file and I think i can't use set storages theres, if a player says hi, reset, bye it won't set my globalstorage to 0 since it's done when the reset is completed. also, if he says hi, reset and then relog the same problem will happen
edit again: managed to fix when the guy relog but not when the guys say "bye" even tho i added
Lua:
elseif msgcontains(msg, 'bye') then
        talkState[talkUser] = 0
        setGlobalStorageValue (197823, 0)

edit:
fixed! changed
Lua:
function onCreatureSay(cid, type, msg)
npcHandler:onCreatureSay(cid, type, msg)
end
to
Lua:
function onCreatureSay(cid, type, msg)
npcHandler:onCreatureSay(cid, type, msg)
local teste = npcHandler:onCreatureSay(msg)
if teste == bye then
setGlobalStorageValue (197823, 0)
end
 
Last edited:
Easier way:
Instead of setting a global storage(which would require 1 for each npc) just set a storage on the npc itself. It would function basically the same way, but you could just ctrl+c and ctrl+v to the other npcs.
 

Similar threads

Back
Top