ArcEmu: Lua Timer - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read http://arcemu.org/fo...showtopic=26903
dfighter  : (01 January 2013 - 05:56 PM) Arcemu wishes you all a happy new year!
Hasbro  : (12 September 2012 - 10:01 AM) Please excuse our outage from the web! Our web host had a major malfunction!
dfighter  : (01 September 2012 - 04:05 PM) Since the spam bots just don't want to stop, I've enabled admin verification when registering.
dfighter  : (23 January 2012 - 09:56 PM) Please note that from now on you will need to confirm your email on the wiki in order to edit it!
Hasbro  : (31 December 2011 - 12:50 PM) Happy New Years all!
Navid  : (26 December 2011 - 04:09 AM) Merry Christmas !!!!!! Happy holidays all :)
WAmadeus  : (24 December 2011 - 03:54 PM) Merry Christmas to all!
dfighter  : (24 December 2011 - 11:05 AM) The Arcemu team wishes y'all a Merry Christmukkah!
Hasbro  : (05 October 2011 - 12:53 PM) Looking for web designers for upcoming web related project. If you're interested in designing user interfaces contact me
dfighter  : (02 September 2011 - 03:47 PM) So who here wants vehicles in Arcemu? :P http://arcemu.org/fo...showtopic=25440
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to irc.freenode.net join channel #arcemu /server irc.freenode.net:6667 /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check http://arcemu.org/fo...showtopic=25274
Hasbro  : (20 May 2011 - 05:27 PM) Looking for people experienced with CMake configuration and setup! Contact me asap
Hasbro  : (15 May 2011 - 05:03 PM) ArcEmu is recruiting C++ programmers, contact Hasbro if interested.
paroxysm  : (03 May 2011 - 06:26 PM) Updated luabridge gossip example to describe the whole gossip creation process rather than just how to create menu. Gossip tutorial
paroxysm  : (23 April 2011 - 11:35 AM) Lua writers can refer to the Luabridge Tutorials section in the Wiki to learn how to write gossip code correctly.
Hasbro  : (20 April 2011 - 05:22 PM) Thank you for your continuous contribution of bug reports, we are working on them.
Hasbro  : (17 April 2011 - 03:20 AM) Please consider donating to support our bills. Donations can be sent using PayPal to donations@arcemu.org - Thank you for your support.
paroxysm  : (10 April 2011 - 12:43 AM) Refer to the Luabridge Tutorials section in the Wiki to learn the new syntax of luabridge.
Resize Shouts Area

Page 1 of 1

Lua Timer

#1 User is offline   IllidanS4 

  • Newbie
  • Group: Members
  • Posts: 6
  • Joined: 12-August 12
  • Gender:Male
  • Server OS:Windows

Posted 14 August 2012 - 12:19 PM

Hi, how to create a timer in Lua which will run a function periodically?
0

#2 User is offline   dfighter 

  • Titles are overrated
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Administrator
  • Posts: 5,189
  • Joined: 14-June 08
  • IRC:dfighter
  • Gender:Male
  • Server OS:Linux

Posted 14 August 2012 - 12:28 PM

You can use the RegisterTimedEvent function for this.
http://arcemu.org/wi...isterTimedEvent

However the example on the wiki is wrong, you should never pass parameters to it that can be removed while the event is still running.
( For example, you start the timer, and the player logs out, the timed event fires and the player is no longer there, so it will end up crashing your server )

Alternatively you can use
RegisterEvent
http://arcemu.org/wi...a_RegisterEvent
This works with Units directly ( Players are also units )
"The demand for free goods is infinite."
0

#3 User is offline   IllidanS4 

  • Newbie
  • Group: Members
  • Posts: 6
  • Joined: 12-August 12
  • Gender:Male
  • Server OS:Windows

Posted 14 August 2012 - 12:29 PM

Oh, thanks, And how to kill it?
0

#4 User is offline   dfighter 

  • Titles are overrated
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Administrator
  • Posts: 5,189
  • Joined: 14-June 08
  • IRC:dfighter
  • Gender:Male
  • Server OS:Linux

Posted 14 August 2012 - 12:36 PM

View PostIllidanS4, on 14 August 2012 - 12:29 PM, said:

Oh, thanks, And how to kill it?

Well you have RemoveTimedEvent for the first.
I have no idea about the second, but you can define tick count, in both of these.
"The demand for free goods is infinite."
0

#5 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 14 August 2012 - 12:36 PM

By registering the timer in the function again.

function GurubashiArenaEvent(pUnit, Event)
-- do somthing 
	print("test")
	RegisterTimedEvent("GurubashiArenaEvent", 5000, 1)
end

RegisterTimedEvent("GurubashiArenaEvent", 5000, 1)


Be aware not to refer in such functions to any NPCs ! Because you don't know if the NPC is valid.

May RegisterTimedEvent("GurubashiArenaEvent", 5000, 0) would make an endless loop (not sure about). But I have noticed that such constellations makes problems if you use reloadscripts command. Because reloadscripts doesn't unregister events.


Edit: Ohhh, 3 posts while I was writing again :D My fingers are not fast enough.
Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#6 User is offline   dfighter 

  • Titles are overrated
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Administrator
  • Posts: 5,189
  • Joined: 14-June 08
  • IRC:dfighter
  • Gender:Male
  • Server OS:Linux

Posted 14 August 2012 - 12:40 PM

View PostMagnifikator, on 14 August 2012 - 12:36 PM, said:

But I have noticed that such constellations makes problems if you use reloadscripts command. Because reloadscripts doesn't unregister events.

If you open a ticket on github about this I might be able to help with it :)

View PostMagnifikator, on 14 August 2012 - 12:36 PM, said:

Edit: Ohhh, 3 posts while I was writing again :D My fingers are not fast enough.

That's not very good, last time I checked girls like fast fingers :P
"The demand for free goods is infinite."
0

#7 User is offline   IllidanS4 

  • Newbie
  • Group: Members
  • Posts: 6
  • Joined: 12-August 12
  • Gender:Male
  • Server OS:Windows

Posted 14 August 2012 - 12:40 PM

Thanks for you help. I am trying to create something like instance portal. When player is close to some location, I want to teleport him somewhere. Can you provide me the best solution?
0

#8 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 14 August 2012 - 12:52 PM

View Postdfighter, on 14 August 2012 - 12:40 PM, said:

If you open a ticket on github about this I might be able to help with it

Yeah, yeah, but please patch this issues 244, 236 (same as issue as 184) first and check an easy one like 211. And than the girls.

Edit:
IllidanS4 question remembers me exactly to the GurubashiArena task I had to solve in earlier time.

Every 3 hours I had to look if there are players in the arena. Either the arena starts or not.

Here are 2 snippets may it helps:

-- Checks how much players are in the zone
function PlayersInArena()
	local count = 0
	local level = 0
	for place, plrs in pairs(GetPlayersInWorld()) do
		if (plrs) then
			if (plrs:GetAreaId() == 2177) then 	-- Gurubashi area ID
				level = level + plrs:GetPlayerLevel()
				count = count + 1
			end
		end
	end
	return count, level
end

function GurubashiArena4(pUnit)
	ArenaPlayers, PlayerLevel = PlayersInArena()
	if (ArenaPlayers>1) then
		-- (St�rtebrecher) 
		SendWorldMsg("Short John Mithrilis in the Gurubashi Arena and "..ArenaPlayers.." heroes ("..PlayerLevel.."). Arena can start.")
		ItsShowtime = true
		
	else
		SendWorldMsg("Gurubashi Arena will not start. Must be minimum 2 players.")
	end
	RegisterTimedEvent("GurubashiArenaEvent", 1, 1)
end

Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#9 User is offline   dfighter 

  • Titles are overrated
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Administrator
  • Posts: 5,189
  • Joined: 14-June 08
  • IRC:dfighter
  • Gender:Male
  • Server OS:Linux

Posted 14 August 2012 - 12:56 PM

View PostMagnifikator, on 14 August 2012 - 12:52 PM, said:

Yeah, yeah, but please patch this issues 244, 236 (same as issue as 184) first and check an easy one like 211. And than the girls.

I will try to make some time in the weekend.
"The demand for free goods is infinite."
0

#10 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 14 August 2012 - 01:05 PM

View Postdfighter, on 14 August 2012 - 12:56 PM, said:

I will try to make some time in the weekend.

Thanks! :)


Edit:

And to IllidanS4:

I wouldn't recommend to do your task with timers. Because I had to check only every 3 hours. But you may have to check that every 1-5 seconds. So your timer triggers up to 86000 times per day to check if there is a player on this location. :D

Better to spawn a go or a npc and do some action/events with them and after that you teleport the player.
Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#11 User is offline   IllidanS4 

  • Newbie
  • Group: Members
  • Posts: 6
  • Joined: 12-August 12
  • Gender:Male
  • Server OS:Windows

Posted 14 August 2012 - 01:12 PM

View PostMagnifikator, on 14 August 2012 - 12:52 PM, said:

Yeah, yeah, but please patch this issues 244, 236 (same as issue as 184) first and check an easy one like 211. And than the girls.

Edit:
IllidanS4 question remembers me exactly to the GurubashiArena task I had to solve in earlier time.

Every 3 hours I had to look if there are players in the arena. Either the arena starts or not.

Here are 2 snippets may it helps:

-- Checks how much players are in the zone
function PlayersInArena()
	local count = 0
	local level = 0
	for place, plrs in pairs(GetPlayersInWorld()) do
		if (plrs) then
			if (plrs:GetAreaId() == 2177) then 	-- Gurubashi area ID
				level = level + plrs:GetPlayerLevel()
				count = count + 1
			end
		end
	end
	return count, level
end

function GurubashiArena4(pUnit)
	ArenaPlayers, PlayerLevel = PlayersInArena()
	if (ArenaPlayers>1) then
		-- (St�rtebrecher) 
		SendWorldMsg("Short John Mithrilis in the Gurubashi Arena and "..ArenaPlayers.." heroes ("..PlayerLevel.."). Arena can start.")
		ItsShowtime = true
		
	else
		SendWorldMsg("Gurubashi Arena will not start. Must be minimum 2 players.")
	end
	RegisterTimedEvent("GurubashiArenaEvent", 1, 1)
end



Thanks a lot, I will use this. One more problem. When starting a taxi flight, the mount is very slow. After teleport, it flies as usual. Got addons ArcGM and ArcCorrect.

Edit:

View PostMagnifikator, on 14 August 2012 - 01:05 PM, said:

Thanks! :)


Edit:

And to IllidanS4:

I wouldn't recommend to do your task with timers. Because I had to check only every 3 hours. But you may have to check that every 1-5 seconds. So your timer triggers up to 86000 times per day to check if there is a player on this location. :D

Better to spawn a go or a npc and do some action/events with them and after that you teleport the player.


Then wouldn't it be nice when calling AddPathNode and map is different from player's to teleport them there? How can I officially request it?
0

#12 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 14 August 2012 - 02:00 PM

I don't understand what you are going to try.

You want to teleport the player while he is flying over some location ?
Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#13 User is offline   IllidanS4 

  • Newbie
  • Group: Members
  • Posts: 6
  • Joined: 12-August 12
  • Gender:Male
  • Server OS:Windows

Posted 14 August 2012 - 02:06 PM

View PostMagnifikator, on 14 August 2012 - 02:00 PM, said:

I don't understand what you are going to try.

You want to teleport the player while he is flying over some location ?


Exactly!
Player starts taxi flight. Then he is flying far from the land above the sea. Teleport him to another map. Continue with flying.
0

#14 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 15 August 2012 - 07:11 AM

In that case, I also would after starting the taxi flight periodically check the location. If it's out of range teleport the player.

However I never made such things, but you can try it in Lua and let us know if and how it works. :D
Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#15 User is offline   IllidanS4 

  • Newbie
  • Group: Members
  • Posts: 6
  • Joined: 12-August 12
  • Gender:Male
  • Server OS:Windows

Posted 15 August 2012 - 07:40 AM

local flightTimer = nil
local timerCount = 0

function TaxiFlight_OnTimer()
  for k,v in pairs(GetPlayersInMap(0)) do
    if v:CalcToDistance(4887.938477, -2425.30859325, 49.236454) <= 10 then
      v:Teleport(530, 7521.054688, -4925.238281, 49.185516, 0)
      timerCount = timerCount - 1
    end
  end
  if timerCount == 0 and flightTimer ~= nil then
    RemoveTimedEvent(flightTimer)
    flightTimer = nil
  end
end

local function OnGossipTalk(pUnit, event, pPlayer)
  pUnit:GossipCreateMenu(50, pPlayer, 0)
  pUnit:GossipMenuAddItem(0, "Take me to Shalandis Isle", 1, 0)
  pUnit:GossipSendMenu(pPlayer)
end

local function OnGossipSelect(pUnit, event, pPlayer, id, intid, code)
  local taxi = LuaTaxi:CreateTaxi()
  taxi:AddPathNode(0, 4288.13, -2843.26, 18.3)
  taxi:AddPathNode(0, 4277.93, -2806.04, 20)
  taxi:AddPathNode(0, 4270.85, -2780.89, 25.23)
  taxi:AddPathNode(0, 4302.07, -2707.44, 27.69)
  taxi:AddPathNode(0, 4341.41, -2674.63, 30)
  taxi:AddPathNode(0, 4887.938477, -2425.30859325, 49.236454)
  taxi:AddPathNode(530, 7583, -4934, 49)
  taxi:AddPathNode(530, 7638, -4972, 46)
  taxi:AddPathNode(530, 7762, -5184, 38)
  taxi:AddPathNode(530, 7831, -5311, 40)
  taxi:AddPathNode(530, 7844, -5444, 39)
  taxi:AddPathNode(530, 7824, -5534, 34)
  taxi:AddPathNode(530, 7807, -5589, 27)
  taxi:AddPathNode(530, 7775, -5635, 19)
  pPlayer:StartTaxi(taxi, 1936)
  if flightTimer == nil then
    flightTimer = RegisterTimedEvent("TaxiFlight_OnTimer", 1000, 0)
  end
  timerCount = timerCount + 1
  pPlayer:GossipComplete()
end

RegisterUnitGossipEvent(5005902, 1, OnGossipTalk)
RegisterUnitGossipEvent(5005902, 2, OnGossipSelect)

The problem is when player starts taxi, it is very slow. When I remove nodes in 530, it has normal speed.
0

Share this topic:


Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users