PDA

View Full Version : Tokens, custom data in them?



celestian
October 24th, 2017, 00:48
So I am trying to make it so I can drag/drop an npc from the npc records and then when im running the game can right click and "load" the npc into the CT. I've done some preliminary work and have been able to get it to show a token instead of a pin but having issues figuring out where I can store the npc node path.

Here is what it looks like in the xml. The first one (shortcuts) is the current style... when you drag/drop a npc on the map it' pins and type is "shortcut". The second is tokens, that one I created drag/dropping and manipulating it so it has a token prototype. But as you can see I'm not sure where I can put the npc.ID-XXXX somewhere so I can later grab it from the doubleclick and/or right click/load.




<shortcuts>
<shortcut>
<x>221</x>
<y>213</y>
<class>npc</class>
<recordname>npc.id-00002</recordname>
</shortcut>
</shortcuts>

<tokens>
<idcounter>1</idcounter>
<token>
<prototype>tokens/Medium/a.png@Letter Tokens</prototype>
<id>1</id>
<x>125</x>
<y>238</y>
</token>
</tokens>



Is there a custom field we can use in token data somewhere/somehow?

Suggestions?

The reason I want to do this is so the pins are room details/etc but the npcs are showing to the DM as tokens. I prefer to see all the NPCs/encounters on the map so if I want another room to react to a situation it's easier to catch it. Also makes sure that I remember which NPCs have been encountered and which haven't. You can do this now but must have ALL the npcs in the CT... and that's just not feasible. This might not make sense to some folks I guess but it's something from Maptools I was a big fan of.

Moon Wizard
October 24th, 2017, 00:55
There is no place to store the NPC path unless you make it. The tokens do not allow any metadata to be attached to them, only names, underlays and widgets.

You would have to craft a custom solution that adds the NPC "link tokens" to some sort of internal database structure that stores the image, the token ID and the NPC link. Then, when a GM selects the option to add to the CT, you would replace the "link token" with the "CT token".

Cheers,
JPG

celestian
October 24th, 2017, 02:31
There is no place to store the NPC path unless you make it. The tokens do not allow any metadata to be attached to them, only names, underlays and widgets.

You would have to craft a custom solution that adds the NPC "link tokens" to some sort of internal database structure that stores the image, the token ID and the NPC link. Then, when a GM selects the option to add to the CT, you would replace the "link token" with the "CT token".

Cheers,
JPG

Perhaps someday we'll have custom data we can populate in tokens but for now I'll see if I can't figure out a ID/node reference system. The problem is I don't see a function to deal with setting the ID so I could then reference it back to a node I maintain... there is a ".getId()" but I don't think that exists until the "node/token" is on the map.

Is there a reason we can't manipulate nodes for things like this? I noticed it was the same for draginfo. setMetaData really was the only reason I could do what I did previously.

Trenloe
October 24th, 2017, 02:57
I built up a database of label data to apply to widgets attached to tokens in the Image label extension (note - not currently updated to v3.3.3 compatibility). I used the token name to match data.

It may give you some ideas. Extension here: https://www.fantasygrounds.com/forums/showthread.php?33696-Image-Text-Label-Extension

celestian
October 24th, 2017, 06:01
I built up a database of label data to apply to widgets attached to tokens in the Image label extension (note - not currently updated to v3.3.3 compatibility). I used the token name to match data.

It may give you some ideas. Extension here: https://www.fantasygrounds.com/forums/showthread.php?33696-Image-Text-Label-Extension

Very good tips, thanks!

I'm still having issues tracking down the actual point where the token data is written. Best I can locate is image.lua, the "onDrop()" but that's not all of it. What I want to do is tweak the bit where it creates the token to run some experiments ... but right now I'm not sure where that is. If I change the type and set a token prototype is places it as a token but that's not enough. It's just at the point I can find there is no "token" to tweak yet.

I suspected parts of it were in manager_token.lua "OnTokenAdd" but by then the draginfo is gone and doesn't really help me.

There is also manager_image.lua and onTokenAdd() but there as well draginfo is not present so I won't have the ability to fiddle with (or map ID's/etc).

What I've had to do so far is detect the type of draginfo (shortcut with node path ^npc.id) and then manipulate it and add it manually with Token.addToken() and return false so it's not added twice. Doing that I can set the names of the tokens to the node ID of the npc which for now is a start but it's not placing the tokens right using the onDrop x, y data. I'm guessing it's scaling.

Would be nice to just inject data into the draginfo node that is applied to token and avoid my kludgie mess ;(.

I'll tinker with it some more after work tomorrow and see if I can come up with a better attack vector.

damned
October 24th, 2017, 06:23
Hi celestian - what are you actually trying to achieve?
Are you re-inventing the wheel? I know its a different approach but pinning an encounter to the map pretty much does the same thing with the same number of clicks.
You also dont run the risk of having an unassociated token on the map (because the GM missed one right click - add to CT) and having players wonder why their attacks arent working.

celestian
October 24th, 2017, 06:55
Hi celestian - what are you actually trying to achieve?
Are you re-inventing the wheel? I know its a different approach but pinning an encounter to the map pretty much does the same thing with the same number of clicks.
You also dont run the risk of having an unassociated token on the map (because the GM missed one right click - add to CT) and having players wonder why their attacks arent working.

I mentioned it at the end of the first post but my plan is to have the tokens on the map, not visible to anyone but GM. Then when I want to use them I'd "add" them to the CT.

The problem with the pins is they aren't very descriptive unless I click on them and read it. Having the tokens pre-placed on the map so I can see where each creature is makes my life as a DM much less stressful ;)

My plan is to ... (once/if I get this working) is to be able to use the select tool and bulk add npcs to the CT. The placeholders will be nuked and replaced with actual tokens that the PCs can see (assuming I make them visible).

Believe me, I get what you're saying and I've been using the "encounters" option for a while. I just can't seem to get comfortable with it. The style I'm describing is what I've used in Maptools for years. Used the same method in roll20 when I used it for a time... I did the same thing with Klooge (yeah, look it up ;) also.

Helps me keep track of npcs easier, visually and also makes it more intuitive for "activating" npcs nearby that might "hear" the noise without having to memorize every single room's contents (or having to click on all of them).

celestian
October 24th, 2017, 22:54
Ran through several ideas I had to make this not so messy, most of them failed... I eventually was able to have the name of the token be the path/node of the object to load. If the NPC dropped had a token image it would use that if not use the first letter thing. When the placeholder token was double clicked it would spawn the NPC (place it in the combat tracker and remove and replace the placeholder token).

It works and it is pretty easy to load them just double clicking the ones I want added.

For this mode I don't need a reference ID and local DB containing links to what I really would like to add. Node ID, foe status, count to spawn? visibility?

I'll add a request to the "list of stuff that would be nice to have" in FG, i.e. token.get/setMetadata[""]="" like is used in draginfo.

In the meantime I gotta figure out why the drop location is off when using drop() x/y cords for the placeholder.

Moon Wizard
October 24th, 2017, 23:40
You might want to add a widget to the "linked, but not to the combat tracker" tokens to be able to identify the difference between free range tokens and CT tokens.

Regards,
JPG

Bidmaron
October 25th, 2017, 00:29
Very nice work, Celestian. This will work for corerpg right, not just 5e?

celestian
October 25th, 2017, 00:57
You might want to add a widget to the "linked, but not to the combat tracker" tokens to be able to identify the difference between free range tokens and CT tokens.


I'll look at that and see what you mean. Not fiddled with widgets much yet.


Very nice work, Celestian. This will work for corerpg right, not just 5e?


Currently all the hacking I did was strictly in CoreRPG, so in theory, yes.

Bidmaron
October 25th, 2017, 02:13
Perhaps we could trouble you to release it in CoreRPG then and not 5e?

celestian
October 25th, 2017, 02:42
On the widget front I was able to add a text widget to the token. Was placing the original name of it onto the token. Unfortunately it wasn't persistent so when I reloaded the token was there but widget was lost. Guess I need to do more research.


Perhaps we could trouble you to release it in CoreRPG then and not 5e?

Sure, shouldn't be to difficult.

celestian
October 25th, 2017, 03:23
Another issue I noticed. Load a map, add some tokens and then export everything. Then load that module elsewhere and the maps are missing tokens.

Seems odd to me. I would think folks would at least use tokens to place objects in a room (doors, fires, tables) so they could move them. I never noticed this behavior before.

damned
October 25th, 2017, 03:28
Another issue I noticed. Load a map, add some tokens and then export everything. Then load that module elsewhere and the maps are missing tokens.

Seems odd to me. I would think folks would at least use tokens to place objects in a room (doors, fires, tables) so they could move them. I never noticed this behavior before.

Yeah - masks and token state are not saved in an export.

Bidmaron
October 25th, 2017, 04:23
I think an extension could fix that, no?

damned
October 25th, 2017, 04:25
I think an extension could fix that, no?

Ordinarily Id say no. But this is Celestian we are talking about so I'm just going to sit back and watch what magic he performs.

celestian
October 25th, 2017, 05:41
Ordinarily Id say no. But this is Celestian we are talking about so I'm just going to sit back and watch what magic he performs.

Hah! And here I was about to give up on this because it was a minor deal... now the gauntlet has been thrown down !

That said... I've been poking around the export code to get a handle how it works and for the life of me I can't figure out why it excludes <tokens> on images but not <shortcuts> yet.

Moon Wizard
October 25th, 2017, 05:51
Its internal to the client, and the way that FG was designed. None of the mask, drawing, pointer or token information is copied on export or copy functions. The system was designed to be used with other records as links (such as encounters).

So, it’s not something that can be edited through an extension.

Regards,
JPG

celestian
October 25th, 2017, 06:03
Its internal to the client, and the way that FG was designed. None of the mask, drawing, pointer or token information is copied on export or copy functions. The system was designed to be used with other records as links (such as encounters).

So, it’s not something that can be edited through an extension.

Regards,
JPG


Bugger.

Guess I'll just keep the code around and see if that changes someday in FGU. Thanks for the insight JPG as always!

Moon Wizard
October 25th, 2017, 07:51
Also, FYI, I was a big user of Klooge for a few years, prior to switching over to FG. I switched in 2008. I spent a lot of effort building out the 3.5E framework over there (just like I ended up doing here as well).

Cheers,
JPG