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
that's all for now
bye
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: