local config = {
-- for teleporting players out of specified area
check_top_left = {x = 1000, y = 1000, z = 7},
check_bottom_right = {x = 1000, y = 1000, z = 7},
-- for teleporting players into area
teleport_position = {x = 1502, y = 1500, z = 1},
sacrifice = 2160,
amount = 10,
wait_time = 1000 * 60 * 10, -- 1000 * 60 * 10 = 10 minutes
global_storage = 45001
}
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 function checkPartyDetails(cid)
-- 0 = no party
-- 1 = in party
-- 2 = party leader
-- 3 = party leader only
local party = getPlayerParty(cid)
if party then
if party == cid then
local members = getPartyMembers(party)
if #members > 1 then
return 2
else
return 3
end
else
return 1
end
end
return 0
end
local function teleport_party(cid, position)
for _, pid in pairs(getPartyMembers(cid)) do
doTeleportThing(pid, position)
end
return true
end
local function teleportPlayersInAreaToTemple(topLeftPosition, botRightPosition)
for _, pid in ipairs(getPlayersOnline()) do
local pos = getThingPosition(pid)
if pos.z <= topLeftPosition.z and pos.z >= botRightPosition.z then
if pos.y >= topLeftPosition.y and pos.y <= botRightPosition.y then
if pos.x >= topLeftPosition.x and pos.x <= botRightPosition.x then
doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
end
end
end
end
return true
end
function greet(cid)
local party_check = checkPartyDetails(cid)
if party_check == 2 then
npcHandler:setMessage(MESSAGE_GREET, "I'm surprised you have come here to (challenge) me.")
talkState[cid] = 0
return true
elseif party_check == 3 then
npcHandler:setMessage(MESSAGE_GREET, "Your party must contain more then yourself.")
else
npcHandler:setMessage(MESSAGE_GREET, "You are not the leader of any party.")
end
talkState[cid] = 0
addEvent (
function ()
npcHandler:releaseFocus(cid)
end, 0
)
return true
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 checkPartyDetails(cid) ~= 2 then
selfSay("Where has your party gone?! Come back when you've found them again.", cid)
talkState[talkUser] = 0
npcHandler:releaseFocus(cid)
return true
end
if msgcontains(msg, "challenge") then
selfSay("To challenge me, you must have a sacrifice, you have it? (10 crystal coins)", cid)
talkState[talkUser] = 1
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
if getPlayerItemCount(cid, 2160) >= 10 then
selfSay("Ok then. I hope you are prepared. Tell me when you are (ready).", cid)
talkState[talkUser] = 2
else
selfSay("You do not have the type of sacrifice that I would like.", cid)
talkState[talkUser] = 0
end
elseif msgcontains(msg, "ready") and talkState[talkUser] == 2 then
talkState[talkUser] = 0
if getPlayerItemCount(cid, 2160) >= 10 then
local cur_time = os.time()
if getGlobalStorageValue(config.global_storage) > cur_time then
selfSay("Another party has already challenged me. Try again in " .. config.wait_time / 60000 .. " minutes.", cid)
npcHandler:releaseFocus(cid)
return true
end
doPlayerRemoveItem(cid, config.sacrifice, config.amount)
selfSay("So be it!", cid)
setGlobalStorageValue(config.global_storage, cur_time + config.wait_time / 1000)
teleport_party(cid, config.teleport_position)
addEvent(teleportPlayersInAreaToTemple, config.wait_time - 100, config.check_top_left, config.check_bottom_right)
npcHandler:releaseFocus(cid)
return true
else
selfSay("Where did your sacrifice go? Ask to (challenge) me again when you've got the sacrifice on you!", cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())