• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Jetro's Mission quest npc 1.0

Jetro

jangeldev
Joined
Aug 1, 2011
Messages
452
Reaction score
68
Location
Venezuela
Hi all, this is my first release on OTLand, first of all i want to clarify something: i'm not the best nor the worst in LUA, so if you consider that i'm doing it wrong i invite you to give me constructive criticism :)

tested on TFS 0.3.6 pl1
Lua:
--[[ Jetro's Mission quest npc 1.0
	ALL CREDITS TO JETRO
	]]--
local config = 
{
	requirements = 
	{
		storage = 35442, --STORAGE REQUIRED
		requiredlevel = false, --REQUIRES LEVEL? TRUE OR FALSE
		level = 300, --LEVEL (IF REQUIRED)
		requiredpremium = false, --REQUIRES PREMIUM? TRUE OR FALSE
		itemsrequired = --ITEMS REQUIRED'S LIST
		{
			[6528] = {amount = 100},    
			[8856] = {amount = 100}
		}, 
	},
 
	rewards = 
	{

		
		expvalue = 100, --EXPERIENCE. (false if it won't give exp)
		expcolor = 35, --COLOR OF ANIMATED TEXT: min = 1, max = 255
		money = 2000, --MONEY. (false if it won't give money)
		reward = --ITEMS'S LIST (false if it won't give items)
		{
			[2277] = {amount = 3},
			[2278] = {amount = 4},
		},	
	}
}
 
 local function getRequiredThings(cid)
		local msg = ""
		local itemsleft = { }
 
			for i,x in pairs(config.requirements.itemsrequired) do
				local item = getPlayerItemCount(cid, i)
				if (item < x.amount) then
					table.insert(itemsleft, x.amount - item.. "x "..getItemNameById(i))
				end
			end
 
			msg = #itemsleft > 0 and "Items: "..table.concat(itemsleft, ", ") or ""
 
		return msg	
	end
 
 
 
 
local itemscap = 0
 
for i,x in pairs (config.requirements.itemsrequired) do
	itemscap = itemscap + getItemWeightById(i, x.amount)
end
 
local requir = {}
for i,x in pairs(config.requirements.itemsrequired) do
	table.insert (requir, x.amount .. "x "..getItemNameById(i))
end
 
 
 
	

	
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 cap = getPlayerFreeCap(cid)
	local s = getPlayerStorageValue(cid, config.requirements.storage) == 1 and true or false
	local lv = getPlayerLevel(cid)
	local prm = isPremium(cid) 
	
	
	--LIST OF MESSAGES THAT THE NPC WILL SAY--
	local msgs = 
	{
		requirements = "Well, i need help to get some items. I need "..table.concat(requir, ", ").. ". Could you help me to get  "..(#requir > 1 and "them" or "it").. "?.",
		reward = "Thanks for helping me, here is your reward!",
		done = "You have already done this mission.",
		notpremium = "Sorry, only players with premium account can make this mission.",
		notitems = "Sorry, you don't have all the items required for this mission "..getRequiredThings(cid),
		notlevel = "Sorry, you don't have the required level for make this mission {"..config.requirements.level.."}",
		wrong = "Huh?", 
		negation = "Ok, maybe next time.."
	}	
	

	local rq = getRequiredThings(cid)

 
	if (msgcontains(msg, 'mission')) then
		if (config.requirements.requiredpremium == true and not prm ) then
			return selfSay(msgs.notpremium, cid)
		end
		if (s == true)then
			return selfSay(msgs.done, cid)
		end
 
		if (config.requirements.requiredlevel == true and lv < config.requirements.level) then
			return selfSay(msgs.notlevel, cid)
		end
		selfSay(msgs.requirements,cid)
		talk_state = 1
 
	elseif (msgcontains(msg, "yes")) and talk_state == 1 then
		if ( rq == "" ) then
			if (cap < itemscap) then
				return selfSay("Sorry, you don't have enough capacity to carry the reward. All weights items.cap", cid)
			end
			if (config.rewards.expvalue ~= false) then
				doPlayerAddExp(cid, config.rewards.expvalue)
				if (config.rewards.expcolor > 255 or config.rewards.expcolor <= 0) then
					config.rewards.expcolor = math.random(255)
				end
				doSendAnimatedText(getThingPos(cid), config.rewards.expvalue, config.rewards.expcolor)
			end
 
			if (config.rewards.money ~= false) then
				doPlayerAddMoney(cid, config.rewards.money)
			end
 
			if (config.rewards.reward ~= false) then
				for i,x in pairs (config.rewards.reward) do
					doPlayerAddItem(cid, i, x.amount)
				end
			end
 
			for i,x in pairs (config.requirements.itemsrequired) do
				doPlayerRemoveItem(cid, i, x.amount)
			end
			doPlayerSetStorageValue(cid, config.requirements.storage, 1)
			selfSay(msgs.reward.."".. rq, cid)
			talk_state = 0
 
		else
			selfSay("Sorry, you don't have all items, you still need "..rq, cid)
			talk_state = 0
		end	
	elseif (msgcontains(msg, "no") and talk_state == 1 ) then
		selfSay(msgs.negation, cid)
		talk_state = 0
	else
		selfSay(msgs.wrong, cid)
	end
 
 
return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

that's all for now
bye ;)
 
Last edited:
lol <short>

Nice Quest. hey jetro, please wait 24hours between bumps.
 
Nice release! Btw there'r a couple of things you can do to improve it (and because you asking for criticism):

Put the focus check at the very begining of the onSay callback, you are wasting time defining varibles/calling functions if you are going to exit anyways.
Lua:
 if(not npcHandler:isFocused(cid)) then
        return false
    end

Define the inner getRequiredThings function and the msgs table outside the callback function
Lua:
local msgs = {...}

local function getRequiredThings(cid)
...
end

function creatureSayCallback(cid, type, msg)
...
end

Also you can take advantage of the fact that lua is a dynamic typed language, instead of using 3 vars for the exp, you can use 2, remove the getexp var and allow expvalue to hold a boolean value/nil value, so if theres no expvalue present OR it is false, it means I dont want the quest to give exp. You can use the same approach with the other type of rewards.
Lua:
expvalue = false -- disabled
		expcolor = 35

Actually, I have made a very similar mission-NPC for my team, except that it works with my Enhanced NPC system and accept multiple quests.

Keep releasing more stuff!
 
Put the focus check at the very begining of the onSay callback,
thanks for the tip

you are wasting time defining varibles/calling functions if you are going to exit anyways.
it means i can use values using functions without using variables? i thought that saving memory usage xd (explain me better plz i don't now too much)



Define the inner getRequiredThings function and the msgs table outside the callback function
notitems message of msgs table needs that function to work, if i put it outside then i receive error. I forgot to put the function outside the main function xd


Also you can take advantage of the fact that lua is a dynamic typed language, instead of using 3 vars for the exp, you can use 2, remove the getexp var and allow expvalue to hold a boolean value/nil value, so if theres no expvalue present OR it is false, it means I dont want the quest to give exp. You can use the same approach with the other type of rewards.
i didn't know that, thanks xd

Actually, I have made a very similar mission-NPC for my team, except that it works with my Enhanced NPC system and accept multiple quests.
nice, maybe later i'll add multiple quest support in the script!

Keep releasing more stuff!
I'll do it :)
 
it means i can use values using functions without using variables? i thought that saving memory usage xd (explain me better plz i don't now too much)

No, that means why do:

Lua:
local cap = getPlayerFreeCap(cid)
	local s = getPlayerStorageValue(cid, config.requirements.storage) == 1 and true or false
	local lv = getPlayerLevel(cid)
	local prm = isPremium(cid)

and then

Lua:
 if(not npcHandler:isFocused(cid)) then
        return false
    end

If the player is not focused, then you wasted a bit of time getting values you'r not going to use, because you are returning from the callback function due the player being unfocused. I see you have fixed it now. :)
 
Ehh.. Yes, i am nuub.
Please help me ^_^

[14/11/2011 19:07:43] [Error - LuaScriptInterface::loadFile] data/npc/scripts/rotworm queen mission.lua:23: '}' expected (to close '{' at line 16) near '{'
[14/11/2011 19:07:43] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/rotworm queen mission.lua
[14/11/2011 19:07:43] data/npc/scripts/rotworm queen mission.lua:23: '}' expected (to close '{' at line 16) near '{'
 
This is great but can you make it like; a NPC that only gives this task to knight?

I want to use this for a quest for custom weapon so a paladin cannot do the task I hope you understand me :p
 
Lua Script Error: [Npc interface]
data/npc/scripts/misja.lua
data/npc/scripts/misja.lua:56: attempt to call global 'getItemWeightById' (a nil value) stack traceback:
[C]: in function 'getItemWeightById'
data/npc/scripts/misja.lua:56: in main chunk
[Warning - NpcScript::NpcScript] Can not load script: data/npc/scripts/misja.lua

Please help me ;/

I use TFS 9.30
 
I'll use it! Thanks alot.

I wanted to find an npc that I could trade items with anytime so I removed "
Lua:
doPlayerSetStorageValue(cid, config.requirements.storage, 1)
" lline to make it unlimited.
 
Here is Great Scripts for Edit Yourself and Create New Mission / Quest.

Code:
------STORAGE-------
------100 do 104-------
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local item1 = 2666
local item2 = 2152
local item3 = 2667
local item4 = 2476
local item5 = 2386
local item7 = 7591
local item9 = 2472
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, 'pomoc')) then
selfSay('Dobrze, ze zdecydowales sie mi pomoc, mam dla Ciebie kilka zadan, po wykonaniu ich otrzymasz nagrode. (aby rozpoczac misje wpisz pokolei MISJA1,MISJA2..)', cid)
end
---------------------------------------------------------
if(msgcontains(msg, 'misja1')) then
selfSay('Niedlugo wyruszam w podroz i potrzebuje paru rzeczy. Przynies mi 10 kawalkow {miesa}.', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'mieso') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,100) > 0) then
selfSay('Wykonales juz ta misje.', cid)
else
if(doPlayerRemoveItem(cid, item1, 10) == TRUE) then
setPlayerStorageValue(cid,100,1)
doPlayerAddExperience(cid,5000)
selfSay('Bardzo ci dziekuje za to mieso. (otrzymales 5000pkt doswiadczenia)', cid)
else
selfSay('Potrzebuje 10 kawalkow miesa..', cid)
end
end
return true
end
----------------------------------------------------------
if(msgcontains(msg, 'misja2')) then
selfSay('Przynies mi jeszcze 50 platynowych {monet}.', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'monety') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,100) < 1) then
selfSay('Najpierw przynies mi 10 kawalkow miesa.', cid)
else
if (getPlayerStorageValue(cid,101) > 0) then
selfSay('Wykonales juz ta misje.', cid)
else
if(doPlayerRemoveItem(cid, item2, 5) == TRUE) then
setPlayerStorageValue(cid,101,1)
doPlayerAddExperience(cid,7000)
selfSay('Dzieki za monety (otrzymujesz 7000pkt doswiadczenia)', cid)
else
selfSay('Potrzebuje 50 platynowych monet...', cid)
end
end
end
return true
end
----------------------------------------------------------
if(msgcontains(msg, 'misja3')) then
selfSay('Bede potrzebowal jeszcze 15 ryb.', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'ryby') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,101) < 1) then
selfSay('Najpierw przynies mi 10 kawalkow miesa i 50 platynowych monet.', cid)
else
if (getPlayerStorageValue(cid,102) > 0) then
selfSay('Wykonales juz ta misje.', cid)
else
if(doPlayerRemoveItem(cid, item3, 15) == TRUE) then
setPlayerStorageValue(cid,102,1)
doPlayerAddExperience(cid,10000)
selfSay('No bardzo ladne rybki, dziekuje. (otrzymales 10000pkt doswiadczenia)', cid)
else
selfSay('Potrzebuje 15 ryb..', cid)
end
end
end
return true
end
----------------------------------------------------------
if(msgcontains(msg, 'misja4')) then
selfSay('Przynies mi {knight armor}, bez niego nie dam sobie rady w podrozy...', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'knight armor') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,102) < 1) then
selfSay('Wykonaj moje poprzednie polecenia...', cid)
else
if (getPlayerStorageValue(cid,103) > 0) then
selfSay('Wykonales juz ta misje.', cid)
else
if(doPlayerRemoveItem(cid, item4, 1) == TRUE) then
setPlayerStorageValue(cid,103,1)
doPlayerAddExperience(cid,20000)
selfSay('Dziekuje, bardzo mi sie przydajesz (otrzymales 20000pkt doswiadczenia)', cid)
else
selfSay('Wciaz czekam...', cid)
end
end
end
return true
end
----------------------------------------------------------
if(msgcontains(msg, 'misja5')) then
selfSay('Potrzebuje jeszcze siekierke ({axe}) do scinania drewna. ', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'axe') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,103) < 1) then
selfSay('Wykonaj moje poprzednie polecenia...', cid)
else
if (getPlayerStorageValue(cid,104) > 0) then
selfSay('Wykonales juz ta misje.', cid)
else
if(doPlayerRemoveItem(cid, item5, 1) == TRUE) then
setPlayerStorageValue(cid,104,1)
doPlayerAddExperience(cid,30000)
doPlayerAddItem(cid, 2466, 1)
doPlayerAddItem(cid, 2488, 1)
doPlayerAddItem(cid, 2491, 1)
selfSay('Ooo dziekuje bardzo. Gotowy na wiecej? (otrzymales 30000pkt doswiadczenia i kilka przedmiotow)', cid)
else
selfSay('Potrzebuje siekierki...', cid)
end
end
end
return true
end
----------------------------------------------------------
if(msgcontains(msg, 'misja6')) then
selfSay('Zabij {30 smokow} i wroc do mnie. ', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, '30 smokow') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,104) < 1) then
selfSay('Wykonaj moje poprzednie polecenia...', cid)
else
if (getPlayerStorageValue(cid,105) > 0) then
selfSay('Wykonales juz ta misje.', cid)
else
if (getPlayerStorageValue(cid,35004) > 29) then
setPlayerStorageValue(cid,105,1)
doPlayerAddExperience(cid,50000)
doPlayerAddItem(cid, 2492, 1)
selfSay('Dziekuje ci. ;] (otrzymales 50000pkt doswiadczenia i DSM)', cid)
else
selfSay('Musisz zabic {30 smokow}...', cid)
end
end
end
return true
end
----------------------------------------------------------
if(msgcontains(msg, 'misja7')) then
selfSay('Potrzebuje czegos do leczenia, przynies mi {great health potion}...', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'great health potion') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,105) < 1) then
selfSay('Wykonaj moje poprzednie polecenia...', cid)
else
if (getPlayerStorageValue(cid,106) > 0) then
selfSay('Wykonales juz ta misje.', cid)
else
if(doPlayerRemoveItem(cid, item7, 1) == TRUE) then
setPlayerStorageValue(cid,106,1)
doPlayerAddExperience(cid,80000)
doPlayerAddItem(cid, 2160, 5)
selfSay('Dziekuje, bardzo mi sie przydajesz ;]. (otrzymales 80000pkt doswiadczenia i 5cc)', cid)
else
selfSay('Dalej czekam...', cid)
end
end
end
return true
end
----------------------------------------------------------
if(msgcontains(msg, 'misja8')) then
selfSay('Teraz cos trudniejszego. Zabij {10 demonow} i przyjdz po nagrode. ', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, '10 demonow') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,106) < 1) then
selfSay('Wykonaj moje poprzednie zadania...', cid)
else
if (getPlayerStorageValue(cid,107) > 0) then
selfSay('Wykonales juz ta misje.', cid)
else
if (getPlayerStorageValue(cid,35006) > 9) then
setPlayerStorageValue(cid,107,1)
doPlayerAddExperience(cid,100000)
selfSay('Dziekuje ci. ;] (otrzymales 100000pkt doswiadczenia)', cid)
else
selfSay('Musisz zabic {10 demonow}...', cid)
end
end
end
return true
end
----------------------------------------------------------
if(msgcontains(msg, 'misja9')) then
selfSay('Sproboj zdobyc dla mnie {MPA} z demonow...', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'MPA') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,107) < 1) then
selfSay('Wykonaj moje poprzednie polecenia...', cid)
else
if (getPlayerStorageValue(cid,108) > 0) then
selfSay('Wykonales juz ta misje.', cid)
else
if(doPlayerRemoveItem(cid, item9, 1) == TRUE) then
setPlayerStorageValue(cid,108,1)
doPlayerAddExperience(cid,200000)
doPlayerAddItem(cid, 2160, 10)
selfSay('Dziekuje... (otrzymales 200000pkt doswiadczenia i 10cc)', cid)
else
selfSay('Przynies mi {MPA}...', cid)
end
end
end
return true
end
----------------------------------------------------------

end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top