I made a NPC and onKill event to emulate some of World of Warcraft's quest. I understand that WoW isn't the only game or the first to do this, but it's one of the well-known ones I also added some examples for you to know how this thing works. It should be fairly easy to understand just by reading the comments in the script, but if some still have trouble understanding I'll probably try to explain a little more.
DONT FORGET TO COMMENT!
global.lua?
quest_giver.lua
onlogin.lua
onkill.lua
I haven't tested but if there's anything wrong just tell me and I'll try to fix.
DONT FORGET TO COMMENT!
global.lua?
Code:
wow_like_quests = {
--[[
[LEVEL_REQUIRED] = {
{
monster = "CREATURENAME",
amount = AMOUNT_TO_KILL,
storage = STORAGE_VALUE,
on_turn_in = function(cid, parameters) -- optional, but would be pointless if you dont add items to player, or atleast experience
doPlayerAddExp(cid, 10000)
doPlayerAddItem(cid, 2160, 1)
end,
on_accept = function(cid, parameters) -- optional
doPlayerSendTextMessage(cid, 22, "You must kill: " .. parameters.amount .. " " .. parameters.monster .. ".")
end,
on_kill = funcction(cid, parameters) -- optional
doPlayerSendTextMessage(cid, 22, "You must kill: " .. parameters.amount .. " " .. parameters.monster .. ".")
end,
on_finish = function(cid, parameters) -- optional
doPlayerSendTextMessage(cid, 22, "Congratulations, you finished the quest! You have killed all required " .. parameters.monster .. ".")
end
}
}
]]
[1] = {
{
monster = "Rat",
amount = 5,
storage = 9474,
on_turn_in = function(cid, parameters)
doPlayerAddExp(cid, 1000)
end
},
{
monster = "Sheep",
amount = 10,
storage = 9476,
on_turn_in = function(cid, parameters)
doPlayerAddExp(cid, 1000)
end
}
},
[2] = {
{
monster = "Cave Rat",
amount = 5,
storage = 9477,
on_turn_in = function(cid, parameters)
doPlayerAddExp(cid, 1000)
end
}
}
}
wow_like_quests_storages = {}
for k,v in pairs(wow_like_quests) do
for i,v in ipairs(v) do
wow_like_quests_storages[v.storage] = v
end
end
quest_giver.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- OTServ event handling functions start
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
-- OTServ event handling functions end
function pick_quest(cid, message, keywords, parameters, node)
if(not npcHandler:isFocused(cid)) then
return false
end
local level = getPlayerLevel(cid)
for k, v in pairs(wow_like_quests) do
local required = tonumber(k)
if(level >= required) then
for i, v in ipairs(v) do
local storage = getPlayerStorageValue(cid, v.storage)
if(storage == -1) then
npcHandler:say("I could use you in slaying ".. v.amount .. " ".. string.lower(v.monster) .. ". Would you like to accept the quest?", cid)
parameters.quest = v
return true
elseif(storage == v.amount) then
setPlayerStorageValue(cid, v.storage, -2)
npcHandler:say("Woah! I didn't except you to be done so fast. Maybe I have more quests for you.", cid)
if(v.on_turn_in) then
v.on_turn_in(cid, v)
end
npcHandler:resetNpc()
return true
end
end
end
end
npcHandler:say("I have no quests to offer you at the moment. Come back when your stronger", cid)
npcHandler:resetNpc()
return true
end
function accept_quest(cid, message, keywords, parameters, node)
if(not npcHandler:isFocused(cid)) then
return false
end
local quest = node:getParent():getParameters().quest
local storage = quest.storage
setPlayerStorageValue(cid, storage, 0)
npcHandler:say("I'm expecting to hear from you again. Don't dissapoint me.", cid)
if(quest.on_accept) then quest.on_accept(cid, quest) end
npcHandler:resetNpc()
return true
end
-- Keyword "Quest" will pick lowest undone quest for you.
local questNode = keywordHandler:addKeyword({'quest'}, pick_quest, {})
questNode:addChildKeyword({'yes'}, accept_quest, {})
questNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too hard for you, eh?'})
npcHandler:addModule(FocusModule:new())
onlogin.lua
Code:
registerCreatureEvent(cid, "WOW_LIKE_QUESTS")
onkill.lua
Code:
function onKill(cid, target)
if(isPlayer(target) == FALSE) then
for k, v in pairs(wow_like_quests_storages) do
local storage = getPlayerStorageValue(k)
if(storage >= 0) then
if(storage < v.amount) then
setPlayerStorageValue(cid, k, storage+1)
if(v.on_kill) then
v.on_kill(cid, parameters)
end
end
if((storage+1) == v.amount) then
if(v.on_finish) then
v.on_finish(cid, parameters)
end
end
end
end
end
return TRUE
end
I haven't tested but if there's anything wrong just tell me and I'll try to fix.
Last edited: