Jump to content

Recommended Posts

One of my first mods was a rather simple one essentially just a few stat changes and cold/heat immunity (http://steamcommunity.com/sharedfiles/filedetails/?id=374046082) However upon working on my next character I want them to have more then just stats, the biggest thing I want is for them to have a custom stat similar to how Woodie has his beaverness meter but as...well a shield.

 

The basic idea is I want my next character (And by extension my current character) to have a "Shield" stat which functions as you would expect, if the character takes damage it's first taken off the shield and when the shield is gone future hits hurt their health and when the character hasn't taken damage within X amount of seconds the shield regens

 

Now While I'm a dummy in programming I think I know a few things the stat would need,  a timer state which would go off if the shield is below it's max counting down until it starts to recharge with the recharge state disabling when the shield is full and the timer resetting if you continue to get hit but theres a few big ones I need to figure out

 

Making it so if it's hit it's taken off the shield

Making it so damage bleeds over to the health if the shield hits 0

Making it so health is hit in general when the shield hits 0

Implimenting said stat both visually on screen and making it function in game.

 

Now while I'm going to try to Frankenstein the stat (AKA what I did with Spartan 115 (AKA stitch parts of other code in and hope it works)) If anybody has any advice on how to pull this off It would be greatly appreciated (and explaining how it works so I can learn to program better but that's your choice if you want to)

You can use other mods for the starting point of yours (for example: Musha, The Puppy Princess has both shield mechanic and visual effect).
The main idea is to create two or more (if it necessary) state of the shield. When it is "isActive" (choose name of state by yourself) the character has an additional visual effect and the shield absorb all incoming damage (maybe there are some function that return damage taken by the character or simple get the character's hit points and subtract the difference from shild's hit points). When it has the active status, but shield hit point is 0 or less, change status to "notActive" (name isn't necessary here too). Status "notActive", for example, do nothing and has an additional visual effect too. Think about it. (I hope my text is understandable =))

So looking at Musha to reverse engineer the shield I think my lack of programming knowledge is showing -.-.

 

So what I can gather the absorption amount reflects how much it takes off their health, with 1 being the sheild takes all of it, unfortunately the shields leveling system has just baffled me into finding where the timer recharge is, where the value of said shield is or where the component for shield is (Given there is no Shield component in it's script section)

 

If there's any more advice feel free to give it ima go and continue ripping my hair out trying to figure this out

Ok after a long day of looking at the class I think I figured our how Musha's shield works and the differences to my shield idea

 

hers is a "It lasts for X seconds" then goes on Cooldown, that said though I can reverse engineer and alter the cooldown to be timers but outside of that I need to make a few changes.

 

the big thing here is it appears I need to make an component for the shield to call it as a constant (Similar to Woddies Beaverness) so I'll have to work on frankensteining both bits of coding, for the component I'll need to make it an If statement like If Component.shield = 0 Component:healthabsorbtion(0) and figure out the timers

 

Should be fun

Edited by Tik115

Alrighty time to get ripped apart here but here goes

 

So for the component I've got 2 states, one for when it's up and one when it recharges, now I've not got it anywhere near done since I need to do things like searching for how the game determines when you get hit so It can link to the shield then I gotta figure out how to bleed over the damage if the shield runs out but for this current basis (of which might be too limited for people to say if it works or not) I have it so each state is activated depending on parameters, The idea is if the shield is above 1 it will be "Active" upon taking damage it is meant to switch to the shield recharge which after the timer goes down it recharges till it's back to full in which the recharge deactivates and the active activates again and if the shield hits 0 it stops protecting the character, so outside of all the stuff i mentioned above i also need to figure out how to do things like rest the timer when hit.

 

local function shield_active
if shield.self.current => 0 then shielddown = false, shieldrecharge = false
inst.components.health:SetAbsorptionAmount(1)
end
else if shield.self.current =< 0 then shielddown = true,
end
end


local function shieldrecharge (regen)
shield_active = false
if shield.self.current => 1 then 
timer.create(cooldown, 5, 1, --not sure what to put here
-- regen:shield.self.current + 1
else inst.components.health:SetAbsorptionAmount(0)
timer.create(cooldown, 5, 1, --not sure what to put here
-- regen:shield.self.current + 1
end
-- if hit it needs to reset the timer would it go here?
end

 

20 hours ago, Tik115 said:

Alrighty time to get ripped apart here but here goes

 

So for the component I've got 2 states, one for when it's up and one when it recharges, now I've not got it anywhere near done since I need to do things like searching for how the game determines when you get hit so It can link to the shield then I gotta figure out how to bleed over the damage if the shield runs out but for this current basis (of which might be too limited for people to say if it works or not) I have it so each state is activated depending on parameters, The idea is if the shield is above 1 it will be "Active" upon taking damage it is meant to switch to the shield recharge which after the timer goes down it recharges till it's back to full in which the recharge deactivates and the active activates again and if the shield hits 0 it stops protecting the character, so outside of all the stuff i mentioned above i also need to figure out how to do things like rest the timer when hit.

 

 

 

And does that code work if you try to run it? (by "work" I just mean; does the game not crash when it runs)

would this be in a custom component file or is this just in the character's file?

Does that "timer.create" code work? I've only ever seen "DoTaskInTime" stuff so I don't know much about how the timer thing works. But if you did a DoTaskInTime you could just have it cancel the task and then start a new one on hit

But as for resetting the sheild, you could use an event listener like this

inst:ListenForEvent("attacked", function(inst)
	--DO THE THING
end)

although "attacked" might not be the right event to listen for. I'm not sure what event is pushed when a sheild is hit. It might be "blocked" or "hit" or something. If it uses the same method the in-game shield does, then you could look in it's component file and find out the event name that happens when it blocks a hit. (it would look something like    inst:PushEvent"eventname" )

7 minutes ago, pickleplayer said:

 

And does that code work if you try to run it? (by "work" I just mean; does the game not crash when it runs)

would this be in a custom component file or is this just in the character's file?

For the first part....would be a smart idea to check that wouldn't it? woops

As for the second one I think making it a component file it would not only be more clean but also would allow me to use it/slighlty modify it for future characters so....Custom component file is the intention

 

I'll look into finding just what event is and y'know actually put it in to see if it works, as for the timercreate iunno, I mean from what i've seen Timer.create IS a Lua thing but it might not work.

 

What about that whole setting states to true and false? would that be how it's done or is it even needed to be done? or with the timer would I make it look (AKA reset timer or goto - Timer inst)?

Well you can find all the code for the forcefeild in hats.lua. its burried in with the code for all the other hats, but it looks like most of what you want is under "ruinshat_proc" on line 114.

 

Or wait a minute. so you want this forcefeild to just be like an armor that regenerates right? You could just make it like a regular peice of armor except that it absorbs all damage and, after a certain time, slowly starts repearing itself. It'd probably be MUCH less complicated to take that aproach. Just take an existing armor item and alter the code to allow it to work like a perminant stat instead of an article of clothing.

Not as an Armour item, the plan is to have it as an actual stat (Similar to Woodie has his unique beaverness stat)

 

The thing is as well making it as armour is I'd have to make sure it doesn't vanish when it hits 0, make it so only the one character can wear it and such

 

I'll look into doing it that way but I would much prefer it to be an actual stat

Edited by Tik115
On 18/01/2016 at 9:37 PM, pickleplayer said:

Oh I know you want it to be a stat but I'm saying you could try to re-work an armor item to function as a stat. Otherwise it sounds like it be really complicated and I'd have no idea where to even start.

Would there be a way to make it be unequpable or to destroy on drop? making it so it will check there's one in the inventory and to add one if there isn't would probs be easy but those two from what I see from people asking for help seems to be a little illusive

 

also I assume to prevent it breaking it would simply not call the "break" component to it and instead turn it's absorbtion to 0?

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