Jump to content

Recommended Posts

@JadeKnightblazer@Mobbstar,

 

Line 220 in "..\scripts\widgets\itemtile.lua"

self.percent:SetString(string.format("%2.0f%%", val_to_show))

Specifically the "%%". It appends a percent sign to the values. (According to this)

 

It's in the "ItemTile:SetPercent(percent)" function. To change it, just override that function in your modmain using AddClassPostConstruct("widgets/itemtile", your_itemtile_postconst)

 

@JadeKnightblazer@Mobbstar,

 

Line 220 in "..\scripts\widgets\itemtile.lua"

self.percent:SetString(string.format("%2.0f%%", val_to_show))

Specifically the "%%". It appends a percent sign to the values. (According to this)

 

It's in the "ItemTile:SetPercent(percent)" function. To change it, just override that function in your modmain using AddClassPostConstruct("widgets/itemtile", your_itemtile_postconst)

 

Thanks, now just to figure out how to use it for only certain items.

 

Was hoping something easy like this could be placed in the customitem script.

 

inst.AddWidget("itemtile")
inst.widgets.itemtile.percent:SetString(" ")
 
but... AddWidget does not work.
 
 
Possible to post an example of your AddClassPostConstruct, with the custom postconst enable / disable certain custom items with the ItemTile:SetPercent.
 
please :-)

 

Edited by JadeKnightblazer

@JadeKnightblazer,

 

Not sure if I understood your question correctly. I think you meant something like this.

local function itemtile_post(self, invitem)    -- save old function    self.old_SetPercent = self.SetPercent    -- override with your own function    self.SetPercent = function(self, percent)        -- call old function first        self:old_SetPercent(percent)        if self.invitem and self.invitem.prefab == "your_item_prefab" then            local oldStr = self.percent:GetString()            self.percent:SetString(string.format("%2.0f", oldStr)) -- remove %        end    endendAddClassPostConstruct("widgets/itemtile", itemtile_post)

Remember to change your_item_prefab accordingly.

 

--Turn off percent on certain Items	local function itemtile_post(self, invitem)    -- save old function    self.old_SetPercent = self.SetPercent     -- override with your own function    self.SetPercent = function(self, percent)		    -- call old function first		self:old_SetPercent(percent)				if self.invitem and self.invitem.prefab == "skitemmealticket" then                          local oldStr = self.percent:GetString()			--self.percent:SetString(string.format("%2.0f", oldStr)) -- remove %			  self.percent:SetString(string.sub(oldStr,1,-2))		end    endendAddClassPostConstruct("widgets/itemtile", itemtile_post)

All placed in the modmain.lua

 

This code does not crash the game at all, nor does it remove the percent indicator =/. Most likely on my end unless others havn't been around to get this run-a-around to work. 

@JadeKnightblazer,

 

Add these print statements and see what they print to the console/log:

--Turn off percent on certain Itemslocal function itemtile_post(self, invitem)    -- save old function    self.old_SetPercent = self.SetPercent        -- override with your own function    self.SetPercent = function(self, percent)             -- call old function first        self:old_SetPercent(percent)                print("Checking prefab")        if self.invitem and self.invitem.prefab == "skitemmealticket" then            local oldStr = self.percent:GetString()            print(oldStr)            --self.percent:SetString(string.format("%2.0f", oldStr)) -- remove %            local newStr = string.sub(oldStr,1,-2)            print(newStr)            self.percent:SetString(newStr)        end    endendAddClassPostConstruct("widgets/itemtile", itemtile_post)

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