Setting Goromorg spells

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Re: Setting Goromorg spells

Post by LocalFire »

I don't know if this would work but try using math.random to determine multiple spells

Code: Select all

local SpellCall = math.random(1,2)
if SpellCall == (1) then
     spawn("water_bolt", self.level, self.x + dx, self.y + dy, self.facing)
     return false
end,
else
if SpellCall == (2) then
     spawn("improved_frostbolt", self.level, self.x + dx, self.y + dy, self.facing)
     return false
end,
This is totally untested and might need tweaking, but should put you on the right path
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443
User avatar
Eightball
Posts: 48
Joined: Thu Jan 09, 2014 8:21 am

Re: Setting Goromorg spells

Post by Eightball »

I tried this based on LocalFire's good suggestion and what I've picked up from other people's monsters.lua.

Code: Select all

onRangedAttack = function(self)
 local dx, dy = getForward(self.facing)
 local SpellCall = math.random(1,2)
   if SpellCall == (1) then
     spawn("water_bolt", self.level, self.x + dx, self.y + dy, self.facing)
     return false
	end,
   else
   if SpellCall == (2) then
     spawn("improved_frostbolt", self.level, self.x + dx, self.y + dy, self.facing)
     return false
 end, 
Something is amiss and I haven't figured out what. When I try to load my mod the error "unexpected symbol near ," appears. It's the first time I've tried such a long script in the midst of a "cloneObject" hook.

I have a question, besides trying to get this working, how can I change something like this to have 3 options rather than just two. I can't just keep tacking "else" lines, but there must be some sort of "or" that I can use. I'd like to change this script to include a third ranged spell.
User avatar
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: Setting Goromorg spells

Post by Dr.Disaster »

This is from the modding section:
onRangedAttack: a hook which is called when the monster performs a ranged attack. The function receives a single parameter, the monster itself. If the function returns false, the ranged attack is cancelled.
It seems to me that those "return false" commands will cancel any attack attempt.

Also those blocks seem bad, I think it should go like this:

Code: Select all

onRangedAttack = function(self)
 local dx, dy = getForward(self.facing)
 local SpellCall = math.random(1,2)
   if SpellCall == 1 then
     spawn("water_bolt", self.level, self.x + dx, self.y + dy, self.facing)
   elseif SpellCall == 2 then
     spawn("improved_frostbolt", self.level, self.x + dx, self.y + dy, self.facing)
   end,
   return true
end, 
User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Re: Setting Goromorg spells

Post by LocalFire »

Eightball wrote:I

I have a question, besides trying to get this working, how can I change something like this to have 3 options rather than just two. I can't just keep tacking "else" lines, but there must be some sort of "or" that I can use. I'd like to change this script to include a third ranged spell.
change the math.random to (1,3) then add a third else if spellCall == (3)
thats how I'd do it anyway you can look at my Fates fool spell in the spell thread to get the idea

That said it's probably possible to do this another way but you'll need a better coder than me to help you.
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443
User avatar
Eightball
Posts: 48
Joined: Thu Jan 09, 2014 8:21 am

Re: Setting Goromorg spells

Post by Eightball »

Here's the script in monsters.lua as it stands now. It finally works (the dungeon will actually load), but the problem is the standard set rangedAttack of goromorgs... This goromorg will not just limit himself to the three spells listed. It will cast its default rangedAttack spell (any of the usual 4 elements) PLUS one of the three listed in OnRangedAttack, at the same time. I tried "rangedAttack = nil," but get the same effect, so I set it back to just doing iceshards as its default for the time being. Any way that I can prevent the double cast or is it just going to be too cool that he casts two spells at once to fix this problem?
SpoilerShow

Code: Select all

 rangedAttack = "ice_shards",
 onRangedAttack = function(self)
   local dx, dy = getForward(self.facing)
   local SpellCall = math.random(1,3)
     if SpellCall == 1 then
     spawn("water_bolt", self.level, self.x + dx, self.y + dy, self.facing)
     elseif SpellCall == 2 then
     spawn("improved_frostbolt", self.level, self.x + dx, self.y + dy, self.facing)
     elseif SpellCall == 3 then
     spawn("ice_shards", self.level, self.x + dx, self.y + dy, self.facing)
     end
   return true
end,
Post Reply