Sign in to follow this  
Safey

Charmander - Currently WIP (Could use Coding help!)

Recommended Posts

Safey    2

Okay so, I've only made one character so far, which was Walnut the opossum. She's gotten quite some love over steam since release, and it has inspired me to make more. The current character of the hour:
charmander.jpg

Things I need help with:

Losing health in the rain, but not if they're wearing things that should keep them dry [x]
Possibly having ONLY ITS TAIL glow [x]
Make it not freeze in the winter [x]
Possible fire damage if not holding weapon [x]

I know the health loss and the freezing wouldn't be too hard but I'm not familiar enough to just know how to code it. I did try editing some of the code I knew and while it wasn't game breaking, Charmander never lost health in the rain.  I also tried looking into WX's code but it didn't do anything.
I know how to make light on the character, like the character glowing or having nightvision, but I'm not sure if it's entirely possible for them to only glow in one spot? If you could help, I'd really appreciate it!

Edited by Safey
  • Like 1

Share this post


Link to post
Share on other sites
Kzisor    1058

@Safey, immunity to freezing: inst:RemoveComponent("freezable")

 

As for the other's there is already a post in this sub forum about fire damage, check pages 2-5 for it. Only making the tail glow is very doable; it would simply need a separate prefab to denote it's tail flame. Give the tail flame prefab the light source and spawn it and force it to follow in the tail position; the torch does this in the exact same way.

  • Like 1

Share this post


Link to post
Share on other sites
Safey    2

@Kzisor
Thanks! I knew the code to make them not freezable was simple as all heck but I wasn't having any luck finding it. And I'll check out the fire damage here soon, it's the code I'm least concerned about finding. 
As for making the tail prefab, I've never done anything like that before, but I'd like to figure it out. If I wanted to use the torch prefab as a main base, taking off the tick, and adding the file name to charmander's prefab, what else would go into it? if you don't really want to just walk me through it that's fine but do you know a good guide I could follow?

Edited by Safey

Share this post


Link to post
Share on other sites
Jjmarco    53

@Safey, You could use the torchfire prefab, which holds the fire of the torch.

You also get a neat particle effect bonus! :razz:

 

Here's how you could do (this is how torches work):

inst.tailfire = SpawnPrefab("torchfire")inst.tailfire.entity:AddFollower() -- adds follower attribute to the fireinst.tailfire.Follower:FollowSymbol(inst.GUID, <symbol>, 0, 0, 0)

Now I have next to no experience with Spriter, so I don't know if there is a 'tail' symbol or something like that. But instead of <symbol>, you have to put the name of the symbol you want the fire to follow.

Instead of '0,0,0' at the end, you can specify an offset to make the fire aligned with the tip of the tail.

 

You might want to listen for the "ms_becameghost" and "ms_respawnedfromghost" events, to hide/show the fire when your character dies/is resurrected.

 

Losing health in the rain, but not if they're wearing things that should keep them dry [ ]

 

You can use the same code as WX-78, it should work. You'll just have to add your own condition if the player is wearing a specific piece of clothing (the umbrella already does that for WX-78, negates all rain damage).

 

Here's WX-78's code, which I modified to work with your character (to put above common_post init and master_postinit):

local function doraindamage(inst, dt)    local bodyitem = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)    -- do not lose health if wearing dry clothing     if bodyitem and bodyitem:HasTag("waterproof") then        return    end    for k, v in pairs(inst.components.inventory.equipslots) do        if v.components.dapperness ~= nil and v.components.dapperness.mitigates_rain then            return -- if holding an umbrella, do not lose health        end    end    -- makes your character lose .5 health at random intervals when it rains    if inst.damage_time > dt then        inst.damage_time = inst.damage_time - dt    else	inst.damage_time = 3 + math.random() * 2	inst.components.health:DoDelta(-.5, false, "rain")    endendlocal function onisraining(inst, israining)    if israining and not inst:HasTag("playerghost") then -- no health loss if ghost!        if inst.damage_task == nil then            inst.damage_task = inst:DoPeriodicTask(.1, doraindamage, nil, .1)        end    elseif inst.damage_task ~= nil then        inst.damage_task:Cancel()        inst.damage_task = nil    endend

 

And in master_postinit, what calls these functions:

inst.damage_time = 3 -- same as WX-78inst:WatchWorldState("israining", onisraining) -- trigger health loss if it starts rainingonisraining(inst, TheWorld.state.israining) -- let's check right now, in case the player spawns and it already rains.

I don't know what you consider dry clothing, so I made it so any body slot item that has the "waterproof" tag will render your character immune to rain damage.

 

Share this post


Link to post
Share on other sites
Safey    2

@Jjmarco Rain damage is now entirely working, thank you! For the:

inst.tailfire = SpawnPrefab("torchfire") inst.tailfire.entity:AddFollower() -- adds follower attribute to the fire inst.tailfire.Follower:FollowSymbol(inst.GUID, , 0, 0, 0)
 
Are you saying that this would all be in the tailfire prefab or this would just be in Charmander's prefab? Does anything need to happen with the anim folder?

Share this post


Link to post
Share on other sites
Jjmarco    53

@Safey, No, this goes in your Charmander's prefab, in master_postinit. torchfire already exists as a prefab, you just have to spawn it.

You don't have to change anything about the anim folder. I'm not sure, because I've never used Spriter, but I think you have to put, instead of <symbol>, the name of the part of the character that you want the fire attached to.

 

Maybe try "tail" ?

Edited by Jjmarco

Share this post


Link to post
Share on other sites
Safey    2

@Kzisor Yeah that's fair, sorry, haha.
@Jjmarco Okay so, I drew the tail and worked on lining it up right. However I ran into a problem.

tumblr_nkex3b3qls1qmfhaco1_1280.png
The fire looks supppper good, problem is it's not sticking on the tail or following the animations, and when they turn around it just kinda stays on the same axis.
Can either of you help?
The current code for the fire looks like this:

inst.tailfire = SpawnPrefab("torchfire")
inst.tailfire.entity:AddFollower() -- adds follower attribute to the fire
inst.tailfire.Follower:FollowSymbol(inst.GUID, "tail-3", -120, -110, 0)

Share this post


Link to post
Share on other sites
Safey    2

@Jjmarco Okay, thanks. It's now following when they turn around and everything. It still isn't like, synced up with an animation. Like if the character does the idle animation the tail will move but the fire will stay in place. I've been thinking about working on a custom idle animation anyway, so that's not a huge deal, but do you know if there's a way for me to fix that part? I just tried out a few different animations and the tail followed fine so, as I said, it's still entirely workable.

Share this post


Link to post
Share on other sites
Jjmarco    53

@Safey, Yeah, I noticed that too. I don't think there is a way to properly attach it to the tip of the tail without doing custom animation.

Unless there is a "tip of the tail" symbol or something like that, but I can't really help you beyond that. Sorry!

Share this post


Link to post
Share on other sites
rezecib    3151

@Safey, Hmm, well the Extended Character Template includes a Spriter project, right? You could add a completely transparent piece to it and animate it in all the animations so that it follows the tip of the tail. It'll be a lot of work, but I don't think there's another way to do it.

  • Like 1

Share this post


Link to post
Share on other sites

 

@Safey, You could use the torchfire prefab, which holds the fire of the torch.

You also get a neat particle effect bonus! :razz:

 

Here's how you could do (this is how torches work):

inst.tailfire = SpawnPrefab("torchfire")inst.tailfire.entity:AddFollower() -- adds follower attribute to the fireinst.tailfire.Follower:FollowSymbol(inst.GUID, <symbol>, 0, 0, 0)

Now I have next to no experience with Spriter, so I don't know if there is a 'tail' symbol or something like that. But instead of <symbol>, you have to put the name of the symbol you want the fire to follow.

Instead of '0,0,0' at the end, you can specify an offset to make the fire aligned with the tip of the tail.

 

You might want to listen for the "ms_becameghost" and "ms_respawnedfromghost" events, to hide/show the fire when your character dies/is resurrected.

 

 

You can use the same code as WX-78, it should work. You'll just have to add your own condition if the player is wearing a specific piece of clothing (the umbrella already does that for WX-78, negates all rain damage).

 

Here's WX-78's code, which I modified to work with your character (to put above common_post init and master_postinit):

local function doraindamage(inst, dt)    local bodyitem = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)    -- do not lose health if wearing dry clothing     if bodyitem and bodyitem:HasTag("waterproof") then        return    end    for k, v in pairs(inst.components.inventory.equipslots) do        if v.components.dapperness ~= nil and v.components.dapperness.mitigates_rain then            return -- if holding an umbrella, do not lose health        end    end    -- makes your character lose .5 health at random intervals when it rains    if inst.damage_time > dt then        inst.damage_time = inst.damage_time - dt    else	inst.damage_time = 3 + math.random() * 2	inst.components.health:DoDelta(-.5, false, "rain")    endendlocal function onisraining(inst, israining)    if israining and not inst:HasTag("playerghost") then -- no health loss if ghost!        if inst.damage_task == nil then            inst.damage_task = inst:DoPeriodicTask(.1, doraindamage, nil, .1)        end    elseif inst.damage_task ~= nil then        inst.damage_task:Cancel()        inst.damage_task = nil    endend

 

And in master_postinit, what calls these functions:

inst.damage_time = 3 -- same as WX-78inst:WatchWorldState("israining", onisraining) -- trigger health loss if it starts rainingonisraining(inst, TheWorld.state.israining) -- let's check right now, in case the player spawns and it already rains.

I don't know what you consider dry clothing, so I made it so any body slot item that has the "waterproof" tag will render your character immune to rain damage.

 

THANKYOU SO MUCH FOR THIS PIECE OF CODE. I cant put it in words, I've spent hours trying to get his code to work. THANKS

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
Sign in to follow this