Setras Posted January 31, 2011 Share Posted January 31, 2011 We had a discuss in one of add-on's topics, but i had thought that everyone should know somevery usefull tricks you can do in AO. So here's the first one: ----------------========(I)========---------------- Creating your own timer. It's helpfull if you need something to renew faster or slower than each second. An example of what it is and how it could be used is in TS3Viewer addon. It shows you who's speaking in your TS room in real time, and sometimes it happens so that you hear multiple people giving short comments and so on and renewing the window each second i not fast enough. What you need is(isuppose you know how to create add-ons and widgets as well as basics of Lua): A dummy widget of any size and position, even a tootally transparent 1x1 pixel one would do the job. Let's say it's called wtKenny. Also we need any WidgetPlayEffect, like fade effect, size or move are OK as well. And a handler with a function that will repeatedley run that effect. So here's a lil example of a timer using widget wtKenny and triggering each 0.25 seconds (250 milliseconds): Code: function timer(params) if params.effectType == ET_FADE and params.wtOwner:IsEqual( wtKenny ) then wtKenny:PlayFadeEffect( 1.0, 1.0, 250, EA_MONOTONOUS_INCREASE ) userMods.SendEvent( "EVENT_250_MS_TIMER", {sender = common.GetAddonName()} ) end end function MyFunctionHere(params) --Insert your code here end function Init() wtKenny = mainForm:GetChildChecked( "Kenny", false ) common.RegisterEventHandler( timer, "EVENT_EFFECT_FINISHED" ) common.RegisterEventHandler( MyFunctionHere, "EVENT_250_MS_TIMER" ) wtKenny:PlayFadeEffect( 1.0, 1.0, 250, EA_MONOTONOUS_INCREASE ) end Init() In this example an event called "EVENT_250_MS_TIMER" is sent to every user addon each 250 milliseconds with params.sender equal to your addon's name. CAUTION /!\ Use unique event name or perform a check to ensure that you've got an event from your timer, because otherwise you'll run functions triggered by other addons, which, for example, could make you run functions twice or even more often than expected! CAUTION /!\ Second parameter in userMods.SendEvent must be a table! ----------------========(II)========---------------- Today evening i'll edit this post and show you how to find direction to target, and maybe tomorrow evening - even a distance to target ;-) Quote Link to comment Share on other sites More sharing options...
Nikon Posted February 2, 2011 Share Posted February 2, 2011 Quote: Today evening i'll edit this post and show you how to find direction to target, and maybe tomorrow evening - even a distance to target ;-) ? Quote Link to comment Share on other sites More sharing options...
Setras Posted February 3, 2011 Author Share Posted February 3, 2011 Yeah, job and stuff... Sleepless night and after i was working all day long, came back 30 minutes ago and i already want to sleep, sry... But here is a LITTLE tip: Attach widget 2D and observe it's on-screen coordinates and player camera rotation. Quote Link to comment Share on other sites More sharing options...
Recommended Posts