What are Mods?
Mods (modifications) is a new way of including scripts into your server. They're like plugin for your web browser (fe. Firefox/Chrome extensions), which can be enabled/disabled by one single click (actually you need to make few more clicks, but it may change in the future). Mods can add new content to the underlying game, modify existing things or fix bugs. They can include new actions, commands, items, weapons and more. Previously (and still in most of OT distributions) you needed to edit couple of files to create something less or more advanced. With mods you can create advanced systems stored just in single file, which can be easily enabled/disabled in one click.
Mod syntax isn't new, its exactly same way of scripting like its done in data/ directory, the only difference is that its all packed into one single file. So - you don't need to use mods, but there are many benefits from using it. Think about simplicity and comfort. Mods were introduced in TFS 0.3.5, and should work with any later distros (including 0.4_DEV series). -Slawkens
1. First we must understand the basic layout of mods.
Code:
[COLOR="Red"]<?[/COLOR][COLOR="Blue"]xml[/COLOR] [COLOR="red"]version[/COLOR]=[COLOR="DarkOrchid"]"1.0"[/COLOR] [COLOR="red"]encoding[/COLOR]=[COLOR="DarkOrchid"]"UTF-8"[/COLOR][COLOR="red"]?>[/COLOR]
[COLOR="blue"]<mod[/COLOR] [COLOR="red"]name[/COLOR]=[COLOR="DarkOrchid"]"Mods Tutorial"[/COLOR] [COLOR="red"]version[/COLOR]=[COLOR="DarkOrchid"]"1.0" [/COLOR][COLOR="red"]author[/COLOR]=[COLOR="DarkOrchid"]"Syntax"[/COLOR] [COLOR="red"]contact[/COLOR]=[COLOR="DarkOrchid"]"[email protected]"[/COLOR] [COLOR="red"]enabled[/COLOR]=[COLOR="DarkOrchid"]"yes"[/COLOR]>
[COLOR="blue"]<description>[/COLOR]
[B]This should inform all users how to use mods correctly.[/B]
[COLOR="blue"]</description>[/COLOR]
[COLOR="blue"]<config[/COLOR] [COLOR="Red"]name[/COLOR]=[COLOR="DarkOrchid"]"tutorial_config"[/COLOR][COLOR="blue"]>[/COLOR][COLOR="Orange"]<![CDATA[
config = {
home = "lualand.net",
cookies = 4,
IQ_needed = 30
}
]]>[/COLOR][COLOR="blue"]</config>[/COLOR]
[COLOR="blue"] <event[/COLOR] [COLOR="Red"]type[/COLOR]=[COLOR="DarkOrchid"]"login"[/COLOR] [COLOR="red"]name[/COLOR]=[COLOR="DarkOrchid"]"Tutorial Login" [/COLOR][COLOR="red"]event[/COLOR]=[COLOR="DarkOrchid"]"buffer"[/COLOR][COLOR="blue"]>[/COLOR][COLOR="Orange"]<![CDATA[
if isIQ(cid) < config.IQ_needed then
doSendURL(cid, config.home)
_result = false
end
]]>[/COLOR][COLOR="Blue"]</event>[/COLOR]
[COLOR="blue"]<globalevent[/COLOR] [COLOR="Red"]name[/COLOR]=[COLOR="DarkOrchid"]"Reward_All" [/COLOR][COLOR="red"]interval[/COLOR]=[COLOR="DarkOrchid"]"10" [/COLOR][COLOR="red"]event[/COLOR]=[COLOR="DarkOrchid"]"script"[/COLOR][COLOR="blue"]>[/COLOR][COLOR="Orange"]<![CDATA[
domodlib('tutorial_config')
function onThink(interval, lastExecution, thinkInterval)
for _, users in ipairs(getPlayersLearning()) do
doGiveCookies(users, config.cookies)
end
return true
end
]]>[/COLOR][COLOR="Blue"]</globalevent>
[COLOR="blue"]<talkaction[/COLOR] [COLOR="Red"]words[/COLOR]=[COLOR="DarkOrchid"]"!stealcookie" [/COLOR][COLOR="red"]event[/COLOR]=[COLOR="DarkOrchid"]"buffer" [/COLOR][COLOR="red"]value[/COLOR]=[COLOR="DarkOrchid"]"doGiveCookies(cid, 1)"[/COLOR][COLOR="blue"]/>[/COLOR]
</mod>[/COLOR]
2. You may have noticed we used 3 different ways to display the code in that example. Well there are 4 ways to include data in mods.
Yes FOUR! Here's the rundown...
First way: Script in CDATA
This method is the most popular and is the easiest to migrate from regular lua scripts.
Make sure its event="script" and not set to event="buffer"
You simply include the entire code from a regular lua file in between the <![CDATA[ and ]]> tags.
Lua:
function modTutorial(cid, IQ)
if isLearning(cid) then
doAddPlayerRep("syntax")
end
return true
end
Second way: Buffer in CDATA
This basically eliminates the need to call return and end the function, its all done for you, all you have todo is...
Lua:
if isLearning(cid) then
doAddPlayerRep("syntax")
_result = false --same as return false when using "script" mode
_result = true --same as return true when using "script" mode
end
Third way: Buffer in value field
You may put very simple (usually 1 lined scripts) in the value field.
Example: value="doGiveCookies(cid, 1)"
NOTE: Event must be set to "buffer"!
Fourth way: Script in separate file
Instead of event="buffer" set to event="script"
Then put the file in the "mods/scripts/" folder
Next set the value field to filename: value="test.lua"
...this lesson is complete, stay tuned for more
Last edited: