whitevo
Feeling good, thats what I do.
Trying to make a NPC what gives tasks, but i lot of script examples in OTland are confusing me.
BTW, this is working script below if someone wants to try it out
picture for file locations
tasks.lua
login.lua
creaturescripts.xml
Task Master.xml
boar.xml
this tasks.lua is activated from NPC
BTW, this is working script below if someone wants to try it out
picture for file locations
tasks.lua
Code:
local tasks =
{
["deer"] = {storage = 10100, killsRequired = 20},
["wolf"] = {storage = 10101, killsRequired = 20},
["boar"] = {storage = 10102, killsRequired = 20},
["bear"] = {storage = 10103, killsRequired = 20}
}
function onKill(cid, target)
local monster = tasks[getCreatureName(target):lower()]
if isPlayer(target) or not monster or isSummon(target) then
return true
end
if (getPlayerStorageValue(cid, monster.storage)-1) < monster.killsRequired and getPlayerStorageValue(cid, monster.storage) >= 1 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.killsRequired..' '..getCreatureName(target)..'s killed.')
end
if (getPlayerStorageValue(cid, monster.storage)-1) == monster.killsRequired 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, 0)
end
return true
end
login.lua
Code:
function onLogin(cid)
--#other stuff--
player:registerEvent("PlayerDeath")
player:registerEvent("tasks")
return true
end
Code:
<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
<!-- This was here before -->
<event type="login" name="PlayerLogin" script="login.lua"/>
<event type="death" name="PlayerDeath" script="playerdeath.lua"/>
<event type="extendedopcode" name="ExtendedOpcode" script="extendedopcode.lua"/>
<event type="kill" name="tasks" script="tasks.lua"/>
</creaturescripts>
Task Master.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Task Master" script="tasks.lua" walkinterval="2000" speed="200" walkradius="4" floorchange="0" speechbubble="3">
<health max="100" now="100"/>
<look type="264" head="78" body="116" legs="95" feet="121" corpse="20339"/>
</npc>
boar.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Boar" nameDescription="a boar" race="blood" experience="60" speed="230" manacost="465">
<health now="3000" max="3000"/>
<look type="380" corpse="13308"/>
<targetchange interval="5000" chance="40"/>
<event name="tasks"/>
... i cut out all the other stuff about monsters.. no need extra information what doesn't help.
</monster>
this tasks.lua is activated from NPC
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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 tasks =
{
["deer"] = {minL = 1, maxL = 3, killsRequired = 20},
["wolf"] = {minL = 2, maxL = 4, killsRequired = 20},
["boar"] = {minL = 2, maxL = 5, killsRequired = 20},
["bear"] = {minL = 2, maxL = 5, killsRequired = 20}
}
npcHandler.messages[MESSAGE_GREET] = "Hello, |PLAYERNAME| do you want a new {task} or {report} a finished one?"
function creatureSayCallback(cid, type, msg)
if (not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
local L = getPlayerLevel(cid)
--NPC OFFERS THESE TASKS IF MATCHED REQUIREMENTS
if msgcontains(msg:lower(), 'task') then
if L >= tasks["deer"].minL and L <= tasks["deer"].maxL then
if getPlayerStorageValue(cid, 10100) < 1 then
selfSay ("Say {deer} for task ", cid)
end
end
if L >= tasks["wolf"].minL and L <= tasks["wolf"].maxL then
if getPlayerStorageValue(cid, 10101) < 1 then
selfSay ("Say {wolf} for task", cid)
end
end
if L >= tasks["boar"].minL and L <= tasks["boar"].maxL then
if getPlayerStorageValue(cid, 10102) < 1 then
selfSay ("Say {boar} for task", cid)
end
end
if L >= tasks["bear"].minL and L <= tasks["bear"].maxL then
if getPlayerStorageValue(cid, 10103) < 1 then
selfSay ("Say {bear} for task", cid)
end
else selfSay ("NO MOAR TASKS!!", cid)
end
elseif msgcontains(msg:lower(), 'check') then
selfSay (getPlayerStorageValue(cid, 10100), cid)
elseif msgcontains(msg:lower(), 'reset') then
setPlayerStorageValue(cid, 10100, -1)
-- PLAYER CAN TAKE TASK IF REQUIREMENTS MATCH
elseif msgcontains(msg, "deer") and L >= tasks["deer"].minL and L <= tasks["deer"].maxL and getPlayerStorageValue(cid, 10100) < 1 then
setPlayerStorageValue(cid, 10100, 1)
questAccepted = selfSay ("You accepted task to kill " .. tasks["deer"].killsRequired .. " deers", cid)
elseif msgcontains(msg, "wolf") and L >= tasks["wolf"].minL and L <= tasks["wolf"].maxL and getPlayerStorageValue(cid, 10101) < 1 then
setPlayerStorageValue(cid, 10101, 1)
selfSay ("You accepted task to kill " .. tasks["wolf"].killsRequired .. " wolves", cid)
elseif msgcontains(msg, "boar") and L >= tasks["boar"].minL and L <= tasks["boar"].maxL and getPlayerStorageValue(cid, 10102) < 1 then
setPlayerStorageValue(cid, 10102, 1)
selfSay ("You accepted task to kill " .. tasks["boar"].killsRequired .. " boars", cid)
elseif msgcontains(msg, "bear") and L >= tasks["bear"].minL and L <= tasks["bear"].maxL and getPlayerStorageValue(cid, 10103) < 1 then
setPlayerStorageValue(cid, 10103, 1)
selfSay ("You accepted task to kill " .. tasks["bear"].killsRequired .. " bears", cid)
-- IF TASK TAKEN IT GIVES FEEDBACK OR REWARD
elseif msgcontains(msg, "report") then
-- deer task
if getPlayerStorageValue(cid, 10100) == 0 then
-- give Skill experience (no idea how)
setPlayerStorageValue(cid, 10100, -1)
selfSay("you completed task", cid)
elseif getPlayerStorageValue(cid, 10100) > 0 then
selfSay("You have killed " .. getPlayerStorageValue(cid, 10100)-1 .. " out of " .. tasks["deer"].killsRequired .. " deers", cid)
end
-- wolf task
if getPlayerStorageValue(cid, 10101) == 0 then
-- give Skill experience (no idea how)
setPlayerStorageValue(cid, 10101, -1)
selfSay("you completed task", cid)
elseif getPlayerStorageValue(cid, 10101) > 0 then
selfSay("You have killed " .. getPlayerStorageValue(cid, 10101)-1 .. " out of " .. tasks["wolf"].killsRequired .. " wolves", cid)
end
-- boar task
if getPlayerStorageValue(cid, 10102) == 0 then
-- give Skill experience (no idea how)
setPlayerStorageValue(cid, 10102, -1)
selfSay("you completed task", cid)
elseif getPlayerStorageValue(cid, 10102) > 0 then
selfSay("You have killed " .. getPlayerStorageValue(cid, 10102)-1 .. " out of " .. tasks["boar"].killsRequired .. " boars", cid)
end
-- bear task
if getPlayerStorageValue(cid, 10103) == 0 then
-- give Skill experience (no idea how)
setPlayerStorageValue(cid, 10103, -1)
selfSay("you completed task", cid)
elseif getPlayerStorageValue(cid, 10103) > 0 then
selfSay("You have killed " .. getPlayerStorageValue(cid, 10103)-1 .. " out of " .. tasks["bear"].killsRequired .. " bears", cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Last edited: