Attachables that Heal the Wearer
Author |
Message |
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Attachables that Heal the Wearer
Either theres a typo in there that I can't see or it's not getting the backpack/actor (assuming it's attached to the actor from the start).
Also, are you checking in the actor veiwer? Cause from what I know scripts won't be able to find other MOs when in the editors.
|
Wed Jul 25, 2012 12:45 am |
|
|
CombatMedic02
Joined: Wed Dec 17, 2008 11:35 am Posts: 122 Location: London
|
Re: Attachables that Heal the Wearer
No? I'm checking in the test scenario on what use to be the skirmish game type bit. The backpack is definitely on him because I see it? >_< Just the lua isn’t working for some odd reason?
|
Wed Jul 25, 2012 1:38 am |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Attachables that Heal the Wearer
Try this instead. Code: function Update(self) if self.wearer == nil then for parent in MovableMan.Actors do if self.RootID = parent.RootID then self.wearer = ToAHuman(parent) break end end else if self.wearer.Health < 100 then self.wearer.Health = self.wearer.Health + 1 end end
end
|
Wed Jul 25, 2012 3:24 am |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
Re: Attachables that Heal the Wearer
Or try this, if that one fails. Code: function Update(self) if self.wearer == nil then for parent in MovableMan.Actors do if self.RootID = parent.ID then self.wearer = ToAHuman(parent) break end end else if self.wearer.Health < 100 then self.wearer.Health = self.wearer.Health + 1 end end
end
|
Wed Jul 25, 2012 4:09 am |
|
|
Bad Boy
Joined: Fri Sep 10, 2010 1:48 am Posts: 666 Location: Halifax, Canada
|
Re: Attachables that Heal the Wearer
I don't see any difference between those two, I think you may have pasted the wrong thing in Roast. Either way, both have a typo (line 4: = instead of ==), so instead of coops' version use this one without the typo: Code: function Update(self) if self.wearer == nil then for parent in MovableMan.Actors do if self.RootID == parent.ID then self.wearer = ToAHuman(parent) break end end else if self.wearer.Health < 100 then self.wearer.Health = self.wearer.Health + 1 end end
end Also, for the sake of making sure things work every step of the way, if this doesn't work then I'd suggest adding the following lines to your create function: print (self.RootID); if you get a number that isn't 255 then try print(MovableMan:GetMOFromID(self.RootID).PresetName); The second one was suggested before but unless I miscounted lines the problem seemed to be with the line below it. This should cause the console to show your actor's name. Also, you can always put up the rte, with that someone can go through it and probably fix the problem quickly and easily instead of having to wait on replies and stuff.
|
Wed Jul 25, 2012 6:36 am |
|
|
CombatMedic02
Joined: Wed Dec 17, 2008 11:35 am Posts: 122 Location: London
|
Re: Attachables that Heal the Wearer
Yay! That works! Many thanks Roast, Coops and Bad Boy. One final question, it heals like... instantly is there anyway I can slow it down a bit? Also how can I add fancy healing effects such as little glowing plus signs? Never had to make a .ini effect for a lua script process before, not sure how they'd link up.
|
Wed Jul 25, 2012 10:03 am |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Attachables that Heal the Wearer
You will need two things. Timers, so that you can space out the healing, and the healing effect in the ini. Timers are relatively simple to work with. Define it at the start of the script, preferably in the create function. Code: function Create(self)
self.healTimer = Timer()
end
All you need to do is have a timer check if it goes past a certain time and if it does, heal the wearer and reset the timer and have a repeating fashion. Code: else if self.wearer.Health < 100 then if self.healTimer:IsPastSimMS('Heal Time In Miliseconds') then self.wearer.Health = self.wearer.Health + 1 self.healTimer:Reset() end else self.healTimer:Reset() end end
You will want a number of timer reset functions in certain places to make sure that your timer isn't going when you don't want it to. The healing effect can be just a simple MOPixel with a glow attached to it (With certain floaty properties if that's your preference), then define it in the script. You will need to define certain other properties for it first though, one most important is the position of the particle, without that your healing effect will just show up in the top left corner of the map since it doesn't have a vector to show where it goes. Code: local healEffect = CreateMOPixel('Your heal effect's name here') healEffect.Pos = self.wearer.Pos + Vector(math.random(-3,3),math.random(-3,3)) healEffect.Vel = Vector(math.random(-5,5),math.random(-5,5)) MovableMan:AddParticle(healEffect)
Add a couple of math.randoms and you got exactly what you want. Do note the comments in the script on where you need to enter in what you want. Code: function Create(self)
self.healTimer = Timer()
end
function Update(self) if self.wearer == nil then for parent in MovableMan.Actors do if self.RootID == parent.ID then self.wearer = ToAHuman(parent) break end end else if self.wearer.Health < 100 then if self.healTimer:IsPastSimMS('Heal Time In Miliseconds') then -- Need a time here self.wearer.Health = self.wearer.Health + 1 for i = 1, math.random(1,3) do local healEffect = CreateMOPixel('Your heal effect's name here') -- Need your Effect's name here healEffect.Pos = self.wearer.Pos + Vector(math.random(-3,3),math.random(-3,3)) healEffect.Vel = Vector(math.random(-5,5),math.random(-5,5)) MovableMan:AddParticle(healEffect) end end else self.healTimer:Reset() end end
end
Also sorry if there ends up being a typo in the script, It's six in the morning where I am.
|
Wed Jul 25, 2012 2:09 pm |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
Re: Attachables that Heal the Wearer
Bad Boy wrote: I don't see any difference between those two, I think you may have pasted the wrong thing in Roast. I swapped parent.RootID with parent.ID, as you did in your script. Here's another minor alteration, all the things you need to change are in the Create function for ease of editing. Code: function Create(self) self.healTimer = Timer(); self.healTime = 1000; --The time delay between healing one point of health, currently one second. self.healEffect = "Heal Effect"; --The PresetName of your healing effect. end
function Update(self) if self.wearer == nil then for parent in MovableMan.Actors do if self.RootID == parent.ID then self.wearer = ToAHuman(parent); break; end end else if self.wearer.Health < 100 then if self.healTimer:IsPastSimMS(self.healTime) then self.wearer.Health = self.wearer.Health + 1; for i = 1, math.random(1,3) do local healEffect = CreateMOPixel(self.healEffect); healEffect.Pos = self.wearer.Pos + Vector(math.random(-3,3),math.random(-3,3)); healEffect.Vel = Vector(math.random(-5,5),math.random(-5,5)); MovableMan:AddParticle(healEffect); end end else self.healTimer:Reset(); end end end
|
Wed Jul 25, 2012 2:38 pm |
|
|
CombatMedic02
Joined: Wed Dec 17, 2008 11:35 am Posts: 122 Location: London
|
Re: Attachables that Heal the Wearer
Aww, you guys are too good to me. Thanks a million! I even understand things a little better now too. I'm going to go play around with heal effects now. Thanks again!
|
Wed Jul 25, 2012 3:09 pm |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Attachables that Heal the Wearer
I just noticed I forgot to put in a reset for the timer when it heals. Code: function Create(self) self.healTimer = Timer(); self.healTime = 1000; --The time delay between healing one point of health, currently one second. self.healEffect = "Heal Effect"; --The PresetName of your healing effect. end
function Update(self) if self.wearer == nil then for parent in MovableMan.Actors do if self.RootID == parent.ID then self.wearer = ToAHuman(parent); break; end end else if self.wearer.Health < 100 then if self.healTimer:IsPastSimMS(self.healTime) then self.wearer.Health = self.wearer.Health + 1; for i = 1, math.random(1,3) do local healEffect = CreateMOPixel(self.healEffect); healEffect.Pos = self.wearer.Pos + Vector(math.random(-3,3),math.random(-3,3)); healEffect.Vel = Vector(math.random(-5,5),math.random(-5,5)); MovableMan:AddParticle(healEffect); end self.healTimer:Reset() end else self.healTimer:Reset(); end end end Also I made it parent.RootID because it's sort of an extra check to make sure it's getting the actor. Because the scripted object's RootID could be something completely different if the actor was attached to something, otherwise parent.ID and parent.RootID would be the exact same thing.
|
Wed Jul 25, 2012 4:03 pm |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
Re: Attachables that Heal the Wearer
The actor can't be attached to anything, and the risk of getting one of the actor's attachables instead of the actor instead could cause problems.
|
Wed Jul 25, 2012 4:06 pm |
|
|
Bad Boy
Joined: Fri Sep 10, 2010 1:48 am Posts: 666 Location: Halifax, Canada
|
Re: Attachables that Heal the Wearer
Roast Veg wrote: I swapped parent.RootID with parent.ID, as you did in your script. Ah, I didn't even notice that, guess I copied your script rather than Coops'. But yeah, I'm with Roast. Since parent is already set to be what we want, we don't want to check for the RootID again. Also, as was mentioned there's the problem that you'll get anything attached to the parent since its RootID would also equal parent.RootID. Gotta watch out for unintended consequences
|
Wed Jul 25, 2012 10:52 pm |
|
|
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
|
Re: Attachables that Heal the Wearer
Great script this, I used it in my custom faction. However is there anyway to add a delay between each +1 hp tick? Like a sleep or wait command or so. Cause right now there's only the delay before the healing actually starts, but once it gets going actors get healed to 100 nearly instantly.
|
Thu Feb 21, 2013 9:51 pm |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
Re: Attachables that Heal the Wearer
The code in this thread is outdated and needlessly complex what with the new attachable scripting system. It should, however, still work properly and there should be a one second delay between each health point regained (self.healTime).
|
Fri Feb 22, 2013 5:15 am |
|
|
Shook
Joined: Fri Feb 16, 2007 8:43 pm Posts: 1695 Location: AH SHIT FUCK AUGH
|
Re: Attachables that Heal the Wearer
Also, popping by to say that you COULD just make the attachable an emitter (so do AddEmitter = AEmitter instead of AddAttachable = Attachable) that has a negative EmissionDamage (can have decimals), and have it emit a null particle (such as Null Bullet from Base.rte). No need for all that crazy Lua when a simple INI thing will do. :U For an example of a POSITIVE EmissionDamage value, see basically every wound in Base.rte/Wounds.ini. Slap a minus in front of that number, and the wounds will actually heal over time rather than damage. Note though, BurstDamage is separate from EmissionDamage, and is only triggered once (with the one common exception being jetpacks).
|
Fri Feb 22, 2013 2:18 pm |
|
|
|
Who is online |
Users browsing this forum: Google [Bot] |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|