• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Simple! Npc talk a message chosen by player

Vrotz

Member
Joined
Apr 7, 2011
Messages
1,071
Reaction score
7
Location
Brazil
Hello,

I would like to create a NPC that call the players for quests! For example, the player pays a price of 500 gp to announce the message and choose which quest he wants to go and announce to the npc that will send a message to everyone.

Follows:
The player has the right to choose 3 quests. Anihi 1, Anihi 2 or Anihi 3. And him choose a Anihi 2! Then the NPC will tell everyone "The player Vrotz is calling all players to go to anihi 2"

How i do that? xD
Thanks!
 
It won't work on TFS 1.0 and is untested, but give it a shot:

----------------
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
npcHandler.talkRadius = 3
NpcSystem.parseParameters(npcHandler)

local Topic = {}

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 greet(cid)
    npcHandler:say('Hello ' ..getPlayerName(cid).. '! I can make a global {broadcast} in case you are searching for a team to embark on a quest.', cid)
    Topic[cid] = nil
    npcHandler:addFocus(cid)
    return false
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
   
    local price1, price2, price3 = 500, 500, 500
   
    if msgcontains(msg, 'broadcast') then
        npcHandler:say('So, you are interested! Very well. And you are looking to gather a team for which quest: {anihi1}, {anihi2}, {anihi3}?', cid)
    elseif msgcontains(msg, 'anihi1') then
        npcHandler:say('That broadcast will cost you ' ..price1.. ' gp. Do we have a deal?', cid)
        Topic[cid] = 1
    elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
        if doPlayerRemoveMoney(cid, price1) then
            doPlayerBroadcastMessage(getNpcCid(), getPlayerName(cid).. " is calling all players to anihi1!")
            npcHandler:say('Here we go - broadcasting live...', cid)
        else
            npcHandler:say('You don\'t have enough money.', cid)
        end
    elseif msgcontains(msg, 'anihi2') then
        npcHandler:say('That broadcast will cost you ' ..price2.. ' gp. Do we have a deal?', cid)
        Topic[cid] = 2
    elseif msgcontains(msg, 'yes') and Topic[cid] == 2 then
        if doPlayerRemoveMoney(cid, price2) then
            doPlayerBroadcastMessage(getNpcCid(), getPlayerName(cid).. " is calling all players to anihi2!")
            npcHandler:say('Here we go - broadcasting live...', cid)
        else
            npcHandler:say('You don\'t have enough money.', cid)
        end
    elseif msgcontains(msg, 'anihi3') then
        npcHandler:say('That broadcast will cost you ' ..price3.. ' gp. Do we have a deal?', cid)
        Topic[cid] = 3
    elseif msgcontains(msg, 'yes') and Topic[cid] == 3 then
        if doPlayerRemoveMoney(cid, price3) then
            doPlayerBroadcastMessage(getNpcCid(), getPlayerName(cid).. " is calling all players to anihi2!")
            npcHandler:say('Here we go - broadcasting live...', cid)
        else
            npcHandler:say('You don\'t have enough money.', cid)
        end
    elseif msgcontains(msg, 'no') and (Topic[cid] == 1 or Topic[cid] == 2 or Topic[cid] == 3) then
        npcHandler:say('Well then.. Maybe some other time.', cid)
        Topic[cid] = nil
    end
   
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_FAREWELL, 'Bye.')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Well goodbye to you too!')
npcHandler:addModule(FocusModule:new())
 
Back
Top