viewtopic.php?f=14&t=3099&start=60
someone know how to add the same effect, but in a potion?nichg wrote:Featherfall Effect
I was asked to repost this here. This is an effect that lets you give the party 'feather fall' for a fixed time, during which all falls through pits will deal no damage. It does not prevent the sound-effects associated with falling however.
The effect requires three things:
- You have to clone the party object in init.lua for the dungeon, and override the onMove and onDamage hooks:
This refers to a scripting object var_storage that must exist somewhere in your dungeon. Every time the party moves, it decrements the duration of their feather fall (you could just as well tie this to a timer to make it realtime). Furthermore, it stores the party's current dungeon level in a global variable in the storage object. When the party falls, their level changes before they take damage, but after onMove is called, so if the stored level and current level are different in onDamage, we know that we've taken damage due to falling down a pit (ostensibly this would also detect coincidences like falling into a fireball or something as falling damage, so there's a small chance it creates some spurious behavior).Code: Select all
cloneObject { name = "party", baseObject = "party", onMove = function(party, dir) var_storage.set_last_level(party.level) var_storage.decrement_feather() return true end, onDamage = function(champion, dmg, dmgtype) if party.level ~= var_storage.get_last_level() then if var_storage.get_feather() then -- Feather fall return false end end return true end }
Now, place a scripting object called 'var_storage' somewhere in the dungeon, with the following code on it:
This scripting object carries global variables indicating whether the party is under the feather fall effect or not, as well as the last level. Since they're global they should be saved, so feather fall will persist across save/load. You must call var_storage.set_feather(15), for example, in order to give the party the feather fall effect (for instance from a potion use script or a spell script, or if the party interacts with a particular fountain or whatever). That would last for 15 steps, and display a message when the effect ended.Code: Select all
last_level = 1 feather_fall = false feather_dur = 0 function set_feather(dur) feather_fall = true feather_dur = dur hudPrint("You feel lighter.") end function decrement_feather() if feather_fall == true then feather_dur = feather_dur - 1 if feather_dur <= 0 then feather_fall = false hudPrint("You feel heavier.") end end end function get_feather() return feather_fall end function set_last_level(lev) last_level=lev end function get_last_level() return last_level end
In principle this setup could be used to create any number of custom conditions or persistent spell effects. I'm not sure yet how to give graphical feedback for the effects, but ostensibly you could do something with creating a light source with particle system and move it with the party so long as the effect is up, then destroying it when the effect ends. I think it'd be weird with teleporters and pitfalls though, since there you move after onMove is done.
