Jump to content

Code: Character Spawning with companion help.


Recommended Posts

Hello! I am making a mod for Don't Starve: Hamlet with a character who spawns with a unique companion creature that respawns, who is not tied to needing or holding an item. It is meant to be an expendable, somewhat strong follower for an 'easy' difficulty character for my younger brother.

By following the Creature Tutorial and digging through prefabs, the creature works fine (animation, behavior, etc.). However, I am having trouble making it spawn only when playing 'Wumpogg', the character in my mod. Instead, the companion does not spawn and the game continues as normal.  (Testing has been done with the tutorial's "spawn for everyone" code in modmain.lua up to this point, but I've commented it out for testing with Wumpogg) How would I make sure it only spawns when playing as Wumpogg?

Additionally, how would I make a respawn function for the follower that respawns it at the start of a new day or after a certain amount of time has passed? Would I modify Chester's code so it is tied to the player being alive as opposed to an item?

Last question: How do I ensure the follower sticks around when going through doors and dungeons, and on save and load? 

Apologies for a long post. I put questions that would delay me in the future to reduce needing to make multiple posts. I have done some digging through the forums and have not been able to find help in an older post (double apologies if there is help and my eyes skimmed over it.) I have looked at and tried Walter and Woby's code as well, but it doesn't seem to work for spawning the creature (though doesn't crash the game unless I return the 'local master_postinit' function. 

A complicated answer is fine, I will slowly understand it once I get it working the first time. Will continue to refine other parts of the mod in hopes of an answer before I take another shot at doing it myself. A huge thank you to anyone who can help!

Link to comment
Share on other sites

My 2 cents would be you are making it too complicated by not having it tied to an item, like Wendy's Abigail.  The trouble I am seeing is that you need the pet tied to something so that you can call it, a spell cast like maxwell or item like abigail.  Maybe just make a custom item and use inst.components.inventory:GuaranteeItems({"pet_item"}) to assure your brother cannot lose it.  This way whenever he spawns in a new area he is guaranteed the item to be in his inventory and can call the pet.  And then, give him an extra inventory slot with inst.components.inventory:SetNumSlots(17) if that is a hangup for you.

All that being said, if you want to keep going on the path you are taking, you could try calling the GetTime() and do something like this...

local function AllowSpawn(inst)
    return (GetTime() - inst.last_spawn_time > TUNING.SPAWN_PET_COOLDOWN)
end

 inst.last_spawn_time = GetTime()

-OR for a once a day spawner-

inst:ListenForEvent( "daytime", function() spawn_pet(inst) end , GetWorld())

Link to comment
Share on other sites

Thank you for the advice! I went ahead and bound the follower to an item for now. That solved everything on the 'make it playable' side. 

Hearing that an item-less follower is complicated does make me want to fiddle with it more just to see if I can get it working, but I guess that's what versions after 1.0 are for!

Well, that wraps things up. Thank you again! (and a thank you from little bro!)

Link to comment
Share on other sites

We have had some success with this for our Rincewind/Luggage mod. The gist is to set the companion as a follower, and within the lead character, make sure to set the lead character as leader.

A key snippet of code from the main character prefab file is: 

local function RebindLuggage(inst, luggage)
    luggage = luggage or TheSim:FindFirstEntityWithTag("luggage")
    if luggage then
        inst.AnimState:PlayAnimation("idle_loop", true)
        luggage.components.follower:SetLeader(inst)
        return true
    end
end

where "inst" is the main character and "luggage" can be replaced with whatever you chose to call your companion.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...