Difference between revisions of "NDOIA"
(9 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 7: | Line 8: | ||
|} | |} | ||
</center> | </center> | ||
− | <p style="width: 60%;margin: 0 auto">Example | + | <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"> | ||
− | + | --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) | ||
</div> | </div> | ||
− | <p style="width: 60%;margin: 0 auto">Example of adding | + | <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"> | ||
− | + | --- 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)) | ||
</div> | </div> | ||
− | <p style="width: 60%;margin: 0 auto">Example | + | |
+ | <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 EXAMPLE BLOCK | |
− | |||
− | |||
</div> | </div> |
Latest revision as of 06:49, 25 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() Paramsuserid - of user to attach. |
Attaches a user to the specified mobile (DOES NOT WORK ON NON-MOBILES). |
Example
CODE EXAMPLE BLOCK