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
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Ask a simple question, get a simple answer

Post by Drakkan »

could I ask somebody to write script which will do following --

I have table called food_table

when I place object coin_gold (its stackable item) on the table, it destroy one coin and spawn gold_food object on the table. In case more gold_coins inserted it should return back the remaining money. And also - this process could be done only once (means only one gold_food could be bought).

Thanks for any help
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

AndakRainor wrote:The offset of the clickable component is the same, but not its size. I will try different sizes tonight and see if I get a better result.
Try this one.

Code: Select all

defineObject{
	name = "dungeon_click_secret_door",
	baseObject = "base_secret_door",
	components = {
		{
			class = "Model",
			model = "assets/models/env/dungeon_secret_door.fbx",
			staticShadow = true,
		},
				{
			class = "Door",
			openVelocity = 0.5,
			closeVelocity = -0.5,
			secretDoor = true,
			openSound = "wall_sliding",
			closeSound = "wall_sliding",
			lockSound = "wall_sliding_lock",
			onOpen = function(self)
						self.go.clickable:setOffset(vec(0,2.8,0))
					end,
			onClose = function(self)
						self.go.clickable:setOffset(vec(0,1.5,0))
					end,
		},

		{
			class = "Clickable",
			offset = vec(0, 1.5, 0),
			size = vec(1.2, 0.8, 0.2),
			frontFacing = true,
			--debugDraw = true,
			onClick = function(self, ...) if getMouseItem() and self.go.door:isOpen() then 
									return false
								 else self.go.door:toggle()
								end
							end,
		},
	},
}
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Drakkan wrote:could I ask somebody to write script which will do following --

I have table called food_table

when I place object coin_gold (its stackable item) on the table, it destroy one coin and spawn gold_food object on the table. In case more gold_coins inserted it should return back the remaining money. And also - this process could be done only once (means only one gold_food could be bought).

Thanks for any help
You should be able to do this yourself, but here. Connect the surface's onInsertItem action to this function.

Code: Select all

done = false
function itemInserted(surface)
  if not done then
    for _,i in surface:contents() do
      if i.go.name == "coin_gold" then
        if i:getStackSize() == 1 then
          i.go:destroy()
        else
          i:setStackSize(i:getStackSize()-1)
        end
        done = true
        surface:addItem(spawn("gold_food").item)
        break
      end
    end
  end
end
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.
RedNova
Posts: 7
Joined: Fri Aug 28, 2015 12:18 pm

Re: Ask a simple question, get a simple answer

Post by RedNova »

How can i change monster attack and defence parameters?
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Do you mean control how they act during a fight?

Or do you mean alter things like damage and protection?
RedNova
Posts: 7
Joined: Fri Aug 28, 2015 12:18 pm

Re: Ask a simple question, get a simple answer

Post by RedNova »

Isaac wrote:Do you mean control how they act during a fight?

Or do you mean alter things like damage and protection?
2.
And why map of my dungeon is blank?
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

In the mod_assets folder you can find a file called items.lua. You can add there a definition for a weapon.

It has to look like that:

Code: Select all

defineObject{
	name = "machete",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/machete.fbx",
		},
		{
			class = "Item",
			uiName = "Machete",
			gfxIndex = 23,
			impactSound = "impact_blade",
			weight = 2.2,
			traits = { "light_weapon", "sword" },
		},
		{
			class = "MeleeAttack",
			attackPower = 12,
			accuracy = 0,
			cooldown = 4.5,
			swipe = "horizontal",
		},
	},
	tags = { "weapon" },
}
How to change behaviour should be obvious, I think.

What do you mean by "my map is blank"?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
RedNova
Posts: 7
Joined: Fri Aug 28, 2015 12:18 pm

Re: Ask a simple question, get a simple answer

Post by RedNova »

Image
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

RedNova wrote:why map of my dungeon is blank?
First, click the arrow in the circle on the automap. Is it still blank after that?
______

To change monster parameters, one usually defines the monster in monsters.lua, with the desired changes.

*However it is also possible to change those parameters during the game via script. The components to affect these parameters are the
monster and monsterAttack.

For instance, if the monster id is my_ogre_1, then to make my_ogre_1 hit really hard, and be very evasive, include this in a script:

Code: Select all

my_ogre_1.monster:setEvasion(45)
my_ogre_1.basicAttack:setAttackPower(150)
my_ogre_1.turnAttack:setAttackPower(150)
my_ogre_1.charge:setAttackPower(150)
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

Oh - sh***!
I havn't read carefully what you have asked, RedNova.

For sure, Isaac is right. He explained how to create a new monster / change behaviour of existing ones.

I did the same - but for Items like weappons... :?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Post Reply