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

Monster Hunt Event

MalyFanek

New Member
Joined
Oct 10, 2019
Messages
37
Reaction score
2
Hello, as the title sais im trying to do monster hunt event which should work like that, if i kill monster1, i get+1 point, monster2 +2 points, monster 3 +3points etc. For now all i have made is:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<mod name="Bad Saiyans Hunt Event" version="8.6" author="" contact="" enabled="yes">
<config name="hunt_config"><![CDATA[
Hunt = {
storages = {1714210, 1819211}, -- storage Count
players = {min = 1, max = 50}, -- min, max players no evento
minLevel = 20, -- level minimo para entrar no event
rewards = {{2160,10},{2494,1}}, -- premios que vai receber
timeToStartEvent = 30, -- segundos para começar o evento
CheckTime = 5, -- time to check event
teleport = {{x=646, y=391, z=7}, {x=1020 , y=1041, z=7}}, --teleport position, position the player goes to
arena = {{x=988,y=1011,z=7},{x=1053,y=1057,z=7}} -- start and end position of the area
}
Hunt_Days = {
["Monday"] = {"09:00","21:00"},
["Tuesday"] = {"09:00","21:00"},
["Wednesday"] = {"09:00","21:00"},
["Thursday"] = {"09:00","21:00"},
["Friday"] = {"09:00","21:00"},
["Saturday"] = {"09:00",'21:00'},
["Sunday"] = {"09:00","15:00"}
}
function removeHuntTp()
local t = getTileItemById(Hunt.teleport[1], 1387).uid
return t > 0 and doRemoveItem(t) and doSendMagicEffect(Hunt.teleport[1], CONST_ME_POFF)
end
function ZerarStorHunt()
setGlobalStorageValue(Hunt.storages[1], 0)
setGlobalStorageValue(Hunt.storages[2], 0)
end
function getPlayersInHuntEvent()
local t = {}
for _, pid in pairs(getPlayersOnline()) do
if isInRange(getPlayerPosition(pid), Hunt.arena[1], Hunt.arena[2]) then
t[#t+1] = pid
end
end
return t
end
function getHuntRewards(cid, items)
local backpack = doPlayerAddItem(cid, 1999, 1) -- backpackID
for _, i_i in ipairs(items) do
local item, amount = i_i[1],i_i[2]
if isItemStackable(item) or amount == 1 then
doAddContainerItem(backpack, item, amount)
else
for i = 1, amount do
doAddContainerItem(backpack, item, 1)
end
end
end
end
function winMonsterEvent()

local max_sto, winner = 0, 0
local monster = getGlobalStorageValue(1819211)
for _, pid in pairs(getPlayersOnline()) do
local sto = getGlobalStorageValue(pid, 1714210)
if sto > max_sto then
max_sto = sto
winner = cid
end
end
if isPlayer(winner) then
temple = getPlayerMasterPos(cid)
local artigo = getPlayerSex(winner) == 0 and "The player" or "The player"
doBroadcastMessage(artigo.." "..getCreatureName(winner).." gained "..getGlobalStorageValue(winner, 1714210).." points and won the event!")
for _, prize in pairs(premios) do
doPlayerAddItem(winner, prize[1], prize[2])
end
doPlayerAddMoney(winner, gold)

else

doBroadcastMessage("[Monster Hunter Event] The event ended and there was no winner.")
setGlobalStorageValue(1819211, 0)
ZerarStorHunt()

end
end
function CheckHuntEvent(delay)
local time = 5
if getGlobalStorageValue(Hunt.storages[1]) ~= (Hunt.players.max+1) then
if delay > 0 and getGlobalStorageValue(Hunt.storages[1]) < Hunt.players.max then
doBroadcastMessage("[Bad Saiyans Hunt Event] Starting in " .. delay .. " minutes! The teleport will be closed when the event start!", MESSAGE_STATUS_WARNING)
elseif delay == 0 and getGlobalStorageValue(Hunt.storages[1]) < Hunt.players.min then
for _, cid in pairs(getPlayersInHuntEvent()) do
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
end
removeHuntTp()
doBroadcastMessage("The Bad Saiyans Hunt event could not start because of to few players participating.\n At least " .. Hunt.players.min .. " players is needed!", MESSAGE_STATUS_WARNING)
ZerarStorHunt()
elseif delay == 0 and getGlobalStorageValue(Hunt.storages[1]) >= Hunt.players.min then
removeHuntTp()
doBroadcastMessage("Good Lucky! The event will start on "..Hunt.timeToStartEvent.." seconds. get ready!")
addEvent(winMonsterEvent, time*1000*60)
end
addEvent(CheckHuntEvent, 60000, delay-1)
end
end
]]></config>
<globalevent name="Hunt_Start" interval="60000" event="script"><![CDATA[
domodlib('hunt_config')
function onThink(interval, lastExecution)
if Hunt_Days[os.date("%A")] then
local hrs = tostring(os.date("%X")):sub(1, 5)
if isInArray(Hunt_Days[os.date("%A")], hrs) and getGlobalStorageValue(Hunt.storages[2]) <= 0 then
local tp = doCreateItem(1387, 1, Hunt.teleport[1])
doItemSetAttribute(tp, "aid", 46111)
CheckHuntEvent(Hunt.CheckTime)
setGlobalStorageValue(Hunt.storages[1], 0)
end
end
return true
end]]></globalevent>
<event type="login" name="Hunt_Login" event="script"><![CDATA[
domodlib('hunt_config')
function onLogin(cid)
registerCreatureEvent(cid, "HuntBatle")
if isInRange(getPlayerPosition(cid), Hunt.arena[1], Hunt.arena[2]) then
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
end
return true
end]]></event>
<event type="combat" name="HuntBatle" event="script"><![CDATA[
domodlib('hunt_config')
if isPlayer(cid) and isPlayer(target) and isInRange(getPlayerPosition(cid), Hunt.arena[1], Hunt.arena[2]) then
doPlayerSendCancel(cid, "You may not attack this player.")
return false
end
return true
]]></event>
<movevent type="StepIn" actionid ="46111" event="script"><![CDATA[
domodlib('hunt_config')
function onStepIn(cid, item, position, fromPosition)
local time = 5
if not isPlayer(cid) then return true end
if getPlayerAccess(cid) > 3 then return doTeleportThing(cid, Hunt.teleport[2]) end
if getPlayerLevel(cid) < Hunt.minLevel then
doTeleportThing(cid, fromPosition, true)
doPlayerSendCancel(cid, "You need to be at least level " .. Hunt.minLevel .. ".")
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
return true
end
if getGlobalStorageValue(Hunt.storages[1]) <= Hunt.players.max then
doTeleportThing(cid, Hunt.teleport[2])
setGlobalStorageValue(Hunt.storages[1], getGlobalStorageValue(Hunt.storages[1])+1)
doBroadcastMessage(getPlayerName(cid) .. " entered the Bad Saiyans Hunt Event! Currently " .. getGlobalStorageValue(Hunt.storages[1]) .. " players have joined!", MESSAGE_STATUS_CONSOLE_RED)
if getGlobalStorageValue(Hunt.storages[1]) == Hunt.players.max then
setGlobalStorageValue(Hunt.storages[1], getGlobalStorageValue(Hunt.storages[1])+1)
removeHuntTp()
doBroadcastMessage("The event will start on "..Hunt.timeToStartEvent.." seconds. get ready!")
addEvent(winMonsterEvent, time*1000*60)
end
end
return true
end]]></movevent>
<talkaction words="/huntstart;!huntstart" access="5" event="buffer"><![CDATA[
domodlib('hunt_config')
if getGlobalStorageValue(Hunt.storages[2]) > 0 then
doPlayerSendCancel(cid, "The event is already starting.") return true
elseif not param or not tonumber(param) then
doPlayerSendCancel(cid, "Use only numbers.") return true
end
local param = tonumber(param) <= 0 and 1 or tonumber(param)
local tp = doCreateItem(1387, 1, Hunt.teleport[1])
doItemSetAttribute(tp, "aid", 46111)
CheckHuntEvent(tonumber(param))
setGlobalStorageValue(Hunt.storages[1], 0)
setGlobalStorageValue(Hunt.storages[2], 1)
]]></talkaction>
<globalevent name="HuntDebug-Start" type="start" event="buffer"><![CDATA[
domodlib('hunt_config')
ZerarStorHunt()
return true]]></globalevent>
</mod>
And its all works fine, it runs on days, talkaction works too but the problem is with

function winMonsterEvent()
Because it always give a winner to the admin even if he got storage -1 ;/



I also added monster with script:


Code:
function onKill(cid, target, lastHit)
if isMonster ( target ) and
getCreatureName ( target ) == 'Bad Raditz [EVENT]' and
getGlobalStorageValue ( cid ,1714210) > 0 then
doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE, 'You have killd 1 of event monster.')


setGlobalStorageValue(cid,1714210, getGlobalStorageValue(cid, 1714210) + 1)
end
return true

end
wanned to add later more monsters that give more than +1 stor value but... first need to finish this, what am i doing wrong? no error in console, nothing, any tips/help or maybe better ideas?
And the 2nd thing, how to make it 3 winners?

/edit
I try to compare the event with this one (not sure can i add link if not please delete this edit) but atleast it might be helpfull


Its edited fire storm event+this one from link if it might help



Im using tibia 8,6 tfs 0,4 rev 3777
 
Last edited:
Back
Top