Jump to content

Adding Sprites


Eggplanticus

Recommended Posts

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 ...

 

Link to comment
Share on other sites

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:create

table 0x1024247087

LOADED UP A TOTAL OF 123 TEXTURES

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 

That's the normal number of textures reported.

 

Link to comment
Share on other sites

 

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:create

table 0x1024247087

LOADED 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 :D

Link to comment
Share on other sites

 

 

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:create

table 0x1024247087

LOADED 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 :D

 

 

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

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

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 by lance789
Link to comment
Share on other sites

 

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:

Link to comment
Share on other sites

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...