Difference between revisions of "NDOIA"
Line 17: | Line 17: | ||
defaultBuffTime = TimeSpan.FromSeconds(30) | defaultBuffTime = TimeSpan.FromSeconds(30) | ||
+ | --- HandleModuleAttached - this is fired when this script gets attached to an object | ||
function HandleModuleAttached() | function HandleModuleAttached() | ||
+ | -- if we received a initializer from the AddModule or template then update default values | ||
if (initializer ~= nil) then | if (initializer ~= nil) then | ||
defaultBuffAmount = initializer.BuffAmount or 5 | defaultBuffAmount = initializer.BuffAmount or 5 | ||
defaultBuffTime = initializer.BuffTime or TimeSpan.FromSeconds(30) | defaultBuffTime = initializer.BuffTime or TimeSpan.FromSeconds(30) | ||
end | end | ||
+ | -- make sure this object can receive the buff as it must be a mobile object | ||
if(this:IsMobile()) then | if(this:IsMobile()) then | ||
SetMobileModExpire(this,"StrengthPlus","Unique_Buff_Handler",defaultBuffAmount,defaultBuffTime) | SetMobileModExpire(this,"StrengthPlus","Unique_Buff_Handler",defaultBuffAmount,defaultBuffTime) | ||
end | end | ||
+ | -- remove this module script from the object now that we added the buff | ||
+ | DelModule(GetCurrentModule()) | ||
end | end | ||
Revision as of 15:53, 9 November 2019
Object Functions & Examples
AddModule(filename,table) filename - Name of script filetable - Initializer table |
The table may be omitted but allows you to send a table package to the script, then use the ModuleAttached Event to handle the table package. |
Example script file named buff_player_strength.lua
--buff players strength by 5 default --the buff duration will be 30 seconds. --if this script receives a initializer from an AddModule, set default values to the initializer values --setup default values defaultBuffAmount = 5 defaultBuffTime = TimeSpan.FromSeconds(30) --- HandleModuleAttached - this is fired when this script gets attached to an object function HandleModuleAttached() -- if we received a initializer from the AddModule or template then update default values if (initializer ~= nil) then defaultBuffAmount = initializer.BuffAmount or 5 defaultBuffTime = initializer.BuffTime or TimeSpan.FromSeconds(30) end -- make sure this object can receive the buff as it must be a mobile object if(this:IsMobile()) then SetMobileModExpire(this,"StrengthPlus","Unique_Buff_Handler",defaultBuffAmount,defaultBuffTime) end -- remove this module script from the object now that we added the buff DelModule(GetCurrentModule()) end --register the event handler for when this module gets attached to the current object RegisterEventHandler(EventType.ModuleAttached, GetCurrentModule(),HandleModuleAttached)
Example of adding a module with a initializer table
Code Block Code Block Code Block
Example of Handling the initializer table on an object
Code Block Code Block Code Block