Jump to content

Recommended Posts

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 by TheShadeofTheNorth

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 = 6

end)

 

EDIT: And keep your kisses to your girl-/boyfriend. Don't make 'em jealous :p

Edited by Mobbstar

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 by TheShadeofTheNorth

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

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 by TheShadeofTheNorth

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)

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 by TheShadeofTheNorth

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.

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 :(

 

 

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.

 

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 : 

G7iBnql.png

 

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 by TheShadeofTheNorth

Actually, yes LOL . I forgot about that  :hypnotized:  :hypnotized:  :hypnotized:  :hypnotized:

 

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 by TheShadeofTheNorth

 

Actually, yes LOL . I forgot about that  :hypnotized:  :hypnotized:  :hypnotized:  :hypnotized:

 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

    return

end

 

See?

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