Ask a simple question, get a simple answer

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!
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: Ask a simple question, get a simple answer

Post by Mysterious »

Hi all.

I am using md_npc monsters in my mod which is cool. Is there a way to stop the damage the party does to them? EG: If the party attacks or cast spells at the monster the damage stuff happens and I don't want that.

Is the a hook or something I can add to the Monster Code. I mean if the monster is attacked nothing happens no blood etc....

I still want the Interact, Set Route, Ongive etc.. to work just not the damage to the monsters. Thanks in advance.
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Mysterious wrote:Hi all.

I am using md_npc monsters in my mod which is cool. Is there a way to stop the damage the party does to them? EG: If the party attacks or cast spells at the monster the damage stuff happens and I don't want that.

Is the a hook or something I can add to the Monster Code. I mean if the monster is attacked nothing happens no blood etc....

I still want the Interact, Set Route, Ongive etc.. to work just not the damage to the monsters. Thanks in advance.
monster_id.monster:setMonsterFlag("Invulnerable",true)

Attacks may still happen, but show zero damage.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Ask a simple question, get a simple answer

Post by MrChoke »

THOM wrote: I know I can do this inside the monster-definition. But what I want to do is to have a monster that behaves like a normal monster and at a certain moment it starts to go to a certain point of the map. So I think I have to add this behaviour during the game to the brain. Or something like that.

BTW the goTo command also understands names of objects, not only items. It works in my dungeon already like this.
Ok, yeah I guess it does make sense that goTo() could be for any object. I guess I never tried anything else. It does have serious limitations though. Of course it will only go after objects on the same level. But even then, if the object is too far or the path too complicated to get to it, the game will ignore the request and not "goTo" anything. It's limitations is one of the main reasons I had to write my own path finding AI.

So here is the easiest way to make a monster do a goTo() on certain condition. Let's say if a floor trigger is activated, he will do the goTo. Here is code that would have to be found in a script called "script_entity_1" on a normal mob: herder_1

Code: Select all

function customThinkFN(brain)
	if floor_trigger_1.floortrigger:isActivated() then
		brain:goTo("dungeon_door_1")
	end
end

function initMonster()
	herder_1.brain:addConnector("onThink", "script_entity_1", "customThinkFN")
end
The way onThink() works is if you do not give a specific brain command, rather you simply return from the function, the default brain behavior will be performed. But as long as that floor trigger is activated, he will not do anything else except goTo that door.
User avatar
THOM
Posts: 1267
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

thanx! works perfect!
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
PedroMoniz
Posts: 16
Joined: Wed Jan 11, 2017 9:46 pm

Re: Ask a simple question, get a simple answer

Post by PedroMoniz »

Hello,

First I want to say thanks for the ui question, I was looking for the graphics component on the class list and not objects and classes category.

Second, I have a question regarding something I already asked about the traits because it has come up again.

Because I have a usableItem and not an Item, I cannot use item functions such as hasTrait or even have access to itemHooks such as onEquipItem.
I was thinking of creating an itemClone and then use this itemClone for the usableItem that i will have on my scene, thus giving me access to the hook functions.

Is this the best way to proceed in regards to usableItems?

Code: Select all


cloneObject{
	name = "Potion_Energy_IC",
	baseObject = "potion_energy",
    components = {
      {
        class = "Item",
	      uiName = "Potion of energy",
        onEquipItem = function(item, champion, slot) 
            print("yo")
            hooks.script.item_OnEquipItem(item, champion, {"magic"})
        end,

         onUnequipItem = function(item, champion, slot) 
            print("yo")
            hooks.script.item_OnEquipItem(item, champion, {"magic"})
        end
      }
   },
}

cloneObject{
	name = "Potion_Energy",
	baseObject = "Potion_Energy_IC",
    components = {
      {
        class = "UsableItem",
	      uiName = "Potion of energy",
	      onUseItem = function(item, champion)
          hooks.script.item_OnUsePotion(item, champion, {"magic"})
        end,
      }
   },
}
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

UsableItem and Item are defined together for usable items.
Example from the asset pack:

Code: Select all

defineObject{
	name = "potion_energy",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/flask.fbx",
		},
		{
			class = "Item",
			uiName = "Energy Potion",
			gfxIndex = 145,
			weight = 0.3,
			stackable = true,
			traits = { "potion" },
		},
		{
			class = "UsableItem",
			--emptyItem = "flask",
			sound = "consume_potion",
			onUseItem = function(self, champion)
				champion:regainEnergy(75)
				champion:playHealingIndicator()
			end,
		},
	},
}
You can use all defined hooks for these components and they will interact fine.
Components usually have no interactions between each other can be used together.
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

Question - Can someone please explain to me the point of the 'cloneObject' add-on when you can just define an object from a base one?
My asset pack [v1.10]
Features a bit of everything! :D
PedroMoniz
Posts: 16
Joined: Wed Jan 11, 2017 9:46 pm

Re: Ask a simple question, get a simple answer

Post by PedroMoniz »

Thank you, did not realise the components worked like that. Does make a lot of sense and it is helpfull.

However, i still have one problem.

Code: Select all

cloneObject{
	name = "Potion_Energy",
	baseObject = "potion_energy",
    components = {
      {
        class = "UsableItem",
	      onUseItem = function(item, champion)
          print(item:getWeight())
        end,
      },
      {
        class = "Item",
        onEquipItem = function(item, champion, slot) 
          print(item:getWeight())
        end,
      }
   },
}
I cannot do something as simple as a getWeigtht although the item has weight.
Any work around?
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

This has to do with references.

I suggest you start using 'self' instead of 'item', would make understanding easier.
The first variable indexes the component that calls the hook.
The UsableItem function's 'item' variable is the equivalent of objectID.usableitem
The Item function's 'item' variable is the equivalent of objectID.item
Since UsableItem doesn't have a getWeight() function, which is why it crashes.
To check the weight of the item through the UsableItem components functions, you'll have to use this:

Code: Select all

onUseItem = function(self, champion)
	print(self.go.item:getWeight())
end

self.go
is called from a components function, and references to the game object holding the component that called self.go
self.go.item:getWeight() from a component = objectID.item:getWeight()
My asset pack [v1.10]
Features a bit of everything! :D
PedroMoniz
Posts: 16
Joined: Wed Jan 11, 2017 9:46 pm

Re: Ask a simple question, get a simple answer

Post by PedroMoniz »

thank you,

A question, is it possible to get the traits? There is an add and a has function, but is there any work around to find the traits?
Post Reply