Page 1 of 1

Screen shake onDamage possible?

Posted: Tue Dec 11, 2012 1:45 am
by Rook
I'm just curious whether it is possible to add a minor screenshake upon taking damage or landing critical hits. I've been messing around with a few scripts, but I'm unable to get any solid results.

Re: Screen shake onDamage possible?

Posted: Tue Dec 11, 2012 1:47 am
by Skuggasveinn
onDealDamage = function(self, champion, damage)
party:shakeCamera(0.5, 0.3)
party:playScreenEffect("damage_screen")

something along this line ?

Re: Screen shake onDamage possible?

Posted: Tue Dec 11, 2012 1:52 am
by Rook
That basically the same to what I'm using. I'm just not sure what to add for (self, champion, damage). Especially damage.

Re: Screen shake onDamage possible?

Posted: Tue Dec 11, 2012 2:12 am
by Komag
you don't need to add anything if you don't want to, they're just useful options

Re: Screen shake onDamage possible?

Posted: Tue Dec 11, 2012 2:19 am
by JohnWordsworth
I would consider doing something like the following in order to have the screen shake whenever the player takes damage (it's a tad harder for monsters, as you have to hook into every monster I believe).

You have to modify the default behaviour when the player takes damage by adding a party hook - these let you have custom lua functions, that you define, called when certain things happen to the party. Either add the following to init.lua or add it to a new file, party.lua and then add an import line to your init file to link in the new file.

Simple Shake Code (based on @Skugasveinn's script).

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",
  onDamage = function(champion, damage, damType)
    party:shakeCamera(0.5, 0.3);
    party:playScreenEffect("damage_screen");
    return true;
  end,
}
Slightly More Complex Shake Code (shakes more on more damage).

The function bit defines your custom logic - champion, damage and damType are parameters passed to your code from the game engine. Here we use those to shake the screen more if you take a higher proportion of damage.

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",
  onDamage = function(champion, damage, damType)
    local intensity = damage / champion:getStatMax("health");
    party:shakeCamera(intensity, 0.3);
    party:playScreenEffect("damage_screen");
    return true;
  end,
}

Re: Screen shake onDamage possible?

Posted: Tue Dec 11, 2012 2:31 am
by Rook
That LUA works wonderfully. Much thanks, John. :)

Re: Screen shake onDamage possible?

Posted: Tue Dec 11, 2012 4:57 am
by Komag
Those are pretty straightforward and clear. I love messing with simple math in functions, it can get clever very fast, good stuff. :)

You can also leave off the "return true" line. It always returns true as a default, you only need to put something if you want it to "return false" or perhaps return some other value (rare/advanced).

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",
  onDamage = function(champion, damage, damType)
    party:shakeCamera(0.5, 0.3);
    party:playScreenEffect("damage_screen");
  end,
}

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",
  onDamage = function(champion, damage, damType)
    local intensity = damage / champion:getStatMax("health");
    party:shakeCamera(intensity, 0.3);
    party:playScreenEffect("damage_screen");
  end,
}