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

NPC Mission

Works great! I might be a lil nooby but I have a lil problem with a conversation between an NPC and a player, while trying to make a mission NPC.

Code:
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(npcHandler.focus ~= cid) then
         return false
     end

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     if msgcontains(msg, "mission") then
         npcHandler:say('Actually, I could have a mission for you, but it is not an easy task! Are you still interested?')
         talkState[talkUser] = 1
         end
         if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         npcHandler:say('Alright then. The remainings of my old sword are still lost somewhere in the old dungeons of northern Edron. Could you find it and bring it back to me?')
         talkState[talkUser] = 0
         end
         if msgcontains(msg, "yes") and talkState[talkUser] == 2 then
         npcHandler:say('Great! Report back to me when you have found it!')
         talkState[talkUser] = 1
     end
     return true
end

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

I can't get him to accept the second 'Yes'. It's quite useless anyway, but I'd like to have it there :)

Ingame:

vihekn.jpg


I'd love to have that 'Great! Report back to me when you have found it!' there before the mission goes on!

This NPC just doesn't want to answer anything after the first 'yes' :(
 
Set talkState to 2 after the first yes.
You also don't have to repeat the msgcontains line for yes, you can just add an if statement for talkState 1 under it instead of next to it and under that an elseif statement for talkState 2.
Code:
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(npcHandler.focus ~= cid) then
         return false
     end

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     if msgcontains(msg, "mission") then
         npcHandler:say('Actually, I could have a mission for you, but it is not an easy task! Are you still interested?')
         talkState[talkUser] = 1
     elseif msgcontains(msg, "yes") then
         if talkState[talkUser] == 1 then
             npcHandler:say('Alright then. The remainings of my old sword are still lost somewhere in the old dungeons of northern Edron. Could you find it and bring it back to me?')
             talkState[talkUser] = 2
         elseif talkState[talkUser] == 2 then
             npcHandler:say('Great! Report back to me when you have found it!')
             talkState[talkUser] = 0
         end
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Monster mission


i have error in console ;/ i say hi / mission and still nothing :

data/npc/scripts/task.lua:14: attempt to call method 'isFocused' (a nil value)
stack traceback:
data/npc/scripts/task.lua:14: in function 'callback'
data/npc/scripts/lib/npcsystem/npchandler.lua:299: in function 'onCreatureSay'
data/npc/scripts/task.lua:8: in function
 
Look in 1 of the npc lua files from your server how it's called there. It could be like the one Laur1 posted.
The example npcs I posted are 8.54+ for npcs with npcchannel.
 
Laur1 npc work in my server but npc is for mission i must now change this npc on Task ;) can succeed ;)

i can't change monster npc ;/ very much errors xd
 
Just change
Code:
if not npcHandler:isFocused(cid) then
     return false
end

To
Code:
if npcHandler.focus ~= cid then
     return false
end


And
Code:
selfSay("Your text.", cid)

To
Code:
npcHandler:say("Your text.")
 
13:51 Test: hi
13:51 Task: Welcome, Test! I have been expecting you.
13:51 Test: mission
13:51 Task: I have a mission for you to kill 5 dragons and 3 dragon lords, do you accept?
13:51 Test: yes
13:51 Task: Good, come back when you killed them.

next i kill 5 dragons and 3 dragon lords back to npc and :

13:53 Test: hi
13:53 Task: Welcome, Test! I have been expecting you.
13:53 Test: mission
13:53 Task: Did you kill 5 dragons and 3 dragon lords?
13:53 Test: yes
13:53 Task: You didn't kill them all.
 
Does your server have creaturescripts and did you added the onKill script?
If you get errors, post them.
 
how i can add onKill script ? and where i must paste this script ? ( creaturescirpts/dragons.lua ) ??
Code:
local config = {
['dragon'] = {amount = 5, storage = 19000, startstorage = 5002, startvalue = 1},
['dragon lord'] = {amount = 3, storage = 19001, startstorage = 5002, startvalue = 1}
}
function onKill(cid, target)
local monster = config[getCreatureName(target):lower()]
if isPlayer(target) or not monster or isSummon(target) then
return true
end

if getPlayerStorageValue(cid, monster.storage) >= -1 and (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
end
if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
end
return true
end
 
i have this script in data/creaturescripts/scripts and not work ;/ i kill monster back on npc and no have reward ;d Task: You didn't kill them all.
 
Can you post how you added it? When you kill the monsters, you should get textmessages.
If you get errors, post them.
 
now i have error in console :
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/dragons.lua:onKill

data/creaturescripts/scripts/dragons.lua:7: attempt to call global 'isSummon' (a nil value)
stack traceback:
data/creaturescripts/scripts/dragons.lua:7: in function
 
Code:
function isSummon(cid)
     return (isCreature(cid) == TRUE and (getCreatureMaster(cid) ~= cid)) and TRUE or FALSE
end

Add this to your lib file (global.lua or function.lua or anything like that).
 
where i must paste this lines ? it seems to me that something was wrong changed :D

: Loading CreatureEvents ...Warning: [Event::loadScript] Can not load script. data/creaturescripts/scripts/dragons.lua
data/creaturescripts/scripts/dragons.lua:18: '' expected near 'end'
 
Post the script.

You have to add that function where the other Lua made functions are added in your server.
Usually this is a Lua file called global.lua or function.lua in a lib folder.
 
Code:
local config = {
     ['dragon'] = {amount = 5, storage = 19000, startstorage = 5002, startvalue = 1},
     ['dragon lord'] = {amount = 3, storage = 19001, startstorage = 5002, startvalue = 1}
}
function isSummon(cid)
     return (isCreature(cid) == TRUE and (getCreatureMaster(cid) ~= cid)) and TRUE or FALSE
end

     if getPlayerStorageValue(cid, monster.storage) >= -1 and (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
         setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
     end
     if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
         setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
     end
     return true
end
 
You are not supposed to delete something from the onKill script. Function onKill executes the script when you kill something.
Add the function isSummon in your function lib file.
 
Last edited:
Back
Top