PDA

View Full Version : Extension Creation Advise for Shadowdark



claedawg
September 8th, 2024, 18:05
Wanting try my hand at creating an extension for Shadowdark. This will be the first time I have created an extension so I am wanting to start with something I believe will be simple. I would like to make an automation for applying an encumbrance penalty if a character has used more gear slots than its max.

ChatGPT has given me a basic outline of the code needed, but I'm not sure if it using the correct field names to pull the required info. Here is the code it suggested. Given that I do not have the required password to see how the ruleset is setup I have no way of verifying if this code will work. What I've attempted so far doesn't even produce an extension for me to load for the game.

Using Notepad++ I entered the following lua coding and saved it as an xml file inside of a folder. Zipped it and changed the file to an ext file.

Any advise?

-- Function to calculate Gear Slots and apply Encumbrance
function updateEncumbranceModifier(character)
local gearSlotsUsed = character.getField("gear_slots_used").getValue(); -- Get current gear slots used
local maxGearSlots = character.getField("max_gear_slots").getValue(); -- Get maximum gear slots

if gearSlotsUsed > maxGearSlots then
local encumbrancePenalty = calculateEncumbrancePenalty(gearSlotsUsed - maxGearSlots); -- Calculate penalty
character.getField("encumbrance_modifier").setValue(encumbrancePenalty); -- Apply penalty
else
character.getField("encumbrance_modifier").setValue(0); -- No penalty if within limit
end
end

-- Function to calculate Encumbrance Penalty
function calculateEncumbrancePenalty(excessSlots)
-- Example logic: For every excess slot, apply a -1 penalty
return excessSlots * -1;
end

-- Event to trigger Encumbrance calculation when gear is added/removed
function onGearSlotChange(character)
updateEncumbranceModifier(character); -- Update encumbrance when gear slots change
end

-- Register this function to run when the gear slots change on the character sheet
DB.addHandler("charsheet.*.gear_slots_used", "onUpdate", onGearSlotChange);

damned
September 8th, 2024, 23:09
ChatGPT does not know FG programming.
You will need to use the /debug tool to identify field names and element names.
A lot of code will also be in CoreRPG and be accessible.

claedawg
September 9th, 2024, 00:14
Shadowdark is not setup the same way. I can see the names of the files in Shadowdark, but do not have access to open them to see the actual lua scripts or even the xml coding (password required for the full unzipping). For example, it does not have the manager_char_encumbrance.lua file like the CoreRPG does. I'm fairly certain that is the file I would use for the lua script if it were CoreRPG. But, even looking at that, I'm not sure how I would change the script for encumbrance penatilities in CoreRPG. I know it already does that, but I can't locate which part of the script actually handles the effect output.

I think the scripting for this is going to be outside of my abilities, at least without being able to see the actual code they use. I might be able to figure it out if I could see it, but still not likely, lol. I have made alterations and cheats for EUIV in the past, but the coding for that is much more simple compared to FG. FG is closer to scripting for NWN & NWN2, which I never was able to wrap my head around either, and that was when my brain worked a lot better than it does now, lol.

damned
September 9th, 2024, 01:12
if you cant access the code how will ChatGPT access the code?
/debug will tell you quite a bit.
you might also ask teh ruleset dev if they can share encumbrance code with you.

Trenloe
September 9th, 2024, 02:39
@claedawg - Shadowdark runs on top of CoreRPG (like most rulesets). So it probably uses the CoreRPG encumbrance manager, more than likely with modification. Without having access to the ruleset code, as you mention, you'll be struggling. As @damned suggests, the ruleset dev will probably be needed to help with how the Shadowdark ruleset handles gear slots etc..

claedawg
September 9th, 2024, 04:05
if you cant access the code how will ChatGPT access the code?


I really wasn't expecting it would due to the password requirement, but I have had it recover a corrupted google doc for me. Doesn't hurt to check sometimes. It also seems to have access to some things that I do not (most likely through a college library where they have acquired legal (hopefully) access. Wish I still had access to the University of Phoenix digital library. It had some stuff in there I would like to get now that is not available publicly without contacting the author (or school where it was submitted as a thesis???) for a direct purchase.

The code it gave me was an example of what you might use if it had not already been defined, going by the looks of it.

Trenloe
September 9th, 2024, 04:39
The code it gave me was an example of what you might use if it had not already been defined, going by the looks of it.
The basic structure is what you might take as a starter - i.e. a DB handler that calls a function to run some code when a specific field is updated within the FG database.

Beyond that, you'lll need to:

Work out which field in the Inventory you need for the DB handler that runs when the number of gear slots changes. Can a single field be used? Or would multiple fields be needed to calculate when the gear slots change? I'm not familiar with the Shadowdark system, either the RPG system itself or the implementation within FG.
Write the handler function that takes the information from the PC database (not the GUI which the example code uses) and performs the calculations needed, applying the relevant encumbrance penalty to the PC.


EDIT: You might be able to do most of the above by creating an example PC within a Shadowdark campaign and looking at the database structure for the character within the campaign db.xml file. One gotcha maybe if the ruleset already caters for an encumbrance penalty and if you can change that via the PC entry in the database.

damned
September 9th, 2024, 05:00
You also have to allow for units - some items like arrows will have up to a certain number of units count as 1 whereas 2 swords will count as 2 items.

bayne7400
September 9th, 2024, 12:51
What are you trying to do? Shadowdark already uses gear slots for encumbrance. So how are you trying to change it from raw?

claedawg
September 9th, 2024, 16:25
Just attempting to add encumbrance penalties. I have not seen any effect of PC die rolls if they are carrying more than the max gear slots. There are other things I would like to try my hand at also, such as codifying the skills, but that would require me to also get the ruleset wizard at some point as I would need to add a new tab to the CS, to make it easier. Basically, just attempting to make the game work better for long term campaigns and such.

Since this system is so simple (compared to other systems) I figured this would be my best bet on learning, rather than attempting to edit D&D the way I want it or creating my own ruleset from scratch.

bayne7400
September 9th, 2024, 17:51
That system does not exist in the rules. It is a binary they can carry X slots. So attempting to add an encumbrance system into the game is going to touch a lot of code depending on what you want it to do. You can always use effects on the CT to implement this.

Why not look at OSE? That would be much easier to modify as all the code is open and it would simply be modifying a few functions.

claedawg
September 9th, 2024, 22:41
That system does not exist in the rules. It is a binary they can carry X slots. So attempting to add an encumbrance system into the game is going to touch a lot of code depending on what you want it to do. You can always use effects on the CT to implement this.

Why not look at OSE? That would be much easier to modify as all the code is open and it would simply be modifying a few functions.

I had thought about it, but I don't want 3-5 different dice mechanics to cover everything. I like the straight up d20 system. I haven't played actual Basic D&D since I was in elementary school in the early 80s, lol.