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

Lua Quest, question

Zorenia

Hoster of Zorenia
Joined
Jan 21, 2009
Messages
598
Reaction score
64
Location
The Netherlands
Hello guys,

I've a question. Is it possible that monsters drop quest items ONLY when a player doing a quest.

Example:
I've got a fisherman quest, where players have to go to trolls, and kill them and loot fish baits.
but.. is it possible without making new monsters.. to drop the fishbaits by trolls ONLY when your doing the quest. so if you finished the quest it's not possible to loot fish baits by the player who's finished it.

Well thanks.
Hope anyone could help me out.
 
Add this event and register it onLogin to every player.
You need to fill in BAIT_ID and QUESTSTORAGE

Should work
LUA:
function addBait(pos, corpseid)
	local corpse = getTileItemById(pos, corpseid)
	if corpse.uid > 0 then
		doAddContainerItem(corpse.uid, BAIT_ID, 1)
	end
end

function onKill(cid, target, lastHit)
	if getCreatureName(target) == "Troll" and getPlayerStorageValue(cid, QUESTSTORAGE) == 1 then
		addEvent(addBait, 1, getThingPos(target), getMonsterInfo(getCreatureName(target)).lookCorpse)
	end
	return true
end
 
Add this event and register it onLogin to every player:
You need to fill in BAIT_ID and QUESTSTORAGE

LUA:
function addBait(pos, corpseid)
	local corpse = getTileItemById(pos, corpseid)
	if corpse.uid > 0 then
		doAddContainerItem(corpse.uid, BAIT_ID, 1)
	end
end

function onKill(cid, target, lastHit)
	if getCreatureName(target) == "Troll" and getPlayerStorageValue(cid, QUESTSTORAGE) == 1 then
		addEvent(addBait, 1, getThingPos(target), getMonsterInfo(getCreatureName(target)).lookCorpse)
	end
	return true
end

only one error there, you forgot to define QUESTSTORAGE's value ;)
 
Thank you for your replay so fast, ehm some questions. Sorry this part is new for me. I'm very random and skilled with otservers and scripting hehe but could you explain little bit better if you want (A) where to put in everything. witch files.

And does this script add the quest item into the monster?
 
Ye it adds the item to corpse of the troll.

You need to change this:
getPlayerStorageValue(cid, QUESTSTORAGE)
Replace QUESTSTORAGE with your storage you are using for the quest

and this:
doAddContainerItem(corpse.uid, BAIT_ID, 1)
Replace BAIT_ID with the itemid of the item you want the troll to drop
 
okaj thanks, but can I also fill in they only loot 5 pieces and than they can't loot them? because they can loot them for the holl server haha :P and the place where I have to fill in the storage is this the storage value that it allowed to loot these items from the monsters?

Like this?
----
LUA:
function addBait(pos, corpseid)
	local corpse = getTileItemById(pos, corpseid)
	if corpse.uid > 0 then
		doAddContainerItem(corpse.uid, 2160, 1)
	end
end
 
function onKill(cid, target, lastHit)
	if getCreatureName(target) == "Troll" and getPlayerStorageValue(cid, 350) == 1 then
		addEvent(addBait, 1, getThingPos(target), getMonsterInfo(getCreatureName(target)).lookCorpse)
	end
	return true
end
 
Ye the storage the player has when he may loot them. If you make that they only can loot 5 it might happen that they don't take every bait and they can't complete the quest.
LUA:
local config = {
	storage = {350, 351},
	id = 2160,
	name = "Troll",
	count = 5
}

function addBait(cid, pos, corpseid)
	local corpse = getTileItemById(pos, corpseid)
	if corpse.uid > 0 then
		doAddContainerItem(corpse.uid, config.id, 1)
		setPlayerStorageValue(cid, config.storage[2], math.max(1, getPlayerStorageValue(cid, config.storage[2])+1))
	end
end

function onKill(cid, target, lastHit)
	if getCreatureName(target) == config.name and getPlayerStorageValue(cid, config.storage[1]) == 1 and getPlayerStorageValue(cid, config.storage[1]) <= config.count then
		addEvent(addBait, 1, cid, getThingPos(target), getMonsterInfo(getCreatureName(target)).lookCorpse )
	end
	return true
end

With little config:
storage = {350, 351}, <-- First one is the storage needed to loot the item, second is the storage where is stored how many the player already looted
id = 2160, <-- Itemid of the item
name = "Troll", <-- monster name
count = 5 <-- the count how many the player may loot like you said 5
 
Great! Summ, thank you very much for your time!
---
Well sorry but now maybe a very stupit question haha! but how to import these exacly in the server?
:(

and does this script works, when a NPC set players storage level needed to loot the baits?
 
In creaturescripts.xml add:
XML:
<event type="kill" name="TrollBait" event="script" value="trollbait.lua"/>

Create trollbait.lua in creaturescripts/scripts and add the script.

Then goto login.lua also in creaturescripts/scripts and add the line:
LUA:
registerCreatureEvent(cid, "TrollBait")
Next to another registerCreatureEvent at the bottom
 
Isn't working I post everything so you could see it. maybe I doing something wrong.

npc script:
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
if(msgcontains(msg, 'favor')) then
selfSay('Good! See, I`ve been chasing a fish, a big one! It`s eluded me for some time now...Nearly had him once i did! Anyways, i need you to gather up eight pieces of bait for me. I heard the trolls to the south have been stealing bait from the local stores. Can you get me some?', cid)
setPlayerStorageValue(cid,300,1)
end
---------------------------------------------------------
if(msgcontains(msg, 'yes')) and getPlayerStorageValue(cid,401) > 0 then
selfSay('Okaj, good luck.', cid)
setPlayerStorageValue(cid,305,1)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'done') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,307) > 0) then
selfSay('You already finished this mission.', cid)
else
if(doPlayerRemoveItem(cid, 2160, 5) == TRUE) then
setPlayerStorageValue(cid,307,1)
doPlayerAddExperience(cid,1000)
selfSay('Thank you! You can started.. (you received 1000 points of experience)', cid)
else
selfSay('You must have more items', cid)
end
end
return true
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

creature.xml
LUA:
<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
	<event type="login" name="PlayerLogin" event="script" value="login.lua"/>

	<event type="joinchannel" name="GuildMotd" event="script" value="guildmotd.lua"/>
	<event type="receivemail" name="Mail" event="script" value="mail.lua"/>
	<event type="reportbug" name="SaveReportBug" script="reportbug.lua"/>
	<event type="advance" name="AdvanceSave" event="script" value="advancesave.lua"/>


	<event type="think" name="Idle" event="script" value="idle.lua"/>
	<event type="think" name="SkullCheck" event="script" value="skullcheck.lua"/>
	
	<event type="kill" name="TrollBait" event="script" value="trollbait.lua"/>
</creaturescripts>

troll bait
LUA:
local config = {
	storage = {305, 306},
	id = 2160,
	name = "Troll",
	count = 10
}
 
function addBait(cid, pos, corpseid)
	local corpse = getTileItemById(pos, corpseid)
	if corpse.uid > 0 then
		doAddContainerItem(corpse.uid, config.id, 1)
		setPlayerStorageValue(cid, config.storage[2], math.max(1, getPlayerStorageValue(cid, config.storage[2])+1))
	end
end
 
function onKill(cid, target, lastHit)
	if getCreatureName(target) == config.name and getPlayerStorageValue(cid, config.storage[1]) == 1 and getPlayerStorageValue(cid, config.storage[1]) <= config.count then
		addEvent(addBait, 1, cid, getThingPos(target), getMonsterInfo(getCreatureName(target)).lookCorpse )
	end
	return true
end

loggin.lua

LUA:
	registerCreatureEvent(cid, "ReportBug")
	registerCreatureEvent(cid, "AdvanceSave")
	registerCreatureEvent(cid, "TrollBait")
	return true
end
 
BTW: 1 freakin bump per day-.-

Small fix:
LUA:
local config = {
	storage = {305, 306},
	id = 2160,
	name = "Troll",
	count = 10
}
 
function addBait(cid, pos, corpseid)
	local corpse = getTileItemById(pos, corpseid)
	if corpse.uid > 0 then
		doAddContainerItem(corpse.uid, config.id, 1)
		setPlayerStorageValue(cid, config.storage[2], math.max(1, getPlayerStorageValue(cid, config.storage[2])+1))
	end
end
 
function onKill(cid, target, lastHit)
	if getCreatureName(target) == config.name and getPlayerStorageValue(cid, config.storage[1]) == 1 and getPlayerStorageValue(cid, config.storage[2]) <= config.count then
		addEvent(addBait, 1, cid, getThingPos(target), getMonsterInfo(getCreatureName(target)).lookCorpse )
	end
	return true
end

I don't really get the sense of that NPC, are you sure it works?
Try this NPC:
LUA:
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 talkState = {}
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	if(msgcontains(msg, 'favor')) then
		selfSay('Good! See, I`ve been chasing a fish, a big one! It`s eluded me for some time now...Nearly had him once i did! Anyways, i need you to gather up eight pieces of bait for me. I heard the trolls to the south have been stealing bait from the local stores. Can you get me some?', cid)
		talkState[cid] = 1
	end

	if(msgcontains(msg, 'yes')) and talkState[cid] == 1 then
		selfSay('Okaj, good luck.', cid)
		setPlayerStorageValue(cid,305,1)
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'done') and getPlayerStorageValue(cid,305) == 1) then
		if (getPlayerStorageValue(cid,307) > 0) then
			selfSay('You already finished this mission.', cid)
		else
			if doPlayerRemoveItem(cid, 2160, 8) then
				setPlayerStorageValue(cid,307,1)
				doPlayerAddExperience(cid, 1000)
				selfSay('Thank you! You can started.. (you received 1000 points of experience)', cid)
			else
				selfSay('You must have more items', cid)
			end
		end
		return true
	end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Well the problem is not the npc, npc just working. But the item will not be placed into the body. and my storage is just right 305. I have. but your script isn't working :( I'll hope you know how to fix it.

Or does anyone got a other script?
 
If there is something that doesn't work it's your NPC my script does just one thing: It works.

Go ingame and write:
/storage <your playername>, 305, 1
and
/storage <your playername>, 306, -1

and kill a troll and open it
 
Sorry mate, my storage is on that level, I checked in datbase. but I killing a troll and there are didn't the coin in it! :(
My npc's gives also the storage numbers.. on the right way nothing more is not happening.
And if I use the command as you said it won't help either.

Damn! :(
 
By replacing:
LUA:
function addBait(cid, pos, corpseid)
	local corpse = getTileItemById(pos, corpseid)
	if corpse.uid > 0 then
		doAddContainerItem(corpse.uid, config.id, 1)
		setPlayerStorageValue(cid, config.storage[2], math.max(1, getPlayerStorageValue(cid, config.storage[2])+1))
	end
end

with:
LUA:
function addBait(cid, pos, corpseid)
	local corpse = getTileItemById(pos, corpseid)
	if corpse.uid > 0 and math.random(100) <= 40  then
		doAddContainerItem(corpse.uid, config.id, 1)
		setPlayerStorageValue(cid, config.storage[2], math.max(1, getPlayerStorageValue(cid, config.storage[2])+1))
	end
end
 
Back
Top