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

CreatureEvent [TASK] Kill "x" monsters and get reward.

ryandometal

Guitarist!
Joined
Dec 18, 2008
Messages
143
Reaction score
0
Location
Brazil
Hello, I know there are several different versions out there, I even did one a while ago, but would like to share one I use and tastes great!

This script is more one of tasks, that is, you talk to the NPC and receive a mission to kill "x" monsters, when completed this mission, you receive your prize. Simple, no? : P

Come on!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
INFO:
Version tested: TFS 0.2x+ (mystic spirit)

First of all, we will make the NPC, and use Behemoth tasks for example.
Open data/npc/scripts/ and create a file named behemoth_task.lua.
Put this script in.

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 quest = 43313 <!-- Storage ID used in quest-->
if msgcontains(msg, 'task') or msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
	selfSay("Heh... I you want to do a task? Sure... can you kill 400 behemoths for me?", cid) 
	talkState[talkUser] = 2
	
    elseif(getPlayerStorageValue(cid, quest) == 2) or talkState[talkUser] == 4 then
	selfSay("Come back here when you finish your mission.", cid)

    elseif(getPlayerStorageValue(cid, quest) == 4) or (getPlayerStorageValue(cid, 667) == 1) or talkState[talkUser] == 5 then
	selfSay("Hm... you already helped me a lot, do not need more of you here, thanks! You expect more missions!", cid)
	
    elseif(getPlayerStorageValue(cid, quest) == 3) then
	selfSay("Hey, great. You've done well! As a small reward I give you this steel boots!", cid)
    doPlayerAddExp(cid, 500000) <--! Exp that you earn when you complete task -->
	doSendAnimatedText(getPlayerPosition(cid),"500000", TEXTCOLOR_WHITE_EXP)
    doPlayerAddItem(cid,2645,1) <!-- ID of reward-->
    setPlayerStorageValue(cid, quest, 0) <!-- If set storage to 0, you can make this task more than one time, but if you want to do this task only 1 time, set it to 4-->
    setPlayerStorageValue(cid, 667, 1) <!-- Storage ID used in quest-->
    talkState[talkUser] = 5		

    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
	selfSay("Thank\'s!, come back for a reward when you kill 400 behemoths {okay}?", cid)
	talkState[talkUser]= 3
	elseif msgcontains(msg, 'ok') or msgcontains(msg, 'okay') and talkState[talkUser] == 3 then
	selfSay("Okay, good hunt!", cid)
    setPlayerStorageValue(cid, quest, 2)
	talkState[talkUser]= 0
end
end

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

Now, open data/creaturescripts/scripts/ and create a folder named "task", and create a file "behemoth_task.lua.

Put it:
Lua:
 function onDeath(cid, corpse, killer)
   local monster = getCreatureName(cid)
   local behemoth = getPlayerStorageValue(killer, 5572)
     if (monster == 'behemoth') and getPlayerStorageValue(killer, 43313) == 2 then

doPlayerSendTextMessage(killer,MESSAGE_STATUS_CONSOLE_BLUE,'You need to kill '.. 400-behemoth..' behemoth.')
setPlayerStorageValue(killer,5572, behemoth+1)

         if behemoth == 400 then <!-- Change 400 to value of monsters that you want to kill in the task -->
           doPlayerSendTextMessage(killer,MESSAGE_STATUS_CONSOLE_BLUE,'You have killed enought behemoths. Come back and talk to NPC for a possible reward.')
           setPlayerStorageValue(killer,5572,-1) 
           setPlayerStorageValue(killer,43313,0)          
         else
         end
     end
 end

Now, open creaturescripts.xml and add this line:
Lua:
<event type="death" name="behemoth" script="task/behemoth.lua"/>

Open your monster folder, search for behemoth, and add this line under "flags":
Lua:
<script>
<event name="behemoth"/>
</script>

It is! You can change the prizes and the EXP that you won in the tasks.
If you get errors, post here to I fix.

Thank you, and rep++ if you use! :D
 
Last edited:
okay im getting this:

[03/03/2010 16:53:30] [Error - CreatureScript Interface]
[03/03/2010 16:53:30] data/creaturescripts/scripts/task/troll.lua:eek:nDeath
[03/03/2010 16:53:30] Description:
[03/03/2010 16:53:30] (luaGetCreatureStorage) Creature not found

What can I do?

I'm using it, this way

PD: Using The Forgotten Server, version 0.3.6 (Crying Damson)

Lua:
function onDeath(cid, corpse, killer)
   local monster = getCreatureName(cid)
   local trolls = getPlayerStorageValue(killer, 5572)
     if (monster == 'troll') and getPlayerStorageValue(killer, 43313) == 2 then

doPlayerSendTextMessage(killer,MESSAGE_STATUS_CONSOLE_BLUE,'You need to kill '.. 10-trolls..' trolls.')
setPlayerStorageValue(killer,5572, troll+1)

         if troll == 10 then
           doPlayerSendTextMessage(killer,MESSAGE_STATUS_CONSOLE_BLUE,'You have killed enought trolls. Come back and talk to NPC for a possible reward.')
           setPlayerStorageValue(killer,5572,-1) 
           setPlayerStorageValue(killer,43313,0)          
         else
         end
     end
 end
 
Lua:
function onDeath(cid, corpse, deathList)
    local killer = deathList[1]
    local monster = getCreatureName(cid)
    local trolls = getPlayerStorageValue(killer, 5572)
    if (monster == 'troll') and getPlayerStorageValue(killer, 43313) == 2 then
        doPlayerSendTextMessage(killer,MESSAGE_STATUS_CONSOLE_BLUE,'You need to kill '.. 10-trolls..' trolls.')
        setPlayerStorageValue(killer,5572, troll+1)
        if getPlayerStorageValue(killer, 5572) == 10 then
            doPlayerSendTextMessage(killer,MESSAGE_STATUS_CONSOLE_BLUE,'You have killed enought trolls. Come back and talk to NPC for a possible reward.')
            setPlayerStorageValue(killer,5572,-1)
            setPlayerStorageValue(killer,43313,0)        
        end
    end
    return true
end
 
Last edited:
Watchout! @up wrote "EMD" in the 3 line (bottom to top), change it to "END"
 
im having trouble with npc and storage values...

somtimes it just close game client with criticla error.

When I say mission it dont seem to change propperly the storage values to 2, so when I say mission after completing 10 monters it only says the begin of the quest again.

I'm trying to fix, but couldnt make it work properly till now.
 
im having trouble with npc and storage values...

somtimes it just close game client with criticla error.

When I say mission it dont seem to change propperly the storage values to 2, so when I say mission after completing 10 monters it only says the begin of the quest again.

I'm trying to fix, but couldnt make it work properly till now.

But the counter works fine?
When you complete 10 monsters, the NPC say the begin, but you need only to say "yes", and you got the prizes.

If you use crying damson, change "setPlayerStorageValue" to "doPlayerSetStorageValue".
 
PD: Nahruto script seems to work cuz' it dont display errors, but coulndt test it at all, cuz' I'm having trouble with npc.


Changed it how you said, but when i say 'yes' it gives critacal error and close window. When I relog it still dont work.

counter dont work, it never appear to me say "ok" or "okay" to really begin the quest. Only display this:

"Come back here when you finish your mission."

If I say bye and come back it say about the mission, if i type 'mission' it begins again like if I was with storage value set to 0 to this quest.

So I assume that I dont know what's happening and that I really can't understand how it is working.

=(
 
PD: Nahruto script seems to work cuz' it dont display errors, but coulndt test it at all, cuz' I'm having trouble with npc.


Changed it how you said, but when i say 'yes' it gives critacal error and close window. When I relog it still dont work.

counter dont work, it never appear to me say "ok" or "okay" to really begin the quest. Only display this:

"Come back here when you finish your mission."

If I say bye and come back it say about the mission, if i type 'mission' it begins again like if I was with storage value set to 0 to this quest.

So I assume that I dont know what's happening and that I really can't understand how it is working.

=(

NPC

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 quest = 5555
    
    if msgcontains(msg, 'task') or msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
        if getPlayerStorageValue(cid, quest) == -1) then
            selfSay("Heh... I you want to do a task? Sure... can you kill 10 trolls for me?", cid)
            talkState[talkUser] = 2
        else
            selfSay("Hm... you already helped me a lot, do not need more of you here, thanks! You expect more missions!", cid)
            talkState[talkUser] = 0
        end
    elseif (talkState[talkUser] == 2  and msgcontains(msg, 'yes')) then
        selfSay("Thank\'s!, come back for a reward when you kill 10 trolls {okay}?", cid)
        talkState[talkUser]= 3
    elseif msgcontains(msg, 'ok') or msgcontains(msg, 'okay') and talkState[talkUser] == 3 then
        selfSay("Okay, good hunt!", cid)
        setPlayerStorageValue(cid, quest, 0)
        talkState[talkUser]= 0
    elseif (getPlayerStorageValue(cid, quest) == 10) and (msgcontains(msg, 'ready') or msgcontains(msg, 'completed')) then
        selfSay("Hey, great. You've done well! As a small reward I give you this steel boots!", cid)
        doPlayerAddExp(cid, 500000)
        doSendAnimatedText(getPlayerPosition(cid), "500000", TEXTCOLOR_WHITE_EXP)
        doPlayerAddItem(cid, 2645, 1)
        setPlayerStorageValue(cid, quest, 11) -- Finished
    elseif (getPlayerStorageValue(cid, quest) == 11) then
        selfSay("Hm... you already helped me a lot, do not need more of you here, thanks! You expect more missions!", cid)
        talkState[talkUser]= 0
     end
end


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

Event

Lua:
local storage = 5555

function onDeath(cid, corpse, deathList)
    local killer = deathList[1]
    local monster = getCreatureName(cid)
    local trolls = getPlayerStorageValue(killer, storage)
    if ((monster:lower() == 'troll') and not isInArray({-1, 10}, trolls)) then
        doPlayerSendTextMessage(killer, MESSAGE_STATUS_CONSOLE_BLUE, 'You need to kill '.. 10 - trolls ..' trolls.')
        setPlayerStorageValue(killer, storage, trolls + 1)
    elseif trolls == 10 then
        doPlayerSendTextMessage(killer, MESSAGE_STATUS_CONSOLE_BLUE, 'You have killed enought trolls. Come back and talk to NPC for a possible reward.') 
    end
    return true
end
 
Last edited:
[03/03/2010 19:15:39] [Error - LuaScriptInterface::loadFile] data/npc/scripts/troll task.lua:20: 'then' expected near ')'
[03/03/2010 19:15:39] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/troll task.lua
[03/03/2010 19:15:39] data/npc/scripts/troll task.lua:20: 'then' expected near ')'


Still problem with NPC script.
Any opinion?
 
Last edited:
Thank you very much!!!

Working properly now!!!

=DDD

Could someone explain me why it was crashing the client?
 
Thank you very much!!!

Working properly now!!!

=DDD

Could someone explain me why it was crashing the client?

selfSay("Thank\'s!, come back for a reward when you kill 400 behemoths {okay}?", 100, cid)

100 = unknown msg type
 
@Vikarious
Sorry for don't answer, I'm too busy now but i think you have fixed the errors, right?

@Nahruto
Thank you for help him and show the error in npc selfsay, i fixed it >.<
 
Not tested, better :d?
Lua:
function onKill(cid, target, lastHit)
local needs = {
	["demon"] = {killStorage = 10002, killsNeed = 100, reward = 2160, rewardCount = 10, addExp = "yes", gainExp = "10000000"},
	["dragon lord"] = {killStorage = 10003, killsNeed = 100, reward = 2160, rewardCount = 10, addExp = "no", gainExp = "1000000"},
	["dragon"] = {killStorage = 10004, killsNeed = 2000, reward = 2160, rewardCount = 10, addExp = "yes", gainExp = "1000000"}
}	
	
	for name, v in pairs(needs) do
		if getCreatureName(target):lower() == name:lower() then
			setPlayerStorageValue(cid, v.killStorage, getPlayerStorageValue(cid, v.killStorage) < 1 and 1 or getPlayerStorageValue(cid, v.killStorage) + 1)				
			if getPlayerStorageValue(cid, v.killStorage) == v.killsNeed then
				doPlayerAddItem(cid, v.reward, v.rewardCount)
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, v.addExp == "yes" and "You have just received "..v.gainExp.." experience and "..v.rewardCount.." "..getItemNameById(v.reward).."." or "You have just received "..v.rewardCount.." "..getItemNameById(v.reward)..".")
				if v.addExp == "yes" then
					doPlayerAddExperience(cid, v.gainExp)
				end
			end
		end
		break
	end
	return true	
end
 
Not tested, better :d?
Lua:
function onKill(cid, target, lastHit)
local needs = {
	["demon"] = {killStorage = 10002, killsNeed = 100, reward = 2160, rewardCount = 10, addExp = "yes", gainExp = "10000000"},
	["dragon lord"] = {killStorage = 10003, killsNeed = 100, reward = 2160, rewardCount = 10, addExp = "no", gainExp = "1000000"},
	["dragon"] = {killStorage = 10004, killsNeed = 2000, reward = 2160, rewardCount = 10, addExp = "yes", gainExp = "1000000"}
}	
	
	for name, v in pairs(needs) do
		if getCreatureName(target):lower() == name:lower() then
			setPlayerStorageValue(cid, v.killStorage, getPlayerStorageValue(cid, v.killStorage) < 1 and 1 or getPlayerStorageValue(cid, v.killStorage) + 1)				
			if getPlayerStorageValue(cid, v.killStorage) == v.killsNeed then
				doPlayerAddItem(cid, v.reward, v.rewardCount)
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, v.addExp == "yes" and "You have just received "..v.gainExp.." experience and "..v.rewardCount.." "..getItemNameById(v.reward).."." or "You have just received "..v.rewardCount.." "..getItemNameById(v.reward)..".")
				if v.addExp == "yes" then
					doPlayerAddExperience(cid, v.gainExp)
				end
			end
		end
		break
	end
	return true	
end

I dont understand your script, can you explain it please?

And if you can I need 1 NPC that you say hi, task, yes. and start the task and when you end the task you say end or other word and then give you exp, reward and 1 storage value (configurable), and then you cant do the task other time, so dont put more msg ingame You need to kill - 1 X monster.

Thanks =)
 
I dont understand your script, can you explain it please?

And if you can I need 1 NPC that you say hi, task, yes. and start the task and when you end the task you say end or other word and then give you exp, reward and 1 storage value (configurable), and then you cant do the task other time, so dont put more msg ingame You need to kill - 1 X monster.

Thanks =)

Nop, this gives you reward automatically when you reach the kills :p
 
Heres a fully working one, tested with tfs 0.3.5 and works fine. (FIXED)
data/npc/scripts
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 t = 
		{
			["Demon"] = {s = 3000, r = 2173},
			["Juggernaut"] = {s = 3001, r = 2173},
			["Hellfire Fighter"] = {s = 3002, r = 2173},
			["Fire Overlord"] = {s = 3003, r = 2173},
			["Sea Serpent"] = {s = 3004, r = 2173},
			["Wyrm"] = {s = 3005, r = 2173},
			["Zombie"] = {s = 3006, r = 2173},
			["Banshee"] = {s = 3007, r = 2173},
			["Medusa"] = {s = 3008, r = 2173},
			["Blazing Fire Elemental"] = {s = 3009, r = 2173},
			["Giant Spider"] = {s = 3010, r = 2173},
			["Frost Dragon"] = {s = 3011, r = 2173},
			["Massive Energy Elemental"] = {s = 3012, r = 2173},
			["Massive Water Elemental"] = {s = 3013, r = 2173}
		}
	for name, v in pairs(t) do
		if msgcontains(msg, 'tasks') or msgcontains(msg, 'task') or msgcontains(msg, 'quest') then
			npcHandler:say('Hey, You look like your so fuckin bored, and I have a good job for you. Do you want to do your first task?', cid)
			talkState[talkUser] = 2
			break
		elseif msgcontains(msg, 'yes') or msgcontains(msg, 'yup') or msgcontains(msg, 'yeah') and talkState[talkUser] == 2 then
			npcHandler:say('Ok, heres your tasks, go and kill 100 of Demons, Juggernaut, Hellfire Fighter, Fire Overlord, Sea Serpents, Wyrms, Zombies, Banshees, Medusa, Blazing Fire Elemental, Giant Spider, Frost Dragon, Massive Energy Elemental, Massive Water Elemental, and come back to take your reward! After your done just come and fucking say reward.', cid)
			talkState[talkUser] = 3
			break
		elseif msgcontains(msg, 'reward') and getPlayerStorageValue(cid, v.s) >= 100 and talkState[talkUser] == 3 then
			npcHandler:say('Congratz, Heres your reward!', cid)
			doPlayerAddItem(cid, v.r, 1)
			break
		else
			npcHandler:say('Ok then.', cid)
			talkState[talkUser] = 0
			break
		end
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Task" script="tasks npc.lua" walkinterval="0" floorchange="0">
	<health now="150" max="150"/>
	<look type="287" corpse="2212"/>
    <parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|. Come here and do my tasks."/>
    </parameters>
</npc>
data/creaturescripts/scripts/tasks.lua
Lua:
function onKill(cid, target, lastHit)
local t = {
	["Demon"] = {s = 3000, msg = "You have killed a Demon"},
	["Juggernaut"] = {s = 3001, msg = "You have killed a Juggernaut"},
	["Hellfire Fighter"] = {s = 3002, msg = "You have killed a Hellfire Fighter."},
	["Fire Overlord"] = {s = 3003, msg = "You have killed a Fire Overlord."},
	["Sea Serpent"] = {s = 3004, msg = "You have killed a Sea Serpent."},
	["Wyrm"] = {s = 3005, msg = "You have killed a wyrm."},
	["Zombie"] = {s = 3006, msg = "You have killed a wyrm."},
	["Banshee"] = {s = 3007, msg = "You have killed a banshee."},
	["Medusa"] = {s = 3008, msg = "You have killed a medusa."},
	["Blazing Fire Elemental"] = {s = 3009, msg = "You have killed a Blazing Fire Elemental."},
	["Giant Spider"] = {s = 3010, msg = "You have killed a Giant Spider."},
	["Frost Dragon"] = {s = 3011, msg = "You have killed a Frost Dragon."},
	["Massive Energy Elemental"] = {s = 3012, msg = "You have killed a Massive Energy Elemental."},
	["Massive Water Elemental"] = {s = 3013, msg = "You have killed a Massive Water Elemental."}
}
local name = getCreatureName(target)
local v = t[name]
	if v then
		if getCreatureName(target) then
			setPlayerStorageValue(cid, v.s, getPlayerStorageValue(cid, v.s)+1)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed a " .. getCreatureName(target) .. ".")
			if getPlayerStorageValue(cid, v.s) >= 100 then
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You have killed the required number.")
			end
		end
	end
	return true
end

login.lua :
Code:
registerCreatureEvent(cid, "tasks")

data/creaturescripts/creaturescripts.xml
Code:
<event type="kill" name="tasks" event="script" value="tasks.lua"/>
 
Last edited:

Similar threads

Back
Top