function checkStageChange(cid)
local playerLevel = getPlayerLevel(cid)
if (playerLevel > stages[#stages].maxLevel) then
setExperienceRate(cid, stages[#stages].multiplier)
return true
end
for i = 1, #stages do
if (playerLevel >= stages[i].minLevel and playerLevel <= stages[i].maxLevel) then
setExperienceRate(cid, stages[i].multiplier)
return true
end
end
return false
end
['dragon'] = {amount = 5, storage = 19000, startstorage = 5002, startvalue = 1},
['dragon lord'] = {amount = 3, storage = 19001, startstorage = 5002, startvalue = 1}
['heros'] = {amount = 3, storage = 19002, startstorage = 5003, startvalue = 1}
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
local storage = 5002
function creatureSayCallback(cid, type, msg)
if npcHandler.focus ~= cid then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, "mission") then
if getPlayerStorageValue(cid, storage) == -1 then
npcHandler:say("I have a mission for you to kill 5 dragons and 3 dragon lords, do you accept?", cid)
talkState[talkUser] = 1
elseif getPlayerStorageValue(cid, storage) == 1 then
npcHandler:say("Did you kill 5 dragons and 3 dragon lords?", cid)
talkState[talkUser] = 1
else
npcHandler:say("You already did the mission.", cid)
end
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, storage) == -1 then
npcHandler:say("Good, come back when you killed them.", cid)
setPlayerStorageValue(cid, storage, 1)
else
if getPlayerStorageValue(cid, 19000) == 5 and getPlayerStorageValue(cid, 19001) == 3 then
npcHandler:say("Good job, here is your reward.", cid)
doPlayerAddItem(cid, 2160, 5)
doPlayerAddExp(cid, 50000)
setPlayerStorageValue(cid, storage, 2)
else
npcHandler:say("You didn't kill them all.", cid)
end
end
if msgcontains(msg, "heros") then
if getPlayerStorageValue(cid, storage) == -1 then
npcHandler:say("I have a task for you to kill 200 Heros, do you accept?", cid)
talkState[talkUser] = 1
elseif getPlayerStorageValue(cid, storage) == 1 then
npcHandler:say("Did you kill 200?", cid)
talkState[talkUser] = 1
else
npcHandler:say("You already did the mission.", cid)
end
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, storage) == -1 then
npcHandler:say("Good, come back when you killed them.", cid)
setPlayerStorageValue(cid, storage, 1)
else
if getPlayerStorageValue(cid, 19002) == 5 and getPlayerStorageValue(cid, 19002) == 3 then
npcHandler:say("Good job, here is your reward.", cid)
doPlayerAddItem(cid, 2160, 5)
doPlayerAddExp(cid, 300000)
setPlayerStorageValue(cid, storage, 2)
else
npcHandler:say("You didn't kill them all.", cid)
end
end
talkState[talkUser] = 0
elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
npcHandler:say("Ok then.", cid)
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
npcHandler:say("Good job, here is your reward, for your second mission kill 3 heros.")
elseif getPlayerStorageValue(cid, storage) == 1 then
npcHandler:say("Did you kill 5 dragons and 3 dragon lords?")
talkState[talkUser] = 1
elseif getPlayerStorageValue(cid, storage) == 2 then
npcHandler:say("Did you kill 5 dragons and heros?")
talkState[talkUser] = 1
['dragon'] = {amount = 5, storage = 19000, startstorage = 5002, startvalue = 1},
['dragon lord'] = {amount = 3, storage = 19001, startstorage = 5002, startvalue = 1},
['hero'] = {amount = 3, storage = 19002, startstorage = 5002, startvalue = 2}
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
local storage = 5002
local monsters = {
["dragons"] = {storage = 5010, mstorage = 19000, amount = 10, exp = 5000, item = {2160, 3}},
["dragon lords"] = {storage = 5011, mstorage = 19001, amount = 10, exp = 10000, item = {2160, 10}},
["heros"] = {storage = 5012, mstorage = 19002, amount = 10, exp = 8000, item = {2160, 8}},
["dwarf guards"] = {storage = 5013, mstorage = 19003, amount = 10, exp = 7000, item = {2160, 7}}
}
function creatureSayCallback(cid, type, msg)
if npcHandler.focus ~= cid then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, "mission") then
if getPlayerStorageValue(cid, storage) == -1 then
local text, n = "", 0
for k, x in pairs(monsters) do
if getPlayerStorageValue(cid, x.storage) == -1 then
n = n + 1
text = text .. ", "
text = text .. ""..x.amount.." {"..k.."}"
end
end
if n > 1 then
npcHandler:say("I have several tasks for you to kill"..text..", which one do you choose?")
talkState[talkUser] = 1
elseif n == 1 then
npcHandler:say("I have one last task for you"..text..".")
talkState[talkUser] = 1
else
npcHandler:say("You already did the missions.")
end
elseif getPlayerStorageValue(cid, storage) == 1 then
for k, x in pairs(monsters) do
if getPlayerStorageValue(cid, x.storage) == 1 then
npcHandler:say("Did you kill "..x.amount.." "..k.."?")
talkState[talkUser] = 2
xmsg = k
end
end
end
elseif monsters[msg:lower()] and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, monsters[msg:lower()].storage) == -1 then
npcHandler:say("Good luck, come back when you killed "..monsters[msg:lower()].amount.." "..msg..".")
setPlayerStorageValue(cid, storage, 1)
setPlayerStorageValue(cid, monsters[msg:lower()].storage, 1)
else
npcHandler:say("You already did the "..msg.." mission.", cid)
end
talkState[talkUser] = 0
elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
if getPlayerStorageValue(cid, monsters[xmsg].mstorage) == monsters[xmsg].amount then
npcHandler:say("Good job, here is your reward.")
doPlayerAddItem(cid, monsters[xmsg].item[1], monsters[xmsg].item[2])
doPlayerAddExp(cid, monsters[xmsg].exp)
setPlayerStorageValue(cid, monsters[xmsg].storage, 2)
setPlayerStorageValue(cid, storage, -1)
else
npcHandler:say("You didn't kill them all.", cid)
end
talkState[talkUser] = 0
elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
npcHandler:say("Ok then.")
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
local config = {
['dragon'] = {amount = 10, storage = 19000, startstorage = 5010, startvalue = 1},
['dragon lord'] = {amount = 10, storage = 19001, startstorage = 5011, startvalue = 1},
['hero'] = {amount = 10, storage = 19002, startstorage = 5012, startvalue = 1},
['dwarf guard'] = {amount = 10, storage = 19003, startstorage = 5013, startvalue = 1}
}
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
local storage = 5003
local monsters = {
["dragons"] = {storage = 5010, mstorage = 19000, amount = 10, exp = 5000, item = {2160, 3}},
["dragon lords"] = {storage = 5011, mstorage = 19001, amount = 10, exp = 10000, item = {2160, 10}},
["heros"] = {storage = 5012, mstorage = 19002, amount = 10, exp = 8000, item = {2160, 8}},
["dwarf guards"] = {storage = 5013, mstorage = 19003, amount = 10, exp = 7000, item = {2160, 7}}
}
function creatureSayCallback(cid, type, msg)
if npcHandler.focus ~= cid then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, "mission") then
if getPlayerStorageValue(cid, storage) == -1 then
local text, n = "", 0
for k, x in pairs(monsters) do
if getPlayerStorageValue(cid, x.storage) == -1 then
n = n + 1
text = text .. ", "
text = text .. ""..x.amount.." {"..k.."}"
end
end
if n > 1 then
npcHandler:say("I have several tasks for you to kill"..text..", which one do you choose?", cid)
talkState[talkUser] = 1
elseif n == 1 then
npcHandler:say("I have one last task for you"..text..".", cid)
talkState[talkUser] = 1
else
npcHandler:say("You already did the missions.", cid)
end
elseif getPlayerStorageValue(cid, storage) == 1 then
for k, x in pairs(monsters) do
if getPlayerStorageValue(cid, x.storage) == 1 then
npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
talkState[talkUser] = 2
xmsg = k
end
end
end
elseif monsters[msg:lower()] and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, monsters[msg:lower()].storage) == -1 then
npcHandler:say("Good luck, come back when you killed "..monsters[msg:lower()].amount.." "..msg..".", cid)
setPlayerStorageValue(cid, storage, 1)
setPlayerStorageValue(cid, monsters[msg:lower()].storage, 1)
else
npcHandler:say("You already did the "..msg.." mission.", cid)
end
talkState[talkUser] = 0
elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
if getPlayerStorageValue(cid, monsters[xmsg].mstorage) == monsters[xmsg].amount then
npcHandler:say("Good job, here is your reward.", cid)
doPlayerAddItem(cid, monsters[xmsg].item[1], monsters[xmsg].item[2])
doPlayerAddExp(cid, monsters[xmsg].exp)
setPlayerStorageValue(cid, monsters[xmsg].storage, 2)
setPlayerStorageValue(cid, storage, -1)
else
npcHandler:say("You didn't kill them all.", cid)
end
talkState[talkUser] = 0
elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
npcHandler:say("Ok then.", cid)
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
elseif monsters[msg:lower()] and talkState[talkUser] == 1 then
npcHandler:say("Good luck, come back when you killed "..monsters[msg:lower()].amount.." "..msg..".", cid)
setPlayerStorageValue(cid, storage, 1)
setPlayerStorageValue(cid, monsters[msg:lower()].storage, 1)
talkState[talkUser] = 0
elseif monsters[msg:lower()] and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, monsters[msg:lower()].storage) == -1 then
npcHandler:say("Good luck, come back when you killed "..monsters[msg:lower()].amount.." "..msg..".", cid)
setPlayerStorageValue(cid, storage, 1)
setPlayerStorageValue(cid, monsters[msg:lower()].storage, 1)
else
npcHandler:say("You already did the "..msg.." mission.", cid)
end
talkState[talkUser] = 0
npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
function isSummon(cid)
return getCreatureMaster(cid) ~= nil or false
end
In your situation your asking if the number is great than 2,4,6.. It will stop on the first 'if' statement.Question about ElseIf
If i have code like this: (not correct code forms, but just wana understand how does elseif work)
If number > 2 then
Say "hi"
elseif number >4 then
Say "bye"
elseif number > 6 then
say "wat"
Which is correct outcome? when the number is 7
1. hi
2. hi
bye
wat
3. wat
Question about talkState
can i have? (so i could have different talkStates at once
local talkState = {}
local talkState2 = {}
anyway, great thread, this will prolly fix my task master NPC problem.
if number < 2 then
say this
elseif number < 4 then
say this
elseif number < 6 then
say this
else
say this
end
if number > 6 then
say this
elseif number > 4 then
say this
elseif number > 2 then
say this
else
say this
end