Adding custom item sprites

Contents

For quite some time now modders were unsuccessfully trying to add custom item icons to the game - until now. Yesterday a member on theindiestone-forums called Eggplanticus finally solved the mystery. He posted a short guide on how to get the icons to work in the game. With his permission I will present you his method here a bit more detailed.

Adding an Item

At first we are going to add a new item to the game. I will not go into the details of the script here (we will have another tutorial about that soon).

module Base
{  
    item TestItem
    {
        Weight = 0.01,
        Type = Normal,
        DisplayName = Test Item,
        Icon = TestItem.png,
    }
}

The important line is "Icon = TestItem.png". It will tell the game which Icon our TestItem will use. Save the file as TestItem.txt in /media/scripts/Mods/TestItem.

 

Adding the Icon

Now we'll add the icon. It is pretty simple actually (save this icon):

 

 You will have to rename it to "Item_TestItem.png". Place it in the root folder of your Project Zomboid installation (it's the one above the /media folder).

 

Loading the Icon with Lua

In the last step we will load the icon with a small Lua script. You can include it in any lua file, but for this tutorial we will create a new one:

TestItemIcons = {}

---
-- This loads the textures. You can add as many
-- as you want.
function TestItemIcons.loadTextures()
    getTexture("Item_TestItem.png");
end

---
-- This will add the item to the inventory for
-- testing purposes.
function TestItemIcons.giveItems()
    getSpecificPlayer(0):getInventory():AddItem("Base.TestItem");
end

Events.OnGameBoot.Add(TestItemIcons.loadTextures);
Events.OnGameStart.Add(TestItemIcons.giveItems);

Save the file as "TestItem.lua" and put it in /media/lua/Mods/TestItem. If you don't have a "Mods" folder yet just create one now!

 

That's it! Basically we are done now. Head into the game and try it out. The script should add the item to your inventory on game start :)

Et voila:

A shiny new item texture! Make sure to show some love to Eggplanticus over at theindiestone-forums!

It seems like lemmy101 is also working on fixing the texture import so this method might be replaced in the future. Of course we will keep you posted about any updates!

Comments

  • Jabermony

    just thought I'd add...
    reading this :
    http://theindiestone.com/forums/index.php/topic/2011-how-to-use-the-modloader/
    helped me a lot .

    Apr 10. 14
  • Jabermony

    Sorry for this ... I can't seem to edit the original comment

    for some reason some of my formatting got deleted ( can't surround things with triangle braces)

    From what I can tell the "best" way to do this is actually to add a "textures" folder to your mod's media folder then add your images into there named as follows:
    Item_itemName.png
    Replace itemName with whatever your item's name is.
    this can then be used as follows in your mod's items.txt file ( or whatever you named it ):
    module testModule
    {
    item testItem
    {
    Weight = 0.01,
    Type = Normal,
    DisplayName = displayName,
    Icon =itemName ,
    }
    }
    itemName should be the same as you used for the Item_itemName.png
    Note:see how you don't need to say Icon=itemName.png

    A lot less hacky than the solution this suggests ( it shouldn't require Lua files at all either )

    Apr 10. 14
  • Jabermony

    Know this is an old post but I thought I'd add here for anyone that comes here trying to add custom item sprites ( like I did ) .
    From what I can tell the "best" way to do this is actually to add a "textures" folder to your mod's media folder then add your images into there named as follows:
    Item_.png
    Replace with whatever your item's name is.
    this can then be used as follows in your mod's items.txt file ( or whatever you named it ):
    module testModule
    {
    item testItem
    {
    Weight = 0.01,
    Type = Normal,
    DisplayName = displayName,
    Icon = ,
    }
    }
    should be the same as you used for the Item_.png

    A lot less hacky than the solution this suggests ( it shouldn't require Lua files at all either )

    Apr 10. 14
  • Austin

    Very awesome. Thanks alot!

    Aug 13. 13
    1 liked this comment.
  • aricane

    Many have tried. Only one prevailed!

    Aug 14. 13
    • RoboMat

      I'm really amazed, that Eggplanticus found it out :D

      I still hope that there will be a more "official" and less "hacky" approach to adding icons soon :)

      Aug 14. 13
  • huntersouls

    im see u explain good but im wish create herbs to heal like resident evil, can pls give little help in code?

    Nov 26. 13
  • zalexouille

    I know this has been a while but i bought the game recently and am eager to modify a few things. I know how to write the scripts i want to implement, but i cannot find the original scripts from the game. (I'm on mac btw) I have looked in every folder, i just can't find any .txt files or the source of all the objects in the game (in order to modify or copy/paste) like you have in paragraph 1.2
    I got folders like Sandbox, Lua, mods etc, but most of it the data is in .bin and i just cant seem to find the scripts for all the original items.
    Does anyone have any clue where/How to get them or am i missing something really obvious?

    Sorry if this isn't relevant here, i couldn't find a better place.

    Sep 25. 15
You need to be logged in to write comments