PDA

View Full Version : Who is going to create the first usefull script?



richvalle
April 23rd, 2007, 21:57
So, who's it going to be and what will it do?

:)

rv

joshuha
April 23rd, 2007, 22:07
I have one built into the source code hehe. Look at the chat_chat.lua file for this section:



-- local dicetable = {};
-- dicetable = draginfo.getDieList();

-- local size = table.maxn(dicetable)
-- for i= 1,size do
-- if (dicetable[i].type == "d10" and dicetable[i].result == 10) then
-- local explodetable = {};
-- table.insert(explodetable, "d10");
-- throwDice("dice", explodetable, 0, "Exploded");
-- end
-- end



Copy the d20 ruleset folder to a new directory and copy the following files: base.xml, desktop.xml, desktop_classes.xml, scripts/chat_chat.lua.
In the chat_chat.lua file comment the above section out.
In the base.xml file change the desktop.xml to your custom ruleset location.
In the desktop.xml file change the desktop_classes.xml to your custom ruleset location.
In the desktop_classes.xml section change the chat_chat.lua reference to your custom ruleset location.

Now roll a d10 or several d10 until you get a 10 and it should roll another one automatically. During the beta this would crash the program but the devs said they fixed it so someone test it out before I can.

richvalle
April 23rd, 2007, 22:12
Ok... the first one not built into the base code.

Cheater. :) :)

rv

nezzir
April 24th, 2007, 00:57
I'm not a programmer, but here's a script I'd really like to see.

Start with text files full of items.
I'd like to be able to select a text file and randomly generate an item from the chosen file.

That would be extremely handy for names, place, things, attributes to items, encounters, equipment, - I could go on and on.

If anyone knows if this is possible, I'd really like to see something on it.

Oberoten
April 24th, 2007, 09:35
Well, it seems to be working now. No bugs and exploding D10s.

Hmmm... I keep poking at it a bit as well to add a stress-die with less than stellar results.

Basically what I need is this :
On a 1 : Reroll and Double the next roll, if that too is a 1 reroll again and double twice. IE x2 x4 x8 x16 x32 x64 x128 etc etc.

On a 0 : Reroll and substract, on a second zero, reroll and double and substract the final roll. IE x-1 x-2 x-4 x-8 x-16 x-32

joshuha
April 24th, 2007, 14:08
Well, it seems to be working now. No bugs and exploding D10s.

Hmmm... I keep poking at it a bit as well to add a stress-die with less than stellar results.

Basically what I need is this :
On a 1 : Reroll and Double the next roll, if that too is a 1 reroll again and double twice. IE x2 x4 x8 x16 x32 x64 x128 etc etc.

On a 0 : Reroll and substract, on a second zero, reroll and double and substract the final roll. IE x-1 x-2 x-4 x-8 x-16 x-32

Since you need to track multiple series (a 1, then do something if you get ANOTHER 1) you will need to use the CampaignRegistry table to hold some flags/values in between the rolls. It wouldn't be terribly difficult and if you are willing to help me test some this weekend I can help you work it out :)

joshuha
April 24th, 2007, 14:09
I'm not a programmer, but here's a script I'd really like to see.

Start with text files full of items.
I'd like to be able to select a text file and randomly generate an item from the chosen file.

That would be extremely handy for names, place, things, attributes to items, encounters, equipment, - I could go on and on.

If anyone knows if this is possible, I'd really like to see something on it.

I don't think we have access to files through the LUA script in FG due to security concerns. However, this could be done easily enough through large table values in LUA. Wouldn't be as customizable as you are looking for but it would still be doable.

Goblin-King
April 24th, 2007, 14:37
Since you need to track multiple series (a 1, then do something if you get ANOTHER 1) you will need to use the CampaignRegistry table to hold some flags/values in between the rolls. It wouldn't be terribly difficult and if you are willing to help me test some this weekend I can help you work it out :)
I just added a fifth optional parameter to chatwindow.throwDice that will get added as the custom data to the roll. You can use this to pass data from one step of the roll to the next. The passed data would be available as draginfo.getCustomData() in the d20 example.

Edit: Available after the next update, of course...

bonzai95
July 19th, 2007, 21:35
So is there any way to check the Crit field to see if the die >= the crit and roll an extra d20 if it is?

joshuha
July 19th, 2007, 21:42
Yes thats easily doable once you parse out whats in the field.

Just in the chat_chat.lua file look for the onDiceLanded event and you would process the results then and do a throwDice() command with the appropiate parameters.

Oberoten
July 19th, 2007, 22:26
*scratches head thoughtfully*
... and somehow I feel totally stupid here?
How would one use this to create a script like that?

I am afraid that I have so far had very little luck in wrapping my head around the LUA functions...

(I managed to make a crit-dice in the Beta using the random functions... but I'd much prefer to be able to use the "normal" dice instead."

bonzai95
July 19th, 2007, 23:03
I was able to add the code to throw an extra d20 on attack if the value of the first is >= x.

I need to replace x with the crit value of the weapon they are using. I'm not sure how to identify the weapon the player is using and the crit field therin.

bonzai

joshuha
July 20th, 2007, 01:23
There are 2 ways to do this depeding on the approach you take. Any attack rolled from the default d20 sheet on the combat tab is flagged as a custom type called fullattack. So thats the first thing that clues us in where we want to put our code.

In the chat_chat.lua file in the onDiceLanded function you'll see an event that processes that type of dragdata.

Checking the result of the roll is the easy part the harder part is getting the crit number from the sheet and this is where there are two approaches.

One is to have the charsheet_fullattack.lua script pass as a custom slot in the dragdata the critical value needed. This is a bit tricky as the default processing in the onDiceLanded assumes each slot is a seperate die roll but not too hard to modify.

The second way is since the name of the weapon is sent as part of the description string to parse that out and look at the weaponlist of the character and loop through until you find it.

Either way isn't too bad and I can throw up some code for it eventually but busy working on Savage Worlds stuff. The first way is cleaner though and most likely will end up being less lines of code.

SirJoe
July 22nd, 2007, 11:22
Hey guys,

I was wondering if someone could help me by creating a script that does dice rolling for my favorite game, Feng Shui.

In Feng Shui, you roll two six-sided dice and minus the second (negative die) from the first (positive die). Each die explode on a 6.

Ideally, I'd like to have button or widget on the FG2 desktop than can be clicked and it will make the rolls and calculate the total.

Any help would be muchly appreciated.

Cheers,
Sir Joe

joshuha
July 23rd, 2007, 00:55
I can probably provide some help for this but it will be a bit before I can devote some time for this. Graphically do you want 2d6 to be thrown still for effect? We can use those as the base results and then remove the original results message, process exploded internally, and report the final results.

SirJoe
July 23rd, 2007, 01:32
I can probably provide some help for this but it will be a bit before I can devote some time for this. Graphically do you want 2d6 to be thrown still for effect? We can use those as the base results and then remove the original results message, process exploded internally, and report the final results.

I'd LOVE :D to see the dice actually roll and explode out, but it's not 100% nessesary really.

Thanks a million for any help you can give me on this. I've already worked out how to implement the combat tracking in FS in a very simple way (just using tokens and a specially-created graphic), so now all I need is the dice and I'll use the 'generic' ruleset for the rest.

Cheers,
JS

SirJoe
September 11th, 2007, 22:40
Hey Joshua,

Any chance to take a look at this Feng Shui dice idea? I'm working on some new adventures and would love to put them into an online gaming environment.
Cheers,
JS

joshuha
September 12th, 2007, 00:57
Hey Joshua,

Any chance to take a look at this Feng Shui dice idea? I'm working on some new adventures and would love to put them into an online gaming environment.
Cheers,
JS

Thought about this more and there are a couple ways to do this. First off, Fantasy Grounds doesn't let the dice results value be negative, I tried and it has no effect.

So for example, through scripting I pass 2d6 to be rolled, and a 3 and a 4 land, I change the dice result value to -4 before it spits it out but the screen still shows 3,4 and hitting the equal icon still shows 7. So here are my proposals on ways around this:

1) Make each one a separate line. So you would see on one line the positive number (and all exploding dice), the next one the negative number (and all exploding dice), and finally an all text third line that shows the total. This is alright but might be a lot of chat spam if every roll works like this.

2) Make them all one line and just display all the aced diced together and inline the totals. Something like Melee {Total 7} [dice icons here]. The dice icons would all get jumbled together though in low/high order so it would be hard to tell which ones exploded for the positive bonus and negative bonus.

3) Make the entire line a text line that spits out (you still get the graphic die rolls though). Something like Melee [6,2] - [4] = 4. This probably is the best solution although not as "pretty" as the others since you don't get the little dice icons with the number but it will fit the best I think.

Let me know, number 3 is the easiest way though and I can probably whip out something for you in a day or so.

SirJoe
September 12th, 2007, 01:06
Option 3 would be fine. Anything that is quick and easy to get a game going. :-)

Cheers,
JS

joshuha
September 12th, 2007, 02:14
Option 3 would be fine. Anything that is quick and easy to get a game going. :-)

Cheers,
JS

Ok here's what I whipped together quickly.

First, you will obviously need to create your own custom ruleset for this.

The first thing I modified is the chatmanager.lua file like so (towards the end of the file):


function test()
-- throws 2d6, labels it Feng Shui and passes a custom paramter called fengshui
ChatManager.control.throwDice("dice", {"d6","d6"}, 0, "Feng Shui", "fengshui");
end

-- Initialization
function onInit()
registerSlashHandler("/whisper", processWhisper);
registerSlashHandler("/die", processDie);
registerSlashHandler("/test",test);
end


All the above does is toss 2 special Feng Shui dice that are d6s with a custom parameter of "fengshui". This uses the nice 3D dice so you still get the effect. The custom parameter is used later to determine when to process these special dice. It works by typing /test but you said you wanted to tie it into a button or something (I will leave that up to you but all you need to do is have it call the same throwDice() command and you can not bother with the above).

The meat of the code is going to be in the chat_chat.lua file. This file contains a function called onDiceLanded() that processes dice that hit the chat box. Find the, elseif draginfo.isType("dice") then, and replace it with the following:


elseif draginfo.isType("dice") then
applyModifierStackToRoll(draginfo);

--look at flag to see if feng shui dice were thrown
local flag = draginfo.getCustomData();
if flag == "fengshui" then
--get die list
dice = draginfo.getDieList();
die1results, die2results = {},{};
die1results[1] = dice[1].result;
die2results[1] = dice[2].result;

---explode first die
if die1results[1] == 6 then
repeat
die1 = math.random(1,6);
table.insert(die1results, die1);
until die1 ~= 6
end

--explode second die
if die2results[1] == 6 then
repeat
die2 = math.random(1,6);
table.insert(die2results, die2);
until die2 ~= 6
end

---build message string
msg = {};
msg.font = "systemfont";
--icon to make sure players can't make up rolls
msg.icon = "indicator_casterspontaneous";
msg.text = draginfo.getDescription();
msg.text = msg.text .. " [";
--build inline results for first die, also get total
totaldie1 = 0;
for i=1,table.maxn(die1results) do
if i < table.maxn(die1results) then
msg.text = msg.text .. die1results[i] .. ",";
else
msg.text = msg.text .. die1results[i] .. "]";
end
totaldie1 = totaldie1 + die1results[i];
end

msg.text = msg.text .. " - [";

--build inline results for first die, also get total
totaldie2 = 0;
for i=1,table.maxn(die2results) do
if i < table.maxn(die2results) then
msg.text = msg.text .. die2results[i] .. ",";
else
msg.text = msg.text .. die2results[i] .. "]";
end
totaldie2 = totaldie2 + die2results[i];
end
total = totaldie1 - totaldie2;
msg.text = msg.text .. " = " .. total;

--check who sent the message
if User.isHost() then
msg.sender = GmIdentityManager.getCurrent();
-- if host, check if die reveals are on
if ChatManager.getDieRevealFlag() then
deliverMessage(msg);
else
msg.icon = "dmdieicon";
addMessage(msg);
end
--get user identity
else
msg.sender = User.getIdentityLabel();
deliverMessage(msg);
end
--dont process normal die results for this flag
return true;
end
end
end


I commented my code to try to explain things as they happen but essentially the logic breaks down like this:

1) Check if dice is flagged with "fengshui" custom parameter.
2) Get dice results from original rolls.
3) Process exploding die from both dice.
4) Build the message string. This part looks long but is just a bunch of string manipulation.

The final results should look like this:
https://www.ptolus-fg.com/images/fengshui.png

Note that I added a message icon in there so you can be sure the players rolled the die via the command. And I put some logic in there if the GM rolls it only adds the message locally if the /die reveal flag is not on (the default is /die hide).

Feel free to modify font, message description, etc. and if you have any questions just let me know.

SirJoe
September 12th, 2007, 04:10
Great! Thank you so much for this. I'll test it out shortly.

I didn't notice before that you are involved with Digital Adventures. Way cool. I am sure we'll end up chatting on some future efforts for DA - I'm doing a little mapping to help out, but plan to package up some adventure materials in the near future. I'm also looking to grab your SW ruleset for FG2 soon.


Cheers dude,
JS