PDA

View Full Version : add handler for xp awarding



Diablobob
July 25th, 2019, 17:31
I am trying to figure out how to make an addHandler to watch the exp field of the party, and trigger a message when they receive xp..

I do not know the best way to trigger it... I'm also not sure if the node I'm having it watch is the correct node... This script is completely off the top of my head... but it is something I am trying to figure out how to approach

I'm not sure if it would be easier to watch the charsheet exp field or the partysheet exp field...

What I am trying to do is when xp is awarded, I am trying to generate a chat message saying how much xp / xp needed each character in the party has...



onInit()
DB.addHandler("charsheet.*.exp", "onUpdate", sendMsg);
end

function sendMsg(expNode)
local expWindow = expNode.getParent();
local nodeChar = expWindow.getParent();
local exp = expNode.getValue();
local expNeeded = DB.getValue(DB.findNode(expWindow),"expneeded","");
local charName = DB.getValue(nodeChar, "name", 0);

local msg {};
msg.text = charName.." has "..exp.."/"..expNeeded.." XP";
Comm.deliverChatMessage(msg);

end


any suggestions? corrections?

V/r,
Diablobob

Trenloe
July 25th, 2019, 17:38
If you want to display a message every time the XP changes it might be best to do it at the character sheet level - then any source of XP (including the player changing it themselves) will product a message.

When you're looking to add DB handlers, create some example data in the campaign, save the campaign data (either type /save in the chat or exit the campaign) and then look at the DB structure in the campaign db.xml file.

In this case, the character XP is stored in charsheet.*.exp and the exp needed is stored in charsheet.*.expneeded

celestian
July 25th, 2019, 23:15
The party already gets chat notice when experience is awarded.

The EXP field is charsheet.*.exp

Diablobob
July 26th, 2019, 01:53
Yes... I want to send an exp left message... so a little something extra...

damned
July 26th, 2019, 04:40
Expand the current message to include the XP awarded AND the XP required?