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

[8.60] Hunter Event

Frikx

Computer Science
Joined
Mar 10, 2013
Messages
128
Solutions
3
Reaction score
31
Location
Spain
GitHub
amatria
>> Hunter Event

> Video:

> /path/to/server/data/lib/hunter_event.lua
Lua:
-- Hunter Event by Frikx

-- Version: 1.0

HunterEvent = {}

HunterEvent.config =
   {
       minPlayers = 2,
       lifes = 3,
       maxDuration = 30,
       winItems =
           {
               {name = 'crystal coin', qty = 100, chance = 100},
               {name = 'magic plate armor', qty = 1, chance = 1}
           },
       enterArea =
           {
               from = {x = 1032, y = 1006, z = 7},
               to = {x = 1034, y = 1008, z = 7}
           },
       playArea =
           {
               from = {x = 1050, y = 1007, z = 7},
               to = {x = 1072, y = 1018, z = 7}
           },
       kickPos = {x = 1000, y = 1000, z = 7},
       isOnArena = 40000,
       globalStatus = 40000,
       accessToIgnore = 3
   }

function HunterEvent.setPlayerStorage(cid, value)
   return doPlayerSetStorageValue(cid, HunterEvent.config.isOnArena, value)
end

function HunterEvent.getPlayerStorage(cid)
   return getPlayerStorageValue(cid, HunterEvent.config.isOnArena)
end

function HunterEvent.addWinnerItems(cid)
   for i = 1, #HunterEvent.config.winItems do
       if math.random(1, 100) <= HunterEvent.config.winItems[i].chance then
           doPlayerAddItem(cid, getItemIdByName(HunterEvent.config.winItems[i].name), HunterEvent.config.winItems[i].qty, true)
       end
   end
end

function HunterEvent.addPlayerSummon(cid)
   local s = getCreatureSummons(cid)
   if table.maxn(s) > 0 then
       for _, sid in ipairs(s) do
           doRemoveCreature(sid)
       end
   end
   doSummonMonster(cid, 'Hunter Event')
end

function HunterEvent.kickPlayerFromArena(cid)
   HunterEvent.setPlayerStorage(cid, 0)
   doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
   doTeleportThing(cid, HunterEvent.config.kickPos)
   doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
   local p = HunterEvent.getPlayersInArena()
   if #p == 1 then
       HunterEvent.kickPlayerFromArena(p[1].pid)
       HunterEvent.addWinnerItems(p[1].pid)
       doSetStorage(HunterEvent.config.globalStatus, 0)
       doBroadcastMessage('[Hunter Event]: '.. getCreatureName(cid) ..' has won the Hunter Event!!')
   end
end

function HunterEvent.removePlayerLife(cid)
   if HunterEvent.getPlayerStorage(cid) == 1 then
       return HunterEvent.kickPlayerFromArena(cid)
   end
   HunterEvent.setPlayerStorage(cid, HunterEvent.getPlayerStorage(cid) - 1)
   doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
   doTeleportThing(cid, {x = math.random(HunterEvent.config.playArea.from.x, HunterEvent.config.playArea.to.x), y = math.random(HunterEvent.config.playArea.from.y, HunterEvent.config.playArea.to.y), z = math.random(HunterEvent.config.playArea.from.z, HunterEvent.config.playArea.to.z)})
   HunterEvent.addPlayerSummon(cid)
end

function HunterEvent.countPlayers()
   local c = 0
   for _, cid in ipairs(getPlayersOnline()) do
       local p = getCreaturePosition(cid)
       if isInRange(p, HunterEvent.config.enterArea.from, HunterEvent.config.enterArea.to) then
           if getPlayerAccess(cid) < HunterEvent.config.accessToIgnore then
               c = c + 1
           end
       end
   end
   return c
end

function HunterEvent.kickPlayersFromWaitingArena()
   for _, cid in ipairs(getPlayersOnline()) do
       local p = getCreaturePosition(cid)
       if isInRange(p, HunterEvent.config.enterArea.from, HunterEvent.config.enterArea.to) then
           doTeleportThing(cid, HunterEvent.config.kickPos)
           doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)   
       end
   end   
end

function HunterEvent.addPlayersToArena()
   for _, cid in ipairs(getPlayersOnline()) do
       local p = getCreaturePosition(cid)
       if isInRange(p, HunterEvent.config.enterArea.from, HunterEvent.config.enterArea.to) then
           doTeleportThing(cid, {x = math.random(HunterEvent.config.playArea.from.x, HunterEvent.config.playArea.to.x), y = math.random(HunterEvent.config.playArea.from.y, HunterEvent.config.playArea.to.y), z = math.random(HunterEvent.config.playArea.from.z, HunterEvent.config.playArea.to.z)})
           if getPlayerAccess(cid) < HunterEvent.config.accessToIgnore then
               HunterEvent.setPlayerStorage(cid, HunterEvent.config.lifes)
               HunterEvent.addPlayerSummon(cid)
           end
       end
   end
end

function HunterEvent.getPlayersInArena()
   local p = {}
   for _, cid in ipairs(getPlayersOnline()) do
       if HunterEvent.getPlayerStorage(cid) > 0 then
           table.insert(p, {pid = cid, pos = getCreaturePosition(cid), lifes = HunterEvent.getPlayerStorage(cid)})
       end
   end
   return p
end

function HunterEvent.checkMaxTime()
   if getGlobalStorageValue(HunterEvent.config.globalStatus) == 1 then
       local p = HunterEvent.getPlayersInArena()
       for i = 1, #p do
           HunterEvent.setPlayerStorage(p[i].pid, 0)
           local s = getCreatureSummons(p[i].pid)
           if table.maxn(s) > 0 then
               for _, sid in ipairs(s) do
                   doRemoveCreature(sid)
               end
           end
           doTeleportThing(p[i].pid, HunterEvent.config.kickPos)
           doSendMagicEffect(p[i].pos, CONST_ME_TELEPORT)
       end
       doBroadcastMessage('[HunterEvent]: Exceed maximum hunt time!!')
       setGlobalStorageValue(HunterEvent.config.globalStatus, 0)
   end
end

function HunterEvent.startArena()
   if getGlobalStorageValue(HunterEvent.config.globalStatus) <= 0 then
       if HunterEvent.countPlayers() >= HunterEvent.config.minPlayers then
           HunterEvent.addPlayersToArena()
           setGlobalStorageValue(HunterEvent.config.globalStatus, 1)
           return doBroadcastMessage('[Hunter Event]: The hunt has started!! Good luck to everyone!!') and addEvent(HunterEvent.checkMaxTime, HunterEvent.config.maxDuration * 60 * 1000)
       else
           return doBroadcastMessage('[Hunter Event]: Not enough players!!') and HunterEvent.kickPlayersFromWaitingArena()
       end
   end
end

> /path/to/server/data/creaturescripts/creaturescripts.xml
XML:
<event type="statschange" name="hunter_event_attack" event="script" value="hunter_event_attack.lua"/>

> /path/to/server/data/creaturescripts/scripts/hunter_event_attack.lua
Lua:
function onStatsChange(target, cid, type, combat, value)
   if getGlobalStorageValue(HunterEvent.config.globalStatus) == 1 then
       if isMonster(cid) and isPlayer(target) and HunterEvent.getPlayerStorage(target) > 0 and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then
           return HunterEvent.removePlayerLife(target) and false
       elseif isPlayer(cid) and isPlayer(target) and HunterEvent.getPlayerStorage(target) > 0 and HunterEvent.getPlayerStorage(cid) > 0 and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then
           return doSendMagicEffect(getCreaturePosition(target), CONST_ME_POFF) and false
       end
   end
   return true
end

> /path/to/server/data/creaturescripts/scripts/login.lua
Lua:
if getGlobalStorageValue(HunterEvent.config.globalStatus) == 0 and isInRange(getCreaturePosition(cid), HunterEvent.config.playArea.from, HunterEvent.config.playArea.to) then
  doTeleportThing(cid, HunterEvent.config.kickPos)
  doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
end
registerCreatureEvent(cid, "hunter_event_attack")

> /path/to/server/data/globalevents/globalevents.xml
XML:
<globalevent name="hunter_event_start" type="start" event="script" value="hunter_event_startup.lua"/>
<globalevent name="hunter_event_lifes" interval="2" event="script" value="hunter_event_lifes.lua"/>
<globalevent name="hunter_event_start" time="01:16" event="script" value="hunter_event_start.lua"/>

> /path/to/server/data/globalevents/scripts/hunter_event_lifes.lua
Lua:
function onThink(interval, lastExecution, thinkInterval)
   if getGlobalStorageValue(HunterEvent.config.globalStatus) > 0 then
       local p = HunterEvent.getPlayersInArena()
       for i = 1, #p do
           doSendAnimatedText(p[i].pos, p[i].lifes, COLOR_RED)
       end
   end
   return true
end

> /path/to/server/data/globalevents/scripts/hunter_event_start.lua
Lua:
function onTimer()
   doBroadcastMessage('[Hunter Event]: Hunter Event starting in 5 minutes!!')
   addEvent(doBroadcastMessage, 2 * 60 * 1000, '[Hunter Event]: Hunter Event starting in 3 minutes!!')
   addEvent(doBroadcastMessage, 4 * 60 * 1000, '[Hunter Event]: Hunter Event starting in 1 minute!!')
   addEvent(HunterEvent.startArena, 5 * 60 * 1000)
   return true
end

> /path/to/server/data/globalevents/scripts/hunter_event_startup.lua
Lua:
function onStartup()
   db.executeQuery("UPDATE `player_storage` SET `value` = 0 WHERE `key` = " .. HunterEvent.config.isOnArena .. ";")
   doSetStorage(HunterEvent.config.globalStatus, 0)
   return true
end

> /path/to/server/data/monster/hunter_event/hunter.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Hunter" nameDescription="a hunter" race="blood" experience="150" speed="600" manacost="0">
   <health now="150" max="150"/>
   <look type="129" head="95" body="116" legs="121" feet="115" corpse="6080"/>
   <targetchange interval="5000" chance="8"/>
   <strategy attack="100" defense="0"/>
   <flags>
       <flag summonable="0"/>
       <flag attackable="0"/>
       <flag hostile="1"/>
       <flag illusionable="1"/>
       <flag convinceable="1"/>
       <flag pushable="0"/>
       <flag canpushitems="1"/>
       <flag canpushcreatures="0"/>
       <flag targetdistance="1"/>
       <flag staticattack="90"/>
       <flag runonhealth="10"/>
   </flags>
   <attacks>
       <attack name="melee" interval="2000" min="-10000" max="-20000"/>
   </attacks>
   <defenses armor="8" defense="10"/>
   <elements>
       <element holyPercent="20"/>
       <element physicalPercent="-20"/>
   </elements>
   <immunities>
       <immunity paralyze="1"/>
       <immunity invisible="1"/>
       <immunity fire="1"/>
       <immunity energy="1"/>
       <immunity poison="1"/>
   </immunities>
   <voices interval="5000" chance="10">
       <voice sentence="Guess who we're hunting, haha!"/>
       <voice sentence="Guess who we are hunting!"/>
       <voice sentence="Bullseye!"/>
       <voice sentence="You'll make a nice trophy!"/>
   </voices>
   <loot>
       <item id="2148" countmax="20" chance="100000"/><!-- gold coin -->
       <item id="2465" chance="10000"/><!-- brass armor -->
       <item id="2461" chance="10000"/><!-- leather helmet -->
       <item id="2649" chance="10000"/><!-- leather legs -->
       <item id="2671" countmax="2" chance="20000"/><!-- ham -->
       <item id="5875" chance="5000"/><!-- sniper gloves -->
       <item id="1987" chance="100000"><!-- bag -->
           <inside>
               <item id="2456" chance="6666"/><!-- bow -->
               <item id="2544" countmax="15" chance="10000"/><!-- arrow -->
               <item id="2546" countmax="5" chance="10000"/><!-- burst arrow -->
               <item id="2147" countmax="2" chance="3333"/><!-- small ruby -->
               <item id="2675" countmax="4" chance="6666"/><!-- orange -->
               <item id="2690" countmax="4" chance="6666"/><!-- roll -->
               <item id="2050" chance="20000"/><!-- torch -->
               <item id="2478" chance="3333"/><!-- brass legs -->
               <item id="2652" chance="2222"/><!-- green tunic -->
               <item id="2201" chance="2500"/><!-- dragon necklace -->
           </inside>
       </item>
   </loot>
</monster>

> /path/to/server/data/monster/monsters.xml
XML:
<monster name="Hunter Event" file="hunter_event/hunter.xml"/>
 
Last edited by a moderator:
Can you give us a paragraph or two of what this script does because I watched a few moments of the video and all i seen was you editing code but then i skipped ahead to almost the end and seen you attacking a red skull while there were hunters spawned.. so I am unsure what is really going on with this hunter system.
Thanks! :)
 
Can you give us a paragraph or two of what this script does because I watched a few moments of the video and all i seen was you editing code but then i skipped ahead to almost the end and seen you attacking a red skull while there were hunters spawned.. so I am unsure what is really going on with this hunter system.
Thanks! :)

Yeah, I'll do it. But, I must admit I thought a lot more people had seen it before.

The first time I saw it was in Spider OT (SpiderOT). It is about hunting each other until there is only one player left in the arena. But, how do you exactly hunt each other if you can't deal damage to your enemies? Easy, when you enter the arena you are given a Hunter that will remove a player's life when touching him. You lose when you have no lifes left.

Since Spider OT is a high-exp server and, at that time, it had a large amount of active players, fighting in this event was super fun :p
 
Back
Top