Bastien067 experiments, new assets and other...

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Bastien067 experiments, new assets and other...

Post by cromcrom »

Hi, shouldn't the last "end" be followed by a coma like "end," ?
A trip of a thousand leagues starts with a step.
bastien067
Posts: 8
Joined: Thu Nov 01, 2012 6:41 am

Re: Bastien067 experiments, new assets and other...

Post 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 ?
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Bastien067 experiments, new assets and other...

Post 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 ^^)
A trip of a thousand leagues starts with a step.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Bastien067 experiments, new assets and other...

Post 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
bastien067
Posts: 8
Joined: Thu Nov 01, 2012 6:41 am

Re: Bastien067 experiments, new assets and other...

Post 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 ?
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Bastien067 experiments, new assets and other...

Post 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.
Last edited by Grimwold on Fri Nov 02, 2012 2:10 pm, edited 1 time in total.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Bastien067 experiments, new assets and other...

Post 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.
bastien067
Posts: 8
Joined: Thu Nov 01, 2012 6:41 am

Re: Bastien067 experiments, new assets and other...

Post 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 !
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Bastien067 experiments, new assets and other...

Post by msyblade »

Grim is a code ninja, ESPECIALLY when it comes to spells.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
Post Reply