PDA

View Full Version : Scripting problem



ttuckel
October 20th, 2013, 17:24
Hello,

I'm working on a ruleset based on the 3.5/Pathfinder's ruleset.
I'm trying to scripting this dice rolling :

A + B + C = D
and a dble click on D = 1D100
Text in the chat box : [Player's Name], [Stat Name], [Stat Value], [Result]

Here is my script code :

<script>
function onSourceUpdate()
local nodeWin = window.getDatabaseNode();
local nCurrentScore = DB.getValue(nodeWin, "abilities." .. target[1] .. ".score");
local nCurrentDamage = DB.getValue(nodeWin, "abilities." .. target[1] .. ".damage");
local nCurrentProgress = DB.getValue(nodeWin, "abilities." .. target[1] .. ".progress");
local nBonus = nCurrentScore + nCurrentDamage + nCurrentProgress;
setValue(nBonus);
end

function onInit()
addSource("abilities." .. target[1] .. ".score");
addSource("abilities." .. target[1] .. ".damage");
addSource("abilities." .. target[1] .. ".progress");

super.onInit();
end

function action(draginfo)
local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
ActionAbility.performRoll(draginfo, rActor, self.target[1]);

return true;
end

function onDragStart(button, x, y, draginfo)
return action(draginfo);
end

function onDoubleClick(x,y)
return action();
end
</script>

It works but the [Stat Value] is not in the chat box.
How can I add "sAbilityStat" in the result in the chat box ?

Thank you in advance and sorry for my bad english !

Tuck.

Moon Wizard
October 21st, 2013, 00:45
You would need to update the ActionAbility script file which contains the performRoll function. It is reference in the base.xml file, and is most likely located at scripts/manager_action_ability.lua in the ruleset directory.

Regards,
JPG

ttuckel
October 21st, 2013, 13:26
Thank you for your response but my capacities in scriting are limited ... !

Here is my manager_action_ability.lua :

function getRoll(rActor, sAbilityStat, nTargetDC, bSecretRoll, bAddName)
local rRoll = {};

-- SETUP
rRoll.aDice = {"d100","d10"};
rRoll.nMod = ActorManager.getAbilityBonus(rActor, sAbilityStat);

-- BUILD THE OUTPUT
rRoll.sDesc = "[CARACTERISTIQUE]";
rRoll.sDesc = rRoll.sDesc .. " Test de ";
rRoll.sDesc = rRoll.sDesc .. " " .. StringManager.capitalize(sAbilityStat);


if bAddName then
rRoll.sDesc = "[ADDNAME] " .. rRoll.sDesc;
end
if bSecretRoll then
rRoll.sDesc = "[MJ] " .. rRoll.sDesc;
end

local rCustom = {};
if nTargetDC then
table.insert(rCustom, { nMod = nTargetDC } );
end

return rRoll, rCustom;
end

function performRoll(draginfo, rActor, sAbilityStat, nTargetDC, bSecretRoll, bAddName)
local rRoll, rCustom = getRoll(rActor, sAbilityStat, nTargetDC, bSecretRoll, bAddName);

ActionsManager.performSingleRollAction(draginfo, rActor, "ability", rRoll, rCustom);
end

my charsheet.main.xml :

<!--CC-->
<number_charabilityscore name="cc" source="abilities.cc.score">
<anchored>
<to>abilityframe</to>
<position>insidetopleft</position>
<offset>105,23</offset>
</anchored>
</number_charabilityscore>
<string_charabilitylabel>
<anchored>
<to>cc</to>
</anchored>
<static>Cap. Combat</static>
</string_charabilitylabel>
<number_charabilityprogress name="ccprogress" source="abilities.cc.progress">
<anchored>
<to>cc</to>
</anchored>
<target>cc</target>
</number_charabilityprogress>
<number_charabilitydamage name="ccdamage" source="abilities.cc.damage">
<anchored>
<to>cc</to>
</anchored>
<target>cc</target>
</number_charabilitydamage>
<number_charabilitybonus name="ccbonus" source="abilities.cc.bonus">
<anchored>
<to>cc</to>
</anchored>
<target>cc</target>
<numberfield>abilities.cc.bonusmodifier</numberfield>
<description>
<text>CC Actuel</text>
</description>
</number_charabilitybonus>

my template.charsheet.main.xml :

<template name="number_charabilitybonus">
<number_chartotal>
<anchored>
<position>right</position>
<offset>93,0</offset>
<size>
<width>36</width>
</size>
</anchored>
<hideonvalue value="0" />
<rollable />


<script>
function onSourceUpdate()
local nodeWin = window.getDatabaseNode();
local nCurrentScore = DB.getValue(nodeWin, "abilities." .. target[1] .. ".score");
local nCurrentDamage = DB.getValue(nodeWin, "abilities." .. target[1] .. ".damage");
local nCurrentProgress = DB.getValue(nodeWin, "abilities." .. target[1] .. ".progress");
local nBonus = nCurrentScore + nCurrentDamage + nCurrentProgress;
setValue(nBonus);
end

function onInit()
addSource("abilities." .. target[1] .. ".score");
addSource("abilities." .. target[1] .. ".damage");
addSource("abilities." .. target[1] .. ".progress");

super.onInit();
end

function action(draginfo)
local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
ActionAbility.performRoll(draginfo, rActor, self.target[1]);

return true;
end

function onDragStart(button, x, y, draginfo)
return action(draginfo);
end

function onDoubleClick(x,y)
return action();
end
</script>
</number_chartotal>
</template>

How can I defined that my "nBonus" value is my "sAbilityStat" and print it on the chatbox ?
Thank you.

Tuck.

cscase
October 21st, 2013, 20:34
I think you'll want to look at the section in that first script where it says "--BUILD THE OUTPUT."

If you aren't sure exactly how it works, start by making some experiments. Change something slightly and see what happens. For example, take one of those lines where it says "rRoll.sdesc =" and make the second half say something about one of the variables you are concerned with, then see what comes out.

As a newcomer to working with this stuff myself, I understand how intimidating it can be. If you persist, you will figure it out. And if you don't figure it out, you'll at least figure out specific questions that you need to focus on, and that will make it easier to get help. Hang in there!

Dakadin
October 22nd, 2013, 01:22
Try changing this line:

rRoll.sDesc = rRoll.sDesc .. " " .. StringManager.capitalize(sAbilityStat);


to this:

rRoll.sDesc = rRoll.sDesc .. " " .. StringManager.capitalize(sAbilityStat) .. " (" .. ActorManager.getAbilityBonus(rActor, sAbilityStat) .. ")";


That should show the stat bonus in parenthesis right after the stat name.