Events

What events are.

To understand what events are consider a simple example: anti-macro gumps that appear in some shards. Typically, if for example you are crafting, while your macro is running the anti-macro gump can appear. In a normal macro you should check for the presence of the gump at every step, with events you can decentralize the check so that the gump can be handled independently while the main macro is running.

Another example where events may be useful is to check the state of connection in a separate place than the main script.

To create events you use the following syntax: SetEventProc(evSpeech,'function_name');

To empty events you need to specify an empty handler SetEventProc(evSpeech,' ');

Extra info and tips

  1. Events called, when Wait method called, so its not a real parallel execution. BTW, thats the reason of using Wait instead of Sleep in Python
  2. when events raised, its added to events queue, and executed in script one by one. Thats why you should NEVER put in event handler heavy things like moving, waiting for something, etc. Only light&fast code!
  3. Event available for all internal and external scripts, working same everywhere.

List of available events:

Samples

//Pascal Sample
Program Test; 

procedure Speech(text,SenderName : String; SenderID : Cardinal); 
begin 
  AddToSystemJournal('Event! Unicode Speech: SenderID = $'+ IntToHex(SenderID,8) + ' ; SenderName =  ' + SenderName + '; SenderText : ' + text); 
end; 

procedure Char_Animation(ID : Cardinal; Action : Word); 
begin 
  AddToSystemJournal('Event! Char Animation: ID = $'+ IntToHex(ID,8) + ' ; Action =  ' + IntToStr(Action)); 
end; 

procedure multiple_Items(ContainerID : Cardinal); 
begin 
  AddToSystemJournal('Event! Add multiple Items In Cont: ContID = $'+ IntToHex(ContainerID,8)); 
end; 

begin 
  SetEventProc(evSpeech,'Speech'); 
  SetEventProc(evCharAnimation,'Char_Animation'); 
  SetEventProc(evAddMultipleItemsInCont,'multiple_Items'); 

  while True do 
	wait(50); 
end.
#Python sample
def drawCallback(objectID):
    print(objectID)
    
SetEventProc('evDrawObject', Callback=drawCallback)

while True:
    Wait(50)