PDA

View Full Version : Send command to chat after each attack



Oso Buho
March 1st, 2018, 15:32
Hi adventurers!

I'm quite new to FG development (even though I'm a developer myself since 1998) and would like to know if it's remotely possible to send a command to the chat - or to the system... what I want to is to do a /save - after each attack that happens.

Is it viable or are extensions blocked from accessing those type of functions?

Thanks

Trenloe
March 1st, 2018, 15:35
Welcome to the forums!

I don't think there's a way to force a campaign DB save through scripting.

And, to be honest, you wouldn't want to do this regularly. Once the campaign DB gets large you'd encounter system delays and slow downs doing a save after every attack. It would make the GM's FG instance (And so everyone's instance) slow down considerably - especially during a fairly system intensive action processing.

I'm curious as to why you'd want to do this? Do you have an issue you're trying to work around? FG issues the save command automatically every 5 minutes anyway...

Oso Buho
March 1st, 2018, 16:29
Welcome to the forums!

I don't think there's a way to force a campaign DB save through scripting.

And, to be honest, you wouldn't want to do this regularly. Once the campaign DB gets large you'd encounter system delays and slow downs doing a save after every attack. It would make the GM's FG instance (And so everyone's instance) slow down considerably - especially during a fairly system intensive action processing.

I'm curious as to why you'd want to do this? Do you have an issue you're trying to work around? FG issues the save command automatically every 5 minutes anyway...

Thanks for your response Trenloe.

Basically I want to access the characters wound status after each attack to add a "visual representation" to my streams.

I've seen that the only place where I can get that value somehow updated is in the db.xml file... but only after the campaign has been save.

Trenloe
March 1st, 2018, 16:32
I've seen that the only place where I can get that value somehow updated is in the db.xml file... but only after the campaign has been save.
You should be able to access the data in the FG database as soon as it changes in FG's memory. The campaign data doesn't need to be saved out to the db.xml file before you can access it. That is just the permanent record of the data. FG will always access it's in memory copy for normal data processing.

So, either anchor a control of the DB field in question, or access the database using the usual FG API commands. You don't need to save to the db.xml file.

LordEntrails
March 1st, 2018, 16:47
You can access the FG memory from an outside application?

Trenloe
March 1st, 2018, 16:56
You can access the FG memory from an outside application?
Ah, yeah - I missed the "to my steams" bit... No, you can't.

@Valgul - sorry for the misleading into.

Maybe you can look at Dulux Oz's Sound extension - this can activate URLs when a certain keyword in the chat window comes up. Maybe you can do something to push data out using a URL/Local OLE registration.

Look at the Sound extension here: https://www.fantasygrounds.com/forums/showthread.php?20320-FG-3-0-CoreRPG-Extensions&p=242586&viewfull=1#post242586 This doesn't just send sound commands, it can be used to send any command that can be send through a browser URL. You'll have to use the Sounds extension (not the OLE one) as I believe it is only the sound extensions that has the chat functionality. If you use this, you'll need to make sure the players don't turn the Sound option on in their campaign settings - just the GM would need this.

Oso Buho
March 1st, 2018, 16:59
That's my "problem", I do have a python program that currently checks the Chat for whos turn it's, then it displays a Character Sheet of sorts on my Stream (The python program updates a local html with the PC data).

My idea was now is to track somehow how damaged the PC is and maybe check some statuses like Poisoned, Stunned, Prone and so on. I need to access the data from out of FG, and the only way I came up with is by accesing the db.xml file...


Ah, yeah - I missed the "to my steams" bit... No, you can't.

@Valgul - sorry for the misleading into.

Maybe you can look at Dulux Oz's Sound extension - this can activate URLs when a certain keyword in the chat window comes up. Maybe you can do something to push data out using a URL/Local OLE registration.

Look at the Sound extension here: https://www.fantasygrounds.com/forums/showthread.php?20320-FG-3-0-CoreRPG-Extensions&p=242586&viewfull=1#post242586 This doesn't just send sound commands, it can be used to send any command that can be send through a browser URL. You'll have to use the Sounds extension (not the OLE one) as I believe it is only the sound extensions that has the chat functionality. If you use this, you'll need to make sure the players don't turn the Sound option on in their campaign settings - just the GM would need this.

Ok, maybe I can actually send to chat the character status, and I can pick up the values from there... mmmm...

Bidmaron
March 1st, 2018, 17:15
What you can do is write an extension to export the desired database data from memeory to a file your application can see. Very easy to do. Write an xml export file. Look at the export API call

Trenloe
March 1st, 2018, 17:24
What you can do is write an extension to export the desired database data from memeory to a file your application can see. Very easy to do. Write an xml export file. Look at the export API call
That's a good idea. As long as it's not exporting a sh1t tonne of data each time.

@Valgul - As an example, here's a simple extension that sets up the export for the DB's calendar node. It exports just an XML file (not a whole module) using DB.export: https://www.fantasygrounds.com/refdoc/DB.xcp#export

You can find the extension here: https://www.fantasygrounds.com/forums/showthread.php?18043-Feature-Request-Export-Calendar-Entries&p=141057&viewfull=1#post141057 This prompts the GM for the filename (sFile) but you can remove that and hard code the filename to a location on your hard drive.

Ikael
March 1st, 2018, 17:36
I would also do this with DB.export feature: https://www.fantasygrounds.com/refdoc/DB.xcp#export

Use python to poll certain file and use the export to write any databasenode data to it. You can use other DB package features to do this. Thereafter each file change will invoke python to read it and act accordingly.

Using the URL approach would require extra layer of work (local python web service) and lacks the flexibility.

Oso Buho
March 1st, 2018, 18:58
That's a good idea. As long as it's not exporting a sh1t tonne of data each time.

@Valgul - As an example, here's a simple extension that sets up the export for the DB's calendar node. It exports just an XML file (not a whole module) using DB...

Thanks a lot! Any idea where should I start looking in order to launch the export every time an attack happens?

Trenloe
March 1st, 2018, 20:51
Thanks a lot! Any idea where should I start looking in order to launch the export every time an attack happens?
It depends which ruleset you're using.

Most commonly it will be in scripts\manager_action_damage.lua. You'll need to do it in the OOB messaging (which runs on the GM side, even for player attacks) as the GM is the only instance that can export.

Oso Buho
March 1st, 2018, 21:18
EDIT: I had to use a full path to save the file.

Ikael
March 1st, 2018, 21:22
local sFile = "PCs.xml";
if sFile then
DB.export(sFile, "charsheet", "character", true);
ChatManager.SystemMessage("Exported characters log.");
end


Will attempt to write PCs.xml file to your OS's root, which is no-go permission-wise. You need to define absolute file path within AppData folder to make sure FG has permissions to write the file.

damned
March 1st, 2018, 23:32
You probably want to tie it to the Damage rolls rather than the Attack rolls.

LordEntrails
March 2nd, 2018, 00:08
A consideration, how are you going to handle healing effects and manual corrections to HPs done either in the CT or on the character sheet? Might need a manual "refresh" command/button.

Bidmaron
March 2nd, 2018, 00:43
What I would do is install an onUpdate handler on the current hit points of any character. Then, it doesn't matter how the hit points change. Your handler will get called and you can re-export whatever you need to export. That db name will vary based on the ruleset, but you would install it like this (do it in the onInit of your extension):


DB.addHandler(sNodeName.. ".*@*","onUpdate",onThingChange);


Where onThingChange is the name of your handler routine to do the export.

and uninstall it like this: (do it in the onClose of your extension):


DB.removeHandler(sNodeName.. ".*@*","onUpdate",onThingChange);

Oso Buho
March 2nd, 2018, 08:12
A consideration, how are you going to handle healing effects and manual corrections to HPs done either in the CT or on the character sheet? Might need a manual "refresh" command/button.

Actually, I'm considering on creating a whole extension that will pick up any update to the health now. I still have one problem though... maybe someone can help.

It truly BOTHERS me that I need to hardcode the whole path where to export the file. Is there no global variable of sorts that I can use to pick up the folder of the Campaign that is currently playing?

Like: DB.export(campaignFolder/PCs.xml, "charsheet", "character", true);

I've seen there a openDataFolder or openCampaignFolder within the Interface Package... but I want to get the Path so I can use it in my export, not to open it.

Thanks.

Oso Buho
March 2nd, 2018, 13:53
UPDATE:

Did it the way I mentioned and it works... or it does 50% of the times.

I'm using the following in different situations (onInit, and every time a players HP updates):
local AppDataFolder = os.getenv('APPDATA');
local PCsFolder = AppDataFolder + '/Roaming/Fantasy Grounds/PCs.xml';
DB.export(PCsFolder, "charsheet", "character", true);

Unfortunately, I get an error on os.getenv being null every now and then, it's random (I would say about 75% of the times.

Any idea on what could be causing this?

Trenloe
March 2nd, 2018, 16:21
os.getenv shouldn't be available. I'm surprised it works at all.

More info here: https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#General_Lua_Programming