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

Help with NPC Mission (x items for Y reward)

Qbecky

New Member
Joined
Mar 11, 2023
Messages
29
Reaction score
1
GitHub
QbeckyX
Hi i would like to create npc that gives mission to loot and give him 100x items (ex. ID 12345) for a reward (ex. 5cc or 100 Tibia Coins).
My NPC code:
Code:
local npcName = "Hellheim"

local npcType = Game.createNpcType(npcName)
local npcConfig = {}

npcConfig.name = npcName
npcConfig.description = npcName

npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 2000
npcConfig.walkRadius = 10

npcConfig.outfit = {
    lookType = 128,
    lookHead = 0,
    lookBody = 0,
    lookLegs = 0,
    lookFeet = 0,
    lookAddons = 2,
    lookMount = 42
}

npcConfig.voices = {
    interval = 15000,
    chance = 20,
    { text = "Welcome to the Hellheim Server!" }
}

npcConfig.flags = {
    floorchange = false
}

-- Npc shop
npcConfig.shop = {
    { clientId = 6545, buy = 2000 },
    { clientId = 130, buy = 100, count = 1 },
    { clientId = 135, buy = 5000, count = 1 },
    { clientId = 138, buy = 600, count = 1 }
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
    npc:sellItem(player, itemId, amount, subType, 0, ignore, inBackpacks)
end
-- On sell npc shop message
npcType.onSellItem = function(npc, player, itemId, subtype, amount, ignore, name, totalCost)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("Sold %ix %s for %i gold.", amount, name, totalCost))
end
-- On check npc shop message (look item)
npcType.onCheckItem = function(npc, player, clientId, subType)
end

-- Create keywordHandler and npcHandler
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)

-- onThink
npcType.onThink = function(npc, interval)
    npcHandler:onThink(npc, interval)
end

-- onAppear
npcType.onAppear = function(npc, creature)
    npcHandler:onAppear(npc, creature)
end

-- onDisappear
npcType.onDisappear = function(npc, creature)
    npcHandler:onDisappear(npc, creature)
end

-- onMove
npcType.onMove = function(npc, creature, fromPosition, toPosition)
    npcHandler:onMove(npc, creature, fromPosition, toPosition)
end

-- onSay
npcType.onSay = function(npc, creature, type, message)
    npcHandler:onSay(npc, creature, type, message)
end

npcType.onCloseChannel = function(npc, creature)
    npcHandler:onCloseChannel(npc, creature)
end

-- Function called by the callback "npcHandler:setCallback(CALLBACK_GREET, greetCallback)" in end of file
local function greetCallback(npc, creature)
    local playerId = creature:getId()
    npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|, you need more info about {hellheim}?")
    return true
end

-- On creature say callback
local function creatureSayCallback(npc, creature, type, message)
    local player = Player(creature)
    local playerId = player:getId()

    if not npcHandler:checkInteraction(npc, creature) then
        return false
    end

    if MsgContains(message, "hellheim") then
        npcHandler:say({
            "The goal is for Hellheim to create an adventure that the player will want to come back to every day. We try to develop the server all the time to add new content and make every player happy!",
            "See more on our {discord group}."
        }, npc, creature, 3000)
        npcHandler:setTopic(playerId, 1)
    elseif MsgContains(message, "discord group") then
        if npcHandler:getTopic(playerId) == 1 then
            npcHandler:say("This the our discord group link: {https://discord.gg/tzZvaETGu3}", npc, creature)
        end
        npcHandler:setTopic(playerId, 0)
    end
    return true
end

-- Set to local function "greetCallback"
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
-- Set to local function "creatureSayCallback"
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

-- Bye message
npcHandler:setMessage(MESSAGE_FAREWELL, "Yeah, good bye and don't come again!")
-- Walkaway message
npcHandler:setMessage(MESSAGE_WALKAWAY, "You not have education?")

npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- Register npc
npcType:register(npcConfig)
 
What TFS Version?
Try this:


Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    local requiredItems = {100, 101, 102}
    local rewardItems = {200, 201, 202}

    if player:getStorageValue(5400) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed this quest.")
        return true
    end

    for _, itemId in ipairs(requiredItems) do
        if player:getItemCount(itemId) <= 0 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You are missing one or more required items.")
            return true
        end
    end

    for _, itemId in ipairs(rewardItems) do
        player:addItem(itemId, 1)
    end

    player:setStorageValue(5400, 1)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations, you have completed the quest!")
    return true
end

If you want an npc:
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Roksas" script="mission_r.lua" walkinterval="0" floorchange="0">
    <health now="2000" max="2000"/>
    <look type="264" head="114" body="119" legs="0" feet="0" corpse="2212"/>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|. I can make some change to it, say {change} or {mission}."/>
    </parameters>
</npc>

Npc lua file:
Lua:
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
    local item_gain_1 = 101 -- reward id 1
    local item_gain_2 = 102 -- reward id 2
    local item_gain_3 = 103 -- reward id 3
    local item_need_1 = 201 -- need item id 1
    local item_need_2 = 202 -- need item id 2
    local item_need_3 = 203 -- need item id 3
    local item_qnt_1 = 1 -- item 1 amount
    local item_qnt_2 = 1 -- item 2 amount
    local item_qnt_3 = 1 -- item 3 amount
    local storageValue = 1001 -- storage value for quest
  
    if(msgcontains(msg, 'mission') or msgcontains(msg, 'change')) then
        if getPlayerStorageValue(cid, storageValue) == -1 then
            selfSay('I need your help. You need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'. Once you have them, I will reward you with '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
            talkState[talkUser] = 1
        else
            selfSay('You have already completed this quest. Thanks for your help!', cid)
            talkState[talkUser] = 0
        end
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if getPlayerItemCount(cid, item_need_1) >= 1 and getPlayerItemCount(cid, item_need_2) >= 1 and getPlayerItemCount(cid, item_need_3) >= 1 then
            selfSay('Excellent! You have retrieved the necessary items. Here is your reward: '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
            doPlayerAddItem(cid, item_gain_1, item_qnt_1)
            doPlayerAddItem(cid, item_gain_2, item_qnt_2)
            doPlayerAddItem(cid, item_gain_3, item_qnt_3)
            setPlayerStorageValue(cid, storageValue, 1)
            talkState[talkUser] = 0
        else
            selfSay('You still need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'.', cid)
            talkState[talkUser] = 0
        end
 
Last edited:
What TFS Version?
Try this:


Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    local requiredItems = {100, 101, 102}
    local rewardItems = {200, 201, 202}

    if player:getStorageValue(5400) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed this quest.")
        return true
    end

    for _, itemId in ipairs(requiredItems) do
        if player:getItemCount(itemId) <= 0 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You are missing one or more required items.")
            return true
        end
    end

    for _, itemId in ipairs(rewardItems) do
        player:addItem(itemId, 1)
    end

    player:setStorageValue(5400, 1)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations, you have completed the quest!")
    return true
end

Or this:

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local player = Player(cid)
local requiredItems = {100, 101, 102}
local rewardItems = {200, 201, 202}

if player:getStorageValue(5400) == 1 then
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed this quest.")
    return true
end

for _, itemId in ipairs(requiredItems) do
    if player:getItemCount(itemId) <= 0 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You are missing one or more required items.")
        return true
    end
end

for _, itemId in ipairs(rewardItems) do
    player:addItem(itemId, 1)
end

player:setStorageValue(5400, 1)
player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations, you have completed the quest and received your reward!")
return true
Im using canary but will try this codes and answer you i forget to sat i want do this quest unlimited that mean player can do this unlimited times
 
I removed the storage check in code so the player can do this unlimited times
Lua:
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
    local item_gain_1 = 101 -- reward id 1
    local item_gain_2 = 102 -- reward id 2
    local item_gain_3 = 103 -- reward id 3
    local item_need_1 = 201 -- need item id 1
    local item_need_2 = 202 -- need item id 2
    local item_need_3 = 203 -- need item id 3
    local item_qnt_1 = 1 -- item 1 amount
    local item_qnt_2 = 1 -- item 2 amount
    local item_qnt_3 = 1 -- item 3 amount
 
    if(msgcontains(msg, 'mission') or msgcontains(msg, 'change')) then
        selfSay('I need your help. You need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'. Once you have them, I will reward you with '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if getPlayerItemCount(cid, item_need_1) >= 1 and getPlayerItemCount(cid, item_need_2) >= 1 and getPlayerItemCount(cid, item_need_3) >= 1 then
            selfSay('Excellent! You have retrieved the necessary items. Here is your reward: '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
            doPlayerAddItem(cid, item_gain_1, item_qnt_1)
            doPlayerAddItem(cid, item_gain_2, item_qnt_2)
            doPlayerAddItem(cid, item_gain_3, item_qnt_3)
            talkState[talkUser] = 0
        else
            selfSay('You still need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'.', cid)
            talkState[talkUser] = 0
        end
    end
end
 
1680957910244.png
@GamerGoiano

This is my code edited with your help:

Code:
local npcName = "Hell Mission"

local npcType = Game.createNpcType(npcName)
local npcConfig = {}

npcConfig.name = npcName
npcConfig.description = npcName

npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 2000
npcConfig.walkRadius = 10

npcConfig.outfit = {
    lookType = 128,
    lookHead = 0,
    lookBody = 0,
    lookLegs = 0,
    lookFeet = 0,
    lookAddons = 2,
    lookMount = 42
}

npcConfig.voices = {
    interval = 15000,
    chance = 20,
    { text = "Welcome to the Hellheim Server!" }
}

npcConfig.flags = {
    floorchange = false
}

-- Npc shop
npcConfig.shop = {
    { clientId = 6545, buy = 2000 },
    { clientId = 130, buy = 100, count = 1 },
    { clientId = 135, buy = 5000, count = 1 },
    { clientId = 138, buy = 600, count = 1 }
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
    npc:sellItem(player, itemId, amount, subType, 0, ignore, inBackpacks)
end
-- On sell npc shop message
npcType.onSellItem = function(npc, player, itemId, subtype, amount, ignore, name, totalCost)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("Sold %ix %s for %i gold.", amount, name, totalCost))
end
-- On check npc shop message (look item)
npcType.onCheckItem = function(npc, player, clientId, subType)
end

-- Create keywordHandler and npcHandler
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
    local item_gain_1 = 35282 -- reward id 1
    local item_gain_2 = 35279 -- reward id 2
    local item_gain_3 = 35284 -- reward id 3
    local item_need_1 = 6499 -- need item id 1
    local item_need_2 = 3003 -- need item id 2
    local item_need_3 = 5710 -- need item id 3
    local item_qnt_1 = 100 -- item 1 amount
    local item_qnt_2 = 1 -- item 2 amount
    local item_qnt_3 = 1 -- item 3 amount
 
    if(msgcontains(msg, 'mission') or msgcontains(msg, 'change')) then
        selfSay('I need your help. You need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'. Once you have them, I will reward you with '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if getPlayerItemCount(cid, item_need_1) >= 1 and getPlayerItemCount(cid, item_need_2) >= 1 and getPlayerItemCount(cid, item_need_3) >= 1 then
            selfSay('Excellent! You have retrieved the necessary items. Here is your reward: '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
            doPlayerAddItem(cid, item_gain_1, item_qnt_1)
            doPlayerAddItem(cid, item_gain_2, item_qnt_2)
            doPlayerAddItem(cid, item_gain_3, item_qnt_3)
            talkState[talkUser] = 0
        else
            selfSay('You still need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'.', cid)
            talkState[talkUser] = 0
        end
    end
end
 
@Qbecky
change:
Lua:
NpcSystem.parseParameters(npcHandler)
to:
Lua:
npcHandler:addModule(NpcSystemModule:new())

Replace {} to () in:
"There is a special {event} that you can participate in to receive amazing rewards."
 
@Qbecky
change:
Lua:
NpcSystem.parseParameters(npcHandler)
to:
Lua:
npcHandler:addModule(NpcSystemModule:new())

Replace {} to () in:
"There is a special {event} that you can participate in to receive amazing rewards."
I created new lua because there was something wrong, i dont had "the is a special {event}".....

Now it looks like:

Code:
local npcName = "Mission Joe"

local npcType = Game.createNpcType("npcName")
local npcConfig = {}

npcConfig.description = "..."

npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 1500
npcConfig.walkRadius = 2

npcConfig.outfit = {
    lookType = 294,
    lookHead = 0,
    lookBody = 0,
    lookLegs = 0,
    lookFeet = 0,
    lookAddons = 0
}

npcConfig.flags = {
    floorchange = false
}

-- Create keywordHandler and npcHandler
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)

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
    local item_gain_1 = 35282 -- reward id 1
    local item_gain_2 = 35279 -- reward id 2
    local item_gain_3 = 35284 -- reward id 3
    local item_need_1 = 6499 -- need item id 1
    local item_need_2 = 3003 -- need item id 2
    local item_need_3 = 5710 -- need item id 3
    local item_qnt_1 = 100 -- item 1 amount
    local item_qnt_2 = 1 -- item 2 amount
    local item_qnt_3 = 1 -- item 3 amount
 
    if(msgcontains(msg, 'mission') or msgcontains(msg, 'change')) then
        selfSay('I need your help. You need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'. Once you have them, I will reward you with '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if getPlayerItemCount(cid, item_need_1) >= 1 and getPlayerItemCount(cid, item_need_2) >= 1 and getPlayerItemCount(cid, item_need_3) >= 1 then
            selfSay('Excellent! You have retrieved the necessary items. Here is your reward: '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
            doPlayerAddItem(cid, item_gain_1, item_qnt_1)
            doPlayerAddItem(cid, item_gain_2, item_qnt_2)
            doPlayerAddItem(cid, item_gain_3, item_qnt_3)
            talkState[talkUser] = 0
        else
            selfSay('You still need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'.', cid)
            talkState[talkUser] = 0
        end
    end
end

-- npcType registering the npcConfig table
npcType:register(npcConfig)

and only error is in console: (cant even spawn /n name NPC) - he is visible in RME editor map but in game not (corretly put spawn and npc on tile)
1680969812663.png


1680969942243.png
 
@Qbecky what TFS version?
canary 2.6.1 we can teamviewer if you want?

@GamerGoiano
I made this npc appear in game, without errors in console, but he doesnt react to say "hi"
Code:
local npcName = "Mission Joe"

local npcType = Game.createNpcType(npcName)
local npcConfig = {}

npcConfig.name = npcName
npcConfig.description = npcName

npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 1500
npcConfig.walkRadius = 2

npcConfig.outfit = {
    lookType = 294,
    lookHead = 0,
    lookBody = 0,
    lookLegs = 0,
    lookFeet = 0,
    lookAddons = 0
}

npcConfig.flags = {
    floorchange = false
}

-- Create keywordHandler and npcHandler
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
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
    local item_gain_1 = 35282 -- reward id 1
    local item_gain_2 = 35279 -- reward id 2
    local item_gain_3 = 35284 -- reward id 3
    local item_need_1 = 6499 -- need item id 1
    local item_need_2 = 3003 -- need item id 2
    local item_need_3 = 5710 -- need item id 3
    local item_qnt_1 = 100 -- item 1 amount
    local item_qnt_2 = 1 -- item 2 amount
    local item_qnt_3 = 1 -- item 3 amount
 
    if(msgcontains(msg, 'mission') or msgcontains(msg, 'change')) then
        npcHandler:say('I need your help. You need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'. Once you have them, I will reward you with '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if getPlayerItemCount(cid, item_need_1) >= item_qnt_1 and getPlayerItemCount(cid, item_need_2) >= item_qnt_2 and getPlayerItemCount(cid, item_need_3) >= item_qnt_3 then
            npcHandler:say('Excellent! You have retrieved the necessary items. Here is your reward: '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
            doPlayerAddItem(cid, item_gain_1, item_qnt_1)
            doPlayerAddItem(cid, item_gain_2, item_qnt_2)
            doPlayerAddItem(cid, item_gain_3, item_qnt_3)
            talkState[talkUser] = 0
        else
            npcHandler:say('You still need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'.', cid)
            talkState[talkUser] = 0
        end
    end
end
1680972128896.png
 
Last edited:
canary 2.6.1 we can teamviewer if you want?

@GamerGoiano
I made this npc appear in game, without errors in console, but he doesnt react to say "hi"
Code:
local npcName = "Mission Joe"

local npcType = Game.createNpcType(npcName)
local npcConfig = {}

npcConfig.name = npcName
npcConfig.description = npcName

npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 1500
npcConfig.walkRadius = 2

npcConfig.outfit = {
    lookType = 294,
    lookHead = 0,
    lookBody = 0,
    lookLegs = 0,
    lookFeet = 0,
    lookAddons = 0
}

npcConfig.flags = {
    floorchange = false
}

-- Create keywordHandler and npcHandler
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
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
    local item_gain_1 = 35282 -- reward id 1
    local item_gain_2 = 35279 -- reward id 2
    local item_gain_3 = 35284 -- reward id 3
    local item_need_1 = 6499 -- need item id 1
    local item_need_2 = 3003 -- need item id 2
    local item_need_3 = 5710 -- need item id 3
    local item_qnt_1 = 100 -- item 1 amount
    local item_qnt_2 = 1 -- item 2 amount
    local item_qnt_3 = 1 -- item 3 amount
 
    if(msgcontains(msg, 'mission') or msgcontains(msg, 'change')) then
        npcHandler:say('I need your help. You need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'. Once you have them, I will reward you with '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if getPlayerItemCount(cid, item_need_1) >= item_qnt_1 and getPlayerItemCount(cid, item_need_2) >= item_qnt_2 and getPlayerItemCount(cid, item_need_3) >= item_qnt_3 then
            npcHandler:say('Excellent! You have retrieved the necessary items. Here is your reward: '..getItemNameById(item_gain_1)..', '..getItemNameById(item_gain_2)..', and '..getItemNameById(item_gain_3)..'.', cid)
            doPlayerAddItem(cid, item_gain_1, item_qnt_1)
            doPlayerAddItem(cid, item_gain_2, item_qnt_2)
            doPlayerAddItem(cid, item_gain_3, item_qnt_3)
            talkState[talkUser] = 0
        else
            npcHandler:say('You still need to retrieve the following items: '..getItemNameById(item_need_1)..', '..getItemNameById(item_need_2)..', and '..getItemNameById(item_need_3)..'.', cid)
            talkState[talkUser] = 0
        end
    end
end
View attachment 74671

I'm not sure how the NPCs in Canary work, but if you can spawn them in-game but their outfits don't show up, it could be because the outfit you're trying to use (294) might not be valid. It might be worth trying to change the looktype to see if that solves the issue. Have you given that a shot yet?
 
Back
Top