5E Character Create Playlist
  1. #1

    Using the <token> data as an icon

    So, following my idea from here, 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:
    Code:
    -- 
    -- 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

  2. #2
    Zeus's Avatar
    Join Date
    Mar 2009
    Location
    Olympus
    Posts
    2,658
    Blog Entries
    2
    Quote Originally Posted by The Crusader of Metal
    So, following my idea from here, 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
    The name of the control is 'token' but it's type is a tokenfield (tokencontrol). See here more library information on the control and its methods. To get the string name of the token path and file name, use the method getPrototype().

    Quote Originally Posted by The Crusader of Metal
    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?
    Essentially correct. Messages accept the string name of an icon which in turn are registered in the ruleset using the notation:

    Code:
    <icon name="exampleicon" file="graphics/icons/some_icon.png" />
    Icons are usually registered in one of the various graphics.xml files in the ruleset folder. I am not aware of a method of creating icons during runtime so I believe these would have to be defined in the ruleset files before the campaign is instantiated and loaded.

    Tokencontrols on the other hand use strings to define the path and filename of the image file containing the token graphic, whilst Portraits can be referenced in place of icons using something like the following:

    Code:
    msg.icon = "portrait_" .. nodeofpccharsheet.getName() .. "_chat";
    However Portraits are not supported for NPCs, only PCs, I think to change this would require a change to FGII itself (not 100% sure though).
    Last edited by Zeus; August 22nd, 2011 at 08:07.
    FG Project Development
    Next Project(s)*: Starfinder v1.2 Starship Combat

    Current Project:
    Starfinder v1.1 - Character Starships
    Completed Projects: Starfinder Ruleset v1.0, Starfinder Core Rulebook, Alien Archive, Paizo Pathfinder Official Theme, D&D 5E data updates
    * All fluid by nature and therefore subject to change.

  3. #3
    Thanks for the answer DrZeuss, I found your explanations really really useful!

    What I did after posting to get it working was that I used an user just to create characters with the same name of the npcs, so I could get the portrait using the exact same idea you showed there. But unfortunately that is a little bit confusing so I don't feel like releasing an extension like this one.

    The name of the control is 'token' but it's type is a tokenfield (tokencontrol). See here more library information on the control and its methods. To get the string name of the token path and file name, use the method getPrototype().
    I am not sure about it because I used the getType() method in the node and it returned 'token'. Also while looking into the page you linked I found this method populateFromImageNode, that I thought would instantiate and create a new image which could be used. Unfortunately it returns an error message saying that this function is nil, so I really think it is of the 'token' type and not of the 'tokencontrol'.

    The <icon> idea is pretty nice, I liked it! The only problem would be needing to add all of the portraits to the extension before hand.

    I am thinking about following the pseudo-pc idea though, would feel like a workaround but at least I wouldn't need to redistribute the extension everytime I added new entries.

    Or if some dev could explain if it is possible to generate portraits for NPCs ...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Product Walkthrough Playlist

Log in

Log in