给win10 command prompt 也设置代理, 使其能正常访问npm,pip等

如果本地 shadowsock 的端口是 1080 ,在 command prompt 敲入:

set HTTP_PROXY=http://127.0.0.1:1080

set HTTPS_PROXY=http://127.0.0.1:1080

即可, 效果维持到关闭此 command prompt 窗口为止

测试, curl www.google.com , 如果能得到返回, 说明成功


来源 :  https://github.com/shadowsocks/shadowsocks-windows/issues/1489

 


如果是 mac 电脑

设置 :

 

取消设置 :

 

 

How to create a nodejs login app with session

 

  •   建立目录  NodeJSLogin , 进入目录

    之后,  执行

    意为:  用ejs 为引擎, 用 express-generator做脚手架工具 , 建立一个 名为 nodejslogin 的项目。

执行此命令之后 , express-genertator 会自动生成很多目录和文件


进入 nodejslogin 目录, 执行

如果是 linux 机器, 执行 :

之后, 在其他机器访问 :

http://IP:3000 即可看到初始网页

 


但是 , opentok程序明显没有用到 express-generator , 证明就是在 package.json 文件中, 没有 express-generator, 只有 “express”: “^4.0.0”,

也就是说, opentok没有用express脚手架 。

这是如何做到的 ?

答: 这是因为 opentok的 rest api 服务用的是 :

https://github.com/AntonioMA/swagger-boilerplate

在这个package 内部, 调用了 express . 和 express session

 

并且设置了例如

app.set(‘view engine’, ‘ejs’);  等 , 所以在 opentok-rtc主程序的server.js 没写这些


如何使用 ejs 模板 ,  见:

https://scotch.io/tutorials/use-ejs-to-template-your-node-application


可以把每一个页面都理解为 rest api request 的 response, 只不过有的 比如 serverhealth返回 json串, 有的返回 html

 

 

 

tokbox webrtc analyze

  • login account :   mzcw2011@sina.cn
  • set tb_api_key 46419702
    set tb_api_secret b8f17a054ccde74e68453464ad6b1c879a75d030

 

  • http://lesscss.org/features/#detached-rulesets-feature — 教程

 

  • How to compile less to css , first use bower download third party component , then create own less which use above component , final use grunt compile it

  •  

     

first new a “bowe.json” file ,which content  is :

then ,  install and download bower

bower install mean install the package specified in bower.json , in this case , tokbox company use the package :

https://github.com/tef-components/

this package is a free less lib for button, theme, text-input , etc .


For how to learn less , see

https://www.tutorialspoint.com/less/nested_rules.htm

a beginner less introduce in Chinese :

https://www.tutorialspoint.com/less/nested_rules.htm

 

  • how to write rest server using swagger and node.js

a) first , how to do a simple node.js server

https://www.codementor.io/olatundegaruba/nodejs-restful-apis-in-10-minutes-q0sgsfhbd

更好的是直接去看 expressjs 的 hello world :  https://expressjs.com/en/starter/hello-world.html

b) opentok-rtc ‘s server is made by swager-boilerplate , which address is :

https://github.com/AntonioMA/swagger-boilerplate

In this site , it say : Simple implementation of a Node Express server described using a Swagger API, in JSON form.

how to make a Node Express server is in point a)

 for swagger , here is a introduce article :

https://mherman.org/blog/swagger-and-nodejs/

c)   swagger-boilerplate 用到了  .yml 文件作为 rest server api 定义文件 , yml 文件2个空格代表一个层级, 多个键值对用 – 分开 

swagger api 的在线编辑界面  http://editor.swagger.io/

如何做一个简单的 swagger api :  https://www.blazemeter.com/blog/create-your-first-openapi-definition-with-swagger-editor/

d) 怎么返回具体的页面

1)  可以在 expressjs 的js 文件 用  sendFile  返回  html , 但这里不是

2)  注意到 package.json 有   “ejs”: “^2.5.5”

3) 实际使用 的方法是 res.render(

4) how to use expressjs and ejs :

https://scotch.io/tutorials/use-ejs-to-template-your-node-application

here is a example : https://mherman.org/blog/swagger-and-nodejs/

  • How to debug node.js
  • JS 部分
  • How and where to connect redis ?

显示所有key    :


对某一个key取value

这里假定 邮箱是key , server 端口 6379


如何从 node.js 存到 redis server ?

在 serverMethods.js中, register的post方法 , 写:

server停止后 , redis 存进去的数据还在


删除


ServerPersistence 是这样被初始化的 :

 

SwaggerBP是从这里

var SwaggerBP = require(‘swagger-boilerplate’);


room 相关的 api 接口

getRoomArchive  ——– 得到room 的所有 archive ,  用 roomname 做参数

url 为 :   https://47.52.61.15:8123/room/111/archive

首先, archive存在哪里 ?

archive 可以被保存的前提是 :

Important: You can only archive sessions that use the OpenTok                                   Media Router (sessions with the media mode set to routed).

就是说只有特定类型的session, 它的archive 才可以被保存 。

如果配置了微软云或者亚马逊云, 会存到配置 ;  如果没有, 会存到 tokbox云, 只保存72小时 。

用户是否只能 record live stream as archive , 能不能上传录制好的视频

getroom 是建立一个临时的session , 以测试用户的音视频连接

getroominfo 是在 persistent store 查询房间号, 如果有, 进入

getUsableSessionInfo. 函数按房间号查询session, 如果没有, 创建新的

 

 

 

 

 

 

 

 

运行并修改 tokbox webrtc 例子程序

opentok 账号

mzcw2011@sina.cn

Passw0rd77#


api key   46419702

project secret :  b8f17a054ccde74e68453464ad6b1c879a75d030

 

环境  win10 64 位

  • dependence :

a)  node.js  ,   已安装 , 64位的

b) Redis

在这里下载 3.2.100 的 zip 版本 并启动 : https://github.com/microsoftarchive/redis/releases/tag/win-3.2.100

 

  • 下载并编译源程序 :

a) 从这里 clone : https://github.com/opentok/opentok-rtc

首先进入 config 文件夹,  修改 config-ci.json 为 :

 

这里的apikey和 apisecret改成自己的

b) 不知道是否还需要安装python, 好像是需要的,因为本机已有,未测试

c)  npm 安装package :     进入程序主目录执行

 

d) 启动服务端, 记得redis要先启动

而且,启动 redis server 之后, 再启动 redis-cli  , 并增加2个键

然后启动 server

 

——————   在 ubuntu 的安装

apt install git

git clone https://github.com/opentok/opentok-rtc.git

apt install nodejs

apt install redis-server

设置redis-server为服务 :

此后要注意 redis 的权限问题,  redis 服务的配置文件在    /etc/redis/redis.conf

其中写到 : pidfile /var/run/redis/redis-server.pid

 

新开一个 putty , 输入 :  redis-server

回到原来的putty ,   进入下载好的  opentok-rtc/config 目录 , 复制 example.json , 重命名为  config.json , 并编辑修改  key 和 secret ,改为自己的 ,

安装 npm

apt install npm

在 opentok-rtc 跟目录下, 执行 npm install

安装所有package 之后, 执行 node server 启动服务器

此时访问  ip:8123 应该可以看到页面了, 但是, 发现css没起作用 ,

a) 安装 less

apt install node-less

b) 安装 bower

执行  bower install –allow-root

c) 安装 grunt

sudo npm install -g grunt

此处要注意, 在 ali ubuntu主机, 如果 npm install grunt –save-dev  ,  会失败,不知道为什么

安装之后 , 在跟目录执行  grunt clientBuild   , 会把  less 生成对应的  css

 

  • 加载 screen-sharing extensions

第一步 , 修改  opentok-rtc-master\screen-sharing-extension-chrome\manifest.json 文件 的这一部分 , 改为 :

 

第二步, 进入 chrome://extensions/  ,  开 developer mode 开光, 选 左上角 load unpacked , 然后选中 整个  screen-sharing-extension-chrome 目录

 

第三步, 修改 服务器  /config/config.json 文件 , 将 screen – sharing 部分改为

 

chromeExtensionId 是客户端 加载 extension之后产生的, 也在 chrome:/extension能看到

最后启动服务, room 会多出一个 screen-share的选项 。

 

 

tokbox 测试环境的搭建

注册账号 ,然后新建一个project , 这样就得到了 api key , 和 secret , 如图

  • 第二步,建server , 以 python 为例 :

sample 程序在  https://github.com/opentok/Opentok-Python-SDK

先建立一个 python 虚拟目录, 这样得到干净的初始环境 。

然后, 安装 flask 和 opentok 库:


安装完成后把例子程序的helloworld项目的 helloworld.py, 根据自己的情况修改为

然后在虚拟环境内执行 ,本机的虚拟环境目录在: F:\Programs\Python\py37virtualenvs\tokbox

如果能出现下图就说明服务启动成功了

有一个常见的错误就是: 当试图 create session时 , 出现

tokbox Failed to create session, invalid credentials 的错误, 这可能是因为测试机器时间和标准时间不一致 ,解决方法是:  setting–>datetime setting –>set time automatically on


成功启动服务后, http://127.0.0.1:5000

如果有摄像头, 就能看到图像。

服务启动后会在页面显示 sessionid 和 生成的  token

 


首先找出刚才建立的server 的 api_key , session_id 和 token  :

46419702

1_MX40NjQxOTcwMn5-MTU2ODI3MTIwOTMzNH5QcEY4aE0ra0owaC9DTTAzdnRoRTlxK2J-UH4

T1==cGFydG5lcl9pZD00NjQxOTcwMiZzaWc9ZDJmZmRmMGU1MmE4YjBkMmQyOTEzMjgzNDBmZjZjYzMwN2EwY2U0ZTpzZXNzaW9uX2lkPTFfTVg0ME5qUXhPVGN3TW41LU1UVTJPREkzTVRJd09UTXpOSDVRY0VZNGFFMHJhMG93YUM5RFRUQXpkblJvUlRseEsySi1VSDQmY3JlYXRlX3RpbWU9MTU2ODI3MjU4OCZleHBpcmVfdGltZT0xNTY4MzU4OTg4JnJvbGU9cHVibGlzaGVyJm5vbmNlPTIwNTQyNiZpbml0aWFsX2xheW91dF9jbGFzc19saXN0PQ==

打开例子程序的 Basic Video Chat 子项目

修改 /js/config.js , 把 api_key , session_id 和 token 等都修改为和之前服务器建立的一致 ,并且把 server_url 的那句注释掉:

 

然后打开  Basic Video Chat 的 index.html 程序, 就可以与服务器互通视频和语音。

How to write an auto-fish scripts for wow classic

  • 建立python 虚拟环境

查看当前python 版本 :  python –version

查看 32bit还是 64bit, 方法是

 

  • 依次安装       numpy  (数学库) :  pip install numpy

matplotlib  (坐标图)  :  pip install matplotlib

opencv-python  (图像识别) :  pip install opencv-python

pyscreenshot  (截屏) : pip install pyscreenshot

pillow  (这个库是替代旧的 image库) : pip install Pillow

autopy (模拟按键)

  • 尝试安装 pip install win32gui , 但不能安装 ,32和64版本都不行,因为 win32gui 只有python 3.6 版本

重新装python 3.6.7

在安装win32gui之后,还要安装 pywin32 

安装完成后, 执行这个脚本测试一下:

方法是先执行, 在新建一个notepad , 然后让 notepad 获得焦点, 会每2秒打字一个 “1”

但是, 这是对 notepad的键盘模拟, 对 wow能不能一样, 待测试。

  • 试试能不能截屏 :

  • 找 bobber (或者叫 float )的方法:

 

 

  • How to know if fish ready

 

  • How to filter loot , for example only keep black mouth

use addon :   EasyLoot

 

  • 参考文章:

https://github.com/YECHEZ/wow-fish-bot  

这个新一些


https://github.com/kioltk/wow-fishipy

这个方法比较旧, 但是opencv用的好

 

 

 

 

  • 参考文章 :  https://www.reddit.com/r/learnpython/comments/22tke1/use_python_to_send_keystrokes_to_games_in_windows/

same purpose with me


https://github.com/kioltk/wow-fishipy/blob/master/fishing.py

主要是学这个


https://github.com/FrontMage/wowAutoFishing

图像识别找 bubble , 声音确定点右键的时机

 

  • 已有的bot :

https://www.ownedcore.com/forums/wow-classic/wow-classic-bots-programs/799510-vanillabuddy-fishbot-support-thread.html

还不知道是什么功能

此外 youtube 也有很多classic fish bot的视频,不知真假

 

 

python 3.7.4 建立虚拟环境

virtual env 可以理解为一个个独立的docker , 互相之间不影响, 比如一个python项目要用到opencv , 最好的办法是把opencv安装在 virtual env 而不是全局 ,这样其他项目仍能保持干净的最初环境。


如何新建 virtual env , 参考文章:

https://docs.python.org/3/library/venv.html

https://docs.python.org/3/tutorial/venv.html

  • 第一步 :

    会创建一个新目录 , 此目录自动生成 include , lib, scripts 子目录, 还有 pyvenv.cfg配置文件
  • 创建好的虚拟目录位于 :  F:\Programs\Python\py37virtualenvs\tokbox
  • mac 系统 , 进入创建好大目录, 执行  source activate

 

 

how to write a new wow classic addon from beginning

  • classic api is base on V 8.1.0 ,

it full reference is here :

The Classic API is based on the 8.1.0 api but then half stripped down. The changes are available here, including for widgets, events, CVars and enums.

Diff: https://github.com/Ketho/BlizzardInterfaceResources/commit/dfe14662c6aeef9a968daf1609b8b8327e610622

API: https://github.com/Ketho/BlizzardInterfaceResources/blob/classic/Resources/GlobalAPI.lua

Wowpedia: https://wow.gamepedia.com/Patch_1.13.2/API_changes

 

正文部分 :

WoW Addon Writing Guide Part One: How to make your first addon
By GalacticGlum Last updated 2019/05/09 at 3:10 PM View Changelog

WoW Addon Writing Guide Part 1 5.4.2+ : How to make your fist Addon
I make gaming videos and make coding tutorials on my YouTube channel! I’m also going to be making a video version of this guide very soon! My YouTube channel is http://youtube.com/galacticglum/
Introduction:
In This Guide you will learn how to write a basic “Hello World” addon and a Basic “Level Up” Congratulation addon in the Programming Language LUA at the end of this guide you should have a completely working addon and basic understanding of what you need to write an addon and what you need to know
*If you want to download a Sample version of this addon for the source code there is a link at the bottom of the guide*
What you will need:
1. Notepad ++ (This is a Free code editor) ** There are different programs like Eclipse IDE, but for this tutorial we will be using Notepad ++ **
Link: http://notepad-plus-plus.org/
2. Basic Computer Knowledge (Just Basic Computer Skills, You need to know how to operate a Computer *you managed to get to this guide so you are good to go*)
3. A WoW Account (For testing purposes)
Tips Before we start:
Remember this guide is for people who don’t know Programming

After this guide you might want to go read and watch some basic LUA tutorials and guides
*There will be links for LUA tutorials at the bottom of the guide*

Remember this can be used on different versions you just need to do a couple different stuff which I explain in the guide
Setting Up
So first and for most you are going to want to download Notepad ++ and install it.
You are also going to want to get the current Interface number. There are numerous of ways of doing this.
Here are a couple of ways.The Best Way is to go on WoW and run this script
/run print((select(4, GetBuildInfo())));
**Thank you Funda for telling me about this script**

You could also steal the Interface number from an updated WoW addon in the TOC File but a simpler way would
be to just Google it (EX. Wow 5.4.2 Interface number) and you should find the Interface number one way or another. The version 5.4.2 Interface number is 50400 but this changes from a version to version. After you obtain the interface number and install Notepad ++ you are going to want to locate your WoW installation folder it is either in C:\Program Files or C:\Program Files (X86) and then go to your Interface Folder inside the WoW installation folder and then into your addon folder inside the interface folder. Inside the addon folder you are going to make a new folder called “HelloWorld” this folder will store all of your addon files so before making the folder make sure you are in this file path:

C:\Program Files\World of Warcraft\_retail_\Interface\Addon\

That is the file path you should have now this is how it should look at the top after you make the
HelloWorld Folder:

C:\Program Files\World of Warcraft\_retail_\Interface\Addon\HelloWorld
Writing Our .TOC File (Table of Contents File)
The TOC File is the first file WoW goes to look to find info about your addon so it is very important to not mess the TOC file up.
The first thing you are going to want to do is to create a new text document and name it HelloWorld you are then going to open it in regular notepad and save it as HelloWorld.toc and save it as all file types. You are now going to see a text document and a .toc file in your folder delete the HelloWorld text document but keep your HelloWorld.toc file. Now open the HelloWorld.toc file in Notepad ++ and paste this code:

## Interface: (Your Interface number)
## Title: (Name of your Addon)
## Author: (Your name here)
## Version: (Version of your Addon)
Copy that and change it to your info
This is how my TOC would look like:

## Interface: 50400
## Title: Hello World
## Author: Shon Verch
## Version: 0.1
Click file in the top left hand side of the Notepad ++ tool-bar and click save
Call this file HelloWorld and if it asks you to overwrite HelloWorld.toc file say yes.
Writing the “HelloWorld” Script
Of course we need to write a script because you can’t make a addon do something before you tell it to do something. So you are going to make a new text document called “main” and open it in Notepad ++ you are then going to paste or type this code:

message(‘HelloWorld’)
Of course you can make this message bigger for example:

message(‘Hi how are you I am good what up’)
But for the sake of this tutorial we are just going to write in the message HelloWorld
After you write in the code you are going to click file in the left hand side of the tool-bar and click save as
You are going to save it as a LUA file so just name it main.lua and it should automatically recognize the .LUA extension.
Now go to your .toc file and type in the main.lua file under your .toc it should look like this:

## Interface: 50400
## Title: Hello World
## Author: Shon Verch
## Version: 0.1

main.lua
The reason you need to put the name of the file there is because WoW needs to know what files to run everytime you run the addon
Now open up your WoW and enable the addon to enable addons on your character selection screen in the bottom left hand side of your screen there should be a button that says addon on it. Click on that and you should see HelloWorld on the list if you have no other addons except the addon you just made press enable all at the bottom the window on the addon screen. If you have more addon just go to the HelloWorld Addon and tick the check-box beside the addon name your addon name should be in yellow if it is in red then that means it is outdated and your interface number is not the correct one for the version.
This is how the addon window looks like:

That is how the addon window should look like.
Now select a character and when you log on you should have a box that says HelloWorld like this:

Hooray it worked
Now you made your first addon but we are not done yet!
A Little More Advanced
Now that we made our first addon the Hello world addon its time to add a Level up Congratulatory feature that congratulates you every time you level up
First make a new text document called “lvup” open this file in Notepad ++ and first insert this line of code:

local Congrats_EventFrame = CreateFrame(“Frame”)
What this code is doing is creating a frame it is also using a local variable versus a bigger variable so it does not interfere with other WoW codes. Next up you are going to want to insert this line of code:

Congrats_EventFrame:RegisterEvent(“PLAYER_LEVEL_UP”)
What this is doing is registering the event that when you level up something happens
So far your new .LUA file should look like this

local Congrats_EventFrame = CreateFrame(“Frame”)
Congrats_EventFrame:RegisterEvent(“PLAYER_LEVEL_UP”)
Now we are going to set the script for the level up congratulation system. To set the script you insert this code:

Congrats_EventFrame:SetScript(“OnEvent”,
This is setting the script for the text message it displays when you level up now we are going to make a function to recognize we levelled up to do this insert this code:

function(self, event, …)
Your .LUA file should look like this:

local Congrats_EventFrame = CreateFrame(“Frame”)
Congrats_EventFrame:RegisterEvent(“PLAYER_LEVEL_UP”)
Congrats_EventFrame:SetScript(“OnEvent”,
function(self, event, …)
Now we are going to use the local variable again we are also going to makeing the level up recognizer that the Addon will run to check if you levelled up just insert this code:

local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = …
Your code should look like this now:

local Congrats_EventFrame = CreateFrame(“Frame”)
Congrats_EventFrame:RegisterEvent(“PLAYER_LEVEL_UP”)
Congrats_EventFrame:SetScript(“OnEvent”,
function(self, event, …)
local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = …
Now we are going to actually right what the message is and who to display to insert this code:

print(Congratulations on reaching level ‘ ..arg1.. ‘, ‘ .. UnitName(“Player”).. ‘! You gained ‘ ..arg2.. ‘ HP and ‘ ..arg3.. ‘ MP!’)
Write a customized message so when you level up you know that the addon worked. Write something WoW Automatically would never say.

your code should now look like this:

local Congrats_EventFrame = CreateFrame(“Frame”)
Congrats_EventFrame:RegisterEvent(“PLAYER_LEVEL_UP”)
Congrats_EventFrame:SetScript(“OnEvent”,
function(self, event, …)
local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = …
print(Congratulations on reaching level ‘ ..arg1.. ‘, ‘ .. UnitName(“Player”).. ‘! You gained ‘ ..arg2.. ‘ HP and ‘ ..arg3.. ‘ MP!’)
end)
now go to file and click save as and save it as:

lvup.lua

Notepad ++ will automatically make it a .lua file if you add the .lua at the end of your name
go back to your .toc file and add lvup.lua to your .toc it should look like this:

## Interface: 50400
## Title: Hello World
## Author: Shon Verch
## Version: 0.1

lvup.lua
main.lua
your .toc file should look like this but with your name and version and all that.
Conclusion
In this guide I taught you how to make a simple addon that Congratulates you when you level up and that says HelloWorld when you log in if you want to disable the HelloWorld popup every time you log in then go to your .toc file and erase main.lua it should look like this:

## Interface: 50400
## Title: Hello World
## Author: Shon Verch
## Version: 0.1

lvup.lua
Thank you for reading and hope you can make a new revolutionary addon
LUA Guide and Video Links:
1. http://www.youtube.com/watch?v=dA9tcPeZa8k
2. http://www.lua.org/pil/1.html
3. http://www.wowwiki.com/Portal:Interface_customization
4. http://wowprogramming.com/
5. http://www.mmo-champion.com/threads/817817-Creating-Your-Own-WoW-Addon
6. http://www.codeproject.com/Articles/284961/A-Simple-World-of-Warcraft-Addon-using-Lua
7.http://www.phailed.me/2011/02/learn-lua-the-hard-way-1/

There are more just search it up on Google
Addon Source Code Download Link
Download: https://www.mediafire.com/?q3v1opqicrvb1a8
Extra Stuff
Have Fun Coding 😀

Guide by WoWlover123

I wrote this guide when I was 12, I am now 14 as of 4/14/2015

I’m currently working on a 2D ORPG called The Five Heroes and I would love for you guys to support me.
Also check out this video tutorial I made teaching you how to program in VB.NET
https://www.youtube.com/watch?v=BwXjsVgBJ9U

Official game website: http://www.tfh.altervista.org/
Official game forums: http://www.thefiveheroes.4umotion.com/

 

 

  • api 函数大全

 

  • 能不能从macro 调用 scripts  ,  或者从 lua script 调用 python  function

因为 script 不允许 condition cast , 因为这会让 blizzard觉得是 AI make decision ,  如果允许, 就会衍生出各种 onekey addon , 最终就是 bot ,

例如 vanilla 版本的  AutoRogue

 

但是 这样是允许的:

但是如果把 SendChatMessage  改为 cast X   就不行

如何绕过这一点 ?  python有一个库是发送 模拟键盘消息的, 如果能从 lua script 调用 ,并实现按下一个按键 ,  是否就可是实现 cast

 

  • simple code

Registers which events the object would like to monitor.

success = frame:RegisterEvent(“event”)
Arguments
event
string – The name of the event to register the object as monitoring.
Returns
success
boolean – Returns true if the event was successfully registered, false if (already) registered.
Example
The snippet below creates a frame, registers it for the CHAT_MSG_YELL event, and sets an OnEvent handler that would print a message whenever that event fires — whenever you hear someone /yell.


关于 frame register event 的更详细解释

→ API events
Contents[show]
← Event API
Events are messages sent by the WoW client to UI code (OnEvent script handlers of Frame derivatives), mostly in reaction to things occurring in the game world. To process events, an addon needs to create an event handler and register it for the events it wishes to receive.

Setting up an event handler Edit
Events are sent to Frame-derived widgets; an add-on needs to create a frame if it does not already own one that can be used for the purpose of handling events. Frames may be created in Lua using the CreateFrame function; or constructed in XML (using the <Frame> tag).

Once a frame has been created, its OnEvent handler must be set to a function that would handle the event on behalf of the addon. The OnEvent script handler may be set using the Lua frame:SetScript() function; or constructed in XML (using <Scripts><OnEvent>function body</OnEvent></Scripts>). The OnEvent handler function receives at least two arguments:

self, a reference to the frame to which the script handler belongs1
event, the name of the event being fired
The remaining event arguments are placed within the vararg exp/ression (…), as well as in the arg1-arg9 variables (the latter mechanic is deprecated and will be removed in Cataclysm[1]). You can extract variables from the vararg expression by simply assigning it to your local variables: local arg1, arg2, arg3 = …;
The addon’s OnEvent script handler function should either handle the event, or call another addon function to handle the event.

In order to receive event notifications, the event handler frame needs to be registered for events the addon needs to handle; use frame:RegisterEvent(“eventName”) to achieve this. The RegisterEvent function can be called at any time after the frame’s creation; the OnLoad script handler is a convenient location to register for the desired events when using XML.

If you no longer wish to receive event notifications for a particular event, use the frame:UnregisterEvent() function. If you wish to disable all event notifications currently delivered to a frame, use the frame:UnregisterAllEvents().

Examples Edit
Hello WorldEdit
The two implementations below are functionally identical: they print “Hello World! Hello PLAYER_ENTERING_WORLD” to the default chat frame when the character zones into the world. Note that the event variable is implicit in the XML OnEvent handler: it is supplied by the OnEvent closure signature.

Using XML

<Ui>
<Frame name=”FooAddonFrame”>
<Scripts>
<OnLoad> self:RegisterEvent(“PLAYER_ENTERING_WORLD”); </OnLoad>
<OnEvent> print(“Hello World! Hello ” .. event); </OnEvent>
</Scripts>
</Frame>
</Ui>
Using Lua

local frame = CreateFrame(“FRAME”, “FooAddonFrame”);
frame:RegisterEvent(“PLAYER_ENTERING_WORLD”);
local function eventHandler(self, event, …)
print(“Hello World! Hello ” .. event);
end
frame:SetScript(“OnEvent”, eventHandler);
XML-Specific Edit
You may bind an already declared Lua function to the OnEvent handler in XML directly, rather than creating another function by providing a function body within the <OnEvent></OnEvent> tags. Doing so will save you memory:

FooAddOn.lua

function FooHandler_OnEvent(self, event, …)
— insert event handling code here
end
FooAddOn.xml

<Ui>
<Script file=”FooAddon.lua”/>
<Frame name=”FooHandler”>
<Scripts>
<OnEvent function=”FooHandler_OnEvent”/>
</Scripts>
</Frame>
</Ui>
Lua-specific Edit
If your frame registers a large number of events, you could reduce the required number of if clauses, and generally simplify your design by doing:

local frame, events = CreateFrame(“Frame”), {};
function events:PLAYER_ENTERING_WORLD(…)
— handle PLAYER_ENTERING_WORLD here
end
function events:PLAYER_LEAVING_WORLD(…)
— handle PLAYER_LEAVING_WORLD here
end
frame:SetScript(“OnEvent”, function(self, event, …)
events[event](self, …); — call one of the functions above
end);
for k, v in pairs(events) do
frame:RegisterEvent(k); — Register all events for which handlers have been defined
end
Note that in the case of the events:XXX functions above, the variable self, implicitly defined by using the function table:functionName notation, will point to the frame handling the event rather than the events table.

The vararg expression Edit
The vararg expression (…) may contain additional arguments supplied by the event. Arguments contained in … can be read by simply assigning them to other variables, possibly using the select function to skip forward to a specific argument in the list.

Consider the example of handling COMBAT_LOG_EVENT:

function eventHandler(self, event, …)
if event == “COMBAT_LOG_EVENT” then
local timestamp, combatEvent, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags =
…; — Those arguments appear for all combat event variants.
local eventPrefix, eventSuffix = combatEvent:match(“^(.-)_?([^_]*)$”);
if eventSuffix == “DAMAGE” then
— Something dealt damage. The last 9 arguments in … describe how it was dealt.
— To extract those, we can use the select function:
local amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing =
select(select(“#”, …)-8, …); — select(“#”, …) returns number of arguments in the vararg expression
— Do something with the damage details …
if eventPrefix == “RANGE” or eventPrefix:match(“^SPELL”) then
— The first three arguments after destFlags in … describe the spell or ability dealing damage.
— Extract this data using select as well:
local spellId, spellName, spellSchool = select(9, …); — Everything from 9th argument in … onward
— Do something with the spell details …
end
end
end
end
Notes Edit
The global this, event, and argX variables are being removed in Cataclysm[1]. Instead, use the arguments passed to the OnEvent script handler.
Relevant API Edit
CreateFrame(“widgetType”[, “name”[, parent[, “inherits”]]])
frame:SetScript(“handlerType”, func)
frame:HookScript(“handlerType”, func)
frame:RegisterEvent(“eventName”) (and possibly frame:RegisterAllEvents() )
frame:UnregisterEvent(“eventName”) (and possibly frame:UnregisterAllEvents() )
Events (API), a listing of events you may subscribe to.
References Edit
^ a b Preparing for Cataclysm
Categories:
Event APIAdd category
Community content is available under CC-BY-SA unless otherwise noted.

 

 

 

5 char multi boxing hotkey scripts and interface setting