View Full Version : Best way to create an item in a character's inventory
Zuger
November 12th, 2017, 10:48
Hello,
I'm trying to create an extension that compute the coins weight for a character.
I do that in three steps :
1 - Counting the coins in order to compute weight.
2 - Insert an item called "Coins weight" in the inventory with the weight of the coins.
3 - Update the encumbrance.
I'm stuck at step 2, i can't add an item to the PC inventory.
This is the code i wrote :
-- This part is supposed to add an Coins Weight entry in the DB
Debug.chat( weight )
Debug.chat(nodePC.getPath() .. '.inventorylist')
local sTempPath = "temp.item";
DB.deleteNode(sTempPath);
local nodeTemp = DB.createNode(sTempPath);
DB.setValue(nodeTemp, "name", "string", "Coins Weight");
DB.setValue(nodeTemp, "weight", "number", weight);
ItemManager.addItemToList(nodePC.getPath() .. '.inventorylist', 'item', nodeTemp, false, 1)
Do you think this is the right way to add an item to the PC inventory ? What Iam I missing ?
damned
November 12th, 2017, 12:15
Welcome Zuger
I wonder if there might be a better/easier way to do this...
Instead of creating an Item in the Inventory you could shuffle Current along to the left and change the label to Equipment, have another called Treasure and another called Total (or skip Treasure)
Me thinks it would be a lot simpler and there is room (Im looking at the 5e sheet here).
Bidmaron
November 12th, 2017, 14:33
But if you insist on creating an item (which I agree with damned seems like a really bad way to do what you want), you need to use createChild, not createNode. The node calls you are using would create a top-level node that there would only be one of them, and it wouldn't be on the characters' sheets (which is I guess what you want for some reason). The deteleNode needs to use the complete node address or you can use deleteChild referencing the inventory item list as the parent.
Does 5e not count coins in encumbrance already? Wow, crazy.
Zuger
November 12th, 2017, 18:35
Does 5e not count coins in encumbrance already? Wow, crazy.
Unless I missed something, but I don't think.
Anyway, thank you all for your support. I implemented Damned solution which work right.
My only concern now is that I have to run the computation manually (I bound the function to a /function).
So I would like to link it to a coin change. I guess I should have to add a call to my function in
<number_dropadd name="coinamount1" source="coins.slot1.amount">
<anchored to="moneytitle" width="30" height="20">
<top anchor="bottom" relation="relative" offset="10" />
<left anchor="center" offset="-160" /></anchored>
<hideonvalue>0</hideonvalue>
<description field="name" />
</number_dropadd>
and all other coins fields.
Is it possible to add a <script> tag to the <number_droppadd> without copying all the dropadd XML ?
Like
<number_dropadd name="coinamount1">
<script>
function onUpdate()
Debug.chat("hooray");
end
</script>
</number_dropadd>
I'm already in a <windowclass name="charsheet_inventory_contents" merge="join">
Is this enough or have I to copy the full <number_droppadd> content in my extension ?
damned
November 12th, 2017, 20:55
You can use onValueChanged(); on the Coin entries to re-calc the Coin Weight whenever Coins are changed.
Yeah - most rulesets dont auto generate encumbrance for Coin. Im guessing this is because its something that most GMs ignore?
Zuger
November 13th, 2017, 04:21
Yeah - most rulesets dont auto generate encumbrance for Coin. Im guessing this is because its something that most GMs ignore?
Yes I think so. Although they shouldn't : coins are really heavy in 5E. 3000 CP weight a chainmail.
So to add the onValueChanged on entries, can I simply add it on the field or have I to copy all the XML field in my ext ?
damned
November 13th, 2017, 05:21
Hehehehe... look up some examples of that function and how its used. Search the forums and do a find in files in the 5e ruleset or CoreRPG ruleset for examples on how to do it...
Always make changes in an extension - and always try not to copy too much code from the ruleset as the more you copy the more likely a future update will break your extension or vice versa.
skj310
November 13th, 2017, 05:43
Let me know when you finish this extension ... I think automating coin weight calc would go along super sweet with the 5e variant encumbrance rule. Good job Zuger!
Zuger
November 13th, 2017, 10:43
Thanks skj310 :)
Having people carrying constantly 5000 GP always bothered me.
Just to share it. To anybody that goes there, overloading an existing field is as simple as :
<windowclass name="charsheet_inventory_contents" merge="join">
<sheetdata>
<number_dropadd name="coinamount1">
<script>
function onValueChanged()
Debug.chat("hooray");
end
</script>
</number_dropadd>
</sheetdata>
</windowclass>
skj310
November 13th, 2017, 11:33
Thanks skj310 :)
Having people carrying constantly 5000 GP always bothered me.
Just to share it. To anybody that goes there, overloading an existing field is as simple as:
Ok Zugar ... totally wanna implement this but am clueless as to where I should place this? Am I placing it here 5E/campaign/record_char_inventory.xml?
skj310
November 13th, 2017, 12:02
ok ... now i looked at your code and record_char_inventory.xml and i see that all it does is send hooray to the chatwindow if i put the script into coin1 through coin6 ... I guess perhaps I ought to have "really looked" at your code excerpt! :)
So then I'm guessing you've not actually worked out how to update the current encumbrance box? Well I guess i wait for a coder to come along and put it all together.
damned
November 13th, 2017, 12:05
Zuger is just posting that she worked out how to call the onValueChanged part of the script and was sharing the answer to her question.
Im sure the extension will appear in good time.
[she/her was used in a gender neutral sense]
skj310
November 13th, 2017, 12:11
:) indeed ... hope i didn't come across as a ****.
Willot
November 13th, 2017, 20:49
I simply created 4 items, Gold Coin, Silver Coin, Copper Coin, Tin Coin and had some gems in there too; gave each a weight and handed out those when they found coins. Didnt use the provided spaces for coins at all. Cant rember the weights I use for one coin but easy enough to work out. So 50xGold Coin = 1lbs. You could even create an item "Coin Pouch" and give your coin items that location
Zuger
November 14th, 2017, 04:47
@skj310 : Yeah wait, I'm still working on it, the extension is not finished, I'm still stuck on some points, one is :
In my onUpdateValue function how do I know in which character I am (which encumbrance should be updated).
@Willot : Adding a coin pouch was my first idea, but it is my first extension, so it is hard for me to figure out what is the best way.
By the way I'm a He ^^
damned
November 14th, 2017, 05:04
Hello heZuger!
You might do some playing with:
local nodeWin = window.getDatabaseNode();
local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
Zuger
November 14th, 2017, 09:08
Thank you damned, that save me a lot of time :)
Zuger
November 14th, 2017, 09:37
Ok, great it work. It is very basic, but it work :)
I guess the next step is sharing it in Armory/extension ?
Zacchaeus
November 14th, 2017, 11:27
Yes, or if it is only for a particular ruleset in the forum for that ruleset.
Willot
November 17th, 2017, 03:54
A Proper container system might be nice for your next project Zuger? :) 40 arrows in a Quiver...
Good job on this tho; its always brothered me the weight of coin things too. Now those pesky PCs are gonna have decide what they are going to do with a horde of 10,000 coins NICE ONe! That'll bugger em! Hahahahaha.
(Im a nice GM really I am ;) )
damned
November 17th, 2017, 05:13
Ponies!
Willot
November 17th, 2017, 05:54
Ponies!
But you have to go back town to get them and the dwarf wont leave (throws him/her self on the pile) "But what is someone comes while we're away!!!"
Then theres always the problem of that guy in green tights with a feather in his cap who appears in the forest and always says something like "Welcome to Sherwood Forest!!!" while your taking your ponies back to town with jingling sacks
Zuger
November 17th, 2017, 05:59
By the way the extension is available here : https://www.fantasygrounds.com/forums/showthread.php?41109-The-weight-of-the-coins
For me is not really to use it as a challenge, but just to show to player that coins weight something, and they are no more granted with a free portable hole to carry them :)
Zuger
November 17th, 2017, 06:01
By the way the extension is available here : https://www.fantasygrounds.com/forums/showthread.php?41109-The-weight-of-the-coins
For me is not really to use it as a challenge, but just to show to player that coins weight something, and they are no more granted with a free portable hole to carry them :)
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.