PDA

View Full Version : Weapon Property Effect in LUA



Alucard339
March 6th, 2020, 20:57
Hi,

Can anyone help me? my players are starting to get equipment with magical effect, like a katana sword that decrease crit range by +1 (19-20). I have put CRIT:+1 in the weapon property,
but now I am trying to find a way to read the property node when he use a weapon to see if its the katana or not.

I need help on how to get the current used weapon different info (nodes).

tx,
Alu

Zacchaeus
March 6th, 2020, 21:22
The correct syntax is 'crit range 19'. See here for more information on weapon properties https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/786659/5E+Item+Sheet+and+Treasure+Parcels#Create-a-Weapon

Alucard339
March 6th, 2020, 21:37
TY for that,

But what if/when i come around a power not described or taken care by 5e.
Is there and easy what to read what is in the current weapon properties or notes??

Zacchaeus
March 6th, 2020, 21:57
TY for that,

But what if/when i come around a power not described or taken care by 5e.
Is there and easy what to read what is in the current weapon properties or notes??

You'll need to be more specific as to what you mean. As noted there are only a couple of things which FG recognises in the weapon properties box and FG handles all of the situations described by these words, such as finesse, crit range and reroll. If you put something in there that FG doesn't recognise then it will be ignored. You would probably use effects for anything else but it depends as I say on what you are thinking about.

Also if you are talking about writing an extension then I can't answer that one.

Alucard339
March 6th, 2020, 23:25
so our ranger has a special crossbow he built with follow 3 effect = on hit slow target (DISINIT); increased dmg (to next dice); sunder (break object instead of normal attack);
I know that from "function calcItemArmorClass(nodeChar)" under manager_char.lua that you can read items different info

I.E.: DB.getValue(vNode, "properties", "");

but i want to read that for the weapon being used for the current attack (I guess with the weapon ID).
Like when range use his crossbow and hit it will automatically put slow effect on target, without us doing it manually.
I already know how to add/remove effect from target/source.
I just need the part on how to read current weapon properties, using the formula above or something like it.

Trenloe
March 7th, 2020, 07:28
Look in the campaign database for the charsheet entry of the PC in question, then find the weapon entry you’re interested in. See which field the weapon properties are stored in. This will give you an idea of the database hierarchy.

See some info here on the FG database: https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Database

See here for info on database nodes: https://www.fantasygrounds.com/refdoc/databasenode.xcp

Depending on what database node reference you have available when you run your code will determine what FG LUA database code you need to use. If you have direct access to the database node of the weapon, then <databasenode>.getValue(<properties field name>) should be enough. But if you only have access to the charsheet database node, then you’ll have to traverse the FG database hierarchy to get to the weapon database node.

Look in the 5E ruleset scripts\manager_action_attack.lua file to see where that code checks for weapon properties to get an example. I’m not in front of my computer right now, so can’t point you to the exact place, but I’m pretty sure that script does reference weapon properties.

Alucard339
March 9th, 2020, 23:03
Tx for the info, I was able to write/change code under 5e ruleset char_weapon.lua (see below). The only issue I still have is with "sPropDmgType". I can't seem to find the right way to read the strings so if the weapon is doing "slashing,piercing,cold" dmg type to get all 3. if you guys can help that would be awesome. if not i am sure later ill figure it out (i am still a bit confuse about how to fully use all the special character with .find or :match).
let me know what you think. I will also create a new post soon about all I was able to change in case someone is interested in some extension. then once i am fully done and i have clean it all up, I'll try to publish my full extension.

function onAttackAction(draginfo)
local rAction = {};
local OutofAmmo = false;
local nodeWeapon = getDatabaseNode();
rAction.nodeWeapon = nodeWeapon
local nodeChar = nodeWeapon.getChild("...")
local rActor = ActorManager.getActor("pc", nodeChar);

-- *** Generate Attack ***
local aWeaponProp = DB.getValue(nodeWeapon, "properties", "");
rAction.bWeapon = true;
rAction.label = name.getValue();
rAction.stat = DB.getValue(nodeWeapon, "attackstat", "strength");
local nWpnSkill =DB.getValue(nodeWeapon, "prof", 0); --- *** Attack and dmg modifier ***
local nWpnprof = 0;
if nWpnSkill == 1 then
nWpnprof = math.floor(DB.getValue(nodeChar, "level", 0) / 8) +1;
elseif nWpnSkill == 2 then
nWpnprof = math.floor(DB.getValue(nodeChar, "level", 0) / 4) +2;
elseif nWpnSkill == 3 then
nWpnprof = math.floor(DB.getValue(nodeChar, "level", 0) /2) +4;
end
rAction.prof = nWpnprof;
if type.getValue() == 0 then -- *** melee wpn ***
rAction.range = "M";
elseif type.getValue() == 1 then -- *** range weapon ***
rAction.range = "R";
elseif type.getValue() == 2 then -- *** throw weapon ***
rAction.range = "R";
end
-- *** Get ALL info from current weapon properties ***
local sPropcategory = aWeaponProp:match("Category:%s(%w+)") or "";
local sPropSize = aWeaponProp:match("Size:%s(%w+)") or "";
local sPropMaterial = aWeaponProp:match("Material:%s(%w+)") or ""; --- *** detemine what special creature it can hit ***
local sPropType = aWeaponProp:match("Type:%s(%w+)") or ""; --- *** will be use to qualify for special feat (ie: samurai = +1 attack when using blades) ***
local nSkillAtkMod =0;
for _,v in pairs(DB.getChildren(nodeChar, "skilllist")) do
if DB.getValue(v, "name", "") == "Wpn ".. sPropType then
nSkillAtkMod = DB.getValue(v, "total", "");
break;
end
end
local sPropBuilder = aWeaponProp:match("Builder:%s(%w+)") or "";
local sPropQuality = aWeaponProp:match("Quality:%s(%w+)") or ""; --- *** Attack modifier ***
local nWpnQuality = 0;
if sPropQuality == "master" then
nWpnQuality = 2;
elseif sPropQuality == "superior" then
nWpnQuality = 1;
elseif sPropQuality == "inferior" then
nWpnQuality = -1;
end
local nPropMagic = tonumber(aWeaponProp:match("Magic Level:%s(%d)")) or 0; --- *** Attack and dmg modifier ***
local nPropMinSTR = tonumber(aWeaponProp:match("MIN STR:%s(%d+)")) or 0; --- *** Attack penalty if not strong enough to use weapon ***
local nActorSTR = ActorManager2.getAbilityScore(rActor, "strength");
local nActorStrMod = math.min((nActorSTR-nPropMinSTR),0);
local nPropSDCNow = tonumber(aWeaponProp:match("SDC:%s(%d+)")) or 0; --- *** Attack penalty if weapon weardown is <50% or <25%***
local nPropSDCFull = tonumber(aWeaponProp:match("SDC:%s%d+.(%d+)")) or 0;
local nSDCMod =0;
if 4*nPropSDCNow < nPropSDCFull then
nSDCMod = -2;
elseif 2*nPropSDCNow < nPropSDCFull then
nSDCMod = -1;
end
local nPropCrit = tonumber(aWeaponProp:match("CRIT:%s(.%d)")) or 0; --- *** Crit range modifier ***
local nCritThreshold = 0;
if rAction.range == "R" then
nCritThreshold = DB.getValue(nodeChar, "weapon.critrange.ranged", 20);
else
nCritThreshold = DB.getValue(nodeChar, "weapon.critrange.melee", 20);
end
local aEffCrit = EffectManager5E.getEffectsByType(rActor, "CRIT", {}, ""); --- *** Look to see if any active effect will change Crit Range ***
local EffCritMod =0;
for k,v in pairs (aEffCrit) do
if v.mod then
EffCritMod = EffCritMod+v.mod
end
end
local nPropATK = tonumber(aWeaponProp:match("ATK%s(.%d+)")) or 0; --- *** Attack modifier due to weapon thickness or other cirtumstance***
local nPropBaseDMG = tonumber(aWeaponProp:match("Base DMG:%s(%d+)")) or 0; --- *** dmg modifier ***
local sPropDmgType = aWeaponProp:match("DMGTYPE:%s(%w+)") or ""; --- *** determine weapon DMGTYPEs ***
-- !!!!!!!!!! still need to get all diffent dmgtype !!!!!!!!!!!!!!!!

rAction.DMGTYPE = sPropDmgType..", "..sPropMaterial
local sPropRange = aWeaponProp:match("Rng:%s(%w+)") or ""; --- *** max range to be able to attack with weapon***
rAction.range = sPropRange;
-- *** Calculate Attack modifier ***
rAction.modifier = DB.getValue(nodeWeapon, "attackbonus", 0) + nSkillAtkMod + nWpnQuality + nPropMagic + nActorStrMod + nSDCMod + nPropATK;
-- *** Calculate Attack Crit Range***
rAction.CritRange = nCritThreshold - nPropCrit - EffCritMod;

-- *** Calculate Weapon Base Dmg rank ***
local nPropExtraDMG = aWeaponProp:match("DR:%s(.%d+)") or 0;
local aDR = EffectManager5E.getEffectsByType(rActor, "DMGRNK", {}, {});
local ActorEffDR =0;
for k,v in pairs (aDR) do
if v.mod then
ActorEffDR = ActorEffDR +v.mod
end
end
rAction.WpnDmgRnk = nPropBaseDMG + nWpnSkill + nPropMagic + nPropExtraDMG + ActorEffDR ;

-- *** Decrement ammo and if not enough ammo stop attack ***
local nMaxAmmo = DB.getValue(nodeWeapon, "maxammo", 0);
local aAMMO = EffectManager5E.getEffectsByType(rActor, "AMMO", {}, rActor);
local ExtraAmmo =0;
for k,v in pairs (aAMMO) do
if v.mod then
ExtraAmmo = ExtraAmmo +v.mod;
end
end
if nMaxAmmo > 0 then
local nUsedAmmo = DB.getValue(nodeWeapon, "ammo", 0);
nUsedAmmo = nUsedAmmo + ExtraAmmo;
if nUsedAmmo >= nMaxAmmo then
ChatManager.Message(Interface.getString("char_message_atkwithnoammo"), true, rActor);
return false;
else
DB.setValue(nodeWeapon, "ammo", "number", nUsedAmmo + 1);
end
end

-- *** Resolve the Attack ***
ActionAttack.performRoll(draginfo, rActor, rAction);

return true;
end

Here is an example of the result with the debug.chat for the rRoll. Attack #1 was a hit, but Attack #2 was such a miss that the goblin counterattack the samurai. and Attack 3 is what a critical hit look like (which in this case actually insert the "Torso Injury" in the hero CTNode.
32017
32023

Alucard339
March 9th, 2020, 23:11
Note: As of now, the dmg are automatically rolled upon a successful hit.

I am also looking to go read Monster file to get their actions so i can pick what i need to help with attack and DMG.
Like for the 5e goblin, when i click on the attack (#1) i want to be able to also go read the action node/scimitar to get the average hit dmg (#2) so I can apply it to my DMG.

anyone can help?

32012