Recommended Posts

FurryEskimo    13

@penguin0616

Good to know.  I don’t see it listed in my ModMain, the ‘Follower’ component, or this other mod’s ModMain.  Am I blind or is it not here?  If it’s messing with the max follow time I’d like to know where it is and how to fix it. (Also how did you know that was the issue?  I like to figure this out on my own when I can, so I don’t have to keep asking for help.)

Edited by FurryEskimo

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616
Dang, I think you're right..  I've only just skimmed this, but it looks like it's screwing with the MaxFollowTime value.  Also apparently there's a hound whistle factor, but oh well, not really relevant right now.

local function OnStartFollowing(inst, data)
    if inst.leadertask ~= nil then
        inst.leadertask:Cancel()
        inst.leadertask = nil
    end
    if data == nil or data.leader == nil then
        inst.components.follower.maxfollowtime = nil
    elseif data.leader:HasTag("player") then
        inst.components.follower.maxfollowtime = TUNING.HOUNDWHISTLE_EFFECTIVE_TIME * 1.5
    else
        inst.components.follower.maxfollowtime = nil
        if inst.components.entitytracker:GetEntity("leader") == nil then
            inst.components.entitytracker:TrackEntity("leader", data.leader)
        end
    end
end

I'm guessing if I want this value to display correctly, I'll need to push a replacement for this in my ModMain.  I'm not really sure how this file factors into how hounds work.

I read it more thoroughly and this seems to be what's activating:

inst.components.follower.maxfollowtime = TUNING.HOUNDWHISTLE_EFFECTIVE_TIME * 1.5

I could try replacing it with my own value, or give myself a hound whistle value, but omg this seems way more complicated than it needs to be..  I just need to set the MaxFollowValue based on the length of the day.

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616
My recollection of how that works is a little vague.  I believe I used AddPostInit(fn) before, but is replacing functions done the same way?  I'll come back to this tomorrow and see if I can find any material online to help me.  It's probably something super easy I've already done before and just don't remember right now.

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616
So I'm 90% sure this is the code I need to add, but am not sure how to replace the old code.  Have you done that before?  I've already done something like this before, don't really remember how I did it..

local function OnStartFollowing(inst, data)
    if inst.leadertask ~= nil then
        inst.leadertask:Cancel()
        inst.leadertask = nil
    end
    if data == nil or data.leader == nil then
        inst.components.follower.maxfollowtime = nil
    elseif data.leader:HasTag("player") then
        if not data.leader:HasTag("houndtamer") then  --Test Code.
            inst.components.follower.maxfollowtime = TUNING.HOUNDWHISTLE_EFFECTIVE_TIME * 1.5
        else
            inst.components.follower.maxfollowtime = TUNING.TOTAL_DAY_TIME * 2.5
        end
    else
        inst.components.follower.maxfollowtime = nil
        if inst.components.entitytracker:GetEntity("leader") == nil then
            inst.components.entitytracker:TrackEntity("leader", data.leader)
        end
    end
end

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616
So, hmm, I'm guessing it would be "inst:RemoveEventCallback("startfollowing", OnStartFollowing)" then I add "inst:ListenForEvent("startfollowing", OnStartFollowing)" to my ModMain, with the code I wrote.  I'm guessing I add it to the "local makeHoundFriend = function(inst)" section of the code.

Share this post


Link to post
Share on other sites
penguin0616    151

@FurryEskimo I don't really remember your code layout, so I'll assume yes.

But important detail: The RemoveEventCallback requires you to use the OLD OnStartFollowing that comes with the hound prefab.

The ListenForEvent uses your NEW OnStartFollowing.

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616
I believe I made the edit as you suggested, but something seems to be off.  The server launches, but I'm brought back to the character select screen and the custom character is missing.  I'm attempting edits to see if I can fix it, but so far nothing has worked.

inst:RemoveEventCallback("startfollowing", OnStartFollowing)  --Test code.
inst:ListenForEvent("startfollowing", OnStartFollowing2)

local function OnStartFollowing2(inst, data)
	if inst.leadertask ~= nil then
		inst.leadertask:Cancel()
		inst.leadertask = nil
	end
	if data == nil or data.leader == nil then
		inst.components.follower.maxfollowtime = nil
	elseif data.leader:HasTag("player") then
		if not data.leader:HasTag("houndtamer") then  --Test Code.
			inst.components.follower.maxfollowtime = TUNING.HOUNDWHISTLE_EFFECTIVE_TIME * 1.5
		else
			inst.components.follower.maxfollowtime = TUNING.TOTAL_DAY_TIME * 2.5
		end
	else
		inst.components.follower.maxfollowtime = nil
		if inst.components.entitytracker:GetEntity("leader") == nil then
			inst.components.entitytracker:TrackEntity("leader", data.leader)
		end
	end
end  --Note: Including this 'end' causes the server to not launch, but not including allows the server to launch, but the character to be unavailable.

 

Edited by FurryEskimo

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616
Still didn't work..  I feel like something else may be off though.  If the last 'end' isn't commented out, the server will fail to launch, but when it is commented out the mod breaks and I can't play as the character.  I added this code around line 1,505:

inst:RemoveEventCallback("startfollowing", OnStartFollowing)  --Test code.

local function OnStartFollowing2(inst, data)
	if inst.leadertask ~= nil then
		inst.leadertask:Cancel()
		inst.leadertask = nil
	end
	if data == nil or data.leader == nil then
		inst.components.follower.maxfollowtime = nil
	elseif data.leader:HasTag("player") then
		if not data.leader:HasTag("houndtamer") then  --Test Code.
			inst.components.follower.maxfollowtime = TUNING.HOUNDWHISTLE_EFFECTIVE_TIME * 1.5
		else
			inst.components.follower.maxfollowtime = TUNING.TOTAL_DAY_TIME * 2.5
		end
	else
		inst.components.follower.maxfollowtime = nil
		if inst.components.entitytracker:GetEntity("leader") == nil then
			inst.components.entitytracker:TrackEntity("leader", data.leader)
		end
	end
--end

inst:ListenForEvent("startfollowing", OnStartFollowing2)

 

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616
Little hard to tell what happened when the server failed to launch.  Right before it fails there's a jumble of code errors (I think) that I've never seen before.

[00:00:01]: MOD ERROR: workshop-2238207705 (The Goodest Boy): Mod: workshop-2238207705 (The Goodest Boy)	
[00:00:01]: Mod: workshop-1842021927 (Pet Follower Badges Together Icon)	Loading modworldgenmain.lua	
[00:00:01]: Mod: workshop-1842021927 (Pet Follower Badges Together Icon)	  Mod had no modworldgenmain.lua. Skipping.	
[00:00:01]: Mod: workshop-1842021927 (Pet Follower Badges Together Icon)	Loading modmain.lua	
[00:00:01]: [string "../mods/workshop-2238207705/modmain.lua"]:1506: attempt to index global 'inst' (a nil value)
LUA ERROR stack traceback:
        ../mods/workshop-2238207705/modmain.lua(1506,1) in main chunk
        =[C] in function 'xpcall'
        scripts/util.lua(723,1) in function 'RunInEnvironment'
        scripts/mods.lua(527,1) in function 'InitializeModMain'
        scripts/mods.lua(501,1) in function 'LoadMods'
        scripts/main.lua(311,1) in function 'ModSafeStartup'
        scripts/main.lua(387,1) in function 'callback'
        scripts/modindex.lua(102,1) in function 'BeginStartupSequence'
        scripts/main.lua(386,1) in function 'callback'
        scripts/modindex.lua(647,1)
        =[C] in function 'GetPersistentString'
        scripts/modindex.lua(621,1) in function 'Load'
        scripts/main.lua(385,1) in main chunk
[00:00:01]: [string "scripts/mainfunctions.lua"]:1106: variable 'global_error_widget' is not declared
LUA ERROR stack traceback:
        =[C] in function 'error'
        scripts/strict.lua(23,1)
        scripts/mainfunctions.lua(1106,1)
        =[C] in function 'GetPersistentString'
        scripts/modindex.lua(621,1) in function 'Load'
        scripts/main.lua(385,1) in main chunk
[00:00:01]: DoLuaFile Error: (null)
[00:00:01]: LuaError but no error string
[00:00:01]: Error loading main.lua
[00:00:01]: Failed mSimulation->Reset()
[00:00:01]: Error during game initialization!
[00:00:01]: [IPC] Signal 'DST_Master_Kill' opened  #000004BC
[00:00:01]: [IPC] Registering handler for signal #000004BC
[00:00:01]: [IPC] Handle #000004BC added to the Eventhandles
[00:00:01]: [IPC] Signal 'DST_Master_Starting' opened  #000004C8
[00:00:01]: [IPC] Sending signal... #000004C8
[00:00:01]: Collecting garbage...
[00:00:01]: lua_gc took 0.04 seconds
[00:00:01]: ~ShardLuaProxy()
[00:00:01]: ~cEventLeaderboardProxy()
[00:00:01]: ~ItemServerLuaProxy()
[00:00:01]: ~InventoryLuaProxy()
[00:00:01]: ~NetworkLuaProxy()
[00:00:01]: ~SimLuaProxy()
[00:00:01]: lua_close took 0.03 seconds
[00:00:01]: Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
[00:00:01]: CurlRequestManager::ClientThread::Main() complete
[00:00:01]: HttpClient2 discarded 0 callbacks.
[00:00:01]: Shutting down

 

server_log.txt modmain.lua

Share this post


Link to post
Share on other sites
penguin0616    151

You really should look at the errors more often.
"attempt to index global inst (a nil value)"

attempting to index (use . or [] on) a global variable names inst (thats right there) that doesn't exist.
image.thumb.png.65e44c1fcafc21e1496cd503da6dcdb3.png
inst is nil in both cases, supposed to use the lines when it's not nil.

Edited by penguin0616

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616
Ohhhh, ok, I see that the listen function is usually in the hound's 'fncommon', where 'inst' is defined.

I tried moving "inst:ListenForEvent("startfollowing", OnStartFollowing2)" to 'local function AddHoundPostInit(fn)' but that didn't work either.

This is weirdly difficult considering all I want it to do is return the right percent value for the hound's loyalty time.  It's almost like there's already a way to train hounds, and I'm just rewriting the code and breaking what's already there.

Share this post


Link to post
Share on other sites
penguin0616    151

@FurryEskimo 

3 minutes ago, FurryEskimo said:

It's almost like there's already a way to train hounds, and I'm just rewriting the code and breaking what's already there.

You are.
 

Quote

I tried moving "inst:ListenForEvent("startfollowing", OnStartFollowing2)" to 'local function AddHoundPostInit(fn)' but that didn't work either.

Then check the new error.
I'm assuming you moved both that the screenshot and description explained.

Edited by penguin0616

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616

You don’t happen to know what code already exists to allow the training of hounds, do you?  It looks to me like there’s a “hound whistle” variable, but I haven’t looked into that yet.

i added the tag “hound” to my character and the hounds just seem to ignore me now.  Before the untrained hounds would follow me, but not attack me, which felt like cheating.

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616

Ah, ok.  I either wasn’t aware that existed, or had forgotten.

So what’s been happening was I did assign a loyalty value based on food, and the code to make it work normally-enough, but this other code is resetting the maxfollowvalue after I’ve set it.  Correct me if I’m wrong, but can’t I just rewrite that block of code, and the game will automatically prioritize the version I wrote?  Actually, this maxfollowvalue also needs to consider if the hound was trained via food or a whistle.  That’s kind of annoying..

Share this post


Link to post
Share on other sites
FurryEskimo    13

@penguin0616
Ok, I think I got it!  At least, I made a breakthrough.  I moved that code into "local makeHoundFriend = function(inst)" and it's working almost how I want it now.  I suspect it's still not quite how I need it, but it seems to be working!  The MaxFollowTime for a dog trained with a whistle is now 4% instead of 100%,but I'll see what I can do about that later.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now