PDA

View Full Version : How to show only the desired version of a skill



Xarxus
July 18th, 2022, 15:46
So here's my solution. It works, but I don't know if what I have done is correct or if it can create problems somewhere.

First of all, I will describe to you what the problem was. I have a ruleset and two (or more modules). Each module has a description of some skills, one of which exists on multiple modules.
When loading both modules nad opening the skill list, you see both versions, which may cause problems as players may be using the outdated version instead of the revised one.

My solution involves the generation of a LUA script which at the time of initialization registers a function (onEvent) to be called for these 5 events: onModuleLoad, onModuleUnload, onModuleAdded, onModuleUpdated and onModuleRemoved.

The function essentially does 3 things:
1. if both modules are loaded it makes a backup of the module skill with the original version (obviously it is tested that this backup is not already present);
2. if both modules are loaded delete the original skill (if it still exists);
3. if the original skill appears in the backups and the original module is loaded, while the one with the revised version is not, restore the original version (obviously testing that it does not already exist).

I would say everything happens very quickly. This solution implies that the ruleset must know which skill to look for and on which module. I am open to any suggestions.

This is added ti base.xml

<script name="SkillVersionManager" file="scripts/skill_version_manager.lua" />

This is part of skill_version_manager.lua - I don't show the search or existence check functions because they are trivial checks of the DB. I think in the end I will leave only the search ones (find), cleaning up the code a bit.


function onInit()
Interface.onDesktopInit = onDesktopInit;
end

function onDesktopInit()
Module.onModuleLoad = SkillVersionManager.onEvent;
Module.onModuleUnload = SkillVersionManager.onEvent;
Module.onModuleAdded = SkillVersionManager.onEvent;
Module.onModuleUpdated = SkillVersionManager.onEvent;
Module.onModuleRemoved = SkillVersionManager.onEvent;
end

function onEvent()
local nodeDest;
local nodeOrig;

if existsBackupVersion() == false
and ModuleManager.isModuleLoaded("Module A") == true
and ModuleManager.isModuleLoaded("ModuleB") == true then
nodeDest = DB.createChild('backup');
nodeOrig = findModuleA(); -- Finds the original verison on Module A
DB.copyNode(nodeOrig, nodeDest);
end

if existsBackupVersion() == true
and existsOriginalVersion() == true
and ModuleManager.isModuleLoaded("ModuleA") == true
and ModuleManager.isModuleLoaded("ModuleB") == true then
nodeOrig = findModuleA();
DB.deleteNode(nodeOrig);
end

if existsBackupVersion == true
and existsOriginalVersion == false
and ModuleManager.isModuleLoaded("ModuleA") == true
and ModuleManager.isModuleLoaded("ModuleB") == false then
nodeDest = DB.createChild('[ path on module A ]');
DB.copyNode(findBackupVersion(), nodeDest);
DB.setCategory(findOriginalVersion, "ModuleA");
end
end

LordEntrails
July 18th, 2022, 15:54
Extensions have a property called LoadOrder. I don't think modules do. But, maybe your extension/ruleset can use some of the code from it (if it is accessible in corerpg or an API). I don't know, and am not a coder/developer but maybe that can be of use to you (if desired, what you are doing sounds reasonable to me.)

Xarxus
July 18th, 2022, 16:49
Yep, but I don't want an extension. It could be hard to manage and a master could forget to load it.
I've found an easier way. So, here is the revised code.



function onInit()
Interface.onDesktopInit = onDesktopInit;
end

function onDesktopInit()
Module.onModuleLoad = SkillVersionManager.onEvent;
Module.onModuleUnload = SkillVersionManager.onEvent;
Module.onModuleAdded = SkillVersionManager.onEvent;
Module.onModuleUpdated = SkillVersionManager.onEvent;
Module.onModuleRemoved = SkillVersionManager.onEvent;

onEvent();
end

function onEvent()
DB.revert(' Path Module A');

if ModuleManager.isModuleLoaded("ModuleA") == true
and ModuleManager.isModuleLoaded("ModuleB") == true then
nodeOrig = findModuleA();
DB.deleteNode(nodeOrig);
end
end

Xarxus
July 21st, 2022, 21:53
I have noticed that the command DB.revert(' Path Module A'); does not work on the client. I have to unload and load by hand.
Anyone have an idea why it doesn't work and hat to do?

Moon Wizard
July 21st, 2022, 22:21
Clients don't support revert command; as they never own module data and revert only works on module data.

Regards,
JPG