LUA API v2 Events - xAranaktu/FC-24-Live-Editor GitHub Wiki
LUA Events
This functionality allows you to execute your lua code before or after certain game function. Make sure that your callback function takes same amount of parameters as the original function.
Examples of scripts using events:
Functions
List of functions for managing events
Game Events
List of game events that can be used
LEInitDoneEvent
This function is triggered when live editor finish its initialization process, just before the UI appears. Use this if you want to execute your code at game startup. Like for example automatically importing your gameplay edited file: auto_import_gameplay.lua
Original function declaration
void LEInitDoneEvent()
Allowed event names
- LEInitDoneEvent (execute before original function)
- pre__LEInitDoneEvent (execute before original function)
- post__LEInitDoneEvent (execute after original function)
CareerModeEvent
This is called very often in career mode. All kind of CM actions go through it.
Original function declaration
bool EventsManager::HandleMessage(EventsManager* _this, EventMessageId event_id, void* event)
Original function paramenters
Type | Name | Description |
---|---|---|
EventsManager* | _this | Pointer to FC EventsManager instance |
EventMessageId | event_id | ID of the event. You can find all ENUM_CM_EVENT_MSG_* in enums.lua |
void* | event | Pointer to event data. Different for every event id. For example for ENUM_CM_EVENT_MSG_DAY_PASSED it may contain info about current date, and for ENUM_CM_EVENT_MSG_INJURY it may contain info about player injury |
Allowed event names
- pre__CareerModeEvent (execute before original function)
- post__CareerModeEvent (execute after original function)
AddEventHandler
Adds callback for game event
Declaration
void AddEventHandler(string event_name, FunctionRef func_ref)
Parameters
Type | Name | Description |
---|---|---|
string | event_name | name of the event with "pre__" or "post__" prefix |
FunctionRef | func_ref | reference to the function that should be executed |
Returns
Doesn't return anything
Example
-- LEInitDone__OnEvent function will be executed at live editor startup (just before the UI shows)
function LEInitDone__OnEvent()
print("Live Editor has done initialization")
end
AddEventHandler("post__LEInitDoneEvent", LEInitDone__OnEvent)
-- DayPassed__OnEvent function will be executed every time you advance in calendar in career mode, before original game code.
function DayPassed__OnEvent(events_manager, event_id, event)
if (
event_id == ENUM_CM_EVENT_MSG_DAY_PASSED -- Day Passed
) then
print("Another day has passed")
end
end
AddEventHandler("pre__CareerModeEvent", DayPassed__OnEvent)
GetEventHandlers
Get list of event handlers made for event by name
Declaration
Event[] GetEventHandlers(string event_name)
Parameters
Type | Name | Description |
---|---|---|
string | event_name | name of the event with "pre__" or "post__" prefix |
Returns
Returns array of Event
Example
local pre_cm_event_handlers = GetEventHandlers("pre__CareerModeEvent")
local post_cm_event_handlers = GetEventHandlers("post__CareerModeEvent")
print(string.format("You have %d pre__CareerModeEvents and %d post__CareerModeEvents", #pre_cm_event_handlers, #post_cm_event_handlers))
RemoveEventHandler
Delete event handler for event by unique id
Declaration
void RemoveEventHandler(string event_name, int event_id)
Parameters
Type | Name | Description |
---|---|---|
string | event_name | name of the event with "pre__" or "post__" prefix |
__int32 | event_id | event unique id |
Returns
Doesn't return anything
Example
local pre_cm_event_handlers = GetEventHandlers("pre__CareerModeEvent")
local post_cm_event_handlers = GetEventHandlers("post__CareerModeEvent")
print(string.format("You have %d pre__CareerModeEvents and %d post__CareerModeEvents", #pre_cm_event_handlers, #post_cm_event_handlers))
if #pre_cm_event_handlers > 0 then
-- Remove first pre__CareerModeEvent
RemoveEventHandler("pre__CareerModeEvent", pre_cm_event_handlers[1].id)
end
if #post_cm_event_handlers > 0 then
-- Remove first post__CareerModeEvent
RemoveEventHandler("post__CareerModeEvent", post_cm_event_handlers[1].id)
end
pre_cm_event_handlers = GetEventHandlers("pre__CareerModeEvent")
post_cm_event_handlers = GetEventHandlers("post__CareerModeEvent")
print(string.format("You have %d pre__CareerModeEvents and %d post__CareerModeEvents", #pre_cm_event_handlers, #post_cm_event_handlers))
ClearEventHandlersForEvent
Delete ALL handlers for event by name
Declaration
void ClearEventHandlersForEvent(string event_name)
Parameters
Type | Name | Description |
---|---|---|
string | event_name | name of the event with "pre__" or "post__" prefix |
Returns
Doesn't return anything
Example
local pre_cm_event_handlers = GetEventHandlers("pre__CareerModeEvent")
local post_cm_event_handlers = GetEventHandlers("post__CareerModeEvent")
print(string.format("You have %d pre__CareerModeEvents and %d post__CareerModeEvents", #pre_cm_event_handlers, #post_cm_event_handlers))
ClearEventHandlersForEvent("pre__CareerModeEvent")
ClearEventHandlersForEvent("post__CareerModeEvent")
pre_cm_event_handlers = GetEventHandlers("pre__CareerModeEvent")
post_cm_event_handlers = GetEventHandlers("post__CareerModeEvent")