Difference between revisions of "NDOIA"

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
<center><p style="width: 60%">[[NDOIA|A]][[NDOIB|B]][[NDOIC|C]][[NDOID|D]][[NDOIE|E]][[NDOIF|F]][[NDOIG|G]][[NDOIH|H]][[NDOII|I]][[NDOIJ|J]][[NDOIK|K]][[NDOIL|L]][[NDOIM|M]][[NDOIN|N]][[NDOIO|O]][[NDOIP|P]][[NDOIQ|Q]][[NDOIR|R]][[NDOIS|S]][[NDOIT|T]][[NDOIU|U]][[NDOIV|V]][[NDOIW|W]][[NDOIX|X]][[NDOIY|Y]][[NDOIZ|Z]]</p></center>
+
<p style="width:60%;margin: 0 auto">[[NewDawnHome|[Main]]] [[NDServerIndexScriptsMain|[Lua Examples]]]</p>
 +
<center><p style="width: 60%">[[NDOIA|A]] [[NDOIB|B]] [[NDOIC|C]] [[NDOID|D]] [[NDOIE|E]] [[NDOIF|F]] [[NDOIG|G]] [[NDOIH|H]] [[NDOII|I]] [[NDOIJ|J]] [[NDOIK|K]] [[NDOIL|L]] [[NDOIM|M]] [[NDOIN|N]] [[NDOIO|O]] [[NDOIP|P]] [[NDOIQ|Q]] [[NDOIR|R]] [[NDOIS|S]] [[NDOIT|T]] [[NDOIU|U]] [[NDOIV|V]] [[NDOIW|W]] [[NDOIX|X]] [[NDOIY|Y]] [[NDOIZ|Z]]</p></center>
 
<p style="color: #DDDD88;font-size: 22px;width:60%;margin: 0 auto">Object Functions & Examples</p>
 
<p style="color: #DDDD88;font-size: 22px;width:60%;margin: 0 auto">Object Functions & Examples</p>
 
<center>
 
<center>
Line 17: Line 18:
 
   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
 
    
 
    
Line 30: Line 36:
 
   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">
 
<div style="width:60%;margin: 0 auto">
   Code Block
+
   --- ApplyStrengthBuff - this will apply the buff_player_strength module with new settings
   Code Block
+
   --@ param: amount - the amount of strength to add/remove from the mobile object
   Code Block
+
   --@ param: duration - a timespan for how long the buff will remain on the object
 +
  function ApplyStrengthBuff(amount,duration)
 +
      --if any bad values come through, just apply the default otherwise proceed as normal
 +
      if(amount == nil or duration == nil) then
 +
          AddModule("buff_player_strength")
 +
      else
 +
          AddModule("buff_player_strength",{BuffAmount=amount,BuffTime=duration})
 +
      end
 +
  end
 +
 
 +
  --Apply the default strength buff of 5 strength for 30 seconds
 +
  ApplyStrengthBuff()
 +
 
 +
  --Apply the strength buff with 15 strength bonus and 45 second duration.
 +
  ApplyStrengthBuff(15,TimeSpan.FromSeconds(45))
 
</div>
 
</div>
<p style="width: 60%;margin: 0 auto">Example of Handling the initializer table on an object</p>
+
 
 +
<center>
 +
{| class="wikitable" | style="width: 60%"
 +
|-
 +
|style="width: 40%"| <p style="color: #DDDD88;font-size: 18px">AttachUser()</p>Params<br>userid - of user to attach. || Attaches a user to the specified mobile (DOES NOT WORK ON NON-MOBILES).
 +
|}
 +
</center>
 +
<p style="width: 60%;margin: 0 auto">Example</p>
 
<div style="width:60%;margin: 0 auto">
 
<div style="width:60%;margin: 0 auto">
   Code Block
+
   CODE EXAMPLE BLOCK
  Code Block
 
  Code Block
 
 
</div>
 
</div>

Latest revision as of 06:49, 25 November 2019

[Main] [Lua Examples]

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

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

 --- ApplyStrengthBuff - this will apply the buff_player_strength module with new settings
 --@ param: amount - the amount of strength to add/remove from the mobile object
 --@ param: duration - a timespan for how long the buff will remain on the object
 function ApplyStrengthBuff(amount,duration)
     --if any bad values come through, just apply the default otherwise proceed as normal
     if(amount == nil or duration == nil) then
         AddModule("buff_player_strength")
     else
         AddModule("buff_player_strength",{BuffAmount=amount,BuffTime=duration})
     end
 end
 
 --Apply the default strength buff of 5 strength for 30 seconds
 ApplyStrengthBuff()
 
 --Apply the strength buff with 15 strength bonus and 45 second duration.
 ApplyStrengthBuff(15,TimeSpan.FromSeconds(45))

AttachUser()

Params
userid - of user to attach.
Attaches a user to the specified mobile (DOES NOT WORK ON NON-MOBILES).

Example

 CODE EXAMPLE BLOCK