Jump to content

Need Help, Character/Item modding, new to coding


Recommended Posts

Thank you all for taking the time to read this.

Me and my wife have taken up creating our own characters recently (she does the art, I do the coding).  I'm not experienced by any means, I have almost zero experience doing anything like this,  but I can read code and kind of make sense of what is going on and have been picking through other mods learning some things as I go.

Here are some things I haven't been able to work out on my own yet, and I'm hoping someone out there can help me.

 

1.  Trigger instant insanity (sanity = 0) when a mandrake is killed near her.

-I tried this one for a little but I felt like there might be a simple command out there to make this work

 

2.  She has a custom mandrake bush-hat.  I'm looking to trigger an invincible state while she is hidden, aka "planted".  However,  I'm worried about being able to abuse invincibility in combat.  The normal "hide" state doesn't stop Charlie or Hounds, and I'm trying to make this like an AFK-type mode, without someone being able to spam-hide to avoid damage (maybe something like a timer before triggering invincible state)

 

3. Following along the same line as #2, while I was working on the hat I started adding the tags like "equippable", "waterproofer", "insulator", etc.  I was trying to make it where if I couldn't become "invincible", I could at least counter-act anything harmful that might occur during these "AFK periods".

I ended up with a code that looked like this:

onuse

Spoiler

local function mandrakebush_onuse(inst)
        local owner = inst.components.inventoryitem.owner
        if owner then
            if TheWorld.state.israining then
            owner.sg:GoToState("hide")
            inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_HUGE)
            inst.components.equippable:IsInsulated()
            inst.components.healer.health = TUNING.HEALING_MED
            inst.components.equippable.dapperness = TUNING.DAPPERNESS_HUGE
            inst.components.insulator:SetInsulation(9999)
            owner.components.hunger.hungerrate = ((-5) * (TUNING.WILSON_HUNGER_RATE))

else
            owner.sg:GoToState("hide")
            --inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL)
            --inst.components.equippable:IsInsulated()
            --inst.components.healer.health = TUNING.HEALING_TINY
            --inst.components.equippable.dapperness = (TUNING.DAPPERNESS_MED)
            --inst.components.insulator:SetInsulation(9999)
            --owner.components.hunger.hungerrate = ((-1) * (TUNING.WILSON_HUNGER_RATE))
            end
        end
    end

stopuse

Spoiler

 local function stopusingmandrakebush(inst, data)
        local hat = inst.components.inventory ~= nil and inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil
        if hat ~= nil and owner.statename ~= "hide" then
            owner.components.hunger.hungerrate = (1 * (TUNING.WILSON_HUNGER_RATE))
            hat.components.useableitem:StopUsingItem()
        end
    end

However, using  owner  in the stopuse caused a crash.  I tried adding  " local owner = inst.components.inventoryitem.owner " above local hat AND below it (mimicking the onuse code, which was the only place I could see  owner  called out in any way special.  Removing this from the stopuse lets me see that the onuse  owner.hungerrate modifier is working, but not getting removed with stopuse.

(sidenote, healer is for on-use healing not health regen, which is what I am looking for, so healer component doesnt work for what i want)

 

3A) Is there any way I can fix this so I can call on player components in the stopuse like it did in the onuse to reset values?

3B) Is there a way I can add these things to an item so I don't have to mess with the player components? 

--Health Regen (over time

--Insulation (Max / Min Temps),  I don't want her freezing or overheating while "planted"

--Hunger Rate

 

3C)  Is there a way to bypass that altogether and set a ListenForEvent type thing with  "mandrakebush_onuse"   and  "stopusingmandrakebush"  in the character.lua?  Essentially, I'm looking for something like this

Spoiler

ListenForEvent  mandrakebush_onuse

add health regen

hunger regen

sanity regen

all that jazz

OR

ListenForEvent  mandrakebush_onuse

AddTag:Planted  (and how to make Planted make said above changes)

OR

ListenForEvent  mandrakebush_onuse

AfterDelay: 10 seconds  SetState: Invincible

 

 

MotherNeedsHelp.zip

Edited by Sm0k
More descriptive title
Link to comment
Share on other sites

Hi,

1) You could catch the event push by TheWorld when an entity die. In your character script add something like

local function CheckMandrakeDeath(inst, data)
	if data and data.inst.prefab == "mandrake_active" then 
		[...do whatever you want...] 
	end
end

------------------------------------------------------------------

inst:ListenForEvent("entity_death", CheckMandrakeDeath, TheWorld)

I wrote that without really checking so there might be typo, malformed function, but the idea is there. By the way, this event "entity_death" is pushed somewhere in the health.lua component script.

2) Several possibility.

You could look for all the entities in a radius around your character with TheSim:FindEntities. If they have a combat component, then check their targets. If their target is your character then prevent the invincible state.

Other possibility is to check the last time your character has been attacked (Combat:GetLastAttackedTime()). If it is above a threshold that you determine, you validate the invincible state, otherwise you don't.

3) I got confused by this one. Maybe posting the crash you get when using that piece of code and a bit more code (like where you use these functions) would help

Edited by ZupaleX
Link to comment
Share on other sites

@ZupaleX,

Thanks for responding.

5 hours ago, ZupaleX said:

 


local function CheckMandrakeDeath(inst, data)
	if data and data.inst.prefab == "mandrake_active" then 
		[...do whatever you want...] 
	end
end

------------------------------------------------------------------

inst:ListenForEvent("entity_death", CheckMandrakeDeath, TheWorld)

 

This looks promising to me, I'll give it a shot.  Does this make it trigger when anyone on the entire map kills a mandrake?  I'd prefer to only do it within a local radius if possible, but I can make global work if necessary.

 

5 hours ago, ZupaleX said:

2) Several possibility.

You could look for all the entities in a radius around your character with TheSim:FindEntities. If they have a combat component, then check their targets. If their target is your character then prevent the invincible state.

Other possibility is to check the last time your character has been attacked (Combat:GetLastAttackedTime()). If it is above a threshold that you determine, you validate the invincible state, otherwise you don't.

3) I got confused by this one. Maybe posting the crash you get when using that piece of code and a bit more code (like where you use these functions) would help

2)  I like both of these suggestions as well, and I'll give them a shot.  However, I may not have expressed just QUITE how new to coding I am.  I've pieced together my code by looking at other characters who did something I wanted (or close to).  But when it comes to making scripts up I'm still very new.  I get the idea behind what you are saying to do, but I'm at a loss as to how to get started and how to make it work.

I'll work on it on my own for sure and try to figure it out, but if someone wanted to make it simple for me I wouldn't object.  Both of these methods sound good to me, but to clarify for anyone who might want to help out:

Spoiler

 I want to take a Bush-Hat (custom mandrake-hat)  and instead of "hide" make it do "invincible", but only after a timer or nobody is trying to target her

 

3)  It was pretty late when I was asking for help and I can see now how that was confusing.  Basically, I was asking if there was a way to make the "invincible" state from #2 a code on a custom character instead of the Mandrake-Hat item.

The reasoning behind this being that if someone ELSE was to use the (Mandrake)Bush-Hat they would go into normal hide state, but if my custom character were to use it they would become "planted" aka "invincible".

I should have mentioned the character we are making to go along with this item is a "Mandrake" character.  I've worked out all the code for her already, but I was wondering if I could add a new line of code to the character instead of the item (leave the item just a re-skinned bush-hat basically), and make it where if the character uses the hat she triggers the "invincible" state.

The code for 3 was all just made up code.  To clarify my question in 3 a bit:

Spoiler

Is there a way to add a trigger event to my custom character for when she uses the custom hat to trigger the "invincible" state.  Something similar to this:

ListenForEvent  mandrakebushhat_onuse

TriggerState "invincible"

(or like this, to follow along with question #2 above)

ListenForEvent mandrakebushhat_onuse

TriggerState "invincible" after 5 seconds (or If_Nobody_Targeting_Her)

 

Keep in mind the code in that is all made-up examples.  I'm not sure of how to actually write out the lines of code to make these things I want happen.  I'm not even sure if "invincible" is a state I can toggle like "hide".  I am literally winging it as I go trying to make things happen.

 

Afterthought:

I'm thinking now I can maybe add a new line into the mandrake bush hat.  Something similiar to 

Spoiler

   If    owner:HasTag("mother")    then   owner.sg:GoToState("invincible")   else   owner.sg:GoToState("hide")

Is GoToState("invincible") even a thing I can do?  And why does the code use owner instead of ThePlayer?  I'm getting  "owner"  from the hats.lua , but I wasn't sure if something like

Spoiler

   If    ThePlayer:HasTag("mother")    then   ThePlayer.sg:GoToState("invincible")   else   ThePlayer.sg:GoToState("hide")

Worked the same way, or if I had to use a mixture like

Spoiler

   If    ThePlayerr:HasTag("mother")    then   owner.sg:GoToState("invincible")   else   owner.sg:GoToState("hide")

 

Link to comment
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
 Share

×
  • Create New...