Difference between revisions of "NDOIA"
Line 54: | Line 54: | ||
--Apply the strength buff with 15 strength bonus and 45 second duration. | --Apply the strength buff with 15 strength bonus and 45 second duration. | ||
ApplyStrengthBuff(15,TimeSpan.FromSeconds(45)) | ApplyStrengthBuff(15,TimeSpan.FromSeconds(45)) | ||
+ | </div> | ||
+ | |||
+ | <center> | ||
+ | {| class="wikitable" | style="width: 60%" | ||
+ | |- | ||
+ | |style="width: 40%"| <p style="color: #DDDD88;font-size: 18px">AttachUser() || . | ||
+ | |} | ||
+ | </center> | ||
+ | <p style="width: 60%;margin: 0 auto">Example</p> | ||
+ | <div style="width:60%;margin: 0 auto"> | ||
+ | CODE EXAMPLE BLOCK | ||
</div> | </div> |
Revision as of 19:07, 11 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 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() |
. |
Example
CODE EXAMPLE BLOCK