Kelrugem
May 24th, 2019, 12:38
Hello :)
For my extension Save versus Tags (for 3.5e/Pathfinder), I may have realized some bug in some function in CoreRPG which I described in the thread of my extension but I am not sure if it will be read there since its description is somewhere in the thread. Therefore I want to describe it also here and I attach also my way of fixing that. In the other thread I wrote:
[...] I found some bug (?) in removeTarget function in the CoreRPG file manager_targeting.lua [...]. removeTarget not only removes some target of the actor (e.g. the caster) it also adds the target to the actor when the target is actually not a target, i.e. removeTarget(actor, Test) adds Test as a target of the actor when Test is not a target of the actor which is probably not the wanted aim of that function, isn't? Therefore I changed that function by adding adding an if-clause checking wether Test is actually a target. One can test that "bug" by taking some player character, then turn "Remove on Miss" in the options to "On" such that also single targets are removed. Make sure that this character has not any target and then drag&drop an attack die from a weapon action onto some NPC in the CT. When it is a miss then that player will get that NPC as target. On the next miss it will be removed, but again it is added after the next miss and so on.
My fix looks like (new stuff in blue and, yes, the arguments of hasTarget in the first if-clause of removeTarget can be made easier probably, isn't it? I had to do it like that since hasTarget(sSourceNode,sTargetNode) didn't work)
function hasTarget(rActorNode,rTargetNode)
local sEntry = rTargetNode.getNodeName();
for _,vTarget in pairs(DB.getChildren(rActorNode, "targets")) do
if DB.getValue(vTarget, "noderef", "") == sEntry then
return true;
end
end
return false;
end
function removeTarget(sSourceNode, sTargetNode)
if hasTarget(ActorManager.getCTNode(ActorManager.getA ctorFromCT(sSourceNode)), ActorManager.getCTNode(ActorManager.getActorFromCT (sTargetNode))) then
local tokenSource = CombatManager.getTokenFromCT(sSourceNode);
local tokenTarget = CombatManager.getTokenFromCT(sTargetNode);
if tokenSource and tokenTarget then
if tokenSource.getContainerNode() == tokenTarget.getContainerNode() then
tokenSource.setTarget(false, tokenTarget.getId());
return;
end
end
local nodeSourceCT = CombatManager.getCTFromNode(sSourceNode);
local nodeTargetCT = CombatManager.getCTFromNode(sTargetNode);
if nodeSourceCT and nodeTargetCT then
notifyToggleTarget(nodeSourceCT, nodeTargetCT);
end
end
end
Best,
Kelrugem
For my extension Save versus Tags (for 3.5e/Pathfinder), I may have realized some bug in some function in CoreRPG which I described in the thread of my extension but I am not sure if it will be read there since its description is somewhere in the thread. Therefore I want to describe it also here and I attach also my way of fixing that. In the other thread I wrote:
[...] I found some bug (?) in removeTarget function in the CoreRPG file manager_targeting.lua [...]. removeTarget not only removes some target of the actor (e.g. the caster) it also adds the target to the actor when the target is actually not a target, i.e. removeTarget(actor, Test) adds Test as a target of the actor when Test is not a target of the actor which is probably not the wanted aim of that function, isn't? Therefore I changed that function by adding adding an if-clause checking wether Test is actually a target. One can test that "bug" by taking some player character, then turn "Remove on Miss" in the options to "On" such that also single targets are removed. Make sure that this character has not any target and then drag&drop an attack die from a weapon action onto some NPC in the CT. When it is a miss then that player will get that NPC as target. On the next miss it will be removed, but again it is added after the next miss and so on.
My fix looks like (new stuff in blue and, yes, the arguments of hasTarget in the first if-clause of removeTarget can be made easier probably, isn't it? I had to do it like that since hasTarget(sSourceNode,sTargetNode) didn't work)
function hasTarget(rActorNode,rTargetNode)
local sEntry = rTargetNode.getNodeName();
for _,vTarget in pairs(DB.getChildren(rActorNode, "targets")) do
if DB.getValue(vTarget, "noderef", "") == sEntry then
return true;
end
end
return false;
end
function removeTarget(sSourceNode, sTargetNode)
if hasTarget(ActorManager.getCTNode(ActorManager.getA ctorFromCT(sSourceNode)), ActorManager.getCTNode(ActorManager.getActorFromCT (sTargetNode))) then
local tokenSource = CombatManager.getTokenFromCT(sSourceNode);
local tokenTarget = CombatManager.getTokenFromCT(sTargetNode);
if tokenSource and tokenTarget then
if tokenSource.getContainerNode() == tokenTarget.getContainerNode() then
tokenSource.setTarget(false, tokenTarget.getId());
return;
end
end
local nodeSourceCT = CombatManager.getCTFromNode(sSourceNode);
local nodeTargetCT = CombatManager.getCTFromNode(sTargetNode);
if nodeSourceCT and nodeTargetCT then
notifyToggleTarget(nodeSourceCT, nodeTargetCT);
end
end
end
Best,
Kelrugem