Fancy_Fox_Pers Posted May 13, 2015 Share Posted May 13, 2015 (edited) Hello, I tried making my character friendly to nature. Birds and bees aren't scared anymore and this was possible by directly ripping off two mods. That's great and all but I also need to make her lose sanity when killing a non-hostile friendly animal, and a sanity regen when being surrounded by them would be nice as well. I also tried using the same two mods (+Wigfrid's files) but it doesn't work as I probably have no idea what I'm doing. Please re-direct me to some guide if that can help me learn more about these things. I'm also going to need info about making consuming meat for a specific character drain sanity; and how to catch bugs (of all kinds) by hand; and info about making friendly animals follow you when feeding it a prefab. In the meantime, please tell me what's wrong and how to fix this : -I have this in the character's lua: local function onkilledother(inst, data)if data ~= nil and data.victim ~= nil thenlocal isfriendly = falselocal ishostile = falsefor k,v in pairs(friendly_tags) doif data.victim:HasTag(v) thenisfriendly = truebreakendendif isfriendly thenfor k,v in pairs(nonfriendly_tags) doif data.victim:HasTag(v) thenishostile = truebreakendendif not ishostile then-- killed a friendly creature, you should feel bad!inst.components.sanity:DoDelta(-20)if inst.components.talker ~= nil theninst.components.talker:Say(GetString(inst, "ANNOUNCE_KILL_INNOCENT_CREATURE"))endendendendend-- Sanity gain from friendly creatures (rabbits, birds, bees, beefalo, etc)local function sanityfn(inst)local x,y,z = inst.Transform:GetWorldPosition() local delta = 0local max_rad = 10local ents = TheSim:FindEntities(x,y,z, max_rad, nil, nonfriendly_tags, friendly_tags) for k,v in pairs(ents) do local distsq = inst:GetDistanceSqToInst(v)delta = delta + TUNING.SANITYAURA_TINY/math.max(1, distsq) end return math.min(delta, TUNING.SANITYAURA_TINY) + inst.components.sanity.rateend And the tags for the above code are specified early on in the filelocal friendly_tags = {"smallcreature", "animal", "pig", "berrythief"}local nonfriendly_tags = {"hostile", "killer", "frog", "mosquito"} And yes, I did add "GLOBAL.STRINGS.CHARACTERS.MIMI.ANNOUNCE_KILL_INNOCENT_CREATURE = "Z'ai fait quoi?"" in the modmain. Nothing crashes, it's just that it doesn't work. Edited May 13, 2015 by Thibooms Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/ Share on other sites More sharing options...
Dragoonoflight Posted May 13, 2015 Share Posted May 13, 2015 If you sift through the asuna character mod theres a sanity debuff when near tentacles, maybe copy that code and rewrite it to do the opposite near birds and stuff? thats about the best advice i can give im new to this myself. Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637261 Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 13, 2015 Author Share Posted May 13, 2015 @Dragoonoflight, I had a look at it, but couldn't find anything about tentacles anywhere in the lua files. Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637298 Share on other sites More sharing options...
DarkXero Posted May 13, 2015 Share Posted May 13, 2015 (edited) That alone does nothing, you have two functions named onkilledother and sanityfn that never get executed. Instead of using FindEntities, I suggest you make use of the FindEntities already in the sanity component, that searches nearby creatures for sanity auras. For example,AddPrefabPostInit("beefalo", function(inst) inst:AddComponent("sanityaura") inst.component.sanityaura.aurafn = function(inst, observer) -- If the guy near the beefalo is your character, and the beefalo doesn't have your character as a target then if observer.prefab == "mycharacter" and inst.components.combat and not (inst.components.combat.target == observer) then return 0.08 end return 0 endend)Regarding to what is missing: What you are missing from Wigfrid's code isinst:ListenForEvent("killed", onkilledother)and what you are missing for the sanityfn isinst:DoPeriodicTask(1, sanityfn)in your masterpostinit. Edited May 14, 2015 by DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637325 Share on other sites More sharing options...
Dragoonoflight Posted May 13, 2015 Share Posted May 13, 2015 AddComponentPostInit("sanityaura", function(self)local old = self.GetAura function self:GetAura(observer) if observer.prefab == "asuna" and self.inst.prefab == "tentacle" then return -10endreturn old(self,observer) endend) end its in the modmain.lua theres a few others dealing with sanity auras as well Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637338 Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 14, 2015 Author Share Posted May 14, 2015 (edited) @DarkXero, Okay so now the sanity reduction on killing the non friendly animals is defitnely working, thanks for that. The sanity gain from being around those animals isn't, unfortunately. And the code you gave me for beefalo's makes me crash for some reason. I think the problem is that it isn't closed right or something. I thought you were missing a ')' (on the first line) but adding that makes it crash as well of course (and yes, I did replace the "mycharacter" by mine ). I thought adding inst:DoPeriodicTask(1, sanityfn)in masterpostinit would work out the sanity gain around animals but it clearly doesn't, the reduction on kill however did work. So here's the code I have that works for what I listed abovelocal friendly_tags = {"smallcreature", "animal", "pig", "berrythief"}local nonfriendly_tags = {"hostile", "killer", "frog", "mosquito"}local function onkilledother(inst, data)if data ~= nil and data.victim ~= nil thenlocal isfriendly = falselocal ishostile = falsefor k,v in pairs(friendly_tags) doif data.victim:HasTag(v) thenisfriendly = truebreakendendif isfriendly thenfor k,v in pairs(nonfriendly_tags) doif data.victim:HasTag(v) thenishostile = truebreakendendif not ishostile then-- killed a friendly creature, you should feel bad!inst.components.sanity:DoDelta(-20)if inst.components.talker ~= nil theninst.components.talker:Say(GetString(inst, "ANNOUNCE_KILL_INNOCENT_CREATURE"))endendendendend-- Sanity gain from friendly creatures (rabbits, birds, bees, beefalo, etc)local function sanityfn(inst)local x,y,z = inst.Transform:GetWorldPosition() local delta = 0local max_rad = 10local ents = TheSim:FindEntities(x,y,z, max_rad, nil, nonfriendly_tags, friendly_tags) for k,v in pairs(ents) do local distsq = inst:GetDistanceSqToInst(v)delta = delta + TUNING.SANITYAURA_TINY/math.max(1, distsq) end return math.min(delta, TUNING.SANITYAURA_TINY) + inst.components.sanity.rateend-- This initializes for both clients and the hostlocal common_postinit = function(inst) -- Minimap iconinst.MiniMapEntity:SetIcon( "mimi.tex" )inst:AddTag("poop_builder") -- She can make poop!inst:AddTag("birdwhisperer") -- Birds won't fly away!end-- This initializes for the host onlylocal master_postinit = function(inst)-- choose which sounds this character will playinst.soundsname = "willow"-- Stats inst.components.health:SetMaxHealth(250)inst.components.hunger:SetMax(150)inst.components.sanity:SetMax(200)inst:ListenForEvent("killed", onkilledother)inst:DoPeriodicTask(1, sanityfn)-- Rabbits dont run awayinst:RemoveTag("scarytoprey")endas you can see, what you said I was missing for the sanityfn is present (line 84), so I don't see the problem. @Dragoonoflight, is it possible to use this for gaining sanity around animals? So far what I tried didn't work. Thanks to the both of you for replying and helping Edited May 14, 2015 by Thibooms Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637477 Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 14, 2015 Author Share Posted May 14, 2015 (edited) @DarkXero, I figured that you might have meant that I had to put the beefalo code in modmain, didn't work either (just in case I was supposed to place it there). Anyways, here's the error I get every time, wether I put it in modmain or the character's lua [string "../mods/Mimi for DST/modmain.lua"]:95: ')' expected (to close '(' at line 86) near '<eof>' Line 86 is the following:AddPrefabPostInit("beefalo", function(inst) Edited May 14, 2015 by Thibooms Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637483 Share on other sites More sharing options...
DarkXero Posted May 14, 2015 Share Posted May 14, 2015 @Thibooms, you are correct, a ) was missing, I updates the post. Also, I full derped. I somehow read that your sanityfn was effectively changing your sanity per tick.But it just returns a rate number. So instead of returning that, you can put DoDelta(number_returned, true).That is to make it work with the periodic task. The line you actually need isinst.components.sanity.custom_rate_fn = sanityfnthat will take your custom rate and incorporate it in the sanity rate recalc. Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637506 Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 14, 2015 Author Share Posted May 14, 2015 (edited) @DarkXero, Thanks, works! I only replaced the line I actually needed, sanity gains and reductions are just fine like this. I also tried making her able to pick insects using wallflower's code (even though it's a Don't Starve character)-- Bugs don't need a netlocal function onpickedfn(inst, picker) if picker and picker.components.sanity then picker.components.sanity:DoDelta(TUNING.SANITY_TINY) end inst:Remove()endlocal function updatebugproperties(inst) if checkCharacter("mimi") then inst:AddComponent("pickable") inst.components.pickable.picksound = "Don't Starve Together Beta/wilson/pickup_plants" if inst.prefab == "butterfly" then inst.components.pickable:SetUp("butterfly") elseif inst.prefab == "bee" then inst.components.pickable:SetUp("bee") elseif inst.prefab == "killerbee" then inst.components.pickable:SetUp("killerbee") end inst.components.pickable.onpickedfn = onpickedfn inst.components.pickable.quickpick = true endendAddPrefabPostInit("butterfly", updatebugproperties)AddPrefabPostInit("bee", updatebugproperties)AddPrefabPostInit("killerbee", updatebugproperties)But it crashes because of the "if checkCharacter("mimi") then", it seems it can't read it or find something. The original code was identical but without "mimi" and that crashed as well. If that problem gets worked out I also hope thatinst.components.pickable.picksound = "Don't Starve Together Beta/wilson/pickup_plants"won't crash because I wasn't sure about the Don't Starve Together Beta part, I assumed this comparing it with the original code and the similiar files Edited May 14, 2015 by Thibooms Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637519 Share on other sites More sharing options...
Dragoonoflight Posted May 14, 2015 Share Posted May 14, 2015 @Thibooms to be honest i wasnt sure if it could work but the logic seemed sound enough to me lol, its just something i stumbled on while digging through files and i thought it might work if you reversed the effect Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637535 Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 14, 2015 Author Share Posted May 14, 2015 @Dragoonoflight, Yeah don't worry about it, all help is good . It also works now so the main goal has been reached Do you happen to know how to effectively check a character for a function (so it only applies to one specific character)?if checkCharacter() thenjust crashes as it can't index it (being a nil value or something). Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637537 Share on other sites More sharing options...
DarkXero Posted May 14, 2015 Share Posted May 14, 2015 @Thibooms, if you copy something you need to copy everything.The original code probably was checkCharacter() and that function defined asif GetPlayer().prefab == "wallflower" then return trueendbut you can't do this. There are multiple players here. If you are going to compare code, don't compare it with single player code, try using multiplayer code.Grass in DST hasinst.components.pickable.picksound = "dontstarve/wilson/pickup_reeds"so you don't need to put Don't Starve Together Beta. Regarding the pickable bugs.The are two approaches. 1) Make a new custom pickable simplified component with a custom action, so when you custom grab a bug, you delete it and it goes to your inventory. This would be the best approach. 2) Reuse the pickable component with the pick action, the functions you have. Given how pickable gets checked in the action and in the stategraph procedure, we can attack the actionhandler in the wilson stategraph.For example:local bugs = { butterfly = true, bee = true, killerbee = true}local function onpickedfn(inst, picker) if picker and picker.components.sanity then picker.components.sanity:DoDelta(GLOBAL.TUNING.SANITY_TINY) end inst:Remove()endlocal function updatebugproperties(inst) inst:AddComponent("pickable") inst.components.pickable.picksound = "Don't Starve Together Beta/wilson/pickup_plants" inst.components.pickable:SetUp(inst.prefab) inst.components.pickable.onpickedfn = onpickedfn inst.components.pickable.quickpick = trueendAddStategraphPostInit("wilson", function(sg) local old = sg.actionhandlers[GLOBAL.ACTIONS.PICK].deststate sg.actionhandlers[GLOBAL.ACTIONS.PICK].deststate = function(inst, action) if action.doer.prefab == "mycharacter" and bugs[action.target.prefab] then updatebugproperties(action.target) end return old(inst, action) endend)local function pickbug(inst, target, position) local actions = {} if target and bugs[target.prefab] then table.insert(actions, GLOBAL.ACTIONS.PICK) end return inst.components.playeractionpicker:SortActionList(actions, target)endAddPrefabPostInit("mycharacter", function(inst) inst:DoTaskInTime(0, function() inst.components.playeractionpicker.rightclickoverride = pickbug end)end) Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637543 Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 14, 2015 Author Share Posted May 14, 2015 (edited) @DarkXero, Once again you helped me out big time (you know, I can understand guides and tutorials, if you can redirect me to any I might not need to ask so much on the forums the whole time ) There's only one tiny little problem though: the character can't plant butterflies to make new flowers. I think this is due to the rightclickoverride. It appears to override everything you do with right click. For instance, if I were to put it on leftclick then I could no longer Examinate things. As for me not copying everything, I did look through the file but I ended up assuming it was just because the current game doesn't work that way any more (and that's true but it kept me from noticing these codes you wrote about it, which are indeed present). Thank you so much, again Edited May 14, 2015 by Thibooms Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637553 Share on other sites More sharing options...
DarkXero Posted May 14, 2015 Share Posted May 14, 2015 @Thibooms,try usinglocal bugpick = AddAction("BUGPICK", "Pick", function(act) local loot = GLOBAL.SpawnPrefab(act.target.prefab) act.doer.components.inventory:GiveItem(loot, nil, act.target:GetPosition()) act.target:Remove() return trueend)bugpick.priority = 4AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(bugpick, "doshortaction"))this in modmain.local bugs = { butterfly = true, bee = true, killerbee = true}inst:DoTaskInTime(0, function() local old = inst.components.playeractionpicker.GetLeftClickActions inst.components.playeractionpicker.GetLeftClickActions = function(self, position, target) local actions = old(self, position, target) if target and bugs[target.prefab] then if not target.replica.inventoryitem:IsHeld() then actions = inst.components.playeractionpicker:SortActionList({ ACTIONS.BUGPICK }, target, nil) end end return actions end end)this in the common_postinit of the character. It should do the trick for butterflies. And move the action from the right click to the left click. Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637566 Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 14, 2015 Author Share Posted May 14, 2015 @DarkXero, Oh, I just edited my last post because I understood the problem, so please ignore that. Going to try what you just posted Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637567 Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 14, 2015 Author Share Posted May 14, 2015 @DarkXero, Works! New bug though : when trying to catch bee's with a bugnet (I know it's foolish since you don't have to but I still tested it) the crashes. I found this in the log: [string "scripts/prefabs/bee.lua"]:47: attempt to index local 'owner' (a boolean value)LUA ERROR stack traceback:scripts/prefabs/bee.lua:47 in (field) onfinish (Lua) <45-59> inst = 110620 - bee (valid:true) worker = 109930 - mimi (valid:true) owner = false Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637570 Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 14, 2015 Author Share Posted May 14, 2015 (edited) @DarkXero, Scratch that, your code works perfectly. The new update must have caused this Here's a screenshot, I tried it by making a new world and disabling all mods: Edited May 14, 2015 by Thibooms Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637572 Share on other sites More sharing options...
DarkXero Posted May 14, 2015 Share Posted May 14, 2015 @Thibooms, you are correct, it is a game bug.Specifically, a game bug that happens with bees that have no home, no hive. This is, spawned via console, or having their homes destroyed. Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637575 Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 14, 2015 Author Share Posted May 14, 2015 @DarkXero, Oh okay now I get it. I did spawn them in. Link to comment https://forums.kleientertainment.com/forums/topic/53919-help-lacking-information/#findComment-637576 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