What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

[Guide] How to use Events

zdennis

New Member
Joined
Aug 2, 2012
Messages
28
Reaction score
0
Maybe some of you have trouble how they should create an event.
event = do my stuff if the event happens.


1. We choose an event. -> http://www.archebuddy.com/API/html/210785147.htm
We will try to create a hotkey which can be done by the event "onKeyDown"
onKeyDown uses the delegate CoreInternal.KeyboardEvent ->http://www.archebuddy.com/API/html/586342424.htm

2. Create a function which will be called
In the api we can see that the delegate looks like this
Code:
public delegate void KeyboardEvent(
	Keys key,
	bool isCtrlPressed,
	bool isShiftPressed,
	bool isAltPressed
)

This means our "get called method" should be look like
Code:
void KeyboardEvent(Keys key,bool isCtrlPressed,bool isShiftPressed,bool isAltPressed)
{
	//Do stuff here
}
3. Register the event
You still know the name of the event? "onKeyDown"
Okay then what name did you gave your "get called method"?

If you did the same like me then the event name is "onKeyDown" and the "get called method" is "KeyboardEvent"

You register it with
Code:
onKeyDown +=  KeyboardEvent
pretty simple.

4. The results
Every time the event "onKeyDown" happens your method will be called.

Here an complete example, feel free to copy and Try to press F8 ;)

Code:
using System;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using ArcheBuddy.Bot.Classes;

namespace YourNamespace
{
    public class YourClass : Core
    {                  
        
        public static string GetPluginAuthor()
        {
            return "";
        }

        public static string GetPluginVersion()
        {
            return "";
        }

        public static string GetPluginDescription()
        {
            return "Event Example";
        }       
       void KeyboardEvent(Keys key,bool isCtrlPressed,bool isShiftPressed,bool isAltPressed)
       {        
            if (key == Keys.F8)  
            {
                Log("Your pressed F8, Congratulations!")
            }
        }  
        
        public void PluginRun()
        {          
			onKeyDown +=  KeyboardEvent;    
			while (true)
				Thread.Sleep(50);
        }
    }
}

Have a nice day :)
 
Last edited:
Code:
                Log("Your pressed F8, Congratulations!")

Semicolon is missing at the end.

Tried to subscribe to the "onKeyDown" and in my case it does not detect the key presses, tried different combinations of keys. Tried the script above "as is", just added the semicolon, doesn’t work as well. Using latest version of AB.
Any ideas what could be the root cause?
 
Does anyone use any AB built-in Events in their scripts and can confirm they are working in the latest version? Can you tell me which one is working, so that I could try to identify whether the problem is on my end or not? Thanks in advance.
-----------------------------------------------------
Кто-нибудь использует АБ эвенты у себя в скриптах? Какой-нибудь достоверно рабочий на последней версии эвент можете сказать, чтобы я мог проверить, это локальная проблема или нет?
 
Does anyone use any AB built-in Events in their scripts and can confirm they are working in the latest version? Can you tell me which one is working, so that I could try to identify whether the problem is on my end or not? Thanks in advance.
-----------------------------------------------------
Кто-нибудь использует АБ эвенты у себя в скриптах? Какой-нибудь достоверно рабочий на последней версии эвент можете сказать, чтобы я мог проверить, это локальная проблема или нет?
Клавиатурные эвенты с вводом гг могут не работать, временно. Все внутриядровые эвенты работают.
 
Клавиатурные эвенты с вводом гг могут не работать, временно.

Для eu/na серверов тоже не работает, там сейчас вообще ничего не стоит :)

Все внутриядровые эвенты работают.
Пример конкретного эвента, который у вас работает, можете сказать, чтобы я у себя проверил?
 
Ну например onChatMessage, секунду назад отработал )
 
Ну например onChatMessage, секунду назад отработал )

Они, конечно, используют разные делегаты, но хотя бы будет, куда копать дальше. Спасибо.
 
Они, конечно, используют разные делегаты, но хотя бы будет, куда копать дальше. Спасибо.

Я говорил, что события, генерируемые напрямую ядром, работают. Системные же под вопросом, не тестировал.
 
Does anyone use any AB built-in Events in their scripts and can confirm they are working in the latest version?

onkeydown event does work. But sometimes it's get fucked up and it doesn't work untill I restart archebuddy. But it does work to 90% or sth like that.
 
onkeydown event does work. But sometimes it's get fucked up and it doesn't work untill I restart archebuddy. But it does work to 90% or sth like that.

Yeah, sorted out after a PC reboot, for some reason restart of AB didn't help...
 
Back
Top