[HELP] Need Script for Alcove Item to alter Monster stats

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
undeaddemon
Posts: 157
Joined: Fri Mar 02, 2012 3:38 pm

Re: [HELP] Need Script for Alcove Item to alter Monster stat

Post by undeaddemon »

OK.. if it is easier to lock the item to the alcove, so that once the HP, and immunity are removed, they cant be added back, then that isn't any type of showstopper, just if its possible to return it, it makes more sense.

Monster will only be on 1 level, there is only 1 of him, he's is sorta a boss type fight, but not a final fight.
Damage or reduction would be fine - chances are the players will not be looking at him when they place the items (most likely they would be avoiding him i would think...
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: [HELP] Need Script for Alcove Item to alter Monster stat

Post by Grimwold »

it's actually not easier to lock the item... just wondered if that might make thematic sense.


OK so this should be the finished script entity immunity_script, I've not had chance to test it myself yet, so there may be a few bugs to work out. don't forget you'll need the monsters.lua entry from my earlier post.

You will need to change the 5 entries at the beginning to refer to the names of your items and monster.

Code: Select all

-- set variables for the immunity specific items and the immune monster
fire_item = "FIRE_ORB"
ice_item = "ICE_ORB"
shock_item = "SHOCK_ORB"
poison_item = "POISON_ORB"
monster_name = "immune_ogre"

-- set up the immunity variables
fire_immunity = 1
ice_immunity = 1
shock_immunity = 1
poison_immunity = 1

-- check immunity when the monster is damaged
function checkImmunity(monster,amount,type)
  if type == "fire" and fire_immunity == 1 then
    return false
  elseif type == "cold" and ice_immunity == 1 then
    return false
  elseif type == "shock" and shock_immunity == 1 then
    return false
  elseif type == "poison" and poison_immunity == 1 then
    return false
  end
end

-- alcove scripts to adjust immunity variables and deal damage

-- function to check if alcove contains item.
function containsItem(entity, item)
  for i in entity:containedItems() do
    if i.name == item then
      return true
    end
  end
  -- if we get here the item was not found
  return false
end


-- function for fire alcove
function fireAlcove(trigger)
  if containsItem(trigger, fire_item) and fire_immunity == 1 then
    fire_immunity = 0
    for i in allEntities(trigger.level) do
      if i.name == monster_name then
        local curr_health = i:getHealth()
        local new_health = 1
        if curr_health > 250 then
          new_health = curr_health - 250
        end
        i:setHealth(new_health)
      end
    end
  end
  if not containsItem(trigger, fire_item) and fire_immunity == 0 then
    fire_immunity = 1
    for i in allEntities(trigger.level) do
      if i.name == monster_name then
        local curr_health = i:getHealth()
        local new_health = curr_health + 250
        i:setHealth(new_health)
      end
    end
  end
end

-- function for ice alcove
function iceAlcove(trigger)
  if containsItem(trigger, ice_item) and ice_immunity == 1 then
    ice_immunity = 0
    for i in allEntities(trigger.level) do
      if i.name == monster_name then
        local curr_health = i:getHealth()
        local new_health = 1
        if curr_health > 250 then
          new_health = curr_health - 250
        end
        i:setHealth(new_health)
      end
    end
  end
  if not containsItem(trigger, ice_item) and ice_immunity == 0 then
    ice_immunity = 1
    for i in allEntities(trigger.level) do
      if i.name == monster_name then
        local curr_health = i:getHealth()
        local new_health = curr_health + 250
        i:setHealth(new_health)
      end
    end
  end
end

-- function for shock alcove
function shockAlcove(trigger)
  if containsItem(trigger, shock_item) and shock_immunity == 1 then
    shock_immunity = 0
    for i in allEntities(trigger.level) do
      if i.name == monster_name then
        local curr_health = i:getHealth()
        local new_health = 1
        if curr_health > 250 then
          new_health = curr_health - 250
        end
        i:setHealth(new_health)
      end
    end
  end
  if not containsItem(trigger, shock_item) and shock_immunity == 0 then
    shock_immunity = 1
    for i in allEntities(trigger.level) do
      if i.name == monster_name then
        local curr_health = i:getHealth()
        local new_health = curr_health + 250
        i:setHealth(new_health)
      end
    end
  end
end

-- function for poison alcove
function poisonAlcove(trigger)
  if containsItem(trigger, poison_item) and poison_immunity == 1 then
    poison_immunity = 0
    for i in allEntities(trigger.level) do
      if i.name == monster_name then
        local curr_health = i:getHealth()
        local new_health = 1
        if curr_health > 250 then
          new_health = curr_health - 250
        end
        i:setHealth(new_health)
      end
    end
  end
  if not containsItem(trigger, poison_item) and poison_immunity == 0 then
    poison_immunity = 1
    for i in allEntities(trigger.level) do
      if i.name == monster_name then
        local curr_health = i:getHealth()
        local new_health = curr_health + 250
        i:setHealth(new_health)
      end
    end
  end
end
you will also need to link each alcove to its appropriate function in this script entity.. e.g. fire_alcove to the fireAlcove function.

note I put in a failsafe that if the monsters health is ever less than 250 when it should lose 250, it instead sets health to 1, so the party can still have the honour of killing it!

Hope this all makes sense (and works as I intend).. I will give it a try myself when I get chance.

EDIT - tested and fixed a bug... seems ok with fire immunity.. and very easy kill once all 4 items in the alcoves!
Last edited by Grimwold on Thu Jan 03, 2013 6:18 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: [HELP] Need Script for Alcove Item to alter Monster stat

Post by Grimwold »

OK finally I think I am done testing and that this script does what is intended... please give it a try and if you find any odd behaviour let me know.

I tested with an immune ogre and simply used 4 appropriate scrolls as my items.
User avatar
undeaddemon
Posts: 157
Joined: Fri Mar 02, 2012 3:38 pm

Re: [HELP] Need Script for Alcove Item to alter Monster stat

Post by undeaddemon »

you will also need to link each alcove to its appropriate function in this script entity.. e.g. fire_alcove to the fireAlcove function.
So.. I need to define what each Alcoves "purpose" is to the player, only linking it to one of the 4 functions, correct?

btw... Thank You!
amazing....
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: [HELP] Need Script for Alcove Item to alter Monster stat

Post by Grimwold »

undeaddemon wrote:
you will also need to link each alcove to its appropriate function in this script entity.. e.g. fire_alcove to the fireAlcove function.
So.. I need to define what each Alcoves "purpose" is to the player, only linking it to one of the 4 functions, correct?
Yes each alcove will be for a specific immunity... you need some way to communicate that the player... and you will need to create the connections in the editor.

Also, when you create the connections from the alcoves to the script.. make sure you tick "activate always" and change the connection type to "any" instead of just "activate"... so it will check when the item is removed.
undeaddemon wrote: btw... Thank You!
amazing....
my pleasure.
User avatar
undeaddemon
Posts: 157
Joined: Fri Mar 02, 2012 3:38 pm

Re: [HELP] Need Script for Alcove Item to alter Monster stat

Post by undeaddemon »

Yeah... sooooo awesome... soooo choice.

That works great.... really.. thanks again ... now... If I can just get this LoG Framework / EXSP working... I have some "wandering lights" the champions will have to avoid whilst performing this, as well !! :)
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: [HELP] Need Script for Alcove Item to alter Monster stat

Post by Komag »

glad you got this worked out! A lot depends on your intentions, such as how you want to explain or describe the logic of what is happening, story-wise.
Finished Dungeons - complete mods to play
Post Reply