Divici Posted March 26, 2020 Share Posted March 26, 2020 (edited) Hey DST community, I've been working on my first mod character, and while I've found out how to do most of what I want for the character, I've been pretty stuck on a few things. So I'm reaching out to you all for some help or to at least point me in the right direction. Thanks in advance. 1. (Biggest Priority) My character has a custom helmet that he can use. I want to block him from being able to use any other item that has an armor tag apart from his custom helmet and sword (see 2. below). I would also like to prevent him from being able to see those recipes in the first place. I was thinking that maybe I'd have to make a blacklist of the specific armors I want to block but that would not account for downloaded mods. I'm very new to coding so any help with this would be great. 2. I'm giving the character 2 swords. One is a basic weapon that does 50 damage. I want the second one to take an armor slot, which I believe I can figure out. what I'm stuck on is, I want that when equipping sword 2, the character gets an additional 50 damage on any weapon equipped. Additionally but not a priority: Is it possible to make the character hold the second weapon in his other hand? He does not need to swing it. 3. I want that each time the character dies, not only does his max health get cut but his max sanity will be cut by 50. To go along with this, each attack the character does adds 0.5 onto the maximum sanity, up to 250 where it caps. As I said above, I'm very new to coding but I'm excited to learn. From searching through the forums I found code that does similar things to the above but not quite the correct solution. Any help would be greatly appreciated. Have a nice day! edit: (Still could use assistance for the first part) Edited April 3, 2020 by Divici Solved part of it Link to comment Share on other sites More sharing options...
SirDoggo Posted March 28, 2020 Share Posted March 28, 2020 I had a similar situation with one of my mods, take a look at the form link I've put in this reply. The code will make it so the character can't wear any armor on the body but still can wear any helmet, I know this isn't the exact solution but take a look as I think it will help you. Link to comment Share on other sites More sharing options...
Divici Posted March 28, 2020 Author Share Posted March 28, 2020 2 hours ago, SirDoggo said: I had a similar situation with one of my mods, take a look at the form link I've put in this reply. The code will make it so the character can't wear any armor on the body but still can wear any helmet, I know this isn't the exact solution but take a look as I think it will help you. Thanks for the help. I tried the code from your Frank LUA: Spoiler --Block Armors local function drop(inst, data) -- The "equip" event gives us a data parameter, as well, with information -- on which slot is affected and the item. -- If it has nothing to do with the BODY-slot, or the item is nil, we do nothing. if data.eslot ~= EQUIPSLOTS.BODY or data.item == nil then return end local item = data.item -- Don't drop item, if there is none, or if it's a backpack, heavy-thing, -- has the tag "tag" (?) or its name contains the phrase "amulet". if item:HasTag("backpack") or item:HasTag("heavy") or item:HasTag("tag") or item.prefab:find("amulet") then return end inst:DoTaskInTime( 0, function() if not inst:IsValid() then return end local item = inst.components.inventory:Unequip(EQUIPSLOTS.BODY) if inst and inst.components.talker then inst.components.talker:Say("I don't need armor!!!") end if item then inst.components.inventory:GiveItem(item) inst.AnimState:OverrideSymbol("swap_body", "nil", "nil") end end ) end I ran my mod character and debug spawned a grass suit but he was still able to equip it. Did I miss something in the code? Also do you know where I can find the tags associated with different types of items? e.g. the tags for dress tab items like "hats" or something. I assume i would just add (or data.eslot ~= EQUIPSLOTS.HEAD) to line 6 and then include the item:HasTag("hats e.t.c"). Link to comment Share on other sites More sharing options...
SirDoggo Posted March 30, 2020 Share Posted March 30, 2020 Yeah you can try that I think that could work, if not there might need to be a separate list for the body and head slots. Sorry for the late reply I wasn't too sure what to suggest next. Link to comment Share on other sites More sharing options...
Divici Posted March 30, 2020 Author Share Posted March 30, 2020 3 hours ago, SirDoggo said: Yeah you can try that I think that could work, if not there might need to be a separate list for the body and head slots. Sorry for the late reply I wasn't too sure what to suggest next. Do I need to add anything to my modmain on somewhere else in the character prefab to get it to work? It doesn't seem to be calling the function when in game. Link to comment Share on other sites More sharing options...
SirDoggo Posted March 30, 2020 Share Posted March 30, 2020 (edited) Does yours look like this? This might be some parts you are missing, for me it is located in charactername.lua The inst:ListenForEvent("equip", drop) is in the local master_postinit. local function drop(inst, data) -- The "equip" event gives us a data parameter, as well, with information -- on which slot is affected and the item. -- If it has nothing to do with the BODY-slot, or the item is nil, we do nothing. if data.eslot ~= EQUIPSLOTS.BODY or data.item == nil then return end local item = data.item -- Don't drop item, if there is none, or if it's a backpack, heavy-thing, -- has the tag "tag" (?) or its name contains the phrase "amulet". if item:HasTag("backpack") or item:HasTag("heavy") or item:HasTag("tag") or item.prefab:find("amulet") or item.prefab:find("vest") or item.prefab:find("hawaiianshirt") or item.prefab:find("raincoat") or item.prefab:find("armorgrass") then return end inst:DoTaskInTime( 0, function() if not inst:IsValid() then return end local item = inst.components.inventory:Unequip(EQUIPSLOTS.BODY) if inst and inst.components.talker then inst.components.talker:Say("It does not fit me.") end if item then inst.components.inventory:GiveItem(item) inst.AnimState:OverrideSymbol("swap_body", "nil", "nil") end end ) end inst:ListenForEvent("equip", drop) Edited March 30, 2020 by SirDoggo Link to comment Share on other sites More sharing options...
Divici Posted March 30, 2020 Author Share Posted March 30, 2020 36 minutes ago, SirDoggo said: Does yours look like this? This might be some parts you are missing, for me it is located in charactername.lua The inst:ListenForEvent("equip", drop) is in the local master_postinit. local function drop(inst, data) -- The "equip" event gives us a data parameter, as well, with information -- on which slot is affected and the item. -- If it has nothing to do with the BODY-slot, or the item is nil, we do nothing. if data.eslot ~= EQUIPSLOTS.BODY or data.item == nil then return end local item = data.item -- Don't drop item, if there is none, or if it's a backpack, heavy-thing, -- has the tag "tag" (?) or its name contains the phrase "amulet". if item:HasTag("backpack") or item:HasTag("heavy") or item:HasTag("tag") or item.prefab:find("amulet") or item.prefab:find("vest") or item.prefab:find("hawaiianshirt") or item.prefab:find("raincoat") or item.prefab:find("armorgrass") then return end inst:DoTaskInTime( 0, function() if not inst:IsValid() then return end local item = inst.components.inventory:Unequip(EQUIPSLOTS.BODY) if inst and inst.components.talker then inst.components.talker:Say("It does not fit me.") end if item then inst.components.inventory:GiveItem(item) inst.AnimState:OverrideSymbol("swap_body", "nil", "nil") end end ) end inst:ListenForEvent("equip", drop) Yep, I tried that without the listen event and of course nothing happened when equipping armor. After adding the listening event under the local master_postinit the game loads up to character selection and after picking my mod character, it crashes. It says that the variable 'drop' is not declared. Let me know if I should upload the crash log or character mod. Link to comment Share on other sites More sharing options...
Divici Posted March 31, 2020 Author Share Posted March 31, 2020 (edited) Also I tried the below code. I got it to block all hats except for my custom hat but couldn't block just armor. --Blocks the use of armor local _Equip = inst.components.inventory.Equip inst.components.inventory.Equip = function(self, item, old_to_active) if not item or not item.components.equippable or not item:IsValid() then return end if item.components.equippable.equipslot == EQUIPSLOTS.HEAD then if not (item.prefab == "boarhat") then self:DropItem(item) self:GiveItem(item) if inst and inst.components.talker then inst.components.talker:Say("It does not fit me.") end return end end return _Equip(self, item, old_to_active) end Any ideas on what I'm missing? Edited March 31, 2020 by Divici Link to comment Share on other sites More sharing options...
Divici Posted April 2, 2020 Author Share Posted April 2, 2020 bump Link to comment Share on other sites More sharing options...
Ultroman Posted April 2, 2020 Share Posted April 2, 2020 On 31.3.2020 at 4:50 AM, Divici said: Also I tried the below code. I got it to block all hats except for my custom hat but couldn't block just armor. --Blocks the use of armor local _Equip = inst.components.inventory.Equip inst.components.inventory.Equip = function(self, item, old_to_active) if not item or not item.components.equippable or not item:IsValid() then return end if item.components.equippable.equipslot == EQUIPSLOTS.HEAD then if not (item.prefab == "boarhat") then self:DropItem(item) self:GiveItem(item) if inst and inst.components.talker then inst.components.talker:Say("It does not fit me.") end return end end return _Equip(self, item, old_to_active) end Any ideas on what I'm missing? Read your code, m8. You only have code that says "if the thing attempting to get equipped is a hat and it is not your hat-prefab, then pocket the item". That's what you got. There's nothing about the BODY slot in there. Here you go. This says: "if the thing attempting to get equipped is a BODY-slot thing of any kind OR it is a HEAD-slot thing that is not your hat-prefab, then pocket the item" local _Equip = inst.components.inventory.Equip inst.components.inventory.Equip = function(self, item, old_to_active) if not item or not item.components.equippable or not item:IsValid() then return end if item.components.equippable.equipslot == EQUIPSLOTS.BODY or item.components.equippable.equipslot == EQUIPSLOTS.HEAD and not (item.prefab == "boarhat") then self:DropItem(item) self:GiveItem(item) if inst and inst.components.talker then inst.components.talker:Say("It does not fit me.") end return end return _Equip(self, item, old_to_active) end Link to comment Share on other sites More sharing options...
Divici Posted April 2, 2020 Author Share Posted April 2, 2020 3 hours ago, Ultroman said: Read your code, m8. You only have code that says "if the thing attempting to get equipped is a hat and it is not your hat-prefab, then pocket the item". That's what you got. There's nothing about the BODY slot in there. Here you go. This says: "if the thing attempting to get equipped is a BODY-slot thing of any kind OR it is a HEAD-slot thing that is not your hat-prefab, then pocket the item" local _Equip = inst.components.inventory.Equip inst.components.inventory.Equip = function(self, item, old_to_active) if not item or not item.components.equippable or not item:IsValid() then return end if item.components.equippable.equipslot == EQUIPSLOTS.BODY or item.components.equippable.equipslot == EQUIPSLOTS.HEAD and not (item.prefab == "boarhat") then self:DropItem(item) self:GiveItem(item) if inst and inst.components.talker then inst.components.talker:Say("It does not fit me.") end return end return _Equip(self, item, old_to_active) end To clarify, I still want my character to be able to wear body and head items. I specifically don't want him to be able to wear items that block damage/armor, except for the custom armor. e.g. He can equip a Dapper Vest but can not equip a Marble Suit, or can equip a Beefalo Hat but not a Football Helmet. I was asking for help with doing it for the HEAD slot assuming that I'd be able to then figure out how to add the BODY as well. Sorry if I was not clear. Link to comment Share on other sites More sharing options...
Ultroman Posted April 2, 2020 Share Posted April 2, 2020 (edited) 46 minutes ago, Divici said: To clarify, I still want my character to be able to wear body and head items. I specifically don't want him to be able to wear items that block damage/armor, except for the custom armor. e.g. He can equip a Dapper Vest but can not equip a Marble Suit, or can equip a Beefalo Hat but not a Football Helmet. I was asking for help with doing it for the HEAD slot assuming that I'd be able to then figure out how to add the BODY as well. Sorry if I was not clear. Easy local _Equip = inst.components.inventory.Equip inst.components.inventory.Equip = function(self, item, old_to_active) if not item or not item.components.equippable or not item:IsValid() then return end if item.components.equippable.equipslot == EQUIPSLOTS.HEAD and item.prefab ~= "boarhat" and item.components.armor or item.components.equippable.equipslot == EQUIPSLOTS.BODY and item.components.armor then self:DropItem(item) self:GiveItem(item) if inst and inst.components.talker then inst.components.talker:Say("It does not fit me.") end return end return _Equip(self, item, old_to_active) end Edited April 2, 2020 by Ultroman Link to comment Share on other sites More sharing options...
Divici Posted April 3, 2020 Author Share Posted April 3, 2020 1 hour ago, Ultroman said: Easy local _Equip = inst.components.inventory.Equip inst.components.inventory.Equip = function(self, item, old_to_active) if not item or not item.components.equippable or not item:IsValid() then return end if item.components.equippable.equipslot == EQUIPSLOTS.HEAD and item.prefab ~= "boarhat" and item.components.armor or item.components.equippable.equipslot == EQUIPSLOTS.BODY and item.components.armor then self:DropItem(item) self:GiveItem(item) if inst and inst.components.talker then inst.components.talker:Say("It does not fit me.") end return end return _Equip(self, item, old_to_active) end OMG!!! Thank you! That worked perfectly. Now I can finally finish the mod and release it. I knew the general code for it but had no idea what the syntax was. I'm definitely about to hit that LUA crash course =). Link to comment Share on other sites More sharing options...
Ultroman Posted April 3, 2020 Share Posted April 3, 2020 1 minute ago, Divici said: OMG!!! Thank you! That worked perfectly. Now I can finally finish the mod and release it. I knew the general code for it but had no idea what the syntax was. I'm definitely about to hit that LUA crash course =). You're welcome Happy to help! Good! You might have learned to do this, actually What I did was simply ask whether the item has the armor component by asking item.components.armor That looks weird, but this looks up the variable called "armor" on the "components" object which is a in a variable on the "item" object. If item is nil, the mod crashes. If item.components is nil, the mod crashes. But they usually aren't If item.components.armor is nil, this will return false, because of the rules Lua has for handling boolean conversions. It will instead return true if item.components.armor is set to ANYTHING ELSE that isn't also in Lua's list of things to consider false, like 0 or an empty string. Link to comment Share on other sites More sharing options...
Yoyo_Dodo Posted May 21, 2022 Share Posted May 21, 2022 (edited) Hello guys Sorry for sneaking into the post, but if you can answer a question for me, please. I have seen this code and in my character mod I have tried to modify it to block only the construction amulet, but nothing works. Also try to keep the other amulets with: or item.prefab:find("yellowamulet") or item.prefab:find("orangeamulet") or item.prefab:find("blueamulet") or item.prefab:find("purpleamulet") But as the tag "amulet" works for all amulets. if I don't add it, the red amuletis blocked, if I keep it, the green amulet stays. if someone could help me please. EDIT: Nevermind, I already solved it Edited May 28, 2022 by Yoyo_Dodo 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