PDA

View Full Version : Skill Hotkey with die



georgethebob
November 1st, 2007, 03:17
I wanted to be able to just drag a skill total down to the hotkey bar and be able to click for a check making those all too often skill checks like listen and spot a little quicker. While I worked out the code to drag the skill total down and it sets a labeled hotkey that you can click and it will then roll a d20 and add the modifer for the skill and displaying the skill name it only has the modifer from when you dragged it down so with a skill level change you have to reset the hotkey.

Locate the following code in charsheet_skills.xml and then highlight the entire selection


draginfo.setType("number");
draginfo.setDescription(desc);
draginfo.setNumberData(getValue());



Once you have the above segment selected paste in the code from below replacing the above text.


draginfo.setType("dice");
draginfo.setDieList({"d20"});
draginfo.setNumberData(getValue());
draginfo.setDescription(desc);


After saving you should be able to drag the skill total to the hotkey bar and on click perform a skill check with modifier and skill name displayed

You will also want to go throught setting up your chatmanager.lua via joshua's post
https://www.fantasygrounds.com/forums/showthread.php?t=6015

Hamish
November 1st, 2007, 07:40
To avoid having to reset the hotkey after you add skill ranks, you can use the code I posted here (https://www.fantasygrounds.com/forums/showthread.php?t=7176&page=2).
Maybe there is a way to combine the two.... I'll see if I can find the time to figure it out!

georgethebob
November 1st, 2007, 17:06
Sounds good Hamish that would be much better.

I worked out the code for the initiative field so that you can perform the same exercise of adding a d20 when you drag from the field.

Find this section of the initiative code in both the charsheet_main.xml and charsheet_combat.xml . On my xml editor it's around line 968 for combat and 1239 for main.



<source>
<name>initiative.misc</name>
<op>+</op>
</source>


After you find it place the following code directly after it.



<script>
function onDrag(button, x, y, draginfo)

draginfo.setType("dice");
draginfo.setDieList({"d20"});
draginfo.setNumberData(window.initiative.getValue( ));
draginfo.setDescription("initiative");

return true;
end
</script>


As another side note if you drag more dice to the hotkey they will not replace the formula but add that die to it even if it is a die dragged from the initiative box. So that if your initiative bonus is changed if you drag the new one down and try to replace the hotkey it will only add another die and not adjust to the new modifier. Check Hamish's post above for away to possibly keep the hotkey updated.

georgethebob
November 1st, 2007, 18:33
Here is the info for setting up saves.

Find the saves section for charsheet_combat.xml and charsheet_main.xml
My editor has them at lines 1064 main and 1352 combat.


First for the combat sheet:
Find the
</modifiernumber> for each of the saves place the following code above it.



<script>
function onDrag(button, x, y, draginfo)

draginfo.setType("dice");
draginfo.setDieList({"d20"});
draginfo.setNumberData(window.fortitudesave.getVal ue());
draginfo.setDescription("Fortitude Save");

return true;
end
</script>


When you are done with the fortitude save it will look like this:


<name>saves.fortitude.misc</name>
<op>+</op>
</source>
<script>
function onDrag(button, x, y, draginfo)

draginfo.setType("dice");
draginfo.setDieList({"d20"});
draginfo.setNumberData(window.fortitudesave.getVal ue());
draginfo.setDescription("Fortitude Save");

return true;
end
</script>
</modifiernumber>

Now repeat this process with the reflex and will saves replacing the word "fortitude" both times in the code with the respective name of the save you are editing.

After this repeat the entire process on the charsheet_combat.xml the only difference is where you put the code. In this .xml file you look for the following code in the saves section for each particular save:


<description>
<text>Fortitude save</text>
</description>
</save>


Put the script code between the
</description> and
</save> So that you're final product looks like this.


<description>
<text>Fortitude save</text>
</description>
<script>
function onDrag(button, x, y, draginfo)

draginfo.setType("dice");
draginfo.setDieList({"d20"});
draginfo.setNumberData(window.fortitudesave.getVal ue());
draginfo.setDescription("Fortitude Save");
return true;
end
</script>
</save>


Just make sure the the save name in the code matches the save section you are in.

Hamish
November 6th, 2007, 09:17
I tried combining our features, and it seems possible. I'm working on it, I still have problems with skills with sublabels.

Valarian
November 6th, 2007, 10:28
I posted this code in the thread regarding automatic die rolling on a double-click (https://www.fantasygrounds.com/forums/showthread.php?t=6015&page=4). This code shows the sublabel of cascade skills like Knowledge and Craft. It may help.

e.g.
Knowledge (History)
Craft (Weaponsmith)
Profession (Herbalist)



function onDoubleClick(x,y)
local label = window.getDatabaseNode().getChild("label").getValue();
local sublabel = window.getDatabaseNode().getChild("sublabel").getValue();

local desc = label;
if not sublabel or sublabel ~= "" then
desc = label .. " (" .. sublabel .. ")";
end

ChatManager.d20Check("d20", getValue(), desc);
return true;
end

Hamish
November 6th, 2007, 14:19
Thanks Valarian, but the problem is I have to do the reverse, I have to find a specific skill node in the database. For example, I know the skill I want to roll is Knowledge (Arcane), but I have to find the node number under skilllist that holds the correct value. I have a function set up to do this, but I never thought about the sublabels, so it doesn't handle those.

I'll look into it, I don't think it will be very difficult.

Hamish
November 14th, 2007, 20:17
Well, it was a little harder than it looked, and it turns out it was in my original coding of the database queries. I posted an update on the code here (https://www.fantasygrounds.com/forums/showthread.php?t=7176&page=2). You must implement those changes if you want to use what I post below.

As for combining our features, I have it set up for skills and abilities at the moment.
For skills change the onDrag function of the numberfield "total" to:

function onDrag(button, x, y, draginfo)
local label = window.getDatabaseNode().getChild("label").getValue();
local sublabel = window.getDatabaseNode().getChild("sublabel").getValue();

local desc = label;
if not sublabel or sublabel ~= "" then
desc = label .. " (" .. sublabel .. ")";
end

draginfo.setType("string");
draginfo.setIcon("d20icon");
draginfo.setStringData("/die 1d20+{skilllist.[" .. string.gsub(desc, " ", "_") .. "].total} " .. desc);
draginfo.setDescription(desc);
return true;
end


For abilities add the following block to the abilitybonus fields: (I've shown strength, just replace all occurences of strength for the other abilities)

<script>
function onDrag(button, x, y, draginfo)
draginfo.setType("string");
draginfo.setIcon("d20icon");
draginfo.setStringData("/die 1d20+{abilities.strength.bonus} Strength");
draginfo.setDescription("Strength");
return true;
end
</script>

I'll post the code for the other things you made draggable later.

Hamish
November 15th, 2007, 10:03
For saving throws, add the following block of code to the "modifiernumber" fields (in charsheet_main.xml) and the "save" fields (in charsheet_combat.xml): (I've shown Fortitude, just replace all occurences of fortitude for the other saves)


<script>
function onDrag(button, x, y, draginfo)
draginfo.setType("string");
draginfo.setIcon("d20icon");
draginfo.setStringData("/die 1d20+{saves.fortitude.total} Fortitude Save");
draginfo.setDescription("Fortitude Save");
return true;
end
</script>

Hamish
November 15th, 2007, 10:14
For initiative rolls, add the following block of code to the linkednumber "initiative" field (in charsheet_main.xml) and to the sheetbonus "initiative" field (in charsheet_combat.xml):


<script>
function onDrag(button, x, y, draginfo)
draginfo.setType("string");
draginfo.setIcon("d20icon");
draginfo.setStringData("/die 1d20+{initiative.total} Initiative");
draginfo.setDescription("Initiative");
return true;
end
</script>