Thaian Citizen
Hexenjäger
I have made a task system, but can't place/load the npc because theres still a misstake in the npc's.lua
data/npc/scripts/tasknpc_rook.lua
and the creature script that goes along:
data/creaturescripts/scripts/task_kill.lua
Note: This was my first attempt for the task stuff and if I remember correctly there's an error when I tried to summon the npc, the console said something like: Expected string but got nil @ some function #of keywordhandler...
If anyone is quick to find and fix the misstake this system should work...
data/npc/scripts/tasknpc_rook.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- actual task monster id is stored in 46999, kill count is stored in 47000
-- if task is done monster storage value+1000 is 1 if the task has been rewarded it is 2
local monsters = {
["rat"] = 47001,
["troll"] = 47002,
}
local reqKills = {
["rat"] = 3,
["troll"] = 5,
}
-- reward array
-- reward monster = { exp, gold, itemsrewardedamount -> item[0]id, item[0]amount, item[0]stackable ... }
local reward = {
["rat"] = { 4000, 1000, 1, 2400, 1, 0 },
["troll"] = { 2000, 3000, 1, 2147, 30, 1 }
}
-- 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
local talkState = {}
local Mob = {}
npcHandler:setMessage(MESSAGE_FAREWELL, "Come back in one piece!")
function onPlayerGreet(cid)
npcHandler:setMessage(MESSAGE_GREET, "Hey |PLAYERNAME|. What do you need?")
return true
end
npcHandler:setCallback(CALLBACK_GREET, onPlayerGreet)
npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, "Hey, |PLAYERNAME|. Wait some, okay?")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Yeah, run... Go ahead and run away like the chicken that you are!")
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, "job") then
npcHandler:say("I'm sitting on welfare money, bitch.")
talkState[talkUser] = 0
return true
end
if msgcontains(msg, "name") then
npcHandler:say("How about I ask for your mother's name, faggot.")
talkState[talkUser] = 0
return true
end
-- task stuff
if msgcontains(msg, "list") then
npcHandler:say("Following monster populations must be decreased: rats, trolls.")
talkState[talkUser] = 0
return true
end
if msgcontains(msg, "task") then
npcHandler:say("Which task would you like to do?")
talkState[talkUser] = 1
return true
end
if msgcontains(msg, "reward") then
npcHandler:say("Did you finish your task?")
talkState[talkUser] = 3
return true
end
-- we asked to do a task, now need to tell the monster name
if (talkState == 1) then
local task = string.lower(msg)
local monster = monsters[task]
if (monster) then
npcHandler:say("Would you like to hunt down " .. reqKills[monster] .. " " .. task .. "s?")
talkState[talkUser] = 2
Mob[talkUser] = monster
end
else
npcHandler:say("There is no " .. task .. "s task available. You can ask me for a list of monsters that need to be slain.")
talkState[talkUser] = 0
Mob[talkUser] = 0
end
return true
end
-- been asked if you really want to hunt that monster
if msgcontains(msg, "yes") and (talkState == 2) then
if (getPlayerStorageValue(cid, Mob) <= 0) then
if (getPlayerStorageValue(cid, 46999) <= 47000) then
setPlayerStorageValue(cid, 46999, Mob)
setPlayerStorageValue(cid, 47000, 0)
setPlayerStorageValue(cid, Mob, 0)
npcHandler:say("Good luck on your hunt!")
end
if (getPlayerStorageValue(cid, Mob) == 1) then
npcHandler:say("If you want your reward for your completed task just ask me for it.")
end
if (getPlayerStorageValue(cid, Mob) == 2) then
npcHandler:say("You already did that task and got rewarded for it.")
end
else
npcHandler:say("TASK SYSTEM ERROR: Please contact a GM with a detailed explanation!")
end
talkState[talkUser] = 0
Mob[talkUser] = 0
return true
end
if msgcontains(msg, "no") and (talkState == 2) then
npcHandler:say("Forget about it then...")
talkState[talkUser] = 0
Mob[talkUser] = 0
return true
end
-- asked for a reward, been asked if we finished our task
if msgcontains(msg, "yes") and (talkState == 2) then
local completed = getPlayerStorageValue(cid, 46999)
doPlayerAddExp(cid, reward[completed][0])
doPlayerAddMoney(cid, reward[completed][1])
if (reward[completed][2] == 1) then
if (reward[completed][5] == 0) then
doPlayerAddItem(cid, reward[completed][3], 1)
else
doPlayerAddItem(cid, reward[completed][3], reward[completed][4])
end
npcHandler:say("Okay, let me give you a reward for your efforts...")
setPlayerStorageValue(cid, completed, 2)
setPlayerStorageValue(cid, 46999, 0)
setPlayerStorageValue(cid, 47000, 0)
talkState[talkUser] = 0
return true
end
if msgcontains(msg, "no") and (talkState == 2) then
npcHandler:say("Go on and finish your task then...")
talkState[talkUser] = 0
return true
end
-- task stuff end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
local focus = FocusModule:new()
npcHandler:addModule(focus)
and the creature script that goes along:
data/creaturescripts/scripts/task_kill.lua
Code:
-- actual task monster id is stored in 46999, kill count is stored in 47000
-- if task is done monster storage value+1000 is 1 if the task has been rewarded it is 2
local monsters = {
["cave rat"] = 47001,
["troll"] = 47002,
["orc"] = 47003,
["rotworm"] = 47004,
}
local reqKills = {
["cave rat"] = 3,
["troll"] = 30,
["orc"] = 30,
["rotworm"] = 150,
}
function onKill(cid, target)
if(isPlayer(target) ~= TRUE) then
local name = getCreatureName(target)
local monster = monsters[string.lower(name)]
local actual = getPlayerStorageValue(cid, 46999)
if(actual and monster) then
local kills = getPlayerStorageValue(cid, 47000)
if(kills == -1) then
kills = 1
end
if(kills >= 1) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You've killed " .. killedMonsters .. " out of " .. reqKills[string.lower(name)] .. " " .. name .. "s.")
setPlayerStorageValue(cid, 47000, kills + 1)
if(kills > reqKills[string.lower(name)]) then
setPlayerStorageValue(cid, monster+1000, 1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations! You have killed enough " .. name .. "s.")
end
end
end
end
return true
end
Note: This was my first attempt for the task stuff and if I remember correctly there's an error when I tried to summon the npc, the console said something like: Expected string but got nil @ some function #of keywordhandler...
If anyone is quick to find and fix the misstake this system should work...