Difference between revisions of "NDOIA"

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search
Line 35: Line 35:
 
   RegisterEventHandler(EventType.ModuleAttached, GetCurrentModule(),HandleModuleAttached)
 
   RegisterEventHandler(EventType.ModuleAttached, GetCurrentModule(),HandleModuleAttached)
 
</div>
 
</div>
<p style="width: 60%;margin: 0 auto">Example of adding a module with a initializer table</p>
+
<p style="width: 60%;margin: 0 auto">Example of adding the buff_player_strength module with an initializer</p>
<div style="width:60%;margin: 0 auto">
 
  Code Block
 
  Code Block
 
  Code Block
 
</div>
 
<p style="width: 60%;margin: 0 auto">Example of Handling the initializer table on an object</p>
 
 
<div style="width:60%;margin: 0 auto">
 
<div style="width:60%;margin: 0 auto">
 
   Code Block
 
   Code Block

Revision as of 15:58, 9 November 2019

ABCDEFGHIJKLMNOPQRSTUVWXYZ

Object Functions & Examples

AddModule(filename,table)

filename - Name of script file
table - 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 the buff_player_strength module with an initializer

 Code Block
 Code Block
 Code Block