Jump to content

Recommended Posts

Hi, there. So instead of asking what's wrong, I'm going to ask questions (shocking news, right?)! What are the requirements for a creature to appear visible once the prefab is correctly created (meaning it's registered as a creature, it doesn't make anything crash and it's a brainless moron at this point)?

Let me have a try at what I need, ok?

-local assets with the anim folder (+ custom sounds)

-local function init_prefa() containing:

local inst = Create Entity --creating the entity, duh
inst.entity : AddTransform() --this allows us to put it in the world
inst.entity : AddAnimState() --now we can animate the mob
inst.AnimState:SetBank("creature") --sorry, what is this again exactly please? I forgot the difference between the bank and the build
inst.AnimState:SetBuild("creature") --doesn't need a "_build" right? if you name it this in the spriter top layer it should be fine, right?
inst:AddComponent("locomotor") --now it can move
inst.components.locomotor.runspeed = 7 --set the speed.
MakeCharacterPhysics(inst, 10, .5) -- this seems fairly straightforward
    inst.Physics:SetCollisionGroup(COLLISION.CHARACTERS) -- what's this?
    inst.Physics:ClearCollisionMask() -- what's this?
    inst.Physics:CollidesWith(COLLISION.WORLD)
    inst.Physics:CollidesWith(COLLISION.OBSTACLES)
    inst.Physics:CollidesWith(COLLISION.CHARACTERS) -- are all of these important? Doesn't "MakeCharacterPhysics" do part of this? Or does that only create its size and dimensions?
 inst.Transform:SetFourFaced() -- This is to allow us to make animations like "idle_loop_down" "idle_loop_side" "idle_loop_up", right? What are the limits to this? I don't see where I can get the info, but if you can tell me where to find it in the game files that's fine too of course
local brain = require "brains/creaturebrain" --sets the brain
inst:SetBrain(brain) -- attaches the brain
inst:SetStateGraph("SGcreature") -- set the stategraph
inst.sg:GoToState("idle") -- is this necessary?
return inst -- "we return the entity so it can be added to the world" or whatever that means

return Prefab( "monsters/creature", init_prefab, assets, nil) -- we register the entity. But is there anything that should be noted about this or can I just always register a new mob under "monsters/creature"?

So that was everything I think is absolutely necessary for the creature to "work" correctly. But if I do just this the creature simply doesn't appear visible even though I have an anim folder. Which really bugs me since I already made all the animations for it. Can the spriter project be any problem? Anything else I should check?

 

Thank you for your time. I hope that this topic will -when progressively answered and thus completed- help out more people :)

Edited by Thibooms
Link to comment
https://forums.kleientertainment.com/forums/topic/66486-questions-about-creatures/
Share on other sites

Just now, Aquaterion said:

you might have to add inst.AnimState:PlayAnimation("idle", true)

Instead of 

inst.sg:GoToState("idle")

under the stategraph?

That seems strange because it seems to be fine on another creature that -for some reason- works perfectly

9 minutes ago, Thibooms said:

Instead of 


inst.sg:GoToState("idle")

under the stategraph?

That seems strange because it seems to be fine on another creature that -for some reason- works perfectly

yea your right, but it never hurts to try. If the monster spawns but is invisible, then it is probably the .zip or the stategraph

 

As for walkspeed and runspeed, it's pretty much what it says. walkspeed is how fast it walks, and runespeed is how fast it runs. In the stategraph you can add if it can walk and/or run. 

The Stategraph afaik just needs to be declared AFTER locomotor, if it can move.

Edited by Aquaterion

@Aquaterion, yep just tried it, same problem. What could go wrong with the zip? Aside from looking at the spriter project, I shouldn't have anything else affecting it, which means that starting to mess with the zip file would be quite inefficient (needing to fix a stupid problem everytime you make a creature or edit it, even though this should be avoidable).

 

Thank you for the fast replies and the info on stategraphs and the locomoter component. I'll edit the original post to delete the question :)

Edited by Thibooms
Just now, Thibooms said:

@Aquaterion, yep just tried it, same problem. What could go wrong with the zip? Aside from looking at the spriter project, I shouldn't have anything else affecting it, which means that starting to mess with the zip file would be quite inefficient (needing to fix a stupid problem everytime you make a creature or edit it, even though this should be avoidable).

maybe you're calling the animations wrong in the stategraph, and are you sure it compiled without errors?

@Aquaterion, that's actually very likely. Do you happen to know where I can find a good DST example on how to use idle_loop_down, idle_loop_side, idle_loop_up animations in the stategraph? Because I thought setting the creature as four faced in the lua and then having the following in the stategraph would allow for the game to recognise those animation layers :

local states=
{
    --This handles the idle state.
    State{

        name = "idle",
        tags = {"idle", "canrotate"},
        onenter = function(inst, playanim)
            inst.AnimState:PlayAnimation("idle", true)
        end,

    },

 

13 minutes ago, Aquaterion said:

and are you sure it compiled without errors?

Well how can I check? The atlas seems fine and I guess the build is named correctly because the game doesn't crash or say anything about it in the log :)

Edit: You're right, it doesn't compile at all. I deleted the anim file to find out. What could be the cause?

Please tell me that using bones isn't the problem ^^'

Edited by Thibooms

In case you'd like to take a good look at it, here's the full stategraph I got (from klei's creature tutorial that's way outdated) :

--Stategraphs are used to present feedback to the player based on the state of the creature.  Here we setup two states,
--one to handle when the creature is idle and one to handle when the creature is running.
local states=
{
    --This handles the idle state.
    State{

        name = "idle",

        --Tags are how we can classify states.  The 'canrotate' tag tells the animation system that these animations can
        --be flipped based on which way the creature is facing which means we don't have to create multiple animations.
        tags = {"idle", "canrotate"},

        --Here is how we define what happens when we enter this state.
        onenter = function(inst, playanim)

            --In this case, all we want to do is play a looping version of the idle animation.
            inst.AnimState:PlayAnimation("idle", true)
        end,

    },

    --This handles the running state.
    State{

        name = "run",

        --Our running animation is also safe to be rotated.
        tags = {"run", "canrotate", "moving" },

        onenter = function(inst, playanim)

            --When entering this state, we now play a looping run animation.
            inst.AnimState:PlayAnimation("run", true)

            --Tell the locomotor that it's ok to start running.
            inst.components.locomotor:RunForward()            
        end,
    },    

    --[NEW] This handles the yell state.
    State{

        name = "yell",

        --[NEW] Our new state along with our run state are tagged as 'moving' so that we can check for either one when we
        --      receive a 'locomote' event from our 'locomotor' component.
        tags = {"yell", "canrotate", "moving"},

        onenter = function(inst, playanim)

            --[NEW] When we first enter this state, we want our creature to yell.  The name of the sound is a combination of the fmod project, 
            --      the folder within the fmod project and the name of the sound event.
            inst.SoundEmitter:PlaySound("tut07/creature/yell")            

            --[NEW] We also want it to play our new fancy yell animation.
            inst.AnimState:PlayAnimation("yell")
        end,

        --[NEW] The events section allows us to handle events specific to the current state we are in.
        --      In this case we are going to switch to the run state as soon as we receive the 'animover'
        --      event which tells us that our yell animation is done.
        events=
        {
            EventHandler("animover", 
                function (inst, data)

                    --[NEW] Time to start running.
                    inst.sg:GoToState("run")
                end
            ),
        }        
    },    
}

--Event handlers are how stategraphs get told what happening with the prefab.  The stategraph then decides how it wants
--to present that to the user which usually involves some combination of animation and audio.
local event_handlers=
{

    --The locomotor sends events to the state graph called 'locomote'.  Here we setup how we're going to handle the event.
    EventHandler("locomote", 
        function(inst) 

            --First we check to see if the locomotor is trying to move our creature.
            if inst.components.locomotor:WantsToMoveForward() then

                --Next we check to see if we're not already in a moving state.
                if not inst.sg:HasStateTag("moving") then

                    --[NEW] Instead of going straight to the run state, let's jump to the yell state first.
                    inst.sg:GoToState("yell")
                end

           --If we're not trying to move forward, then all we want to do is stand still.
            else

                --So if we're not already standing still.
                if not inst.sg:HasStateTag("idle") then
                    
                    --Let's start standing still.
                    inst.sg:GoToState("idle")
                end
            end
        end),
}

--Register our new stategraph and set the default state to 'idle'.
return StateGraph("wurm_thibaud", states, event_handlers, "idle", {})

2 minutes ago, Aquaterion said:

How exactly did you create your creature.zip ? did you take an existing mob and edit the atlas-0.tex or did u decompile it, edit parts or did you start from scratch?

I did it from scratch with spriter and then it compiled. But it seems like some error has occured. Would you like the "exported" file?

2 minutes ago, Aquaterion said:

Btw could you post your actual creature code?

Yes, sir :) :

--Here we list any assets required by our prefab.
local assets=
{
    --this is the name of the Spriter file.
    Asset("ANIM", "anim/wurm_thibaud.zip"),
    
    --[NEW] This is the FMOD file which contains all of the sound events.
    --Asset("SOUNDPACKAGE", "sound/tut07.fev"),

    --[NEW] This is the FMOD file which contains all the actual sound data.
    --Asset("SOUND", "sound/tut07.fsb"),    
}

--This function creates a new entity based on a prefab.
local function init_prefab()

    --First we create an entity.
    local inst = CreateEntity()

    --Then we add a transform component se we can place this entity in the world.
    inst.entity:AddTransform()

    --Then we add an animation component which allows us to animate our entity.
    inst.entity:AddAnimState()
    -- inst.AnimState:PlayAnimation("idle", true)
    inst.entity:AddSoundEmitter()
    inst.entity:AddDynamicShadow()
    inst.entity:AddMiniMapEntity()
    inst.entity:AddNetwork()
    
    --The bank name is the name of the Spriter file.
    inst.AnimState:SetBank("wurm_thibaud")

    --The build name is the name of the animation folder in spriter.
    inst.AnimState:SetBuild("wurm_thibaud")

    
    --We need to add a 'locomotor' component otherwise our creature can't walk around the world.
    inst:AddComponent("locomotor")

    --Here we can tune how fast our creature runs forward.
    inst.components.locomotor.runspeed = 7

    --We need to add a 'physics' component for our character to walk through the world.  Lucky for us, this
    --this is made easy for us by the 'MakeCharacterPhysics' function.  This function sets up physics,
    --collision tags, collision masks, friction etc.  All we need to give it is a mass and a radius which 
    --in this case we've set to 10 and 0.5.
    MakeCharacterPhysics(inst, 10, .5)

    inst.Physics:SetCollisionGroup(COLLISION.CHARACTERS)
    inst.Physics:ClearCollisionMask()
    inst.Physics:CollidesWith(COLLISION.WORLD)
    inst.Physics:CollidesWith(COLLISION.OBSTACLES)
    inst.Physics:CollidesWith(COLLISION.CHARACTERS)
    
    inst.Transform:SetFourFaced()
    
    --We need a reference to the brain we want to attach to our creature.
    local brain = require "brains/wurm_thibaudbrain"

    --And then we attach the brain to our creature.
    inst:SetBrain(brain)

    inst:SetStateGraph("SGwurm_thibaud")
    inst.sg:GoToState("idle")
    
    --return our new entity so that it can be added to the world.
    return inst
end

--Here we register our new prefab so that it can be used in game.
return Prefab( "monsters/wurm_thibaud", init_prefab, assets, nil)

 

btw when I said to add the

-- inst.AnimState:PlayAnimation("idle", true)

you have to call it after setting bank and build, most likely, but I doubt it will change anything.

And as far as I know for DST, you need to add networking to it;

inst.entity:AddNetwork()

if not TheWorld.ismastersim then
	return inst
end

inst.entity:SetPristine()

im not that great with animation stuff but I guess you could post it

3 minutes ago, Aquaterion said:

you have to call it after setting bank and build, most likely, but I doubt it will change anything.

Probably won't now the anim is gone but good to know anyway :)

I will also add the networking, thanks. Is that because in DST you're always on a server?

 

Here's the animation file, have fun with it ^^'' (it's normally unzipped and in a file called "exported" which is in the mod folder along with anim folder, scripts, modmain, etc; just to be clear)

wurm_thibaud.zip

I took a screenshot just in time before the window was about to close;

fd60dad5755c4ee6da5c999540e7bc46.png


It seems bone_030 has an issue  "doesn't exist on first key frame." if you fix that, you'd probably progress somewhere.

I've never used bones in spriter so I've got no clue how I could go about fixing it myself.

 

Edited by Aquaterion
Just now, Thibooms said:

@Aquaterion, thank you very much for your help man.

I don't know where to find this bone though. I'll try to see what the result is if I just delete the bones. :)

It does seem like bone 30 is unused, not sure how to remove bones tho

Just now, Aquaterion said:

It does seem like bone 30 is unused, not sure how to remove bones tho

Luckily Spriter has a button "delete from all frames" and I'm able to select all bones without touching the sprites. The even greater thing about this is that the animation does stay intact, so that's a good thing.

 

Unfortunately, the game still doesn't compile it for some reason.

Here's the updated spriter project (boneless) if you'd like to give it a shot :) :

 

wurm_thibaud.scml

I don't think that has anything to do with compiling, last update, not the 1 that happens like 20 mins ago, I kept seeing PREFABSWAPMANAGEr RAIN in the console, and that has the same stuff. Did you crash when loading a world? If you did, its probably an update that fked it. If you crashed on entering a world, create a new 1

Edited by Aquaterion

@Aquaterion yeah I noticed the game just updated.

Yeah I crashed with a pre-existing world (no worries, just one I casually use to test out mods)

 

So, did it not compile for you then? Did it? If so, why? ^^ Sure doesn't work for me at the moment.

1 minute ago, Thibooms said:

@Aquaterion yeah I noticed the game just updated.

Yeah I crashed with a pre-existing world (no worries, just one I casually use to test out mods)

 

So, did it not compile for you then? Did it? If so, why? ^^ Sure doesn't work for me at the moment.

the zip i gave u the the compiled version, which means u should put it in anim.zip, and therefore, doesn't need to compile.

Just now, Aquaterion said:

the zip i gave u the the compiled version, which means u should put it in anim.zip, and therefore, doesn't need to compile.

Yeah I know but that means that I can't compile, which is annoying when making changes or when making new creatures :(

Just now, Thibooms said:

Yeah I know but that means that I can't compile, which is annoying when making changes or when making new creatures :(

just an fyi, i put all ur images in a folder rather than being all running wild. Question is, did it work?

uncompiled.zip

@Aquaterion, ok thanks. It seems to compile now. I think the problem was that I had spriter opened up, meaning the files were in use. This is also responsible for not allowing you to delete such files, so I can see why it didn't compile.

 

I still crash when opening a world though (same crash)

Just now, Thibooms said:

@Aquaterion, ok thanks. It seems to compile now. I think the problem was that I had spriter opened up, meaning the files were in use. This is also responsible for not allowing you to delete such files, so I can see why it didn't compile.

 

I still crash when opening a world though (same crash)

did u try to create a new world? I don't think the crash has to do with ur mod, maybe you have another mod activated? turn off all mods except urs

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
×
  • Create New...