Jump to content

Recommended Posts

Hey hey, so I've flung together some crude animations for a custom weapon to utilize. I'll be tweaking them a lot later on, but for the moment I need to make sure I can actually get them to play in the right way.

Naturally I've used the animation template provided a lot around this forum, and I've also utilized the Equippable Item template provided by Cheerio, although heavily changed at this stage. The only remaining part is the 'wand' naming in the file paths, which I didn't feel I had to worry about changing.

The stage I am at now involves making the weapon use the animations, but I've yet to find out where to begin with that. I don't recall seeing a guide here that covered this specific stage for someone like me. The animations created using the animation template are naturally contained by themselves right now, I'm not sure if I need to find a way to place them with the swap_weapon.scml or the character.scml, and then code them in so the weapon will use them when it's being used to attack.

Any aid is much appreciated, and I can add more clarity if needed.

:wilson_love:

I've learned thus far that to change the animation my weapon uses, I'm going to have to learn a little bit about Stategraphs, assuming I'm looking in the right direction at least.

If anyone knows any examples of such things I can learn from, that'd also be dandy!

If you want to add this animation as a new state, you will need to use AddStategraphState to add this new state to the stategraph. You will need to add it to the server and client, otherwise you may encounter problems. Then, depending on when you want the animation to be played, you can also add an actionhandler, which will automatically run the state if a certain action is perfomed, with AddStategraphActionHandler.

Quick example from the Shields mod:

Spoiler

local shield_block = State{
        name = "shield_block",
        tags = { "blocking", "busy" },

        onenter = function(inst)
            inst.components.locomotor:Stop()
            inst.components.locomotor:Clear()
			inst:PerformBufferedAction()
			local weapon = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
			if weapon then
                weapon.components.equippable.onunequipfn(weapon, inst)
            end
			local shield = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
			inst.AnimState:SetMultiSymbolExchange("swap_object", "hand")

		   	inst.AnimState:OverrideSymbol("swap_object", "swap_hylianshield", "swap_right_hylianshield")
			
			inst.AnimState:Show("ARM_carry")
			
			inst.AnimState:PlayAnimation("parry_pre") -- here you can let your animation play
			inst.AnimState:PushAnimation("parry_loop", true)
			inst.sg:SetTimeout(inst.AnimState:GetCurrentAnimationLength())

        end,
    }
AddStategraphState("wilson", shield_block)
AddStategraphState("wilson_client", shield_block)

You can call this state by running inst.sg:GoToState("shield_block") somewhere in a function.

If you don't care that your animation may be interrupted, you can also just run inst.AnimState:PlayAnimation("your_animation") in a function.

If you want to change an existing actionhandler, for example if you want your special animation to play if you attack something, you will need to change things a bit.

Spoiler

AddStategraphPostInit("wilson",function(sg)
    if sg.actionhandlers and sg.actionhandlers[GLOBAL.ACTIONS.ATTACK] then
        local old_deststate = sg.actionhandlers[GLOBAL.ACTIONS.ATTACK].deststate
        sg.actionhandlers[GLOBAL.ACTIONS.ATTACK].deststate = function(inst,action,...)
            if not (inst.sg:HasStateTag("attack") and action.target == inst.sg.statemem.attacktarget or inst.components.health:IsDead()) then
                local weapon = inst.components.combat ~= nil and inst.components.combat:GetWeapon() or nil
                if weapon:HasTag("A_Tag") then -- just an example, you can make the condition whatever you want
                    return "your_new_state"
                else
                    return old_deststate(inst,action,...)
                end
            end
        end
    end
end)
        

This hooks the function which determines which state is chosen if you attack something.

I hope that helps, there are a few mods which change/add stategraphs, you can have a look at the shields mod, a more complex mod is Reforged, where they change quite a lot.

  • Like 1
  • Big Ups 1

Thanks for the help @Monti18! I got all the code written up pretty quickly thanks to you.:wilson_love:

However I'm still a goober. I did look up a lot of different examples to make sure I got it right, and somewhere down the line I must have forgotten something.

The code runs as much as I can expect. The game doesn't crash, the weapon still works it's magic and it *tries* to run the animation. But instead of doing so, the character simply vanishes until I move the character manually.

At the moment I can only theorize that I haven't set-up the animations correctly in the code, and I'll continue to try and solve this next problem. 

Any further aid into this invisible animation issue is welcome! I can provide the relevant code if it's needed, which I can guess it will be this time around.

  • Like 1

Yeah this is probably a problem with the animation.

You can try to run ThePlayer.AnimState:PlayAnimation("your_animation") in the command line and see if your animation is played (may be needed to run that on the client and not the server)

You can also have a look at the client log, it should tell you if it can't find an animation.

If your not able to find the error with that, you can post your code and I will have a look :)
 

  • Like 1

@Monti18 Made another look into the animations, using your suggested method in-game.

The client.log did managed to tell me this for any specific animation I tried to load. 

Quote

[00:01:49]: Could not find anim [FROMNUM] in bank [wilson]

I made an effort to figure out what that means but from the looks of it, it can mean a couple things. Among the attached items is the layout of the anim bank, considering that the bank isn't called [wilson] I imagine that's a potential source of my problems. Aside from that, I've also provided the two files related to the stategraph for you.

Thanks again for the aid!:wilson_love:

c1c9a8a5ad39664572623c96b53a13f3.png

modmain.lua maxgun_stategraph.lua

  • Like 1

Yes this is probably your problem, that the bank isn't called wilson :D

As you can see, the game doesn't know this animation, as for players the bank is always called wilson, only the build changes :)

You're welcome! I hope it gonna work now!

P.S:Why do you have a AddPrefabPostInit in the PrefabFiles table? It would be better to just put it like that in the modmain. Also if you want to import files, it's easier to use modimport as it directly sets the environment to that of the modmain :)

  • Like 1

I've set the animation bank back to 'wilson' and checked in-game for any changes. Oddly, there are none. The animation is still invisible.

Assuming that my code has no glaring issues, as you felt no need to correct me on any of it, I can only really shift my attention to other causes.

From what I understand, the bank being called 'wilson' should cause the game to merge the animations in my .zip/build with existing ones. However it doesn't seem to be doing so as the game still cannot figure out what I'm asking of it. Perhaps I'm not properly letting the game know it needs it? Or have I done something wrong in Spriter?

At the moment I'm not quite sure where I'm going wrong, but I'm this close to reaching my goal so I've got to figure out my mistake.

P.S. re: This mod is essentially a personal-use extension of an existing mod on the Steam workshop. I've been hesitant to send code for people to see when I've asked for help due to the fact the some of it wasn't technically mine and I didn't want to cause any disrespect to the original modder. The 'AddPrefabPostInit' was written by the original modder, and I've simply chosen to leave it despite it looking strangely placed. Perhaps I'm being too reserved, since I have added a lot to it. But still.

Did you load the anim file in the modmain? This could also be the cause.

If this doesn't work, look again at the logs to see what is written there.

As far as I can see it looks good, so it's probably the loading of the anim or something with spriter that causes this problem.

You will be able to fix it! ;)

P.S. re re: Ah ok I see. Personally I don't care if somebody changes my mod for himself, as long as it's only for a small amount of persons :D But you never know how other people see that :D

 

  • Like 1

It's in my modmain, for sure. The last Asset entry is " Asset("ANIM", "anim/maxgunfire.zip"), " which contains a fresh .zip that hasn't been touched yet. So the .zip still has the atlas files and such alongside the anim file. Can't imagine the comma is ruining me.

I had a line-by-line look over the client.log again but my inexperience may be failing to spot an issue related to the animation. I've attached it for you, in case you see anything I don't. I believe I've tried calling the file everywhere I can think of including outside the modmain, so I'll turn my focus to Spriter and seeing if anything is off there.

Genuinely though, thanks for sticking around this long to help deal with this magical mystery issue. You're a champ!:wilson_love:

Quick edit: I will also add, since I feel like Spriter isn't the root cause of the problem, that the animation templates 'Test Animation' function played the animation just fine.

client_log.txt

Edited by TheAlphaDehur

The comma is fine!

I had a look at the client log and I think I see where it went wrong. It's looking for the animation called "max", but you don't have an animation called max. You called it maxgunfire as seen in the screenshot from Spriter. Try replacing inst.AnimState:PlayAnimation("max") with inst.AnimState:PlayAnimation("maxgunfire") in the stategraph and see if it works. If it doesn' work, you can upload the folder in exported where the animation is saved or DM it to me if you would rather have it not publicly accessible and I will have a look :)

Haha thanks I'm flattered! :wilsoalmostangelic:

  • Like 1

Eyyyy! That did it! I feel like I might be dreaming. I never actually would've thought that calling it 'maxgunfire' would have worked, the game knows what _up/_down/_side mean I suppose. But I don't recall reading that anywhere.

With that all the hard parts of the mod are done! Just some testing, refining and hopefully minimal bug fixing and I can rest.

Many thanks once again! I may have actually been stuck on this for a while without you.:wilson_love:

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...