Difference between revisions of "NDOIA"

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search
Line 7: Line 7:
 
|}
 
|}
 
</center>
 
</center>
<p style="width: 60%;margin: 0 auto">Example of adding a module without a initializer table</p>
+
<p style="width: 60%;margin: 0 auto">Example script file named buff_player_strength.lua</p>
 
<div style="width:60%;margin: 0 auto">
 
<div style="width:60%;margin: 0 auto">
   Code Block
+
   --buff players strength by 5 default
   Code Block
+
   --the buff duration will be 30 seconds.
   Code Block
+
   --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)
 +
 
 +
  function HandleModuleAttached()
 +
      if (initializer ~= nil) then
 +
          defaultBuffAmount = initializer.BuffAmount or 5
 +
          defaultBuffTime = initializer.BuffTime or TimeSpan.FromSeconds(30)
 +
      end
 +
      if(this:IsMobile()) then
 +
          SetMobileModExpire(this,"StrengthPlus","Unique_Buff_Handler",defaultBuffAmount,defaultBuffTime)   
 +
      end
 +
  end
 +
 
 +
  --register the event handler for when this module gets attached to the current object
 +
  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 a module with a initializer table</p>

Revision as of 15:46, 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)
 
 function HandleModuleAttached()
     if (initializer ~= nil) then
         defaultBuffAmount = initializer.BuffAmount or 5
         defaultBuffTime = initializer.BuffTime or TimeSpan.FromSeconds(30)
     end
     if(this:IsMobile()) then
         SetMobileModExpire(this,"StrengthPlus","Unique_Buff_Handler",defaultBuffAmount,defaultBuffTime)    
     end
 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