Page 2 of 2

Re: Setting Goromorg spells

Posted: Thu Feb 06, 2014 12:02 pm
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

Re: Setting Goromorg spells

Posted: Fri Feb 07, 2014 1:32 pm
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.

Re: Setting Goromorg spells

Posted: Fri Feb 07, 2014 1:58 pm
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, 

Re: Setting Goromorg spells

Posted: Sat Feb 08, 2014 11:31 am
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.

Re: Setting Goromorg spells

Posted: Wed Feb 26, 2014 10:03 am
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,