Пользовательские дополнения

На главную


common.RegisterEventHandler( eventFunction, sysEventName, params )

Подписывает обработчик аддона на указанное событие. На одно событие может быть несколько обработчиков. Функция-обработчик принимает один параметр - таблицу.

Также обработчику можно сопоставить параметры params. Это фильтр, представленный таблицей. Когда инициируется скриптовое сообщение, и обработка доходит до данного зарегистрированного обработчика, то проверяется, что в инициированном сообщении имеются точно такие же поля, точно с такими же значениями, что и в фильтре. И только в этом случае управление передаётся обработчику.

params - необязательный параметр метода, то есть его можно вообще не указывать. В этом случае поля сообщения не будут проверяться на соответствие для такого обработчика и управление перейдёт в него в любом случае, при любых параметрах сообщения.

Для common.RegisterEventHandler() есть обратный метод common.UnRegisterEventHandler(). Если от обработчика сообщения необходимо отказаться, то ему нужно передать такие же params, как и при регистрации.

Также можно отказаться от любой обработки сообщения с помощью common.UnRegisterEvent( sysEventName ).

-- библиотека:
common

-- объявление:
function RegisterEventHandler( eventFunction, sysEventName, params )

-- параметры:
eventFunction: function - функция-обработчик
sysEventName: string - название события
params: table or nil - необязательный параметр (можно опустить) с таблицей описывающей фильтр сообщения

-- возвращаемые значения:
нет

-- прототип функции-обработчика:
function OnEventHandler( params )

-- параметры OnEventHandler:
params: table - параметры события

-- возвращаемые значения OnEventHandler:
нет

-- примеры:
function OnEventSample( params )
end

function OnEventSampleMainPlayer( params )
end

common.RegisterEventHandler( OnEventSample, "EVENT_SAMPLE" )
common.RegisterEventHandler( OnEventSampleMainPlayer, "EVENT_SAMPLE", { unitId = avatar.GetId() } ) -- обрабатывать сообщения только от главного игрока

Search: "CategoryLuaApi" "CategoryCommon"

CategoryCommon
EventAddonLoadStateChanged
EventUserScreenshot
FunctionCommonAddonCreateChildForm
FunctionCommonCreateValuedObject
FunctionCommonCreateValuedText
FunctionCommonEnableUIRender
FunctionCommonExtractWStringFromValuedText
FunctionCommonFormatFloat
FunctionCommonFormatInt
FunctionCommonGetAddonInfo
FunctionCommonGetAddonMainForm
FunctionCommonGetAddonName
FunctionCommonGetApiType
FunctionCommonGetBitAnd
FunctionCommonGetBitOr
FunctionCommonGetCredits
FunctionCommonGetCSSList
FunctionCommonGetDateTimeFromMs
FunctionCommonGetEmptyWstring
FunctionCommonGetInstanceIdByInteger
FunctionCommonGetIntFromWString
FunctionCommonGetLocalDateTime
FunctionCommonGetMsFromDateTime
FunctionCommonGetRandFloat
FunctionCommonGetRandInt
FunctionCommonGetScriptCfgVar
FunctionCommonGetStateManagedAddons
FunctionCommonGetStateName
FunctionCommonGetTerritoryInfo
FunctionCommonGetTexturePath
FunctionCommonIsEmptyValuedObject
FunctionCommonIsEmptyWstring
FunctionCommonIsOnPayToPlayShard
FunctionCommonIsSubstring
FunctionCommonIsSubstringEx
FunctionCommonIsTextFiltered
FunctionCommonIsUIRenderEnabled
FunctionCommonIsValuedObject
FunctionCommonIsValuedText
FunctionCommonIsWString
FunctionCommonLogError
FunctionCommonLogInfo
FunctionCommonLogWarning
FunctionCommonMakeUserAddonFullName
FunctionCommonMakeUserScreenshot
FunctionCommonOnEvent
FunctionCommonOnReaction
FunctionCommonQuitGame
FunctionCommonRegisterEventHandler
FunctionCommonRegisterReactionHandler
FunctionCommonRequestIntegerByInstanceId
FunctionCommonSetCursor
FunctionCommonSetTextValues
FunctionCommonStateLoadManagedAddon
FunctionCommonStateLoadManagedAddonGroup
FunctionCommonStateUnloadManagedAddon
FunctionCommonStateUnloadManagedAddonGroup
FunctionCommonUnRegisterEvent
FunctionCommonUnRegisterEventHandler
FunctionCommonUnRegisterReactionHandler
FunctionCompareWString
FunctionCompareWStringEx
FunctionEscapeWString
FunctionGetWStringLength
FunctionGlobal
FunctionTruncateWString


CategoryLuaApi CategoryFunction CategoryCommon

На главную