Host versus User issue, manager_action_init.lua
I am having an issue that only seems to be a user side problem, NOT a host/DM side.
Currently I have a effect applied when someone rolls initiative for a spell. That is so that if they are hit before their turn there is a notification about spell interruption.
When the DM/Host rolls initiative the value is set properly for nInit in the effect (i.e. the initiative value just rolled).
When the Player/User rolls initiative the value is set to the PREVIOUSLY rolled initiative.
Here is the relevant code.
Code:
function onResolve(rSource, rTarget, rRoll)
ActionsManager2.decodeAdvantage(rRoll);
local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
Comm.deliverChatMessage(rMessage);
local nTotal = ActionsManager.total(rRoll);
notifyApplyInit(rSource, nTotal);
-- now we apply effect if this was a spell cast initiative
if (rRoll and rRoll.spellPath) then
applySpellCastingConcentration(rSource,rRoll);
end
end
function applySpellCastingConcentration(rSource,rRoll)
local nTotal = ActionsManager.total(rRoll);
local sActorType, nodeActor = ActorManager.getTypeAndNode(rSource);
local nodeSpell = DB.findNode(rRoll.spellPath);
local nodeChar = nodeActor;
if not string.match(nodeActor.getPath(),"^combattracker") then
nodeChar = CharManager.getCTNodeByNodeChar(nodeActor);
end
-- if not in the combat tracker bail
if not nodeChar or not nodeSpell then
return;
end
Debug.console("manager_action_init.lua","applySpellCastingConcentration","nodeChar",nodeChar);
--local nTotal = rRoll.nT
-- build effect fields
local sSpellName = DB.getValue(nodeSpell,"name","");
local rEffect = {};
local sEffectString = "(C)";
local sEffectFullName = "Casting " .. sSpellName .. "; " .. sEffectString;
rEffect.nDuration = 1;
rEffect.sName = sEffectFullName;
rEffect.sLabel = sEffectString;
rEffect.sUnits = "rnd";
rEffect.nInit = DB.getValue(nodeChar,"initresult",0);
rEffect.sSource = nodeChar.getPath();
rEffect.nGMOnly = 0;
rEffect.sApply = "action";
Debug.console("manager_action_init.lua","applySpellCastingConcentration","rEffect.nInit",rEffect.nInit);
Debug.console("manager_action_init.lua","applySpellCastingConcentration","sEffectFullName",sEffectFullName);
Debug.console("manager_action_init.lua","applySpellCastingConcentration","nodeChar.getPath()",nodeChar.getPath());
-- need to do some error checking to make sure we only add it once
-- verify existing "effect_source" and "label" isn't the same as this one.
local bFound = false;
for _,nodeEffect in pairs(DB.getChildren(nodeChar, "effects")) do
local sLabel = DB.getValue(nodeEffect,"label","");
local sSource = DB.getValue(nodeEffect,"source_name","");
Debug.console("manager_action_init.lua","applySpellCastingConcentration","sLabel",sLabel);
Debug.console("manager_action_init.lua","applySpellCastingConcentration","sSource",sSource);
-- if (sSource == nodeSpell.getPath()) then
if (sLabel == sEffectFullName and sSource == nodeChar.getPath()) then
bFound = true;
break;
end
end -- for item's effects list
if bFound then
-- effect already exists
return;
end
-- lastly add effect
local sUser = User.getUsername();
local sIdentity = User.getCurrentIdentity(sUser);
EffectManager.addEffect(sUser, sIdentity, nodeChar, rEffect, true);
end
Here is an example of the debug output for DM for an initiative roll of 12.
Code:
Runtime Notice: Reloading ruleset
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'nodeChar' | databasenode = { combattracker.list.id-00001 }
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'rEffect.nInit' | #12
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'sEffectFullName' | s'Casting Bless; (C)'
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'nodeChar.getPath()' | s'combattracker.list.id-00001'
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'sLabel' | s'IFT: ARMOR(plate mail,platemail);ATK: 1'
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'sSource' | s''
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'sLabel' | s'Casting Bless; (C)'
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'sSource' | s'combattracker.list.id-00001'
Network Notice: 'Gorig' connected
Network Warning: Unable to locate requested file 'Tokens/Elf_Male_Archer2_feather_woodland_bow.png@TP46 Heroic Characters 2 Tokens'
Database Notice: Campaign saved.
Here a follow up roll made by a Player using the same character. The player rolled 16 but as you can see it's showing 12.
Code:
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'nodeChar' | databasenode = { combattracker.list.id-00001 }
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'rEffect.nInit' | #12
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'sEffectFullName' | s'Casting Bless; (C)'
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'nodeChar.getPath()' | s'combattracker.list.id-00001'
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'sLabel' | s'IFT: ARMOR(plate mail,platemail);ATK: 1'
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'sSource' | s''
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'sLabel' | s'Casting Bless; (C)'
Runtime Notice: s'manager_action_init.lua' | s'applySpellCastingConcentration' | s'sSource' | s'combattracker.list.id-00001'
The DM can continue to roll and see the initiative value that matches the roll made right then (not previous).
I'm sure this is an "access" thing but I'm not sure where. I've already given players access to the CT node they "own" so im baffled where else they need it for this to work properly.