HunkInsland13 Posted March 7, 2014 Share Posted March 7, 2014 Truly I am not modder and want to create a mod that would make only giving food to a pig once was your friend forever (or until the death of one of the two). Alguin could help me, not a lot of codes. (Excuse my English I'm learning it now). Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/ Share on other sites More sharing options...
HunkInsland13 Posted March 8, 2014 Author Share Posted March 8, 2014 This is what I have so far... local function OnGetItemFromPlayer(inst, giver, item) --I eat food if item.components.edible then --meat makes us friends (unless I'm a guard) if item.components.edible.foodtype == "MEAT" or item.components.edible.foodtype == "HORRIBLE" then if inst.components.combat.target and inst.components.combat.target == giver then inst.components.combat:SetTarget(nil) elseif giver.components.leader and not inst:HasTag("guard") theninst.SoundEmitter:PlaySound("dontstarve/common/makeFriend")giver.components.leader:AddFollower(inst) inst.components.follower:AddLoyaltyTime(item.components.edible:GetHunger() * TUNING.PIG_LOYALTY_PER_HUNGER) end end if inst.components.sleeper:IsAsleep() then inst.components.sleeper:WakeUp() end end I guess this is what I should change, but I'm not sure how. Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-426332 Share on other sites More sharing options...
squeek Posted March 8, 2014 Share Posted March 8, 2014 (edited) All you have to do is this in your modmain.lua file: TUNING.PIG_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000TUNING.PIG_LOYALTY_PER_HUNGER = TUNING.PIG_LOYALTY_MAXTIMEThat'll make the loyalty last for 10,000 days. There's no easy way to make it truly infinite, but 10,000 days is probably good enough. Edited March 8, 2014 by squeek 1 Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-426396 Share on other sites More sharing options...
HunkInsland13 Posted March 9, 2014 Author Share Posted March 9, 2014 It worked, thanks, but now I want to prevent pigs from becoming Werepigs and ruin the friendship. Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-427227 Share on other sites More sharing options...
squeek Posted March 10, 2014 Share Posted March 10, 2014 (edited) Untested, but this should work:local saved_onwere_fn = nillocal function RemoveWerebeast(inst) if inst.components.werebeast then if not saved_onwere_fn then saved_onwere_fn = inst.components.werebeast.onsetwerefn end inst:RemoveComponent("werebeast") endendlocal function AddWerebeast(inst) if not inst.components.werebeast then inst:AddComponent("werebeast") inst.components.werebeast:SetOnWereFn(saved_onwere_fn) inst.components.werebeast:SetTriggerLimit(4) endendAddPrefabPostInit("pigman", function(inst) inst:ListenForEvent("startfollowing", RemoveWerebeast) inst:ListenForEvent("stopfollowing", AddWerebeast)end) Edited March 10, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-428066 Share on other sites More sharing options...
HunkInsland13 Posted March 11, 2014 Author Share Posted March 11, 2014 This will sooner or later?Example:local function OnGetItemFromPlayer(inst, giver, item) --I eat food if item.components.edible then --meat makes us friends (unless I'm a guard) if item.components.edible.foodtype == "MEAT" or item.components.edible.foodtype == "HORRIBLE" then if inst.components.combat.target and inst.components.combat.target == giver then inst.components.combat:SetTarget(nil) elseif giver.components.leader and not inst:HasTag("guard") theninst.SoundEmitter:PlaySound("dontstarve/common/makeFriend")giver.components.leader:AddFollower(inst) inst.components.follower:AddLoyaltyTime(item.components.edible:GetHunger() * TUNING.PIG_LOYALTY_PER_HUNGER) TUNING.PIG_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000 TUNING.PIG_LOYALTY_PER_HUNGER = TUNING.PIG_LOYALTY_MAXTIME end end if inst.components.sleeper:IsAsleep() then inst.components.sleeper:WakeUp() end end local saved_onwere_fn = nil local function RemoveWerebeast(inst) if inst.components.werebeast then if not saved_onwere_fn then saved_onwere_fn = inst.components.werebeast.onsetwerefn end inst:RemoveComponent("werebeast") endend local function AddWerebeast(inst) if not inst.components.werebeast then inst:AddComponent("werebeast") inst.components.werebeast:SetOnWereFn(saved_onwere_fn) inst.components.werebeast:SetTriggerLimit(4) endend AddPrefabPostInit("pigman", function(inst) inst:ListenForEvent("startfollowing", RemoveWerebeast) inst:ListenForEvent("stopfollowing", AddWerebeast)end) Or like this: local saved_onwere_fn = nil local function RemoveWerebeast(inst) if inst.components.werebeast then if not saved_onwere_fn then saved_onwere_fn = inst.components.werebeast.onsetwerefn end inst:RemoveComponent("werebeast") endend local function AddWerebeast(inst) if not inst.components.werebeast then inst:AddComponent("werebeast") inst.components.werebeast:SetOnWereFn(saved_onwere_fn) inst.components.werebeast:SetTriggerLimit(4) endend AddPrefabPostInit("pigman", function(inst) inst:ListenForEvent("startfollowing", RemoveWerebeast) inst:ListenForEvent("stopfollowing", AddWerebeast)end) local function OnGetItemFromPlayer(inst, giver, item) --I eat food if item.components.edible then --meat makes us friends (unless I'm a guard) if item.components.edible.foodtype == "MEAT" or item.components.edible.foodtype == "HORRIBLE" then if inst.components.combat.target and inst.components.combat.target == giver then inst.components.combat:SetTarget(nil) elseif giver.components.leader and not inst:HasTag("guard") theninst.SoundEmitter:PlaySound("dontstarve/common/makeFriend")giver.components.leader:AddFollower(inst) inst.components.follower:AddLoyaltyTime(item.components.edible:GetHunger() * TUNING.PIG_LOYALTY_PER_HUNGER) TUNING.PIG_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000 TUNING.PIG_LOYALTY_PER_HUNGER = TUNING.PIG_LOYALTY_MAXTIME end end if inst.components.sleeper:IsAsleep() then inst.components.sleeper:WakeUp() end end Thanks for your help. Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-428616 Share on other sites More sharing options...
squeek Posted March 11, 2014 Share Posted March 11, 2014 No, put the code in your modmain.lua, do not modify pigman.lua.You should have a modmain.lua (dont_starve/mods/yourmodname/modmain.lua) that looks like this:TUNING.PIG_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000TUNING.PIG_LOYALTY_PER_HUNGER = TUNING.PIG_LOYALTY_MAXTIMElocal saved_onwere_fn = nil local function RemoveWerebeast(inst) if inst.components.werebeast then if not saved_onwere_fn then saved_onwere_fn = inst.components.werebeast.onsetwerefn end inst:RemoveComponent("werebeast") endend local function AddWerebeast(inst) if not inst.components.werebeast then inst:AddComponent("werebeast") inst.components.werebeast:SetOnWereFn(saved_onwere_fn) inst.components.werebeast:SetTriggerLimit(4) endend AddPrefabPostInit("pigman", function(inst) inst:ListenForEvent("startfollowing", RemoveWerebeast) inst:ListenForEvent("stopfollowing", AddWerebeast)end) Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-428630 Share on other sites More sharing options...
HunkInsland13 Posted March 12, 2014 Author Share Posted March 12, 2014 Thanks for your help, the mod works well with pigs but I am still having the same problem with Werepigs. Here is the mod so far I would like if you could prove it.http://www.mediafire.com/download/idwyfc9ahwrp8a9/BFF+prueba.zip Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-429305 Share on other sites More sharing options...
squeek Posted March 12, 2014 Share Posted March 12, 2014 No problem. Turns out removing the werebeast component doesn't work because it doesn't remove the event listeners. This will work (and it's actually a better solution):local WereBeast = GLOBAL.require "components/werebeast"local WereBeast_SetWere_base = WereBeast.SetWerefunction WereBeast:SetWere(time) -- only call the base function if we do not have a leader local hasleader = self.inst and self.inst.components.follower and self.inst.components.follower.leader ~= nil if not hasleader then WereBeast_SetWere_base(self, time) endendYour modmain.lua should look like this:TUNING.PIG_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000TUNING.PIG_LOYALTY_PER_HUNGER = TUNING.PIG_LOYALTY_MAXTIMElocal WereBeast = GLOBAL.require "components/werebeast"local WereBeast_SetWere_base = WereBeast.SetWerefunction WereBeast:SetWere(time) -- only call the base function if we do not have a leader local hasleader = self.inst and self.inst.components.follower and self.inst.components.follower.leader ~= nil if not hasleader then WereBeast_SetWere_base(self, time) endend Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-429323 Share on other sites More sharing options...
HunkInsland13 Posted March 12, 2014 Author Share Posted March 12, 2014 Squeek Thanks, you helped me a lot, I hope you do not mind but I put you as the author of the mod with me because without you there would not have done, thanks again. 1 Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-429379 Share on other sites More sharing options...
HunkInsland13 Posted April 11, 2014 Author Share Posted April 11, 2014 @squeek help me!!!I need help with the max time friendship of the RabbitMan, Spiders (With Webber), and Catcoons.I tough is the same before but dosnt work: TUNING.RABBIT_CARROT_LOYALTY = TUNING.TOTAL_DAY_TIME * 10000 TUNING.CATCOON_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000 TUNING.SPIDER_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000TUNING.SPIDER_LOYALTY_PER_HUNGER = TUNING.SPIDER_LOYALTY_MAXTIME Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-450415 Share on other sites More sharing options...
iWitch Posted April 11, 2014 Share Posted April 11, 2014 because you have to code their "loyalty". they are not pigs. Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-450595 Share on other sites More sharing options...
HunkInsland13 Posted April 12, 2014 Author Share Posted April 12, 2014 because you have to code their "loyalty". they are not pigs.What i have to use then?In DS and RoG with Webber you can make friends of the spiders and the rabits and catcoons with each other character, this means they have loyalty but i really dont now. What i need, help me. Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-451203 Share on other sites More sharing options...
iWitch Posted April 12, 2014 Share Posted April 12, 2014 (edited) oh yes they have on RoG, but its limited to webberlocal function ShouldAcceptItem(inst, item, giver) if giver.prefab ~= "webber" then return false endand according to this code local loyaltyTime = item.components.edible:GetHunger() * TUNING.SPIDER_LOYALTY_PER_HUNGER inst.components.follower:AddLoyaltyTime(loyaltyTime)you just need to make TUNING.SPIDER_LOYALTY_PER_HUNGER really huge well there a way to change food accepting to other character or to all GLOBAL.TUNING.SPIDER_LOYALTY_PER_HUNGER = 10000 local function MyShouldAcceptItem(inst, item, giver) if inst.components.sleeper:IsAsleep() then return false end if inst.components.eater:CanEat(item) then return true endend local function TweakSpider(inst) if inst and inst.components and inst.components.trader then inst.components.trader:SetAcceptTest(MyShouldAcceptItem) endend AddPrefabPostInit("spider", TweakSpider)add this to modmain.lua in your mod and any player character will be able to be friend with spiders Edited April 12, 2014 by iWitch Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-451340 Share on other sites More sharing options...
iWitch Posted April 12, 2014 Share Posted April 12, 2014 i didnt played in RoG yet, lol, but catcoons have some limitations on food type if item:HasTag("cattoy") or item:HasTag("catfood") or item:HasTag("cattoyairborne") then and there other variable to keep their loyality: inst.components.follower:AddLoyaltyTime(TUNING.CATCOON_LOYALTY_PER_ITEM) so you have to make TUNING.CATCOON_LOYALTY_PER_ITEM big, not TUNING.CATCOON_LOYALTY_MAXTIME Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-451345 Share on other sites More sharing options...
iWitch Posted April 12, 2014 Share Posted April 12, 2014 (edited) rabbits doesnt have loyality thingy, but bunnymans do inst.components.follower:AddLoyaltyTime(TUNING.RABBIT_CARROT_LOYALTY)But i am not sure if you able to use them all in one time, you have to check retargetfn/onnewtarget/onattacked of this prefabs and their brains to be sure that they dont attack each other, but i am too lazy to do it. For example if you have 1 spider loyal to you and other which is not,they share targets with other spiders. So if non-loyal spider get attacked with your loyal bunnyman, your loyal spider probably will attack bunnyman too. Same thing with bunnymans. Edited April 12, 2014 by iWitch Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-451350 Share on other sites More sharing options...
HunkInsland13 Posted April 13, 2014 Author Share Posted April 13, 2014 oh yes they have on RoG, but its limited to webberlocal function ShouldAcceptItem(inst, item, giver) if giver.prefab ~= "webber" then return false endand according to this code local loyaltyTime = item.components.edible:GetHunger() * TUNING.SPIDER_LOYALTY_PER_HUNGER inst.components.follower:AddLoyaltyTime(loyaltyTime)you just need to make TUNING.SPIDER_LOYALTY_PER_HUNGER really huge well there a way to change food accepting to other character or to all GLOBAL.TUNING.SPIDER_LOYALTY_PER_HUNGER = 10000 local function MyShouldAcceptItem(inst, item, giver) if inst.components.sleeper:IsAsleep() then return false end if inst.components.eater:CanEat(item) then return true endend local function TweakSpider(inst) if inst and inst.components and inst.components.trader then inst.components.trader:SetAcceptTest(MyShouldAcceptItem) endend AddPrefabPostInit("spider", TweakSpider)add this to modmain.lua in your mod and any player character will be able to be friend with spidersTanks, i just proveit this for now and work fine but i dont understand how make them loyal for ever.Tanks for your help im going to keep trying for make this work. Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-452161 Share on other sites More sharing options...
iWitch Posted April 13, 2014 Share Posted April 13, 2014 (edited) Obviously for making them true_loyal_forever you have to change "follower" component scripts/followerforever.luaFollower = require "components/follower" function Follower:GetLoyaltyPercent() return 1 -- 100% loyality, if someone checksend function Follower:LongUpdate(dt)end function Follower:AddLoyaltyTime(time)self.targettime = 10000 --just in case if someone checking this outside Follower componentend return Followermodmain.lua:tmpFollower = require "followerforever"this changes is dangerous in long term and probably its require some limitation with calling old functions.But atm i dont see any problem. Edited April 13, 2014 by iWitch Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-452287 Share on other sites More sharing options...
Tzimiscelord Posted April 13, 2014 Share Posted April 13, 2014 this mod already exist in STEAM http://steamcommunity.com/sharedfiles/filedetails/?id=246296775&searchtext= With a cool image, even Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-452603 Share on other sites More sharing options...
HunkInsland13 Posted April 14, 2014 Author Share Posted April 14, 2014 Obviously for making them true_loyal_forever you have to change "follower" component scripts/followerforever.luaFollower = require "components/follower" function Follower:GetLoyaltyPercent() return 1 -- 100% loyality, if someone checksend function Follower:LongUpdate(dt)end function Follower:AddLoyaltyTime(time)self.targettime = 10000 --just in case if someone checking this outside Follower componentend return Followermodmain.lua:tmpFollower = require "followerforever"this changes is dangerous in long term and probably its require some limitation with calling old functions.But atm i dont see any problem.This Work with every creature? Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-453046 Share on other sites More sharing options...
iWitch Posted April 14, 2014 Share Posted April 14, 2014 its should, test itpigs is unfriendly to character that i play, so i haven't reason to test it, i don't need such functionality. Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-453330 Share on other sites More sharing options...
HunkInsland13 Posted April 15, 2014 Author Share Posted April 15, 2014 this mod already exist in STEAM http://steamcommunity.com/sharedfiles/filedetails/?id=246296775&searchtext= With a cool image, evenCan you pass me the mod for klei, i dont know this mod exist. Link to comment https://forums.kleientertainment.com/forums/topic/32397-mod-friendship-with-pigs/#findComment-453926 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