icantevenname Posted February 15, 2018 Share Posted February 15, 2018 I want to give my character a perk that allows her to instantly recruit pigs just by walking nearby. Though, I want to limit it to three at a time and have it happen when she's close to the pig. I tried to use the One Man Band's code to figure it out on my own, but couldn't figure it out. Mind giving me a hand? Link to comment https://forums.kleientertainment.com/forums/topic/87625-attracting-pigs/ Share on other sites More sharing options...
. . . Posted February 15, 2018 Share Posted February 15, 2018 (edited) I think this mod character has an ability similar to that http://steamcommunity.com/sharedfiles/filedetails/?id=1166220990 you can look at how it's done in its code Edited February 15, 2018 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/87625-attracting-pigs/#findComment-1004374 Share on other sites More sharing options...
icantevenname Posted February 15, 2018 Author Share Posted February 15, 2018 @SuperDavid Err... It don't seem to work as advertised... Fun fact: All of the coding in the prefab is in one line. Link to comment https://forums.kleientertainment.com/forums/topic/87625-attracting-pigs/#findComment-1004425 Share on other sites More sharing options...
K1NGT1GER609 Posted February 15, 2018 Share Posted February 15, 2018 Here: local master_postinit = function(inst)--reference on where it goes local function addpig(inst) local x,y,z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x,y,z, 5, {"pig"}, {"manrabbit"}, nil) for k,v in pairs(ents) do if v.components.follower and not v.components.follower.leader and not inst.components.leader:IsFollower(v) and inst.components.leader.numfollowers < 3 then inst.components.leader:AddFollower(v) end end end inst:DoPeriodicTask(.5, addpig, nil, inst) few notes to consider: the manrabbit is there to make sure you only make friends with pigs for free not bunnymen, 5 is the radius that makes pigs your friends edit it to your desired radius, the periodic task .5 is reasonable amount of time this activates. Last is this goes inside the character lua file. Link to comment https://forums.kleientertainment.com/forums/topic/87625-attracting-pigs/#findComment-1004468 Share on other sites More sharing options...
icantevenname Posted February 15, 2018 Author Share Posted February 15, 2018 @K1NGT1GER609 The code as is would make the game crash, due to the function not being closed off. I tried to add an "end" between the last two ends, then the game crashes due to the inst not being declared. It stopped crashing when I placed that "end" under the inst. But it doesn't seem to work. Link to comment https://forums.kleientertainment.com/forums/topic/87625-attracting-pigs/#findComment-1004588 Share on other sites More sharing options...
K1NGT1GER609 Posted February 15, 2018 Share Posted February 15, 2018 As is? You didn't read the note on the master_postinit saying that its a reference on where the code goes and master_postinit should be in your character lua file already. local function addpig(inst) local x,y,z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x,y,z, 5, {"pig"}, {"manrabbit"}, nil) for k,v in pairs(ents) do if v.components.follower and not v.components.follower.leader and not inst.components.leader:IsFollower(v) and inst.components.leader.numfollowers < 3 then inst.components.leader:AddFollower(v) end end end inst:DoPeriodicTask(.5, addpig, nil, inst) There I removed the master_postinit make it a bit easier for you. Link to comment https://forums.kleientertainment.com/forums/topic/87625-attracting-pigs/#findComment-1004614 Share on other sites More sharing options...
icantevenname Posted February 15, 2018 Author Share Posted February 15, 2018 @K1NGT1GER609 That was quite to oversight on my part. Link to comment https://forums.kleientertainment.com/forums/topic/87625-attracting-pigs/#findComment-1004631 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