Darkot Posted May 12, 2014 Share Posted May 12, 2014 Hello, everyone. I've been using the wonderful guides provided on this forum to make a personal character mod. Things have been going pretty smoothly with it. I've managed to iron out all of the problems I've faced thus far. However, I've caught a snag that I can't for the life of me figure out. I'm trying to make it so my character actively gains sanity when he has followers. Here is what I have currently:local function leaderbonus(inst) if inst.components.leader.numfollowers() >= 0 then inst.components.health.maxhealth = 500 --else inst.components.health.maxhealth = 5 endend Right now, I just have it modifying max health by a large amount so I can clearly see whether or not the effects are being applied. I figured I could just swap it out for something along the lines of "inst.components.sanity.rate = inst.components.sanity.rate + "Insert tuning file modifier name here", after it successfully passed this test. But...not luck =/ I imagine that it's the way that I'm writing it, because the premise isn't very abstract. Which wouldn't be surprising, because I'm still very much a noob when it comes to coding. I'd really appreciate some advice =xThanks for the help! Link to comment https://forums.kleientertainment.com/forums/topic/36365-stat-increase-from-having-followers-help-request/ Share on other sites More sharing options...
Darkot Posted May 12, 2014 Author Share Posted May 12, 2014 UPDATE: Took another crack at it today, and changed it to this:local function leaderbonus(inst) if inst.components.leader.numfollowers ~= 0 then --if inst.components.leader:CountFollowers() ~= 0 then print ("working") inst.components.health.maxhealth = 500 elseif inst.components.leader.numfollowers == 0 then --elseif inst.components.leader:CountFollowers() == 0 then print ("not working") inst.components.health.maxhealth = 5 end --isleader(inst)endNow, half of it is working. If the follower count is 0, then his maxhealth goes down to 5, and gives me the "not working" message in the console. However, it's still not raising his maxhealth when he does have followers.BUT, I just tried adding "inst.components.leader.numfollowers = 10" under my character's "local fn = function(inst)", and it worked..it gave him 500 maxhealth. So...that leads me to believe that the code is completely functional, but numfollowers isn't updating when I get a follower for some reason? Link to comment https://forums.kleientertainment.com/forums/topic/36365-stat-increase-from-having-followers-help-request/#findComment-478876 Share on other sites More sharing options...
debugman18 Posted May 12, 2014 Share Posted May 12, 2014 (edited) UPDATE: Took another crack at it today, and changed it to this:local function leaderbonus(inst) if inst.components.leader.numfollowers ~= 0 then --if inst.components.leader:CountFollowers() ~= 0 then print ("working") inst.components.health.maxhealth = 500 elseif inst.components.leader.numfollowers == 0 then --elseif inst.components.leader:CountFollowers() == 0 then print ("not working") inst.components.health.maxhealth = 5 end --isleader(inst)endNow, half of it is working. If the follower count is 0, then his maxhealth goes down to 5, and gives me the "not working" message in the console. However, it's still not raising his maxhealth when he does have followers.BUT, I just tried adding "inst.components.leader.numfollowers = 10" under my character's "local fn = function(inst)", and it worked..it gave him 500 maxhealth. So...that leads me to believe that the code is completely functional, but numfollowers isn't updating when I get a follower for some reason? It's because you're simply running the function once and leaving it at that, so it doesn't know when you get followers. Add this to your character:inst:DoPeriodicTask(0, function() leaderbonusend)There are better ways to do this, but this would be the simplest. Edited May 12, 2014 by debugman18 Link to comment https://forums.kleientertainment.com/forums/topic/36365-stat-increase-from-having-followers-help-request/#findComment-478937 Share on other sites More sharing options...
simplex Posted May 12, 2014 Share Posted May 12, 2014 (edited) It's because you're simply running the function once and leaving it at that, so it doesn't know when you get followers. Add this to your character:inst:DoPeriodicTask(0, function() leaderbonusend)There are better ways to do this, but this would be the simplest.I think you meant leaderbonus(inst) .Or:local SOME_REASONABLE_DELAY_BUT_PLEASE_GREATER_THAN_ZERO = 0.25inst:DoPeriodicTask(SOME_REASONABLE_DELAY_BUT_PLEASE_GREATER_THAN_ZERO, leaderbonus)Strictly speaking, @Darkot, the delay (or more precisely the interval) can be zero, causing the function to run in every frame, but that's a bit... excessive. Edited May 12, 2014 by simplex Link to comment https://forums.kleientertainment.com/forums/topic/36365-stat-increase-from-having-followers-help-request/#findComment-478951 Share on other sites More sharing options...
debugman18 Posted May 12, 2014 Share Posted May 12, 2014 I think you meant leaderbonus(inst) .Or:local SOME_REASONABLE_DELAY_BUT_PLEASE_GREATER_THAN_ZERO = 0.25inst:DoPeriodicTask(SOME_REASONABLE_DELAY_BUT_PLEASE_GREATER_THAN_ZERO, leaderbonus)Strictly speaking, @Darkot, the delay (or more precisely the interval) can be zero, causing the function to run in every frame, but that's a bit... excessive. Sorry, I posted hastily. Yes, ideally it would be greater than zero. I don't see the harm however, in attaching it to the player, since there is only ever (currently) one player entity. Better to make a habit of using intervals higher than zero, though. Link to comment https://forums.kleientertainment.com/forums/topic/36365-stat-increase-from-having-followers-help-request/#findComment-478998 Share on other sites More sharing options...
Darkot Posted May 13, 2014 Author Share Posted May 13, 2014 It's because you're simply running the function once and leaving it at that, so it doesn't know when you get followers. Add this to your character:inst:DoPeriodicTask(0, function() leaderbonusend)There are better ways to do this, but this would be the simplest. I think you meant leaderbonus(inst) .Or:local SOME_REASONABLE_DELAY_BUT_PLEASE_GREATER_THAN_ZERO = 0.25inst:DoPeriodicTask(SOME_REASONABLE_DELAY_BUT_PLEASE_GREATER_THAN_ZERO, leaderbonus)Strictly speaking, @Darkot, the delay (or more precisely the interval) can be zero, causing the function to run in every frame, but that's a bit... excessive. @debugman18 @simplex Haha, guess it's pretty apparent how little I know about coding. The solution seem so obvious now that you point it out. Don't know how I expected it to continually run otherwise xP Thanks a bunch for the help, guys. Worked like an absolute charm! Link to comment https://forums.kleientertainment.com/forums/topic/36365-stat-increase-from-having-followers-help-request/#findComment-479247 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