User Tools

Site Tools


addons:events

This is an old revision of the document!


Events

One of the main ways that Ashita allows addons to obtain various important data from the hook is through the method of events. Events are callback functions that are fired within an addons Lua state whenever the hook core handles something that warrants an addon to be notified. This can happen for things such as incoming or outgoing packets, chat commands entered by the user, etc.

The following events are currently valid within Ashita's core hook that are exposed to addons:

  • load
  • unload
  • command
  • incoming_packet
  • outgoing_packet
  • incoming_text
  • outgoing_text
  • prerender
  • render
  • timerpulse

Registering To Events

Addon developers can register to an event using one of two methods. The short-hand method, or the long-hand method. In most cases, the short-hand method will be ideal and recommended.

Short-hand Method

ashita.register_event('load', function()
    print('Load event fired!');
end);

Long-hand Method

function loadfunction()
    print('Load event fired!');
end
 
ashita.register_event('load', loadfunction);

Event: load

Called when the current addon is being loaded. (Also called when the addon is reloaded.)

ashita.register_event('load', function()
    print('Load event fired!');
end);

Parameters

  • None

Returns

  • None

Event: unload

Called when the current addon is being unloaded. (Also called when the addon is reloaded.)

ashita.register_event('unload', function()
    print('Unload event fired!');
end);

Parameters

  • None

Returns

  • None

Event: command

Called when a command has been entered in the game.

ashita.register_event('command', function(cmd, nType)
    print('Command event fired!');
    return false;
end);

Parameters

  • cmd - (string) The command that was entered.
  • nType - (number) The type of command that was entered.

Returns

  • bool - True if the addon handled the command, false otherwise to allow further addons to process the command.

Event: incoming_packet

Called when the game client is receiving an incoming packet.

ashita.register_event('incoming_packet', function(id, size, packet, packet_modified, blocked)
    print('Incoming packet event fired!');
    return false;
end);

Parameters

  • id - (number) The packet id being processed.
  • size - (number) The size of the packet being processed.
  • packet - (string) The raw packet data.
  • packet_modified - (string) The raw packet data that has been modified by other addons and plugins.
  • blocked - (bool) True if the packet has been blocked by another addon or plugin, false otherwise.

Returns

  • bool - True if the packet should be dropped/blocked, false otherwise.
  • or
  • table - A table containing new packet data that should be used to modify the packet.

Event: outgoing_packet

Called when the game client is sending an outgoing packet.

ashita.register_event('outgoing_packet', function(id, size, packet, packet_modified, blocked)
    print('Outgoing packet event fired!');
    return false;
end);

Parameters

  • id - (number) The packet id being processed.
  • size - (number) The size of the packet being processed.
  • packet - (string) The raw packet data.
  • packet_modified - (string) The raw packet data that has been modified by other addons and plugins.
  • blocked - (bool) True if the packet has been blocked by another addon or plugin, false otherwise.

Returns

  • bool - True if the packet should be dropped/blocked, false otherwise.
  • or
  • table - A table containing new packet data that should be used to modify the packet.

—-

addons/events.1492828182.txt.gz · Last modified: 2017/04/21 19:29 by atom0s