-
Notifications
You must be signed in to change notification settings - Fork 11
plugin
Some command handlers and some event handlers have support for Plugins
.
Let's configure a new lua script handler for when the player uses the item 1740 (chest). Open \mtanksl.OpenTibia.GameData\data\plugins\config.lua
.
plugins = {
actions = {
{ type = "PlayerUseItem", opentibiaid = 1740, filename = "use.lua" },
...
},
...
}
And then open \mtanksl.OpenTibia.GameData\data\plugins\actions\use.lua
.
function onuseitem(player, item)
print("Player " .. player.Name .. " used item " .. item.Id)
return false
end
Let's configure a new lua script handler for when the player uses the item 1740 (chest) using self registration. Create a new file at \mtanksl.OpenTibia.GameData\data\plugins\scripts\[file].lua
(replace [file]
with a file name) with the following code.
function onuseitem(player, item)
print("Player " .. player.Name .. " used item " .. item.Id)
return false
end
registeractionsplayeruseitem(1740, onuseitem)
Let's configure a new C# handler for Light Spell. Open \mtanksl.OpenTibia.GameData\data\plugins\config.lua
.
plugins = {
...
spells = {
...
{ words = "utevo lux", name = "Light", group = "Support", cooldown = 2, groupcooldown = 2, level = 8, mana = 20, soul = 0, premium = false, vocations = { vocation.knight, vocation.paladin, vocation.druid, vocation.sorcerer, vocation.eliteknight, vocation.royalpaladin, vocation.elderdruid, vocation.mastersorcerer }, requirestarget = false, filename = "OpenTibia.GameData.Plugins.Spells.LightSpellPlugin" },
...
},
...
}
And then open \mtanksl.OpenTibia.GameData\data\plugins\spells\LightSpellPlugin.cs
.
public class LightSpellPlugin : SpellPlugin
{
public LightSpellPlugin(Spell spell) : base(spell)
{
}
public override PromiseResult<bool> OnCasting(Player player, Creature target, string message)
{
return Promise.FromResultAsBooleanTrue;
}
public override Promise OnCast(Player player, Creature target, string message)
{
return Context.AddCommand(new ShowMagicEffectCommand(player, MagicEffectType.BlueShimmer) ).Then( () =>
{
return Context.AddCommand(new CreatureAddConditionCommand(player,
new LightCondition(new Light(6, 215), new TimeSpan(0, 6, 10) ) ) );
} );
}
}
Let's configure a new C# handler for Light Spell using self registration. Create a new file at \mtanksl.OpenTibia.GameData\data\plugins\scripts\[file].lua
(replace [file]
with a file name) with the following code.
public class LightSpellPlugin : SpellPlugin
{
public class LightSpellPluginScript : Script
{
public override void Start()
{
Context.Server.Plugins.AddSpellPlugin(false, new LightSpellPlugin(new Spell()
{
Words = "utevo lux",
Name = "Light",
Group = "Support",
Cooldown = TimeSpan.FromSeconds(2),
GroupCooldown = TimeSpan.FromSeconds(2),
Level = 8,
Mana = 20,
Soul = 0,
Premium = false,
Vocations = new[] { Vocation.Knight, Vocation.Paladin, Vocation.Druid, Vocation.Sorcerer, Vocation.EliteKnight, Vocation.RoyalPaladin, Vocation.ElderDruid, Vocation.MasterSorcerer }
} ) );
}
public override void Stop()
{
}
}
public LightSpellPlugin(Spell spell) : base(spell)
{
}
public override PromiseResult<bool> OnCasting(Player player, Creature target, string message)
{
return Promise.FromResultAsBooleanTrue;
}
public override Promise OnCast(Player player, Creature target, string message)
{
return Context.AddCommand(new ShowMagicEffectCommand(player, MagicEffectType.BlueShimmer) ).Then( () =>
{
return Context.AddCommand(new CreatureAddConditionCommand(player,
new LightCondition(new Light(6, 215), new TimeSpan(0, 6, 10) ) ) );
} );
}
}
You can compile the plugins and let the server load it during startup.
Take a look at the project mtanksl.OpenTibia.Plugins
. This is one example that contains ammunition, runes, spells and weapons definitions.
The compiled plugin must be placed at \mtanksl.OpenTibia.GameData\data\dlls\[pluginname]\[pluginname].dll
(replace [pluginname]
with a plugin name).
If not using self registration, the filename parameter in \mtanksl.OpenTibia.GameData\data\plugins\config.lua
must have the following format [classname], [pluginname]
(replace classname
with the full namespace plus class name and [pluginname]
with the plugin name).