Eggplanticus Posted August 10, 2013 Share Posted August 10, 2013 Hi All, I am new to this forum / pz modding in general. I am working on a mod I'm calling CO2, where I am trying to add things like diet pop and mentos (or Mint-O's in my mod to avoid trademark infringement) so I can make mentos bombs. I wanted to add my own sprites to the game, so I started to dig around in the pz sources. After digging around in the sources I realized that there is a way to add sprites to the game: 1)in the script (.txt) portion put:Icon = spritename.png, 2)put your sprite in the project zomboid *root* (parent of media) directory with name:Item_spritename.png 3) Load the sprite with lua:... function modulename.loadTextures() local texas = getTexture("Item_spritename.png");end Events.OnGameBoot.Add(modulename.loadTextures); Attached is a screenshot for proof. My diet soda icon still needs some work. If we could access member texmap of the Texture class, I could make this much less hacky. Actually, we just need a function like setName() that acts on member texmap instead of member textures. Then we could load the external png from a directory like media/modname/ and rename it using setName() to Item_IconName ... kinyoshi, Kurn1207, Suomiboi and 3 others 6 Link to comment Share on other sites More sharing options...
7Roses Posted August 10, 2013 Share Posted August 10, 2013 aaah the getTexture still works saw that in the priv forum but thought that was code not in the work for 2.9.9.10 anymore think you just solved a problem a lot of item adding mods have Link to comment Share on other sites More sharing options...
Kurn1207 Posted August 11, 2013 Share Posted August 11, 2013 You sir are a legend, will be worth restoring my mod to get the few unique items back in thanks a lot buddy Link to comment Share on other sites More sharing options...
lance789 Posted August 11, 2013 Share Posted August 11, 2013 So how exactly would the file look when and which file would you edit to make this happem? Link to comment Share on other sites More sharing options...
kinyoshi Posted August 11, 2013 Share Posted August 11, 2013 How did I not see this yesterday??? Now I've got to try to make textures for my mods. (sprites, whatever!!) Good work Eggplanticus!!!! Link to comment Share on other sites More sharing options...
kinyoshi Posted August 11, 2013 Share Posted August 11, 2013 So how exactly would the file look when and which file would you edit to make this happem? I'm sure RoboMat will add it to his Tutorial here. Link to comment Share on other sites More sharing options...
RoboMat Posted August 11, 2013 Share Posted August 11, 2013 I can't get it to work at the moment. Maybe I'm too tired - will try again later on. Link to comment Share on other sites More sharing options...
lemmy101 Posted August 11, 2013 Share Posted August 11, 2013 Just do: Icon = Thing and put: Item_Thing.png in media/inventory/ RoboMat 1 Link to comment Share on other sites More sharing options...
Eggplanticus Posted August 11, 2013 Author Share Posted August 11, 2013 I can't get it to work at the moment. Maybe I'm too tired - will try again later on.Ok, Just do: Icon = Thing and put: Item_Thing.png in media/inventory/ Thanks, I will try this out! update: This does not work for me. The images are never loaded: from the log: WorldScreen:createtable 0x1024247087LOADED UP A TOTAL OF 123 TEXTURES^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ That's the normal number of textures reported. Link to comment Share on other sites More sharing options...
RoboMat Posted August 11, 2013 Share Posted August 11, 2013 It doesn't work for me also lemmy Link to comment Share on other sites More sharing options...
lemmy101 Posted August 11, 2013 Share Posted August 11, 2013 I can't get it to work at the moment. Maybe I'm too tired - will try again later on.Ok, Just do: Icon = Thing and put: Item_Thing.png in media/inventory/ Thanks, I will try this out! update: This does not work for me. The images are never loaded: from the log: WorldScreen:createtable 0x1024247087LOADED UP A TOTAL OF 123 TEXTURES^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ That's the normal number of textures reported. hmm odd, I've used this a million times myself. :S every time we put inventory items IN in fact they are there until we pack them. tho you should totally ignore the 'total of 123 textures' as it's not counting a lot and should be removed, considering there are over half a million textures Link to comment Share on other sites More sharing options...
Eggplanticus Posted August 11, 2013 Author Share Posted August 11, 2013 I can't get it to work at the moment. Maybe I'm too tired - will try again later on.Ok, Just do: Icon = Thing and put: Item_Thing.png in media/inventory/ Thanks, I will try this out! update: This does not work for me. The images are never loaded: from the log: WorldScreen:createtable 0x1024247087LOADED UP A TOTAL OF 123 TEXTURES^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ That's the normal number of textures reported. hmm odd, I've used this a million times myself. :S every time we put inventory items IN in fact they are there until we pack them. tho you should totally ignore the 'total of 123 textures' as it's not counting a lot and should be removed, considering there are over half a million textures hahaha! Well, I was using it as a diagnostic to get my first implementation to work, since it increments that number for each texture I load with getTexture() For whatever reason it's not automatically loading the pngs in that directory. Link to comment Share on other sites More sharing options...
lemmy101 Posted August 11, 2013 Share Posted August 11, 2013 yeah the point is it loads the texture at the moment the inventory item is created for the first time.... Will look into it when I get a mo, but the method I described has worked for about 2 years since the inventory item system was first coded in :S Link to comment Share on other sites More sharing options...
lance789 Posted August 11, 2013 Share Posted August 11, 2013 (edited) Hi All, I am new to this forum / pz modding in general. I am working on a mod I'm calling CO2, where I am trying to add things like diet pop and mentos (or Mint-O's in my mod to avoid trademark infringement) so I can make mentos bombs. I wanted to add my own sprites to the game, so I started to dig around in the pz sources. After digging around in the sources I realized that there is a way to add sprites to the game: 1)in the script (.txt) portion put:Icon = spritename.png,2)put your sprite in the project zomboid *root* (parent of media) directory with name:Item_spritename.png 3) Load the sprite with lua:... function modulename.loadTextures() local texas = getTexture("Item_spritename.png");end Events.OnGameBoot.Add(modulename.loadTextures);Attached is a screenshot for proof. My diet soda icon still needs some work. If we could access member texmap of the Texture class, I could make this much less hacky. Actually, we just need a function like setName() that acts on member texmap instead of member textures. Then we could load the external png from a directory like media/modname/ and rename it using setName() to Item_IconName ...in which lau do i put this in? or am i to create a new one? EDIT:: Doesn't seem to work for me D: Edited August 11, 2013 by lance789 Link to comment Share on other sites More sharing options...
Eggplanticus Posted August 11, 2013 Author Share Posted August 11, 2013 Hi All, I am new to this forum / pz modding in general. I am working on a mod I'm calling CO2, where I am trying to add things like diet pop and mentos (or Mint-O's in my mod to avoid trademark infringement) so I can make mentos bombs. I wanted to add my own sprites to the game, so I started to dig around in the pz sources. After digging around in the sources I realized that there is a way to add sprites to the game: 1)in the script (.txt) portion put:Icon = spritename.png,2)put your sprite in the project zomboid *root* (parent of media) directory with name:Item_spritename.png 3) Load the sprite with lua:... function modulename.loadTextures() local texas = getTexture("Item_spritename.png");end Events.OnGameBoot.Add(modulename.loadTextures);Attached is a screenshot for proof. My diet soda icon still needs some work. If we could access member texmap of the Texture class, I could make this much less hacky. Actually, we just need a function like setName() that acts on member texmap instead of member textures. Then we could load the external png from a directory like media/modname/ and rename it using setName() to Item_IconName ... in which lau do i put this in? or am i to create a new one? If you don't have a lua file already, create your own lua file whose only purpose is to load textures:example co2.lua: Co2 = {}; function Co2.loadTextures() local texas = getTexture("Item_Co2DietPopBottle.png"); texas = getTexture("Item_mintos.png");end Events.OnGameBoot.Add(Co2.loadTextures); example co2.txt: module Co2 { imports { Base } item MintosBomb { Weight = 0.9, Type = Food, DisplayName = Mintos Bomb, ReplaceOnUse = PopBottleEmpty, Icon = Co2DietPopBottle.png, } item DietPopBottle { HungerChange = 5, Weight = 0.8, Type = Food, UnhappyChange = -10, ThirstChange = -85, DisplayName = Diet Soda, ReplaceOnUse = PopBottleEmpty, Icon = Co2DietPopBottle.png, } item Mintos { HungerChange = -5, Weight = 0.1, Type = Food, UnhappyChange = -10, DisplayName = Mint-O's, Icon = mintos.png, } recipe Mintos Bomb { destroy DietPopBottle, Mintos, Result:MintosBomb, Time:5.0, }}screenshot of wip co2 mod: RoboMat 1 Link to comment Share on other sites More sharing options...
RoboMat Posted August 11, 2013 Share Posted August 11, 2013 Btw I think you don't need the local variable to use getTexture() function modulename.loadTextures() getTexture("Item_spritename.png"); getTexture("Item_2.png"); getTexture("Item_3.png");...end Events.OnGameBoot.Add(modulename.loadTextures); This should work aswell Link to comment Share on other sites More sharing options...
Aricane Posted August 11, 2013 Share Posted August 11, 2013 Give this man a medal! RoboMat 1 Link to comment Share on other sites More sharing options...
lemmy101 Posted August 11, 2013 Share Posted August 11, 2013 erm.... item DietPopBottle { HungerChange = 5, Weight = 0.8, Type = Food, UnhappyChange = -10, ThirstChange = -85, DisplayName = Diet Soda, ReplaceOnUse = PopBottleEmpty, Icon = Co2DietPopBottle.png, } There is NO WAY that could possiblyy work, because in code I'm taking the contents of Icon and putting media/inventory/Item_ at the start and .png at the end and calling getTexture on it, so that would be getTexture("media/inventory/Item_Co2DietPopBottle.png.png") If that does work then frankly my head will explode. Link to comment Share on other sites More sharing options...
RoboMat Posted August 11, 2013 Share Posted August 11, 2013 erm.... item DietPopBottle { HungerChange = 5, Weight = 0.8, Type = Food, UnhappyChange = -10, ThirstChange = -85, DisplayName = Diet Soda, ReplaceOnUse = PopBottleEmpty, Icon = Co2DietPopBottle.png, } There is NO WAY that could possiblyy work, because in code I'm taking the contents of Icon and putting media/inventory/Item_ at the start and .png at the end and calling getTexture on it, so that would be getTexture("media/inventory/Item_Co2DietPopBottle.png.png") If that does work then frankly my head will explode. It works ... I specifically had to put the .png in my script to make it work :/ BTW It only works when the texture is in the JAVA folder (so 'above' the media folder) Link to comment Share on other sites More sharing options...
Eggplanticus Posted August 11, 2013 Author Share Posted August 11, 2013 erm.... item DietPopBottle { HungerChange = 5, Weight = 0.8, Type = Food, UnhappyChange = -10, ThirstChange = -85, DisplayName = Diet Soda, ReplaceOnUse = PopBottleEmpty, Icon = Co2DietPopBottle.png, } There is NO WAY that could possiblyy work, because in code I'm taking the contents of Icon and putting media/inventory/Item_ at the start and .png at the end and calling getTexture on it, so that would be getTexture("media/inventory/Item_Co2DietPopBottle.png.png") If that does work then frankly my head will explode. You just prepend a bare "Item_" to Icon and call getTexture() on that. I think you did it to be compatible with the texture packs. That's why my hack requires part of the filename in Icon so that "Item_" + Icon results in a valid filename. I got this information by decompiling the classes and looking at the function:public InventoryItem InstanceItem(String param) Link to comment Share on other sites More sharing options...
speider Posted August 11, 2013 Share Posted August 11, 2013 so freaking cool gj dude Link to comment Share on other sites More sharing options...
RoboMat Posted August 11, 2013 Share Posted August 11, 2013 I've written a small tutorial based on the one by Eggplanticus (with his permission): http://pz-mods.net/guide/adding-custom-item-sprites/ Kurn1207 1 Link to comment Share on other sites More sharing options...
RegularX Posted August 11, 2013 Share Posted August 11, 2013 not 404 : ) Link to comment Share on other sites More sharing options...
RoboMat Posted August 11, 2013 Share Posted August 11, 2013 404 Fixed:http://pz-mods.net/guide/adding-custom-item-sprites/ Link to comment Share on other sites More sharing options...
kinyoshi Posted August 12, 2013 Share Posted August 12, 2013 (edited) It works fine for me. . Edit, My bad, I posted that it worked before reading that you guys got it working Edited August 12, 2013 by kinyoshi Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now