icantevenname Posted November 3, 2021 Share Posted November 3, 2021 The title's the gist of it, I'm making a weapon with an armor value, but I want it to turn into an armorless version when it breaks. I plan on making so that it can be turned back into the normal version, but that's as simple as making a custom craft recipe and I already know how to do that. Link to comment Share on other sites More sharing options...
skittles sour Posted November 3, 2021 Share Posted November 3, 2021 you can remove the armor component, or you can take use the ReplacePrefab function. You can also take advantage of the perishable component, since the perishable:Perish() function checks whether the item is being held in an inventory or container and puts the replacement at the same spot. Link to comment Share on other sites More sharing options...
icantevenname Posted November 4, 2021 Author Share Posted November 4, 2021 ReplacePrefab sounds useful, what has it so I can look into it? Link to comment Share on other sites More sharing options...
skittles sour Posted November 4, 2021 Share Posted November 4, 2021 (edited) its in main functions. it's only in dst though and not in ds. ds has another function whose name escapes me Edited November 4, 2021 by Bad Willow Link to comment Share on other sites More sharing options...
icantevenname Posted November 7, 2021 Author Share Posted November 7, 2021 On 11/3/2021 at 11:49 PM, Bad Willow said: its in main functions. it's only in dst though and not in ds. ds has another function whose name escapes me Found it, but I have no idea how to tell the game to Listen for the weapon breaking. I think I've seen it somewhere, but I don't remember where. Actually, I just realized something, shouldn't I have the weapon Listen for it breaking and then tell the game to spawn the broken version? Do I even needĀ ReplacePrefab at all? Link to comment Share on other sites More sharing options...
skittles sour Posted November 7, 2021 Share Posted November 7, 2021 you should probably look inside the finite uses component, there's an on finish callback function available there, or you can listen for the event of tool break, which I think the finite uses component pushes. Link to comment Share on other sites More sharing options...
icantevenname Posted November 8, 2021 Author Share Posted November 8, 2021 (edited) 21 hours ago, Bad Willow said: you should probably look inside the finite uses component, there's an on finish callback function available there, or you can listen for the event of tool break, which I think the finite uses component pushes. So like this? inst:AddComponent("finiteuses") inst.components.finiteuses:onfinished = fn And then make a Function that has SpawnPrefab? Edited November 8, 2021 by icantevenname Link to comment Share on other sites More sharing options...
skittles sour Posted November 8, 2021 Share Posted November 8, 2021 yeah the gist of it is that. but the colon operator of lua is a very specific operator, it is short for table.function = function(table, ...), so it'd be simply finiteuses.onfinished = your function Link to comment Share on other sites More sharing options...
icantevenname Posted November 10, 2021 Author Share Posted November 10, 2021 finiteuses' a no-go. The game swaps between armor% and use% in the HUD and when it breaks from armor% hitting zero, nothing happens. Link to comment Share on other sites More sharing options...
icantevenname Posted November 11, 2021 Author Share Posted November 11, 2021 I looked into the armor component an' found this line... inst.components.inventoryitem.owner:PushEvent("armorbroke", { armor = inst }) So do I listen for armorbroke and then have it push my function? Link to comment Share on other sites More sharing options...
skittles sour Posted November 11, 2021 Share Posted November 11, 2021 yeah i've also noticed the problem with the hud when doing a hamlet mod for the thunderhat recently, my solution ended up being using the timer component instead of the fueled component for a lightning charge level. you can either suffer the swap or try to work around oneĀ of the components, for example, instead of using the armor component properly, trying to reduce damage in another way, such as a buff. as for the event, in my experience, declaring a function in a component is a lot more reliable than listening for an event, since sometimes the event is not pushed - an example of this is the equippable component where the onunequipfn can be called without the unequipped event pushed. but your code looks good to me. Link to comment Share on other sites More sharing options...
icantevenname Posted November 17, 2021 Author Share Posted November 17, 2021 I wanna try my listen idea first. What's a prefab that listens for something that I could look at? I've tried thinking of one, but can't. Link to comment Share on other sites More sharing options...
icantevenname Posted December 3, 2021 Author Share Posted December 3, 2021 Okay, this is what I came up with... local function SpawnBustedBrella(inst) inst:ListenForEvent("armorbroke", function() SpawnPrefab("brella_busted") end) end ...but nothing happens. What did I do wrong? 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