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

Lua LMS - BAD interval

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,249
Solutions
71
Reaction score
621
Location
Hell
So I have this event installed on my server and it seems to be working exactly as it should but the only problem is that when there's one player left in the arena he/she has to wait 2 hours in order to be tp back to temple..

7 200 000 ms = 2h
7 320 000 ms = 2h 2min (2min is for waiting in the "waiting room")
HTML:
        <globalevent name="LastMan" interval="7200000" event="script" value="LMS/lastman.lua"/>
        <globalevent name="arena" interval="7320000" event="script" value="LMS/arena.lua"/>

now since arena.lua is being executed every 2h + 2min. It is not able to make another scan on the arena after it has been executed the first time.

What is the solution to this?
 
@GOD Wille

Lastman.lua
Lua:
 local createpos = {x = 32344, y = 32231, z = 7} -- Every 2h where will the Teleport Appear
 local topos = {x = 32532, y = 32220, z = 7} -- Where will the Teleport take you
 local msg = "Last man standing event TP has now been closed! It will open again in 2 hours! All participants get Ready for a Fight!"
 local timetoclose = 120 -- in second
 local function remove()
    local tp = getTileItemById(createpos,1387).uid
    if tp ~= 0 then
        doRemoveItem(tp)
        doBroadcastMessage(msg)
    end
 end
 function onThink(interval)
    doCreateTeleport(1387, topos, createpos)
    doBroadcastMessage("Last man standing event TP is now open!\nCatch the teleport within "..timetoclose.." seconds! Teleport is Located in Temple.")
    addEvent(remove,timetoclose*1000)
    return true
 end

Arena.lua
Lua:
local t = {
   tmp = {
       {x = 32535, y = 32219, z = 7}, -- northwest corner of area where players must stand in order to join the event
       {x = 32539, y = 32221, z = 7} -- south east corner
   },
   arena = {
       {x = 32541, y = 32215, z = 7},
       {x = 32553, y = 32225, z = 7}, -- se corner of arena
       {x = 32547, y = 32220, z = 7} -- center of arena
   },
   
   from = {x = 32541, y = 32215, z = 7}, -- top left cornor of the playground (random players teleportation)
       to = {x = 32553, y = 32225, z = 7}, -- bottom right cornor of the playground (random players teleportation)
   
   minPlayers = 2, -- min players required to start the battle
   noPlayers = 1, -- no players
   prize = {2160} -- rewards
}
local kick = 0

function onThink()
   local arenaPlayers = {}

   for x = t.arena[1].x, t.arena[2].x do
       for y = t.arena[1].y, t.arena[2].y do
           for z = t.arena[1].z, t.arena[2].z do
               local pos = {x = x, y = y, z = z}
               local n = getTileInfo(pos).creatures
               if n ~= 0 then
                   pos.stackpos = 1
                   local c = getThingfromPos(pos)
                   while c.uid ~= 0 do
                       if c.itemid == 1 and c.type == 1 then
                           table.insert(arenaPlayers, c.uid)
                           if #arenaPlayers == n then
                               break
                           end
                       end
                       pos.stackpos = pos.stackpos + 1
                       c = getThingfromPos(pos)
                   end
               end
           end
       end
   end

   if #arenaPlayers == 1 then
       local p = getPlayerMasterPos(arenaPlayers[1])
           doTeleportThing(arenaPlayers[1], {x=32369, y=32241, z=7})
       doSendMagicEffect(p, CONST_ME_TELEPORT)
       doPlayerSendTextMessage(arenaPlayers[1], MESSAGE_STATUS_CONSOLE_BLUE, "You won a battle and received your reward.")
       doBroadcastMessage(getCreatureName(arenaPlayers[1]) .." won a Last Man Standing battle.")
       doPlayerAddItem(arenaPlayers[1], t.prize[math.random(#t.prize)], 10)
       kick = 0
   elseif #arenaPlayers > 1 then
       if kick == 0 then
           kick = os.time()
       else
           if os.time() - kick >= 840 then
               kick = 0
               for i = 1, #arenaPlayers do
                   doTeleportThing(arenaPlayers[i], {x=32369, y=32241, z=7})
                   doPlayerSendTextMessage(arenaPlayers[i], MESSAGE_STATUS_WARNING, "Too even, try harder next time.")
               end
           end
       end
   elseif #arenaPlayers == 0 then
       kick = 0
       
       local players = {}
       for x = t.tmp[1].x, t.tmp[2].x do
           for y = t.tmp[1].y, t.tmp[2].y do
               for z = t.tmp[1].z, t.tmp[2].z do
                   local c = getTopCreature({x = x, y = y, z = z})
                   if c.type == 1 then
                       table.insert(players, c.uid)
                   end
               end
           end
       end

       if #players >= t.minPlayers then
           for i = 1, #players do
               local p = {x = math.random(t.from.x, t.to.x), y = math.random(t.from.y, t.to.y), z = math.random(t.from.z, t.to.z)}
               doTeleportThing(players[i], p)
               doSendMagicEffect(p, CONST_ME_TELEPORT)
               doPlayerSendTextMessage(players[i], MESSAGE_STATUS_WARNING, "The battle begins. Survive for glory!")
           end
       --[[else
           for i = 1, #players do
               doTeleportThing(players[i], {x=32369, y=32240, z=7})
               doPlayerSendTextMessage(players[i], MESSAGE_STATUS_WARNING, "The event didn't start because there isn't enough players in area!")
           end]]
       end
   end
   return true
end
 
Don't you already have a thread of this?

edit:nvm its someone else with the same code.

You should change
Lua:
local createpos = {x = 32344, y = 32231, z = 7} -- Every 2h where will the Teleport Appear
 local topos = {x = 32532, y = 32220, z = 7} -- Where will the Teleport take you
 local msg = "Last man standing event TP has now been closed! It will open again in 2 hours! All participants get Ready for a Fight!"
 local timetoclose = 120 -- in second
 local function remove()
    local tp = getTileItemById(createpos,1387).uid
    if tp ~= 0 then
        doRemoveItem(tp)
        doBroadcastMessage(msg)
    end
 end
 function onThink(interval)
    doCreateTeleport(1387, topos, createpos)
    doBroadcastMessage("Last man standing event TP is now open!\nCatch the teleport within "..timetoclose.." seconds! Teleport is Located in Temple.")
    addEvent(remove,timetoclose*1000)
    return true
 end

to

Lua:
local createpos = {x = 32344, y = 32231, z = 7} -- Every 2h where will the Teleport Appear
 local topos = {x = 32532, y = 32220, z = 7} -- Where will the Teleport take you
 local msg = "Last man standing event TP has now been closed! It will open again in 2 hours! All participants get Ready for a Fight!"
 local timetoclose = 120 -- in second

 function onThink(interval)
    local teleport = doCreateTeleport(1387, topos, createpos)
    doBroadcastMessage("Last man standing event TP is now open!\nCatch the teleport within "..timetoclose.." seconds! Teleport is Located in Temple.")
    addEvent(teleport:remove(),timetoclose*1000)
    return true
 end
 
@Itutorial Thats not the problem.. the problem is that winner has to wait 2h+2min to be TP'd back to temple. Why? because arena.lua is being executed 2 minutes after lastman.lua (tp creation) - players will have 2minnutes to catch the TP..
 
I know thats not the problem. I was just giving you a better code for that. Honestly, this LMS code is trash IMO. I would rather give you mine then mess with that one.

There should be a onKill code that stops LMS when the second to last player is killed. That's the fastest way to go about it.
 
Last edited by a moderator:
Its set up for TFS 1.2...I am too lazy to transfer.... I can give you the codes but you have to change them to work with your distro. It shouldn't be to hard.
 
I fixed it for you.


Delete everything you have from lms (last man standing)
and download lms.rar, add in globalevents...



<globalevent name="LastMan" time="19:00" event="script" value="lms/lastman.lua"/>
<globalevent name="arena" time="19:02" event="script" value="lms/arena.lua"/>
<globalevent name="inito" interval="30000" event="script" value="lms/init.lua"/>


19:00 tp open
19:02 event start
30000 -- 30 seconds to the winner to win the prize.


scan:
Antivirus scan for 390f7c503ea1ca3c302fe245e60277101989dd500eccdf85478bd89db367ed7e at UTC - VirusTotal

bye :D
 

Attachments

I fixed it for you.


Delete everything you have from lms (last man standing)
and download lms.rar, add in globalevents...



<globalevent name="LastMan" time="19:00" event="script" value="lms/lastman.lua"/>
<globalevent name="arena" time="19:02" event="script" value="lms/arena.lua"/>
<globalevent name="inito" interval="30000" event="script" value="lms/init.lua"/>


19:00 tp open
19:02 event start
30000 -- 30 seconds to the winner to win the prize.


scan:
Antivirus scan for 390f7c503ea1ca3c302fe245e60277101989dd500eccdf85478bd89db367ed7e at UTC - VirusTotal

bye :D

So I can just as good use interval on lastman & arena in order to execute the event every 2h ?

Thank you very much.
 
Yes, but to perform the event every 2 hours would have to change the lastman and arena to "onThink" instead of "onTime" and the tags too

Sorry my bad english XD
 
Back
Top