DICE PACKS BUNDLE
Page 1 of 3 123 Last
  1. #1

    Helperscript for weapon damage.

    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:
    Code:
    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

  2. #2

    support for multiplier notation added

    Hi,

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

    Here's the code:
    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
    Last edited by Kurald; May 21st, 2010 at 14:30.

  3. #3
    Spyke's Avatar
    Join Date
    Jun 2005
    Location
    Yorkshire, UK
    Posts
    886
    Impressive. I'm away travelling at the moment, but I'll take a look next week when I get back.

    Spyke
    Free GURPS tools for Fantasy Grounds at www.spyke.me.

  4. #4
    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.
    Last edited by Kurald; May 21st, 2010 at 14:29.

  5. #5

    swing & thrust damage from charactersheet_main

    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

    Code:
    function onDrag(button, x, y, draginfo)
    	local characterNode = getDatabaseNode().getParent().getParent().getParent(); -- 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

  6. #6

    Attack field in personalities

    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)
    Last edited by Kurald; May 23rd, 2010 at 08:59.

  7. #7
    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.

  8. #8
    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.

  9. #9
    no, they work directly. The script parsed the text written as damage and converts it into damage dice.

  10. #10
    I must be missing something because I'm not getting any drag-able from the character sheets.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
FG Spreadshirt Swag

Log in

Log in