[Script] for timed effects with stats
Posted: Mon Oct 01, 2012 9:00 pm
I need to create some items (potions) with temporarily incremented character stats like Strength, Dexterity, Vitality...
This is my working script for strength boost. In onUseItem hook you can create your own timed effect and in the script function stopEffect_ returns values back. Problem is with too much functions for deactivate timers. Deactivating the timers for effects is some sort of "luberjack" script because I don't find the way to call function with PARAMETER from connector.
It would be much simplier by using some sort of this: addConnector("activate","scriptEffects","stopEffect(PARAMETER)")
@AH: is there any way to connect function with parameter from spawned timer?
Script entity with ID=scriptEffects
Clone object in items.lua
This is my working script for strength boost. In onUseItem hook you can create your own timed effect and in the script function stopEffect_ returns values back. Problem is with too much functions for deactivate timers. Deactivating the timers for effects is some sort of "luberjack" script because I don't find the way to call function with PARAMETER from connector.
It would be much simplier by using some sort of this: addConnector("activate","scriptEffects","stopEffect(PARAMETER)")
@AH: is there any way to connect function with parameter from spawned timer?
Script entity with ID=scriptEffects
Code: Select all
-- script for timed effects --
--
-- "strBoost": increasing strength
--
ActiveEffect = {}
function activateEffect(effect, champion, amount, duration)
if self.ActiveEffect[effect.."_"..champion] then
return false
end
fw.debugPrint("Effect "..effect.." is activated: Champion="..champion..", Amount="..amount..", Duration="..duration.."s")
self.ActiveEffect[effect.."_"..champion] = { amount=amount, duration=duration }
local timer = findEntity("timer_effect_"..effect.."_"..champion)
timer:setTimerInterval(duration)
timer:activate()
return true
end
function stopEffect_strBoost(id)
local champion = party:getChampion(id)
champion:setStatMax("strength", champion:getStatMax("strength") - self.ActiveEffect["strBoost_"..id].amount)
self.ActiveEffect["strBoost_"..id] = nil
local timer = findEntity("timer_effect_strBoost_"..id)
timer:deactivate()
playSound("generic_spell")
print("strBoost deactivated for champion="..id)
print("Actual Stat="..champion:getStat("strength")..", StatMax="..champion:getStatMax("strength"))
hudPrint(champion:getName().." feels less stronger!")
end
function stopEffect_strBoost_1()
self.stopEffect_strBoost(1)
end
function stopEffect_strBoost_2()
self.stopEffect_strBoost(2)
end
function stopEffect_strBoost_3()
self.stopEffect_strBoost(3)
end
function stopEffect_strBoost_4()
self.stopEffect_strBoost(4)
end
spawn("timer",1,1,1,0, "timer_effect_strBoost_1")
timer_effect_strBoost_1:addConnector("activate","scriptEffects","stopEffect_strBoost_1")
spawn("timer",1,1,1,0, "timer_effect_strBoost_2")
timer_effect_strBoost_2:addConnector("activate","scriptEffects","stopEffect_strBoost_2")
spawn("timer",1,1,1,0, "timer_effect_strBoost_3")
timer_effect_strBoost_3:addConnector("activate","scriptEffects","stopEffect_strBoost_3")
spawn("timer",1,1,1,0, "timer_effect_strBoost_4")
timer_effect_strBoost_4:addConnector("activate","scriptEffects","stopEffect_strBoost_4")Code: Select all
cloneObject{
name = "potion_giant_strength",
baseObject = "potion_healing",
uiName = "Potion of Giant Strength",
description = "After drink, character obtain the Giant Strenght for 1 minute.",
gfxIndex = 149,
onUseItem = function(self, champion)
playSound("consume_potion")
local effect = "strBoost"
local amount = 10
local duration = 60
local str_old = champion:getStatMax("strength")
local isActive = scriptEffects.activateEffect( effect, champion:getOrdinal(), amount, duration)
if isActive then
champion:modifyStatCapacity("strength", amount)
champion:modifyStat("strength", amount)
print("Actual Str="..str_old..", Max="..champion:getStatMax("strength"))
hudPrint(champion:getName().." feels much stronger!")
else
hudPrint(champion:getName().." can use only one effect of Giant Strength at the same time!")
end
return true
end,
weight = 0.6,
}