function in a cloned object definition: question
Posted: Sat Feb 07, 2015 6:47 pm
I'm going to make a wizard object that give party underwater breathing ability while in hand and until wizard have energy left.
To make wizard consume energy while holding that object i set, in 'onEquipItem', to spawn a timer that call a function. But as i thought i can't just put the function in the "onEquipItem" component.
Is there a way to place the function directly inside object code, without the need to place a script entity in game with that function and call this function form the object.
If can help my script so far is:
Commented function (function scendeEnergiaVigorsol()) is the function that cause editor crash.
To make wizard consume energy while holding that object i set, in 'onEquipItem', to spawn a timer that call a function. But as i thought i can't just put the function in the "onEquipItem" component.
Is there a way to place the function directly inside object code, without the need to place a script entity in game with that function and call this function form the object.
If can help my script so far is:
Code: Select all
defineObject{
name = "vigorsol_bowl",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/essence_air.fbx",
},
{
class = "Item",
uiName = "Vigorsol bowl",
description = "A fresh air explosion. Uses energy over time.",
gfxIndex = 347,
impactSound = "impact_blunt",
weight = 1,
traits = { "two_handed" },
onEquipItem=function(self,champion,slot)
if slot==1 or slot==2 or slot==11 or slot==12 then
local energiaRimasta=champion:getEnergy()
if energiaRimasta > 0 then
for i = 1, 4, 1 do
party.party:getChampion(i):setConditionValue("water_breathing", 360)
end
end
local xParty, yParty, dParty, lParty = party:getPosition()
spawn("timer",lParty,1,1,1,0,"timerEnergiaVigorsol")
--local timerVigorsol = findEntity("timerDanno_" .. nFuocoFatuo)
timerEnergiaVigorsol.timer:setTimerInterval(1)
timerEnergiaVigorsol.timer:setDisableSelf(false)
timerEnergiaVigorsol.timer:setTriggerOnStart(true)
timerEnergiaVigorsol.timer:setCurrentLevelOnly(false)
timerEnergiaVigorsol.timer:addConnector("onActivate", self.go.id, "scendeEnergiaVigorsol")
timerEnergiaVigorsol.timer:start()
--[[
function scendeEnergiaVigorsol()
energiaRimasta=champion:getEnergy()
if energiaRimasta > 0 then
champion:setEnergy(energiaRimasta-100)
elseif energiaRimasta <=0 then
timerEnergiaVigorsol:destroy()
for i = 1, 4, 1 do
party.party:getChampion(i):removeCondition("water_breathing")
end
end
end
--]]
end
end,
onUnequipItem=function(self,champion,slot)
if slot==1 or slot==2 or slot==11 or slot==12 then
for i = 1, 4, 1 do
party.party:getChampion(i):removeCondition("water_breathing")
end
end
timerEnergiaVigorsol:destroy()
end
},
{
class = "Particle",
particleSystem = "essence_air",
},
{
class = "Light",
offset = vec(0, 0.4, 0),
range = 1.5,
color = vec(0.5, 1, 1),
brightness = 30,
castShadow = false,
},
{
class = "EquipmentItem",
slot = "Weapon",
},
},
}