Page 2 of 2
Re: Bastien067 experiments, new assets and other...
Posted: Fri Nov 02, 2012 9:19 am
by cromcrom
Hi, shouldn't the last "end" be followed by a coma like "end," ?
Re: Bastien067 experiments, new assets and other...
Posted: Fri Nov 02, 2012 1:02 pm
by bastien067
Thank you for all your comments.
It dont need a coma after the last "end", i works perfectly like this.
I continue with the monk spell, and i'm trying to make a heal over timer, something like : "heals 5 hp every 3 seconds for 30 seconds..."
So i started this code :
Code: Select all
defineSpell{
name = "monk_hot",
uiName = "Vitality of the Bear",
skill = "unarmed_combat",
level = 5,
runes = "ABC",
manaCost = 20,
onCast = function(champion, x, y, direction, skill,)
monk_hot_timer:destroy()
spawn("timer", party.level, party.x, party.y, party.facing, "monk_hot_timer")
playSound("heal_party")
monk_hot_timer:setTimerInterval(3)
monk_hot_timer:activate()
if monk_hot_timer:isActivated(true)
then
champion:modifyStat("health", 5)
end
end,
}
So for the moment it's not complete ...
This code is supposed to heal the monk every 5 seconds.. that all, there is no 30 sec limit : it's just for testing purposes for the moment..
But it dont work and i dont undertand why ! i tried a lot of things... i think this is the way I use monk_hot_timer:isActivated that is wrong.. but i don't know how to solve it... When i try to launch the project in the éditor it says : <name> or '...' expected near ')' but it don't help me to undersand...
Can you help me with this on please ?
Re: Bastien067 experiments, new assets and other...
Posted: Fri Nov 02, 2012 1:19 pm
by cromcrom
Maybe there is an issue with spawning Timers. Just create it in your mod, and activate it when needed ?
Then maybe you will need a function that is called by the timer, and heals the champion.
You can also check the error.log in LoG, it most of the times provides usefull informations.
Then, try to print stuff (print("stuff")), it can help you figure out where something is going wrong (I have had looooots of issues with nil values ^^)
Re: Bastien067 experiments, new assets and other...
Posted: Fri Nov 02, 2012 1:25 pm
by Grimwold
Firstly.. I think for a spell as complicated as this you will need to put the bulk of the code in a script entity in your dungeon. e.g.
Code: Select all
onCast = function(champion, x, y, direction, skill)
return monk_hot_script.beginHeal(champion,skill)
end
then create a script entity in your dungeon called
monk_hot_script and write your code in the form of a function called
beginHeal
You will need to create a variable in that script entity that stores the champion you want to heal (because the timer you spawn will not know which champion originally cast the spell!) and you will also need a function in the same script entity that you will activate every time the timer hits 3 seconds to perform the heal.
If I have time I will have a little play around with some script and try to put together an example.
(my Hold Monster Spell is an example of how to handle a more complicated duration type spell -
viewtopic.php?f=14&t=3475&start=80#p39822)
Also worth noting... you will run into problems with timer:destroy() if the timer does not exist, so best to check if it's there before trying to destroy it... I do this in my Hold Monster spell.
Code: Select all
local h_timer = findEntity("hold_timer")
if h_timer ~= nil then
h_timer:destroy()
end
Re: Bastien067 experiments, new assets and other...
Posted: Fri Nov 02, 2012 1:54 pm
by bastien067
Ok thank you very much Grimwold. So if i understand correctly there is no way to achieve this without a script entity in the dungeon ?
I'll try with script entity then...
I have a stupid question : if i do this do i have to add the script entity on each level of the dungeon or only once ?
Re: Bastien067 experiments, new assets and other...
Posted: Fri Nov 02, 2012 2:04 pm
by Grimwold
bastien067 wrote:Ok thank you very much Grimwold. So if i understand correctly there is no way to achieve this without a script entity in the dungeon ?
I'll try with script entity then...
I have a stupid question : if i do this do i have to add the script entity on each level of the dungeon or only once ?
Just once. and no I don't think you can do it without, the timer needs to connect to a function to achieve what you want.
Actually. I now have a working spell... I'll paste the code in just a sec.
Re: Bastien067 experiments, new assets and other...
Posted: Fri Nov 02, 2012 2:09 pm
by Grimwold
Define the spell in
spells.lua
Code: Select all
defineSpell{
name = "monk_hot",
uiName = "Vitality of the Bear",
skill = "unarmed_combat",
level = 5,
runes = "ABC",
manaCost = 20,
onCast = function(champion, x, y, direction, skill)
return monk_hot_script.beginHeal(champion,skill)
end,
}
Create a
script entity called
monk_hot_script
Code: Select all
-- store the ordinal value of the Monk --
-- we can't store a champion entity because it won't get saved in a save-game file --
-- we store the ordinal instead of the position in case the champions are moved around --
monk_ord = 1 -- set a starting value, this will be overwritten when the spell is cast.
-- find the champion ID from the ordinal number --
function findChampionByOrdinal(ord)
for ch = 1,4 do
if party:getChampion(ch):getOrdinal() == ord then
return party:getChampion(ch)
end
end
end
function beginHeal(champion,skill)
monk_ord = champion:getOrdinal()
local hot_timer_list = {"monk_hot_timer","monk_hot_stop_timer"}
for _,itimer in ipairs(hot_timer_list) do
local hot_timer = findEntity(itimer)
if hot_timer ~= nil then
hot_timer:destroy()
end
end
playSound("heal_party")
spawn("timer", party.level, party.x, party.y, party.facing, "monk_hot_timer")
:setTimerInterval(3)
:activate()
:addConnector("activate","monk_hot_script","hotHeal")
spawn("timer", party.level, party.x, party.y, party.facing, "monk_hot_stop_timer")
:setTimerInterval(30)
:activate()
:addConnector("activate","monk_hot_timer","deactivate")
:addConnector("activate","monk_hot_stop_timer","deactivate")
end
function hotHeal()
local hot_monk = findChampionByOrdinal(monk_ord)
hot_monk:modifyStat("health", 5)
hudPrint(hot_monk:getName() .. " is healed")
end
When the spell is cast we:
* save the Ordinal of the champion to refer to later
* destroy the hot timers if they exist
* spawn a timer on a 3 sec interval to call the heal function
* spawn a timer on a 30 sec interval to deactivate both timers and hence end the spell.
Re: Bastien067 experiments, new assets and other...
Posted: Fri Nov 02, 2012 10:49 pm
by bastien067
Wow Grimwold you are coding fast !!!
I would never have been able to do this code by myself...
There thing I dont understand in the code I have to study it more, but thank to you i'll be able to complete my "monk set" so thank you very much !
Re: Bastien067 experiments, new assets and other...
Posted: Fri Nov 02, 2012 11:42 pm
by msyblade
Grim is a code ninja, ESPECIALLY when it comes to spells.