• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua [TFS 0.X] Npc who teleport by item - consuming double money

potinho

Intermediate OT User
Joined
Oct 11, 2009
Messages
1,252
Solutions
17
Reaction score
104
Location
Brazil
Hello everyone, everything good?

I have an NPC that takes a player to a certain location asking for an item and an amount of money, but I have 2 problems:

I asked him to request 5 crystal coins (50k) and he is asking for 100k. I would also like the NPC to ask for two items for sacrifice, how to configure this way?

npc.lua
Lua:
local tab = {
    pos = {x = 766, y = 253, z = 6}, -- x, y, z destination
    item = {2557, 30}, -- {itemID, count}
    price = 5 -- crystal coin amout
}

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
    if (msgcontains(msg, 'boat')) then
        talkState[talkUser] = 1
        selfSay('Are you sure?', cid)
        selfSay('Remember: you need '..tab.item[2]..' '..getItemNameById(tab.item[1])..' and '..tab.price..' crystal coins to be teleported. Do you want to go in anyway?', cid)
    elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if (getPlayerItemCount(cid, tab.item[1]) >= tab.item[2] and doPlayerRemoveMoney(cid, tab.price * 10000)) then 
            doTeleportThing(cid, tab.pos)
             doPlayerRemoveItem(cid, tab.item[1], tab.item[2])
            doPlayerRemoveMoney(cid, tab.price * 10000)    
            doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
            selfSay('Here you are. Have a good lucky and a nice travel, thanks for help.', cid)
        else
            talkState[talkUser] = 0
            selfSay('I can not teleport you. You do not have the required items.', cid)
        end
    elseif (msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        talkState[talkUser] = 0
        selfSay('Okay, maybe another time.', cid)
    end
    
    return true
end

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

Evil Puncker

I know nothing
TFS Developer
Joined
May 30, 2009
Messages
8,535
Solutions
260
Reaction score
4,526
8coPwoN.png


change the first one to getPlayerMoney(cid) or something
 
Top