Jump to content

Recommended Posts

I'm losing sleep over this, I want to remove the percentage number on item icons (server with indestructible items), I know what file that code is in, i know what LINE it is, but I'm new to DST modding and don't know how to make it work. 

I copied some random basic "modinfo", made all the alterations, made it server side, and by looking at similar mods, it seems that they simply copy the altered .lua files to the mod folder and it works, so I did this, I put the "scripts/widgets/itemtile.lua" there and simply changed the percentage text font size to 0. But it simply doesn't work, after hours banging my head, this forum is my last hope, do I need to write something on the "mainmod" file? Do I NEED a "mainmod" file at all? Can someone help me with this?

The file name is "itemtile", the code section is this one:

function ItemTile:SetPercent(percent)
    if not self.item:HasTag("hide_percentage") then
        if not self.percent then
            self.percent = self:AddChild(Text(NUMBERFONT, 42))
            if JapaneseOnPS4() then
                self.percent:SetHorizontalSqueeze(0.7)
            end
            self.percent:SetPosition(5,-32+15,0)
        end
        local val_to_show = percent*100
        if val_to_show > 0 and val_to_show < 1 then
            val_to_show = 1
        end
        self.percent:SetString(string.format("%2.0f%%", val_to_show))
    end
end

And I simply need to change the " self.percent = self:AddChild(Text(NUMBERFONT, 42))" to " self.percent = self:AddChild(Text(NUMBERFONT, 0))".

How can I make a mod like this work? Also, in the same file I can remove the green perishable items background, it would be nice too. 

Edited by Awibilei
Grammar
41 minutes ago, Serpens said:

cant you just use the existing indestructable items mod, which simply removes the "finiteuses" component? This will automatically also removes the percentages. Dont know the exact name of that mod currently.

I tested a lot of "infinite items" mods, none of them removed the percentage number, but if you're saying there's one that does it I'm gonna give it another look, at least now I know there is one like that around, thank you. 

1 minute ago, Awibilei said:

I tested a lot of "infinite items" mods, none of them removed the percentage number, but if you're saying there's one that does it I'm gonna give it another look, at least now I know there is one like that around, thank you. 

you simply have to do in modmain:
AddPrefabPostInit("theprefab",function(inst)
    inst:RemoveComponent("finiteuses")
end)
This will remove the finiteuses (which is used for weapons and tools) from yourprefab. And therefore also the percentage.

Edited by Serpens
1 hour ago, Serpens said:

you simply have to do in modmain:
AddPrefabPostInit("theprefab",function(inst)
    inst:RemoveComponent("finiteuses")
end)
This will remove the finiteuses (which is used for weapons and tools) from yourprefab. And therefore also the percentage.

I found the mod you were referring to, there's 3 things I have to get rid of, "finiteuses", "fueled" and "perishable", thing is, this way I need to manually change every item, one by one, is there a way to get rid of those item flags quickier? Something like "removeComponent("finiteuses")" to apply to the whole "prefabs" folder? 

Or if I were to simply do as I said earlier and change the percentage font to 0, what would I need to write on the "mainmod"? 

Edited by Awibilei
50 minutes ago, Awibilei said:

I found the mod you were referring to, there's 3 things I have to get rid of, "finiteuses", "fueled" and "perishable", thing is, this way I need to manually change every item, one by one, is there a way to get rid of those item flags quickier? Something like "removeComponent("finiteuses")" to apply to the whole "prefabs" folder? 

Or if I were to simply do as I said earlier and change the percentage font to 0, what would I need to write on the "mainmod"? 

changing a precentage display is muuuuuch more complicated then everyhting else. It is one of the most complicated I can imagine :D Mostly because it is a client display and messing with clients is always difficult, unless it is a client_only mod and you only want to remove the precentage for only the players who have the client mod installed (but as client mod you can not make items last infinite)

You can use instead:
AddComponentPostInit("finiteuses",function(self)
    self.inst:DoTaskInTime(0,function(inst)
        inst:RemoveComponent("finiteuses")
    end)
end)
This will make everything with finiteuses remove that component after the game was loaded.

Edited by Serpens
12 minutes ago, Serpens said:

changing a precentage display is muuuuuch more complicated then everyhting else. It is one of the most complicated I can imagine :D Mostly because it is a client display and messing with clients is always difficult, unless it is a client_only mod and you only want to remove the precentage for only the players who have the client mod installed (but as client mod you can not make items last infinite)

You can use instead:
AddComponentPostInit("finiteuses",function(self)
    self.inst:DoTaskInTime(0,function(inst)
        inst:RemoveComponent("finiteuses")
    end)
end)
This will make everything with finiteuses remove that component after the game was loaded.

I tried using your code but for some reason it only worked for "perishable" items, removing the green background, anyway, I don't want to take much of your time as you already helped a lot, but can you help me with the percentage display? It's alright for it to be a client only mod, I use another one to get infinite item uses anyway. 

Unless it would be really difficult to change that, even being client only. 

Again, thank you for your time.

The code above worked fine for me, had a firestaff with infinite uses and no percentage displayed. This is still the recommended way.

If you still want to hide the percentage:
I just saw in the itemtile code is written:
if not self.item:HasTag("hide_percentage") then
so you can also add this Tag to everything you dont want to see percentages on. Eg also within the AddComponentPostInit, add the tag to self.inst.

And another way to hide percentage would be:

AddClassPostConstruct("widgets/itemtile",function(self)
    if self.percent~=nil then
        self.percent:Hide() -- simply hide it
    end
    local old_SetPercent = self.SetPercent
    local function new_SetPercent(percent,...)
        local ret
        if old_SetPercent~=nil then
            ret = old_SetPercent(percent,...)
        end
        if self.percent~=nil then
            self.percent:Hide() -- simply hide it
        end
        return ret
    end
    self.SetPercent = new_SetPercent
end)

This will overwrite the "SetPercent" function, but remebers the original function. So our new function will first call the original function ,which will set up the precentage, but directly after it, we will simply Hide() it. If your mod is "all client require" and you want it to work for every percentage of every item, regardless what/what happens, then one single mod is enough (so no need for client_only and no need for complicated code (it gets complicated if the server has to tell the clients whento hide precentage and when to show percentage. But if you always want to hide all percentages, it is easy)

Edited by Serpens
29 minutes ago, Serpens said:

The code above worked fine for me, had a firestaff with infinite uses and no percentage displayed. This is still the recommended way.

If you still want to hide the percentage:
I just saw in the itemtile code is written:
if not self.item:HasTag("hide_percentage") then
so you can also add this Tag to everything you dont want to see percentages on. Eg also within the AddComponentPostInit, add the tag to self.inst.

And another way to hide percentage would be:


AddClassPostConstruct("widgets/itemtile",function(self)
    if self.percent~=nil then
        self.percent:Hide() -- simply hide it
    end
    local old_SetPercent = self.SetPercent
    local function new_SetPercent(percent,...)
        local ret
        if old_SetPercent~=nil then
            ret = old_SetPercent(percent,...)
        end
        if self.percent~=nil then
            self.percent:Hide() -- simply hide it
        end
        return ret
    end
    self.SetPercent = new_SetPercent
end)

This will overwrite the "SetPercent" function, but remebers the original function. So our new function will first call the original function ,which will set up the precentage, but directly after it, we will simply Hide() it. If your mod is "all client require" and you want it to work for every percentage of every item, regardless what/what happens, then one single mod is enough (so no need for client_only and no need for complicated code (it gets complicated if the server has to tell the clients whento hide precentage and when to show percentage. But if you always want to hide all percentages, it is easy)

THAT'S IT! It worked flawlessly, thank you very much for the help, I'm the type of guy that only knows how to change numbers on scripts that other people wrote hahah, I would never manage to do this on my own, so again, thank you.

  • Developer

this removes all of these components from every prefab in the game, making them not exist.

AddPrefabPostInitAny(function(inst)
	inst:RemoveComponent("finiteuses")
	inst:RemoveComponent("fueled")
	inst:RemoveComponent("perishable")
end)
  • Like 1
On 23.10.2019 at 12:04 AM, Zarklord said:

this removes all of these components from every prefab in the game, making them not exist.


AddPrefabPostInitAny(function(inst)
	inst:RemoveComponent("finiteuses")
	inst:RemoveComponent("fueled")
	inst:RemoveComponent("perishable")
end)

True, but that code runs for ALL items. You only need it to run for the specific items which get the components added to them, which is exactly what Serpens' code does.

  • Developer
14 hours ago, Ultroman said:

True, but that code runs for ALL items. You only need it to run for the specific items which get the components added to them, which is exactly what Serpens' code does.

yeah, but for prefabs lacking those components, that code does nothing, RemoveComponent has the proper safeguards in place to prevent errors on prefabs lacking those components.

  • Like 1
2 hours ago, Zarklord said:

yeah, but for prefabs lacking those components, that code does nothing, RemoveComponent has the proper safeguards in place to prevent errors on prefabs lacking those components.

:D:D I hate to answer on this and waste your/my time, but maybe you have a good reason ultroman and I dont see:

If a prefab does not have the component, why should we try to remove the component from them? So "my solution" was to do AddComponentPostInit for finiteuses, for perishable, armor and for fueled. So this would be 4 blocks of code and everything should be fine. So I see no reason to use AddPrefabPostInitAny. Advantage would be shorter code. Disadvantage may be calling RemoveComponent for a thousand things more than necessary and thus wasting time.

Edited by Serpens
  • Developer
40 minutes ago, Serpens said:

:D:D I hate to answer on this and waste your/my time, but maybe you have a good reason ultroman and I dont see:

If a prefab does not have the component, why should we try to remove the component from them? So "my solution" was to do AddComponentPostInit for finiteuses, for perishable, armor and for fueled. So this would be 4 blocks of code and everything should be fine. So I see no reason to use AddPrefabPostInitAny. Advantage would be shorter code. Disadvantage may be calling RemoveComponent for a thousand things more than necessary and thus wasting time.

RemoveComponents first line of code is checking whether the component exists, scheduling tasks is way more code intensive than blanket removing a component.

  • Like 1
6 hours ago, Serpens said:

:D:D I hate to answer on this and waste your/my time, but maybe you have a good reason ultroman and I dont see:

If a prefab does not have the component, why should we try to remove the component from them? So "my solution" was to do AddComponentPostInit for finiteuses, for perishable, armor and for fueled. So this would be 4 blocks of code and everything should be fine. So I see no reason to use AddPrefabPostInitAny. Advantage would be shorter code. Disadvantage may be calling RemoveComponent for a thousand things more than necessary and thus wasting time.

That is exactly what I meant :D Did I wod it weirdly? Do not use AddPrefabPostInitAny unless you're absolutely sure you know that that's the only way to achieve what you want. It's insanely heavy.

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