Anarchuz Posted May 2, 2015 Share Posted May 2, 2015 Hey guys i just started modding, And am creating 4 characters who represent my friends, so we can play as ourself on our server, and just finished my artwork for the first one, compiled it and worked out fine.now i want to add custom perks to him. I have some experience with programming, normally i manage fine looking at other peoples scripts, but i cant seem to wrap my head around his one. I want to add these custom perks to my friends characters: -Can eat a gold nugget for a nice, hunger health boost-Can ONLY eat goldnugget or crockpot recipes, nothing less.-When finding a goldnugget , gets a nice sanity boost, when loosing one drops same amount i dont expect you guys do make me al the code, just point me in the right direction, im really eager to learn all of this and make some cool custom characters --below first working model of my friends yosisi char, still WIP dont be to harsh with the critics Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/ Share on other sites More sharing options...
DarkXero Posted May 2, 2015 Share Posted May 2, 2015 I was going to point you to Wigfrid to check out SetDiet, but there's a small issue.Gold nuggets are FOODTYPE.ELEMENTAL, giving you elementals for diet would make you eat a lot more.Also, crock pot foods don't belong to a specific foodtype.So you need something more specific.local crockfoods = require("preparedfoods")-- Perk 2local master_postinit(inst) inst.components.eater:SetDiet({FOODGROUP.OMNI, FOODTYPE.ELEMENTAL}, {FOODGROUP.OMNI, FOODTYPE.ELEMENTAL}) local self = inst.components.eater local old = self.Eat function self:Eat(food, force) if crockfoods[food.prefab] then return old(self, food, force) end if food.prefab == "goldnugget" then -- Perk 1 food.components.edible.healthvalue = 10 food.components.edible.hungervalue = 20 food.components.edible.sanityvalue = 5 return old(self, food, force) end endendWe import the crockpot foods table list. They don't have a foodtype, so we need to check they are crockpot foods somehow.We make the character's diet to be almost everything, crock foods and minerals.However, we override the eating function to make it so crockpot recipes and goldnuggets make the cut and go through.Also, when we are going to eat a goldnugget, we edit its values right then, so they are unique to the character. What does "finding" and "losing" in your third perk mean? Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-633848 Share on other sites More sharing options...
Anarchuz Posted May 2, 2015 Author Share Posted May 2, 2015 I was going to point you to Wigfrid to check out SetDiet, but there's a small issue.Gold nuggets are FOODTYPE.ELEMENTAL, giving you elementals for diet would make you eat a lot more.Also, crock pot foods don't belong to a specific foodtype.So you need something more specific.local crockfoods = require("preparedfoods")-- Perk 2local master_postinit(inst) inst.components.eater:SetDiet({FOODGROUP.OMNI, FOODTYPE.ELEMENTAL}, {FOODGROUP.OMNI, FOODTYPE.ELEMENTAL}) local self = inst.components.eater local old = self.Eat function self:Eat(food, force) if crockfoods[food.prefab] then return old(self, food, force) end if food.prefab == "goldnugget" then -- Perk 1 food.components.edible.healthvalue = 10 food.components.edible.hungervalue = 20 food.components.edible.sanityvalue = 5 return old(self, food, force) end endendWow thanks alot already, gonna stare at this code till it makes sense to me, With dropping and finding i mean picking a gold nugget upmakes ur sanity go up, and loosing one out of your inventory, making it dropWe import the crockpot foods table list. They don't have a foodtype, so we need to check they are crockpot foods somehow.We make the character's diet to be almost everything, crock foods and minerals.However, we override the eating function to make it so crockpot recipes and goldnuggets make the cut and go through.Also, when we are going to eat a goldnugget, we edit its values right then, so they are unique to the character. What does "finding" and "losing" in your third perk mean? Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-633900 Share on other sites More sharing options...
Anarchuz Posted May 2, 2015 Author Share Posted May 2, 2015 Somehow my written text dissapeared... But thnx alot for that piece of code, its gonnaget me started for sure, with finding and loosing i mean, picking a gold nugget up, and with dropping i mean, picking one up or loosing one with crafting or somehting, just the same sanity boost u get for picking flower, but he we also loose sanity of he looses the nugget Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-633901 Share on other sites More sharing options...
Anarchuz Posted May 2, 2015 Author Share Posted May 2, 2015 btw darkXero, after looking lots of threads i see the most help are yours xD thnx alot of helping so many newbie modders Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-633915 Share on other sites More sharing options...
DarkXero Posted May 2, 2015 Share Posted May 2, 2015 Alright, then it would look like this.local master_postinit(inst) inst:ListenForEvent("onpickup", function(inst, data) if data.item.prefab == "goldnugget" then inst.components.sanity:DoDelta(5) end end) inst:ListenForEvent("dropitem", function(inst, data) if data.item.prefab == "goldnugget" then inst.components.sanity:DoDelta(-5) end end) local self = inst.components.builder local old = self.RemoveIngredients function self:RemoveIngredients(ingredients) for item, ents in pairs(ingredients) do for k, v in pairs(ents) do for i = 1, v do if k.prefab == "goldnugget" then self.inst.components.sanity:DoDelta(-5) end end end end old(self, ingredients) endendCharacter gains 5 sanity when picking up gold nugget. Character loses 5 sanity when dropping gold nugget. Character loses 5 sanity for each gold nugget he loses making a recipe. I listen to events that get pushed when performing the PICKUP (has that event right off the bat) and DROP actions (has the event pushed in the DropItem function in Inventory, that executes). I override the builder RemoveIngredients function that the character gets in order to make use of the fact that it gets called to remove ingredients off your inventory when crafting stuff. Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-633974 Share on other sites More sharing options...
Anarchuz Posted May 2, 2015 Author Share Posted May 2, 2015 Wow thanks dude, you're so much help man , hope ill figure to do this myself soon , any tips for good tutorials or other material what could help me learn this? found most videos , but they are pretty basic. Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-633989 Share on other sites More sharing options...
Hyaciao Posted May 2, 2015 Share Posted May 2, 2015 I'm a beginner just like you. (also just got helped by DarkXero in a pinch). But I figured I might plop my pennies worth, all suggestions might hold some value right? Anyways to the point. How about making a deny all except "x" function? Though this probably not the most elegant solution. (Basing this on the perk where player can't attack specific enemies by listing up specifically which one passes)In that sense, you can specify what crock pot recipe is acceptable[i'm assuming you don't want them to wet goop] and only gold. Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-633991 Share on other sites More sharing options...
Anarchuz Posted May 2, 2015 Author Share Posted May 2, 2015 Ok i need to step up my game xD...where can i start to learn this **** xD Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-634012 Share on other sites More sharing options...
DarkXero Posted May 2, 2015 Share Posted May 2, 2015 (edited) The only thing I recommend is learning any language, like C. Or maybe python for beginners.You can always come here to ask. Trying to figure out don't starve by itself is quite a task, since you first learn how the language works, the basics behind lua as a scripting language, and then you learn the paradigms behind the data structures, how classes are implemented, how stategraphs, prefabs and components are linked, etc. I learned by myself, by trial and error, in like 1 to 2 months. By overriding the Eat function, the character gets to put the food on their mouth, but not eat it, he will say "I can't do that."To make it trigger the spiting animation, you can override the PrefersToEat function. To give the character a very strict diet, we will override the function entirely.inst.components.eater:SetDiet({FOODGROUP.OMNI, FOODTYPE.ELEMENTAL})local allowed ={ meatballs = true, goldnugget = true}function inst.components.eater:PrefersToEat(inst) return allowed[inst.prefab]endNow he can only eat meatballs and goldnuggets. Edited May 2, 2015 by DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-634014 Share on other sites More sharing options...
Hyaciao Posted May 2, 2015 Share Posted May 2, 2015 Although this is not my thread, I figure I might as well ask since DarkXero recently posted an interesting example: Can I alter the above code components to have it apply to an equipment denial? I am thinking about using the (onequip) (onunequip) command such as below.inst.components.onequip:SetDiet({WEAPON.OMNI, WEAPON})local allowed ={ spear = true, pickaxe = true, axe = true, torch = true, }function inst.components.onequip:Weaponlimit(inst) return allowed[inst.prefab]end Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-634028 Share on other sites More sharing options...
DarkXero Posted May 2, 2015 Share Posted May 2, 2015 No, onequip is not a component. You have all components in scripts/components. Also, onequip tends to be a function that runs after something was equipped, so that check would be pointless.That is, if the class has the onequip parameter and uses it. Also, there is no such thing as a weaponlimit function. Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-634030 Share on other sites More sharing options...
Hyaciao Posted May 2, 2015 Share Posted May 2, 2015 Ah that makes so much more sense now. Thank you! Link to comment https://forums.kleientertainment.com/forums/topic/53426-help-with-custom-perks/#findComment-634036 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