PDA

View Full Version : Helperscript for weapon damage.



Kurald
May 21st, 2010, 08:38
Hi,

I created a helper script for rolling damage. It evaluates a damage expression in the weapon list and creates the dice for rolling the damage.

the script is one function:


function onDrag(button, x, y, draginfo)
local value = getValue(); --get damage value
value = string.lower(value); --convert to lower case
--amount: number of dies
--dietype: type of die
--modifier: modifier for the die roll
test,_, amount, dietype, modifier = string.find(value,"(%d+)d(%d*)([+-]?%d*)");
print(test) --if it matches a fully evaluated damage (e.g. 3d+2) and not sw+1 or thr+1
if test~=nil then
if dietype == "" then --set dicetype to d6 if not present (GURPS style)
dietype = 6;
end
if modifier == "" then --set modifier to 0 if not present
modifier = 0;
end
--Debug output - enable if needed
--print("Amount: "..amount);
--print("Dietype: "..dietype);
--print("Modifier: "..modifier);
local dielist = {} --declare dielist
for i=1,amount do --fill dielist according to the expression
dielist[i]="d"..dietype;
end
draginfo.setType("dice");
draginfo.setDieList(dielist);
draginfo.setNumberData(modifier);
draginfo.setDescription("damage:");
else
print("no constant damage found");
end
return true;
end


There's still one problem: I did not figure out yet how I can include the weapon name in the draginfo description

insertion points: charsheet_weapons.xml

<textlistitemvalue name="handweapon_damage">
<textlistitemvalue name="rangedweapon_damage">


insert the following tag:
<script file="scripts/onDragParser.lua" />

and save the code above into the file mentioned in the script tag.

Please test it and check if you like it. Of course you may include it into your code base if you like spyke. As far as I see it, it does not automate any GURPS mechanics. It only grabs the dice. It does not calculate the damage if it is stat-based. This way it should comply to the licence.

Please feel free to try it and give feedback.

regards,
Kurald

Kurald
May 21st, 2010, 08:51
Hi,

I just added support for the multiplier notation of GURPS (e.g. 6dx3).

Here's the code:


function onDrag(button, x, y, draginfo)

local name = "";
-- check weapon name. dependent on Spykers GURPS ruleset
if window.rangedweapon_name_mode ~= nil then
name = window.rangedweapon_name_mode.getValue();
end
if window.handweapon_name ~= nil then
name = window.handweapon_name.getValue();
end

local value = getValue(); --get damage value
value = string.lower(value); --convert to lower case
--amount: number of dies
--dietype: type of die
--modifier: modifier for the die roll
test,_, amount, multiplier = string.find(value,"(%d+)d(x%d+)"); --GURPS 6dx3-like damage notation
if test~=nil then
--Debug output - enable if needed
--print("Amount: "..amount);
--print("Multiplier: "..multiplier);
local dielist = {} --declare dielist
for i=1,amount do --fill dielist according to the expression
dielist[i]="d6";
end
draginfo.setType("dice");
draginfo.setDieList(dielist);
draginfo.setNumberData("0");
draginfo.setDescription(name.." damage, multiply by "..multiplier..":");
else
test,_, amount, dietype, modifier = string.find(value,"(%d+)d(%d*)([+-]?%d*)");
if test~=nil then
if dietype == "" then --set dicetype to d6 if not present (GURPS style)
dietype = 6;
end
if modifier == "" then --set modifier to 0 if not present
modifier = 0;
end
--Debug output - enable if needed
--print("Amount: "..amount);
--print("Dietype: "..dietype);
--print("Modifier: "..modifier);
local dielist = {} --declare dielist
for i=1,amount do --fill dielist according to the expression
dielist[i]="d"..dietype;
end
draginfo.setType("dice");
draginfo.setDieList(dielist);
draginfo.setNumberData(modifier);
draginfo.setDescription(name.." damage:");
else

print("no constant damage found");
end
end
return true;
end


I had to include and additional regex for that.

regards,
Kurald

Spyke
May 21st, 2010, 10:28
Impressive. I'm away travelling at the moment, but I'll take a look next week when I get back.

Spyke

Kurald
May 21st, 2010, 14:13
I'm glad if I can give you something back. The ruleset you created is great.

------------------

Added support for weapon name. Wepon name now displayed on die roll. Code added to the second code window.

Kurald
May 21st, 2010, 22:28
I included handling for swing and thrust damage. The damage entered in the main tab will be read and modified according to the entered damage.

E.g.: main tab: Thrust 1d6-1, Weapon: Katana thrust+1
this information will 'automagically' transformed into 1d6 and the draginfo will be created appropriatly.

Next step: filter the wounding modifier (cr, imp, pi+, ...) and include them in the description posted.
Example: Knife damage (imp): 2+1



function onDrag(button, x, y, draginfo)
local characterNode = getDatabaseNode().getParent().getParent().getParen t(); -- get charsheet db node
local statsNode = characterNode.getChild("stats"); -- get stats db node
local thrustNode = statsNode.getChild("thrust"); -- get thrust damage db node
local swingNode = statsNode.getChild("swing"); -- get swing damage db node

local thrust = thrustNode.getValue(); -- read thrust damage
if thrust == nil then thrust = "" end
local swing = swingNode.getValue(); -- read swing damage
if swing == nil then swing = "" end

local name = "";
-- check weapon name. dependent on Spykers GURPS ruleset
if window.rangedweapon_name_mode ~= nil then
name = window.rangedweapon_name_mode.getValue();
end
if window.handweapon_name ~= nil then
name = window.handweapon_name.getValue();
end

local value = getValue(); --get damage value
value = string.lower(value); --convert to lower case
-- check if swing or thrust damage. if that is the case, replace the damage with die damage and proceed normally
-- swing
test,_,summand = string.find(value,"sw([+-]?%d*)");
if test~=nil then
--we have swing damage
--dissect swing damage and add the summand
test,_, amount, dietype, modifier = string.find(swing,"(%d+)d(%d*)([+-]?%d*)");
if test == nil then return true; end -- no swing damage entered
if modifier == "" then --set modifier to 0 if not present
modifier = 0;
end
if summand == "" then
summand = 0;
end
summand = summand + modifier;
if summand<0 then
value = amount.."d"..summand;
else
value = amount.."d+"..summand;
end
end
test,_,summand = string.find(value,"thr([+-]?%d*)");
if test~=nil then
--we have swing damage
--dissect swing damage and add the summand
test,_, amount, dietype, modifier = string.find(thrust,"(%d+)d(%d*)([+-]?%d*)");
if test == nil then return true; end -- no thrust damage entered
if modifier == "" then --set modifier to 0 if not present
modifier = 0;
end
if summand == "" then
summand = 0;
end
summand = summand + modifier;
if summand<0 then
value = amount.."d"..summand;
else
value = amount.."d+"..summand;
end
end


print("Value: "..value);
--amount: number of dies
--dietype: type of die
--modifier: modifier for the die roll
test,_, amount, multiplier = string.find(value,"(%d+)d(x%d+)"); --GURPS 6dx3-like damage notation
if test~=nil then
--Debug output - enable if needed
--print("Amount: "..amount);
--print("Multiplier: "..multiplier);
local dielist = {} --declare dielist
for i=1,amount do --fill dielist according to the expression
dielist[i]="d6";
end
draginfo.setType("dice");
draginfo.setDieList(dielist);
draginfo.setNumberData("0");
draginfo.setDescription(name.." damage, multiply by "..multiplier..":");
else
test,_, amount, dietype, modifier = string.find(value,"(%d+)d(%d*)([+-]?%d*)");
if test~=nil then
if dietype == "" then --set dicetype to d6 if not present (GURPS style)
dietype = 6;
end
if modifier == "" then --set modifier to 0 if not present
modifier = 0;
end
--Debug output - enable if needed
--print("Amount: "..amount);
--print("Dietype: "..dietype);
--print("Modifier: "..modifier);
local dielist = {} --declare dielist
for i=1,amount do --fill dielist according to the expression
dielist[i]="d"..dietype;
end
draginfo.setType("dice");
draginfo.setDieList(dielist);
draginfo.setNumberData(modifier);
draginfo.setDescription(name.." damage:");
else

print("no constant damage found");
end
end
return true;
end

Kurald
May 23rd, 2010, 08:10
I just added drag&drop for personalities as well. It supports (2) different attacks by using different (left / middle) mouse buttons. The damage has to be seperated by ; and it can not contain sw / thr as these are not included in the sheet.

I want to add support for additional weapons using shift/alt/ctrl to distinguish the different weapons, but I don't know if I can get the state of these keys.

----------------------------------------------------------------------------------------------------
I just found the input and changed the coding:

MB1 selects the first damage,
MB1+shift selects the second
MB1+alt selects the third
MB2 selects the 4th
MB2+shift the 5th
MB2+alt the 6th

ctrl reveals the dice (built-in function)

The order is how the keys are arranged on the keyboard (from top left to lower right)

Kurald
May 23rd, 2010, 08:40
Next plans: throwing 3d6 on skills & displaying the skill name and level. This way the GM can ask for a skill roll and the player just has to throw the dice via drag and drop. And the GM has all the information needed.

saithan
August 1st, 2010, 17:59
these would really help me gain better control over the flow of my gurps games
can some one please elaborate on getting these scripts functional.

with the first script I created onDragParser.lua placing the code into it

the opened the charsheet_weapons.xml
and added <script file="scripts/onDragParser.lua" /> after each of the two points.
<textlistitemvalue name="handweapon_damage">
<textlistitemvalue name="rangedweapon_damage">
loaded my gurps_4e campaign and see nothing to drag.

does these scripts need a button or such added to the charactersheet to make them function?

thanks in advance.

Kurald
August 1st, 2010, 18:12
no, they work directly. The script parsed the text written as damage and converts it into damage dice.

saithan
August 1st, 2010, 18:42
I must be missing something because I'm not getting any drag-able from the character sheets.

Kurald
August 1st, 2010, 20:48
I sent you a pm where you can download my version of the GURPS ruleset.

ronnke
August 1st, 2010, 22:08
You should try and co ordinate with spyke so that we do not have divergent rulesets for GURPS. These additions are pretty cool.

saithan
August 15th, 2010, 22:48
this was something I built off of Kuralds awesome work.
added his 3d6 function to the weapon level also showing the weapon level in the output any modifier in the modstack gets applied to that number and the modified target number is shown with the results as such "swings Flail(10-4=6):" then the result.



function onDrag(button, x, y, draginfo)
print("Entering function");

local name = "";
name = window.handweapon_name.getValue();
local method = window.handweapon_mode.getValue();
local level = window.handweapon_skilllevel.getValue();
local des= ModifierStack.getDescription(true);
local modifier = ModifierStack.getSum();
local equal ="=";
if modifier > 0 then
des ="+";
end


if des == "+" then
nulevel = level + modifier;
elseif des == "" then
nulevel = level + modifier;
end

if ModifierStack.isEmpty() then
modifier="";
equal = "";
nulevel="";

end


local dielist = {} --declare dielist
for i=1,3 do --fill dielist according to the expression
dielist[i]="d6";
end

draginfo.setType("dice");
draginfo.setDieList(dielist);
draginfo.setDescription(method.."s "..name.."("..level..des..modifier..equal..nulevel.."):");
ModifierStack.reset()
return true;
end

it is sloppy I know.
latter maybe I can add a parsing function to the dice land in the chat lua to state weather the roll is a possible success of failure.

saithan
August 17th, 2010, 04:28
ok i added a parser tothe chat_chat lua ondiceland function it reads the target number to roll and compares it to the result and tells you possible hit if the result is lower than the target. it also detects critical hit or miss on 3 or 18.

local entry = {};
entry.font = "systemfont";
entry.text = draginfo.getDescription();
entry.dice = draginfo.getDieList();

applyModifierStackToRoll(draginfo);

entry.diemodifier = draginfo.getNumberData();

-- never hide rolls (for secret rolls use your desktop as it isn't for players anyway)
-- entry.dicesecret = false;

-- highest roll
local bestresult = 0;
for k, d in ipairs(entry.dice) do
--if d.result > bestresult then
bestresult = bestresult + d.result;
--end
end

local target =string.match(entry.text,"%b()");
if target == nil then
bestresult="";
else
target = string.match(target, "%d+");

bestresult = string.match(bestresult, "%d+");
if target == "" then
--do nothing
else
if tonumber(bestresult)== "3" then
bestresult="[Critical Hit!]";
elseif tonumber(bestresult)== "18" then
bestresult = "[Critical Miss!]";

else

if tonumber(bestresult) <= tonumber(target) then
bestresult = "[ Possible Hit! ]";
else
bestresult = "";
end
end
end
end

entry.text = entry.text.. bestresult;
if User.isHost() then
entry.sender = GmIdentityManager.getCurrent();
else
entry.sender = User.getIdentityLabel();
end

if User.isHost() then
entry.icon = "portrait_gm_token";
else
entry.icon = "portrait_" .. User.getCurrentIdentity() .. "_miniportrait";
end

-- Deliver the chat entry
deliverMessage(entry);
return true;



the other part was minor altered to make it work.
made "onDragWeaonsSkill.lua"


function onDrag(button, x, y, draginfo)
print("Entering function");

local name = "";
name = window.handweapon_name.getValue();
local method = window.handweapon_mode.getValue();
local level = window.handweapon_skilllevel.getValue();
local des= ModifierStack.getDescription(true);
local modifier = ModifierStack.getSum();
local equal ="=";
if modifier > 0 then
des ="+";
end


if des == "+" then
nulevel = level + modifier;
elseif des == "" then
nulevel = level + modifier;
end
nulevel = "("..nulevel..")";
if ModifierStack.isEmpty() then
modifier="";
equal = "";
nulevel="";
if nulevel == "" then
level = "("..level..")";
end

end


local dielist = {} --declare dielist
for i=1,3 do --fill dielist according to the expression
dielist[i]="d6";
end

draginfo.setType("dice");
draginfo.setDieList(dielist);
draginfo.setDescription(method.."s "..name.." "..level..des..modifier..equal.." "..nulevel..":");
ModifierStack.reset()
return true;
end


added the call for it on the weapon_skills section of the weapons xml.
again this is sloppy I'm no lua programmer I figure since you have to still manually enter any modifiers into the stack and manually adjust figures etc. this should still come within the SJgames online policy.

again thanks goes to spyke, Kurald and tarostar.

Kurald
August 17th, 2010, 05:17
you just have to remember that gurps works the other way round. The modifier modify the target number and not the die roll (like most other rpgs and fantasy ground does).

But thank you for sharing your code. I think I'll put it in my ruleset as well.

saithan
August 17th, 2010, 11:27
already thought of that,it is set to when you grab the die ondrag the modifier from the stack in called and reset and then applied to the target number instead of the roll.

saithan
August 17th, 2010, 23:29
found two bugs in the code I submitted.

first where the code finds looks for the unmodified target pattern.

local target =string.match(entry.text,"%b()");

change the "%b()" to "%(%d+%)"

found this bug when using Kuralds ranged weapon damage, since I use spyke's GCA import/export to insert my characters into FG the ranged weapons in the weapon field sometimes look like such: Large Knife (thrown)
causing a conflicting instance of the %b() patern.

next where it looks for critical hits or misses:
tonumber(bestresult)== "3"
and
tonumber(bestresult)== "18"

change the "3" to tonumber('3')
change the 18 to tonumber('18')

these two I have no excuse other than I do not know what I'm doing and getting clueless in my old age.

Spyke
August 19th, 2010, 19:04
Sorry I've been out the loop for a while, guys. Been very busy. I will get round at some point before too long to reviewing the various code contributions and figuring out what I'm comfortable with building into the main ruleset.

Spyke

saithan
August 28th, 2010, 20:48
finally figured out how to get kuralds script to the skills tab. took a while of hacking about.
I discovered that the charsheet_templates.xml was over riding the ondrag function.

so i edited the section for the textlistitemvalue template. by first removing the nodrag tag.
then below the onlosefocus() function, I added the onDrag function.


function onDrag(button, x, y, draginfo)

local checker = "";


if not editmode then
if hoverontext then
draginfo.setType("shortcut");
draginfo.setShortcutData(window[linktarget[1]].getValue());
draginfo.setIcon(window[linktarget[1]].icon[1].normal[1])
return true;
else

checker = getDatabaseNode().getName();
if checker == "skill_level" then
local level = window.getDatabaseNode().getChild("skill_level").getValue();
local name = window.getDatabaseNode().getChild("skill_name").getValue();
local des= ModifierStack.getDescription(true);
local modifier = ModifierStack.getSum();

local equal ="=";
if modifier > 0 then
des ="+";
end

if des == "+" then
nulevel = level + modifier;
elseif des == "" then
nulevel = level + modifier;
end

nulevel = "("..nulevel..")";
if ModifierStack.isEmpty() then
modifier="";
equal = "";
nulevel="";
if nulevel == "" then
level = "("..level..")";
end

end


local dielist = {};
for i=1,3 do
dielist[i]="d6";
end


draginfo.setType("dice");
draginfo.setDieList(dielist);
draginfo.setDescription("#"..name.." "..level..des..modifier..equal.." "..nulevel..":");
ModifierStack.reset();

end


return true;

end
end


end


after that I thought it should give a different message than the weapons tab.
note the # in the line:
draginfo.setDescription("#"..name.." "..level..des..modifier..equal.." "..nulevel..":");
so it can be found by the parser in the chat_chat.lua which ws modified to handle messages starting with #.



local entry = {};
entry.font = "systemfont";
entry.text = draginfo.getDescription();
entry.dice = draginfo.getDieList();

applyModifierStackToRoll(draginfo);

entry.diemodifier = draginfo.getNumberData();

-- never hide rolls (for secret rolls use your desktop as it isn't for players anyway)
-- entry.dicesecret = false;

-- highest roll
local bestresult = 0;
for k, d in ipairs(entry.dice) do
--if d.result > bestresult then
bestresult = bestresult + d.result;
--end
end

local target =string.match(entry.text,"%(%d+%)");
if target == nil then
bestresult="";
else
target = string.match(target, "%d+");

bestresult = string.match(bestresult, "%d+");
if target == "" then
--do nothing
else
if tonumber(bestresult)== tonumber('3') then
bestresult="[Critical Hit!]";
elseif tonumber(bestresult)== tonumber('18') then
bestresult = "[Critical Miss!]";

else

if tonumber(bestresult) <= tonumber(target) then
bestresult = "[ Possible Hit! ]";
else
bestresult = "";
end
end
end

if string.match(entry.text, "%#") and bestresult == "[ Possible Hit! ]" then
bestresult = "[Success!]";
entry.text = string.gsub(entry.text, "%#", "");
end

if string.match(entry.text, "%#") and bestresult == "" then
bestresult = "[Failure!]";
entry.text = string.gsub(entry.text, "%#", "");
end

if string.match(entry.text, "%#") and bestresult == "[Critical Hit!]" then
bestresult = "[Crtical Success!]";
entry.text = string.gsub(entry.text, "%#", "");
end

if string.match(entry.text, "%#") and bestresult == "[Critical Miss!]" then
bestresult = "[Crtical Failure!]";
entry.text = string.gsub(entry.text, "%#", "");
end

end

entry.text = entry.text.. bestresult;
if User.isHost() then
entry.sender = GmIdentityManager.getCurrent();
else
entry.sender = User.getIdentityLabel();
end

if User.isHost() then
entry.icon = "portrait_gm_token";
else
entry.icon = "portrait_" .. User.getCurrentIdentity() .. "_miniportrait";
end

-- Deliver the chat entry
deliverMessage(entry);
return true;

end


as before the modifier is intercepted to apply it to the skill instead of the roll.

these are all modifications to Kuralds helper script.

yako2020
March 4th, 2013, 14:35
I wonder if there is some way and if there is how do I make adjustments to damage rolls for different types of attack (cut, pierce, impale).
And I wonder if you can build something that reduces the damage before modifiers.
Example: I have a character with ST 15 and a spear.
He 1d6 + 3 damage, say he attack an NPC with leather armor (DR 2 *). And the damage roll has rolled 6. The damage will be 9 -2 (DR) = 7 +100% = 14
In FG he says I got attacked successfully, roll the damage when he shows the amount and type but in doing the calculations.
I just believe that this would facilitate more life for all, since getting the exact result can already drag for HP (player or NPC) and decrement.
I also believe that it would be no problem, at least in my view.

Saith_mobile
March 4th, 2013, 15:24
I have plans for making a calculator tool. However there are no plans for making the process automated. that then becomes a direct violation of the SJGames policy.

yako2020
March 4th, 2013, 16:50
Cool a calculator will help a lot and need some way to convince Uncle Steve and his agents to allow automation (just kidding), but that would be interesting.

saithan
March 4th, 2013, 21:11
i myself am not into the automation.I have found it just as simple to inform the players they were hit and where and how much damage the players can then look at their armor locations and easily deduce the damage that got through.

S Ferguson
March 5th, 2013, 02:11
Could you PM me so I can get a copy of this, Been out of GURPS for a while, and want to start back up. This piece of code looks like something I'd use.

Saith_mobile
March 5th, 2013, 13:22
http://enhanced.vlexofree.com
No need to pm. You can also contact me in the chat weekdays after 6:00pm est gmt -5
If you want a tour of the features (not had time to make documentation).