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!
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

https://ibb.co/iZmgbd
https://ibb.co/i6r8NJ

This code doesn't work.
I'm looking for a working code that destroys the cheese when placed on the pedestal and gets replaced by in this case for example a horned fruit

Code: Select all

function surfaceDestroy(surface, item)
	for _,i in surface:contents() do
		if i.go.name == item then 
			i.go:destroy()		
			return true 
		end
	end
end

function checkcheese(pedestal)
	if surfaceDestroy(g1_pedestal_4.surface, "cheese") then
		playSound("magic")
		g1_pedestal_4.surface:addItem(spawn("horned_fruit").item)
    end
end
User avatar
Zo Kath Ra
Posts: 940
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

Pompidom wrote: Wed Jul 04, 2018 5:07 pm This code doesn't work.
Does it crash?
Does the cheese not get destroyed?
Does the horned fruit not appear?
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

The cheese doesn't get destroyed :)
billb52

Re: Ask a simple question, get a simple answer

Post by billb52 »

Hi Pompidom, Try this method which I got sometime ago it might help.

This example converts 'remains_of_toorum' when placed upon an altar to a tome_wisdom
Place a script_entity on map with ID. tome_converter
add the following code:

Code: Select all

count = 0

function convert()
	local s = tome_altar.surface
	for _,e in s:contents() do
		if e.go.name == "remains_of_toorum" then
			e.go:destroy()
			spawn("tome_wisdom", self.go.level, self.go.x, self.go.y, self.go.facing,
			self.go.elevation, "tome_wisdom_"..count)
			s:addItem(findEntity("tome_wisdom_"..count).item)
			tome_altar_fx.controller:activate()
			tome_secret.controller:activate()
			hudPrint("Thankyou for your Offering")
			mine_door_spear_2.door:open()
			count=count+1
		end
	end
end
--------------------------------------------------------------------------
Place an altar where you require, with an ID. tome_altar then with connector onInsertItem -->
tome_altar --> convert -- of course use your own objects ie. pedestal
Place a spawner on top of altar with the ID. tome_altar_fx and have the spawnedEntity named
'teleportation_effect'
Place a 'secret' with ID. tome_secret nearby

Just change your object/items to suit.
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

Worx great after making it shorter :)
Thank you :)

Code: Select all

function convert()
	local s = g1_pedestal_4.surface
	for _,e in s:contents() do
		if e.go.name == "dm_food_cheese_fresh" then
			e.go:destroy()
			playSound("secret")
			hudPrint("Just what I wanted! Come back if you have more!")
			g1_pedestal_4.surface:addItem(spawn("bread").item)
		end
	end
end
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

Is there a way to create a simple alcove script where any item you throw into becomes exactly 1 copper coin?
No matter what the item is without having to make a list?
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

Hey All,
I wish to inquire about Collision Groups (and 'bits'... if it isn't too complex)... Specifically, I want to know -
1. Does LoG2 asset pack / main campaign have all Collision Groups listed / defined??
2. How do you calculate CollisionMasks using 'bits' ?
3. Can we define our own Collision Groups ?

Ive done a bunch of reading on these topics but not much within the LoG2 context or Lua language, eg:
https://www.aurelienribon.com/post/2011 ... -filtering
http://www.iforce2d.net/b2dtut/collision-filtering
https://stackoverflow.com/questions/390 ... mask-works

Ive also searched the forum - turned up a few threads which were useful,
viewtopic.php?f=22&t=13935&p=105423&hil ... up#p105423
....but still did not clear everything up

Any help appreciated :-)
Akroma
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

By default, every projectile and collider has a collision mask of 1. If bit.band([projectile mask], [collider mask]) ~= 0, then the projectile will collide with that collider. Otherwise, it won't; the projectile will pass through.

So most projectiles will collide with most projectile colliders, since bit.band(1, 1) is equal to 1, not 0. If you set a projectile's collision mask to 0, it won't collide with any projectile colliders, since bit.band(0, anything) is equal to 0. Note that it will still collide with solid tiles.

If you want a projectile that only collides with a few colliders, you could set its collision mask to 2, and set the collision group to 2 for the colliders you want it to collide with; bit.band(1, 2) is 0, but bit.band(2, 2) is not. Or if you want that collider to collide with default projectiles too, make its collision group 3, since bit.band(1, 3) and bit.band(2, 3) are both nonzero.

The only example of this in the asset pack is the fire rune trap. It has a projectile collider with a collision group of 2, so almost everything passes through it, but the dispel projectile has a collision mask of 3, so it hits rune traps.

If you're working with a large number of collision bits, you probably want to enter them as hexadecimal constants (prefix with 0x) rather than decimal ones. So use 0x14 instead of 20, for example; it's much easier to tell which bits are present that way. Unfortunately, Lua does not let you enter binary constants like some languages, just decimal and hexadecimal. Also, because of how the bit library works*, avoid using numbers greater than 0x7fffffff or lower than -0x8000000.

akroma222 wrote:3. Can we define our own Collision Groups ?
No. Do you need more than 32 collision groups?

*I've been typing out bit.band() every time instead of just saying "AND" because it's not a real bitwise AND; numbers in Grimrock are all double precision floating point, so the real AND of 1 and 3 would actually be 0. This would be a pain in the butt to work with, so instead, the bit library basically converts the numbers to 32-bit integers and back. That's why you get unwanted results if you try to use numbers outside the 32-bit integer range.
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.
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Ask a simple question, get a simple answer

Post by kelly1111 »

Is there a way , or has anyone ever made in indoor cave with ground elevation ?
Would that be possible to make?
And if so , how would I achieve that?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Definitely possible. Give your ceiling objects dontAdjustHeight = true, so that the heightmap doesn't prevent them from tiling. Other than that, everything would work just like an outdoor heightmapped level.
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.
Post Reply