Jump to content

[SOLVED] [Build 34.28] How to add a Custom Icon Sprite


Berdryn

Recommended Posts

Hello!  UPDATE: Solved script is at the bottom!

 

I've been searching on the forums here, on steam and on the old pz-mods site as well as reddit. Maybe i'm missing something but here is the problem;

 

Custom item is a container that I want to add my own graphics for. Essentially, I am trying to replicate the Hydrocraft mod's Dogs as containers. I have a 64x64 iso square I am trying to use as a dummy graphic.

 

Going into my item;

   Icon = CustomIcon, 

 

I have the graphic named Item_CustomIcon.png in media\textures\;

 

I thought that if you define the icon name in the script, Icon = CustomIcon, you don't need to include the Item_ or .png.

Could someone help me or point me towards something? Really wracking my brain. I heard of a method to do it with Lua but then read that it wasn't needed. 

 

There was a short tutorial on pz-mods by Eggplanticus. Here is my version. It still won't let me load the graphic on my item. Could it be due to its size of 64x64? 

 

CustomItemIcons = {}

function CustomItemIcons.loadTextures()
    --getTexture("Item_CustomItem.png");
	getTexture("Item_MortalVessel.png");
end

Events.OnGameBoot.Add(CustomItemIcons.loadTextures);

 

Edited by Berdryn
Link to comment
Share on other sites

Ok so after trying so many things, this is what fixed my issue.

 

In ../media/textures/ folder, I had my a sub folder with my mod name_textures. Deleting this folder and having my Item_CustomIcon.png just in the base textures folder seems to get it to work!

 

Upon further testing. You do need to load the texture via the lua file. The one I have above works, just gotta add the new icon names. I've also found that a 64x64 image size doesn't seem to work, only 32x32. It looks a bit odd currently with the 2x texturepack TIS made.

 

See the image below?

Ideally, I want this box to be the same size as the tile below it. On the off chance someone actually reads this;

 

DO YOU KNOW A WAY TO CENTER AN ITEM ON DROP?

 

I want to drop the box anywhere but I want it to snap to the very center of the tile its on. Is this some fancy lua code?

 

Box on 2x texturepack.

32on64.jpg

 

Box on 1x texturepack

See the issue? Why won't the game take in 64x64 icons? 

 

32on32.jpg

 

I don't get this forum and why it keeps adding more than one image.. at the end.

32on32.jpg

32on32.jpg

Edited by Berdryn
Link to comment
Share on other sites

Here is the solved script for adding a custom icon to your mod.

First you must make sure you have the proper file structure set up for your mod, plenty of info out there on this but i'll show you real quick.

Your mod, in my case iGod, is in a folder just called iGod. Inside of this you have media, inside that folder you have lua. Inside of THAT folder you have 3 sub folders; client, server and shared. Because even in singleplayer, you are still hosting a server as far as the code is concerned (I think, I read this somewhere on the forums. I think maybe on pz-mods.net). Shared is where I place my lua scripts, with the hope that it can be used by the client and the server.

Looks like this: iGod/media/lua/shared 

Now that you know where the lua goes, here is the script:
 

CustomItemIcons = {}

function CustomItemIcons.loadTextures()

	getTexture("Item_CustomIcon.png");
	--getTexture("Item_CustomIcon.png");
	
end

Events.OnPreMapLoad.Add(CustomItemIcons.loadTextures);

This sets up the table to store the stuff, the function to actually code it and getTexture with your named file after Item_. The game uses Item_ as a way to tell its an icon I guess. In your item code, you don't need to add Item_ or .png. It will look like this:

 

		item CustomItem
		{
			DisplayName	=	Custom Item with Custom Icon,
			Type		=	Food,
			Icon		=	CustomIcon,	
			Weight		=	0.0,
			
			DaysFresh = 1,
			DaysTotallyRotten = 1,

		}

I hope i've explained it all well enough. It took a few days to figure out on my own and asking questions on the forum (thanks to those who answered, @tommysticks also!

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