Scripting Item So Monsters Ignore Party

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Hitrison
Posts: 6
Joined: Wed Jan 04, 2017 1:04 am
Location: Georgia

Scripting Item So Monsters Ignore Party

Post by Hitrison »

Hi folks. Sorry if this is obvious or has been asked before (or even if there's already something in the game that does this), but I would like some help with scripting (which I have little experience with, as you'll be able to tell). I want to write a script so that when the party has a specific item the forest ogres on that floor will ignore them, but I'm not sure exactly what the best way to go about doing that would be. Thanks.

edit: This is in Grimrock 2, btw.
edit 2: Words, what are those?
Last edited by Hitrison on Tue Jan 17, 2017 11:08 pm, edited 1 time in total.
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Scripting Item So Monsters Ignore Party

Post by kelly1111 »

Your text seems to be missing
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Scripting Item So Monsters Ignore Party

Post by zimberzimber »

You add an onThink function to the ogres brain (you have to define a new monster for this), check if the party is carrying the item (party.party:isCarrying(string)), and set the sight radius to 0.
The monster might still react to the party if they stand too close, but that can be easily fixed with disabling the attack components.
Here is a very useful thread for monster brains: viewtopic.php?f=22&t=9720
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Hitrison
Posts: 6
Joined: Wed Jan 04, 2017 1:04 am
Location: Georgia

Re: Scripting Item So Monsters Ignore Party

Post by Hitrison »

Cool, thanks!
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Scripting Item So Monsters Ignore Party

Post by minmay »

zimberzimber wrote:You add an onThink function to the ogres brain (you have to define a new monster for this), check if the party is carrying the item (party.party:isCarrying(string)), and set the sight radius to 0.
The monster might still react to the party if they stand too close, but that can be easily fixed with disabling the attack components.
Here is a very useful thread for monster brains: viewtopic.php?f=22&t=9720
Setting sight radius is a bad hack that is unlikely to do what you want (consider what happens when the monster gets attacked for example). It's more likely that you want this:

Code: Select all

onThink = function(self)
  if party.party:isCarrying("stone_of_ogre_ignorance") then
    return self:wander() 
  else
    return false -- use original brain behaviour
  end
end
This way it will behave just like an ogre that is unaware of the party while the stone is carried.
If you additionally want the ogre to NEVER attack change it to this:

Code: Select all

onThink = function(self)
  if party.party:isCarrying("stone_of_ogre_ignorance") then
    return self:wander() or self:wait()
  else
    return false -- use original brain behaviour
  end
end
(BrainComponent:wander() can still fall through; self:wait(), however, will never fall through so the monster will never do anything other than move and wait)

edit: also, read the linked thread at your own risk because most of the posts in there are completely wrong
Last edited by minmay on Wed Jan 18, 2017 4:05 am, edited 4 times in total.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Scripting Item So Monsters Ignore Party

Post by zimberzimber »

I did self:wander, and the monster just ignored that command.

About the linked thread, I don't know whats in the comments, but the main post covers whats needed.

EDIT: Missed the return part, but the monster will still occasionally use attacks. Looks the same as setting sight radius to 0 in terms of monster behavior, so you still have to disable melee attacks and such.
My asset pack [v1.10]
Features a bit of everything! :D
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Scripting Item So Monsters Ignore Party

Post by minmay »

It's not the same as setting sight radius to 0. The code I posted makes it just like the ogre is unaware of the party, what you're noticing is that being unaware doesn't prevent monsters from attacking. (I can write a full explanation of BrainComponent:wander() and OgreBrain if you're really interested.) I amended the post with a version that will never attack or charge.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Hitrison
Posts: 6
Joined: Wed Jan 04, 2017 1:04 am
Location: Georgia

Re: Scripting Item So Monsters Ignore Party

Post by Hitrison »

The "self:wander() or self:wait()" code seems to be working well. And yes, if the party has the item (in my mod, called a hall pass) I don't want the ogres to attack at all.
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Scripting Item So Monsters Ignore Party

Post by akroma222 »

Hey All,
seems like the right thread for it - has anyone tried / succeeded in recreating the Invisibility condition??
Im going to be making a custom condition (Stealth) similar to Invisibility and was wondering how the nuts and bolts of it works...

Akroma :)
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Scripting Item So Monsters Ignore Party

Post by zimberzimber »

akroma222 wrote:Hey All,
seems like the right thread for it - has anyone tried / succeeded in recreating the Invisibility condition??
Im going to be making a custom condition (Stealth) similar to Invisibility and was wondering how the nuts and bolts of it works...

Akroma :)
Same code minmay posted, but check for a condition and other things (like party distance) instead.
I think it will still put the monster out of a guarding position, but I think you can fix this by checking if it was guarding, and tell it to guard again.
My asset pack [v1.10]
Features a bit of everything! :D
Post Reply