TheShadeofTheNorth Posted July 11, 2015 Share Posted July 11, 2015 YES PEEPS! I need to know how to check damage taken, who answer my question right will receive a kiss in the cheek . Thanks! Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/ Share on other sites More sharing options...
Mobbstar Posted July 11, 2015 Share Posted July 11, 2015 inst:ListenForEvent("attacked",function(inst,data)end) or the "healthdelta" event, which fires whenever the health changes (you need to check whether it's damage then) Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653619 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 11, 2015 Author Share Posted July 11, 2015 (edited) Ooooooooh, here... a kiss! The thing is, can you give me an example of an if else statement with event listeners @%1; ? I made a code without an event listener 2 days ago, well, didn't work,but didn't crashed hahaha.local Rage = function(inst) local init_damage = damageinst:DoPeriodicTask(1, function() if damage > 0 and self.inst.components.health:IsInvincible() == false then local RageChance = math.random()end if RageChance > 0.5 then inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULT * 2inst.components.locomotor.walkspeed = 12 inst.components.locomotor.runspeed = 12else inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULT inst.components.locomotor.walkspeed = 4 inst.components.locomotor.runspeed = 6endend)end Edited July 11, 2015 by TheShadeofTheNorth Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653629 Share on other sites More sharing options...
Mobbstar Posted July 11, 2015 Share Posted July 11, 2015 (edited) Ooooooooh, here... a kiss! The thing is, can you give me an example of an if else statement with event listeners @%1; ? I made a code without an event listener 2 days ago, well, didn't work,but didn't crashed hahaha. For starters, a periodic task is created once. You can usually create it in the main function "fn", though in your case you may be trying to create a "rage form" of sorts. If so, keep a variable for the task so you can cancel it when needed (e.g. "inst.ragetask = inst:DoPeriodic...." -> "inst.ragetask:Cancel()") .Where does "damage" come from? If you never made a variable with that name, it'll crash obviously, because there is no "damage" declared yet. More importantly, what's "init_damage" for? Actually, I think you may want to listen for the event "onhitother" i.e. attacking something. Here's my suggestion (not tested ingame): inst:ListenForEvent("onhitother", function(inst,data) --do this whenever the instance hits something if data.damage > 0 and not self.inst.components.health:IsInvincible() then --"not" means what it sounds like if math.random() > 0.5 then --do the chance thing directly, as the local variable didn't get out of this if block inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULT * 2 inst.components.locomotor.walkspeed = 12 inst.components.locomotor.runspeed = 12 return --that makes the function stop here, meaning the last part is only accessed if this code didn't already run end end inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULT inst.components.locomotor.walkspeed = 4 inst.components.locomotor.runspeed = 6end) EDIT: And keep your kisses to your girl-/boyfriend. Don't make 'em jealous Edited July 11, 2015 by Mobbstar Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653634 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 11, 2015 Author Share Posted July 11, 2015 (edited) Lol , not even me know what init_damage was for , got lost on my thoughs that day LOL. You explained very well, kisses to you thank you! I'll see if the code works right now. Btw, do you know how to use the print command? ;-; Edited July 11, 2015 by TheShadeofTheNorth Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653639 Share on other sites More sharing options...
Mobbstar Posted July 11, 2015 Share Posted July 11, 2015 Lol , not even me know what init_damage was for , got lost on my thoughs that day LOL. You explained very well, kisses to you thank you! I'll see if the code works right now. Btw, do you know how to use the print command? ;-; You use print like this: print("This is a string, you can place an unlimited amount of variables, data or strings in the parentheses if you seperate them with commas, like so",42,init_damage,"foo") Looks in the log like this: This is a blablabla like so 42 nil foo Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653649 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 11, 2015 Author Share Posted July 11, 2015 (edited) Oh, awesome,everything worked ! Now i just need to set the time the character will have the speed and damage boost , 'cause it gets the buff for 1 sec and everything go back to normal. I wanted something like 10~15 sec(similar to settimeout in javascript). I think i'm bothering you too much, sorry haha. Edited July 11, 2015 by TheShadeofTheNorth Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653654 Share on other sites More sharing options...
Mobbstar Posted July 12, 2015 Share Posted July 12, 2015 Oh, awesome,everything worked ! Now i just need to set the time the character will have the speed and damage boost , 'cause it gets the buff for 1 sec and everything go back to normal. I wanted something like 10~15 sec(similar to settimeout in javascript). I think i'm bothering you too much, sorry haha. Set him to rage and at the same time do: inst:DoTaskInTime(seconds,function) by the way, you can use "math.random" not only for chance calculations, but also for a random number between x and y: math.random(10,15) Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653717 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 12, 2015 Author Share Posted July 12, 2015 (edited) So , the purpose of inst:DoTaskInTime is to set a timer to a task? Another thing learned today boys LOL. Well it worked but it delays the rage form ,i think you misunderstood(and dunno why i mentioned the setimeout function wtf) , what i wanted was to add a duration to the boost the rage function provided. Plot twist : Or maybe i'm doing everything wrong . It's like that right now : inst:ListenForEvent("attacked", function(inst,data) if data.damage > 0 then and not self.inst.components.health:IsInvincible() then if math.random() > 0.5 then inst:DoTaskInTime(15,function(inst,data) inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULT * 2 inst.components.locomotor.walkspeed = 10 inst.components.locomotor.runspeed = 10 print ("RAGE!") return end) end end inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULT inst.components.locomotor.walkspeed = 5 inst.components.locomotor.runspeed = 7end) Ty for the reply! Edited July 12, 2015 by TheShadeofTheNorth Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653727 Share on other sites More sharing options...
Mobbstar Posted July 12, 2015 Share Posted July 12, 2015 So , the purpose of inst:DoTaskInTime is to set a timer to a task? Another thing learned today boys LOL. Well it worked but it delays the rage form ,i think you misunderstood(and dunno why i mentioned the setimeout function wtf) , what i wanted was to add a duration to the boost the rage function provided. Plot twist : Or maybe i'm doing everything wrong . Ty for the reply! No, you leave the thing as is, but set a timer for turning it off again. Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653728 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 12, 2015 Author Share Posted July 12, 2015 I tried the inverse code inst:ListenForEvent("attacked", function(inst,data) --do this whenever the instance gets attacked if data.damage > 0 and not self.inst.components.health:IsInvincible() then if math.random() > 0.5 then-- self.inst.components.talker:Say("YAAAAAAAAAAAAAAAAR") inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULT * 1.5 inst.components.locomotor.walkspeed = 10 inst.components.locomotor.runspeed = 10 print ("RAGE!")inst:DoTaskInTime(15, function() inst.components.locomotor.walkspeed = 5 inst.components.locomotor.runspeed = 7 end) return end end inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULT inst.components.locomotor.walkspeed = 5 inst.components.locomotor.runspeed = 7end)Still the same 1 sec effect Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653783 Share on other sites More sharing options...
Mobbstar Posted July 12, 2015 Share Posted July 12, 2015 I tried the inverse code inst:ListenForEvent("attacked", function(inst,data) --do this whenever the instance gets attacked if data.damage > 0 and not self.inst.components.health:IsInvincible() then if math.random() > 0.5 then-- self.inst.components.talker:Say("YAAAAAAAAAAAAAAAAR") inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULT * 1.5 inst.components.locomotor.walkspeed = 10 inst.components.locomotor.runspeed = 10 print ("RAGE!")inst:DoTaskInTime(15, function() inst.components.locomotor.walkspeed = 5 inst.components.locomotor.runspeed = 7 end) return end end inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULT inst.components.locomotor.walkspeed = 5 inst.components.locomotor.runspeed = 7end)Still the same 1 sec effect Try adding a print() in the undo function? I don't see why it would have a delay, based on this code. In general, when confusion rises, it's not a bad idea to spam print() in every single if-block that's faintly related. Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653789 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 12, 2015 Author Share Posted July 12, 2015 (edited) Yeah, the rage is still working for one second,based on the code the rage was supposed to stop only after 15 seconds. I used print on the function when he does not rage and provoked some bees. See what i got : It is working, but the effect of the rage do not last, i can see the character bursting for 1 sec and then BAM , he goes to normal running again. I'll print the undo function and i'll see what i can get. EDIT: Yeah, after 15 sec i got the print command in the console, i don't kno why it's not working properly. Edited July 12, 2015 by TheShadeofTheNorth Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653805 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 13, 2015 Author Share Posted July 13, 2015 (edited) OKay i give up, can't figure out why this is only lasting 1 sec. *TheShadeofTheNorth has disconnected* . Edited July 13, 2015 by TheShadeofTheNorth Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653886 Share on other sites More sharing options...
Mobbstar Posted July 13, 2015 Share Posted July 13, 2015 OKay i give up, can't figure out why this is only lasting 1 sec. *TheShadeofTheNorth has disconnected* . Do you modify any of the stats in another chunk of code? Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653889 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 13, 2015 Author Share Posted July 13, 2015 (edited) Actually, yes LOL . I forgot about that inst:ListenForEvent("hungerdelta", function(inst, data) if (inst.components.hunger.current < 30) then -- current hunger percent--print ("Super Hungry!") inst.components.sanity.dapperness = TUNING.DAPPERNESS_MED*-2 inst.components.locomotor.walkspeed = 2 inst.components.locomotor.runspeed = 2 elseif (inst.components.hunger.current < 60) then -- current hunger percent-- print ("Hungry!") inst.components.sanity.dapperness = TUNING.DAPPERNESS_MED*-1.5 inst.components.locomotor.walkspeed = 3 inst.components.locomotor.runspeed = 4 elseif (inst.components.hunger.current < 100) then -- current hunger percent-- print (" Getting hungry!") inst.components.sanity.dapperness = TUNING.DAPPERNESS_MED*-1 inst.components.locomotor.walkspeed = 5 inst.components.locomotor.runspeed = 7 else -- when it becomes more than or equal to 100 inst.components.locomotor.walkspeed = 5 inst.components.locomotor.runspeed = 7 endend) 90% it's the culprit, testing right now. I'm such an idiot. EDIT: IT IS the culprit. Now i got a problem, i need to make one not to interfere with another,well,more tasks ahead for me! Yaay!Mobbstar the genius strikes agaiiiiin! HAHAHAHA Edited July 13, 2015 by TheShadeofTheNorth Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653894 Share on other sites More sharing options...
Mobbstar Posted July 13, 2015 Share Posted July 13, 2015 Actually, yes LOL . I forgot about that 90% it's the culprit, testing right now. I'm such an idiot. EDIT: IT IS the culprit. Now i got a problem, i need to make one not to interfere with another,well,more tasks ahead for me! Yaay!Mobbstar the genius strikes agaiiiiin! HAHAHAHA It happens to the best of us. Anyways, this one is easy to solve. When the character enrages, create a boolean for that: inst.rage = true in the undo function, you undo it like so: inst.rage = false or inst.rage = nil in the hungerbased check, you first and foremost test for that variable rage. if inst.rage then returnend See? Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653896 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 13, 2015 Author Share Posted July 13, 2015 Mobbstar, the one and only , the savior of the humanity, thanks a lot! Now i can get in some dark stuff like make the character glow and another perks.Seriously, your help made me continue with the ideia of a berseker character. Link to comment https://forums.kleientertainment.com/forums/topic/56083-damage-checks/#findComment-653898 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now