Difference between revisions of "NDOIA"

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search
 
Line 60: Line 60:
 
{| class="wikitable" | style="width: 60%"
 
{| class="wikitable" | style="width: 60%"
 
|-
 
|-
|style="width: 40%"| <p style="color: #DDDD88;font-size: 18px">AttachUser() || .
+
|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>
 
</center>

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