The Crusader of Metal
August 22nd, 2011, 02:51
So, following my idea from here (https://www.fantasygrounds.com/forums/showthread.php?p=113408), I started developing such an extension. I got pretty far but hit a roadblock. I can get the <token> value from the npc which is speaking. This value is from type token which I found no documentation, but its value is something on the likes of: tokens/host/Portraits/port001.JPG
If I try to pass this value to the field icon of the message object, nothing appears on the chat, not even the GM logo. I believe it is because this is just a prototype for a token and not an actual one which can be used as an icon, right? Is there a way I can create such an icon to be used?
I just changed the chat_entry.lua file, which follows:
--
-- Please see the license.html file included with this distribution for
-- attribution and copyright information.
--
function onInit()
ChatManager.registerEntryControl(self);
end
function onDeliverMessage(msg, mode)
if mode == "chat" then
local bOptPCHT = OptionsManager.isOption("PCHT", "on");
if User.isHost() then
gmid, isgm = GmIdentityManager.getCurrent();
msg.sender = gmid;
if isgm then
msg.font = "chatgmfont";
if bOptPCHT then
msg.icon = "portrait_gm_token";
end
else
msg.font = "chatnpcfont";
if bOptPCHT then
local token = findNPCPortrait(msg.sender);
if token then
msg.icon = token;
else
msg.icon = "portrait_gm_token";
end
end
end
else
if bOptPCHT then
local sCurrentId = User.getCurrentIdentity();
if sCurrentId then
msg.icon = "portrait_" .. sCurrentId .. "_chat";
end
end
end
elseif mode == "emote" then
if User.isHost() then
local gmid, isgm = GmIdentityManager.getCurrent();
if not isgm then
msg.sender = "";
msg.text = gmid .. " " .. msg.text;
end
end
end
return msg;
end
function findNPCPortrait(npcName)
local rootNode = DB.findNode("npc");
if rootNode then
local npcs = rootNode.getChildren();
if not npcs then
return nil;
end
for npcKey, npc in pairs(npcs) do
local name = npc.getChild("name");
if name then
if name.getText() == npcName then
local token = npc.getChild("token").getValue();
if token then
return token;
end
end
end
end
end
return nil;
end
function onTab()
ChatManager.doAutocomplete();
end
If I try to pass this value to the field icon of the message object, nothing appears on the chat, not even the GM logo. I believe it is because this is just a prototype for a token and not an actual one which can be used as an icon, right? Is there a way I can create such an icon to be used?
I just changed the chat_entry.lua file, which follows:
--
-- Please see the license.html file included with this distribution for
-- attribution and copyright information.
--
function onInit()
ChatManager.registerEntryControl(self);
end
function onDeliverMessage(msg, mode)
if mode == "chat" then
local bOptPCHT = OptionsManager.isOption("PCHT", "on");
if User.isHost() then
gmid, isgm = GmIdentityManager.getCurrent();
msg.sender = gmid;
if isgm then
msg.font = "chatgmfont";
if bOptPCHT then
msg.icon = "portrait_gm_token";
end
else
msg.font = "chatnpcfont";
if bOptPCHT then
local token = findNPCPortrait(msg.sender);
if token then
msg.icon = token;
else
msg.icon = "portrait_gm_token";
end
end
end
else
if bOptPCHT then
local sCurrentId = User.getCurrentIdentity();
if sCurrentId then
msg.icon = "portrait_" .. sCurrentId .. "_chat";
end
end
end
elseif mode == "emote" then
if User.isHost() then
local gmid, isgm = GmIdentityManager.getCurrent();
if not isgm then
msg.sender = "";
msg.text = gmid .. " " .. msg.text;
end
end
end
return msg;
end
function findNPCPortrait(npcName)
local rootNode = DB.findNode("npc");
if rootNode then
local npcs = rootNode.getChildren();
if not npcs then
return nil;
end
for npcKey, npc in pairs(npcs) do
local name = npc.getChild("name");
if name then
if name.getText() == npcName then
local token = npc.getChild("token").getValue();
if token then
return token;
end
end
end
end
end
return nil;
end
function onTab()
ChatManager.doAutocomplete();
end