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!
Marskilla
Posts: 16
Joined: Sun Mar 17, 2019 9:08 pm

Re: Ask a simple question, get a simple answer

Post by Marskilla »

Marskilla wrote: Thu Apr 18, 2019 9:47 am (...)Anyway thanks for the knockbak method ! Much more clean than a destroy() (...)
Ok, I tried your method as is. I had this problem :

Image

I ended up with :

Code: Select all

function testknockback()
	myFacing = party.facing
	destination = (party.facing+2)%4
	print(tostring(myFacing).." -> "..tostring(destination))
	if (destination ~= nil) then
		party.party:knockback(destination)
	end
end
In fact the modulo is not correct (%4 will do the job).

But the main point is when I use this with the chest open, the chest close itself, then open itself and I have my flickering again ! Here is the full code :

Code: Select all

function checkContent()
	nbArtefact=0
	for myIndex, myObject in chest_2.surface:contents() do
		if (myObject.go.name == "fidget_spinner" or myObject.go.name == "vilson_orb" or myObject.go.name == "lava_truc") then
			nbArtefact = nbArtefact + 1
			playSound("secret")
		else
			hudPrint("Je ne veux pas de ce " .. myObject.go.name) 	-- On dit qu'on en veut pas
			party.party:shakeCamera(0.05,2)                       			-- on secoue
			myObject.go:destroy()					    			-- on degage l'objet
			spawner_1.spawner:activate()
		end
	end
	if (nbArtefact == 3) then
		gotoFin()
	end
end

function gotoFin()
	--on joue un son et on fait bouger la camera et fondu au noir
	playSound("force_field_cast")
	party.party:shakeCamera(0.1,1.5)
	
	myFacing = party.facing
	destination = (party.facing+2)%4
	if (destination ~= nil) then
		party.party:knockback(destination)
	end
	
	GameMode.fadeOut(0, 2)
	
	--on attend la fin de l'effet pour lancer la video 
	delayedCall("script_entity_2", 2, "piegeMovie")	
end

function piegeMovie()	
	GameMode.playVideo("mod_assets/cinematics/piege.ivf")
	--chest_2:destroy() --pour eviter le flickering
	GameMode.fadeIn(0,0.5)
    --On teleporte !
	party:setPosition(16, 17, 0, 0, 14)
end
checkContent() is called with the chest.OnInsertItem() event. Here is the tiles configuration :

Image

If it seems too tricky, I'll stick with the destroy method. We're clearly not in "simple question, simple answer" anymore.
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 »

Marskilla wrote: Thu Apr 18, 2019 9:47 am I searched http://www.grimrock.net/modding/scripti ... yComponent...
There is a better, and more up-to-date scripting reference to use.

https://github.com/JKos/log2doc/wiki

Code: Select all

--altered script

function closeChest()
	party.party:knockback( (party.facing+2)%4)
end

function checkContent()
	nbArtefact=0
	for myIndex, myObject in chest_2.surface:contents() do
		if (myObject.go.name == "fidget_spinner" or myObject.go.name == "vilson_orb" or myObject.go.name == "lava_truc") then
			nbArtefact = nbArtefact + 1
			playSound("secret")
		else
			hudPrint("Je ne veux pas de ce " .. myObject.go.name) 	-- On dit qu'on en veut pas
			party.party:shakeCamera(0.05,2)                       			-- on secoue
			myObject.go:destroy()					    			-- on degage l'objet
			spawner_1.spawner:activate()
		end
	end
	if (nbArtefact == 3) then
		delayedCall(self.go.id,.01, 'closeChest')   --added line to call closeChest
		gotoFin()
	end
end

function gotoFin()
	--on joue un son et on fait bouger la camera et fondu au noir
	playSound("force_field_cast")
	party.party:shakeCamera(0.1,1.5)
	
	myFacing = party.facing
	destination = (party.facing+2)%4
	if (destination ~= nil) then
		party.party:knockback(destination)
	end
	
	GameMode.fadeOut(0, 2)
	
	--on attend la fin de l'effet pour lancer la video 
	delayedCall("script_entity_2", 2, "piegeMovie")	
end

function piegeMovie()	
	GameMode.playVideo("mod_assets/cinematics/piege.ivf")
	--chest_2:destroy() --pour eviter le flickering
	GameMode.fadeIn(0,0.5)
    --On teleporte !
	party:setPosition(16, 17, 0, 0, 14)
end

User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Ask a simple question, get a simple answer

Post by vanblam »

How do I add a part to this that will tell it not to spawn if there is a particular object in a 3x3 area?

Code: Select all

if g.map:getElevation(g.x,g.y) == g.elevation then
			local choice = math.random()
			if choice >= 0.85 then
				g:spawn("rc_edge_support_01")
			elseif choice >= 0.7 then
				g:spawn("rc_edge_support_02")
			elseif choice >= 0.55 then
				g:spawn("rc_edge_support_03")
			elseif choice >= 0.4 then
				g:spawn("rc_edge_support_04")
			end
		end
Any ideas? :P
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 »

In principle, you would make a boolean condition that is checked in an IF block that encloses the spawn code; bypassing it if true.

To determine if the condition should be true, you can use a pair of nested FOR loops [3x3] that check the tile addresses for the presence of your object, and set the boolean variable if found.

example: (Spawns a statue only if no daggers are found in the searched region)

Code: Select all

function itemCheck()
	local item = "dagger"
	local itemFound = false
	local map = Dungeon.getMap(1)

	for x = 14, 16 do
		for y = 14, 16 do
			for obj in map:entitiesAt(x, y) do
				if obj.name == item then
					itemFound = true
				end
			end
		end
	end	


	if not itemFound then
		---[[
			
			--spawn code
			playSound('secret')
			spawn("snake_statue", 1, 15,14,0,0)
			
		---]]
	end
end

itemCheck()
*It can be very useful to use the x & y locations of the script_entity itself in the logic. This allows for the script object to be moved, and have the logical locations automatically move with it; and self.go:spawn() would create an object wherever the script itself is placed.

In the above, the hard-coded x & y locations could be offsets of self.go.x and self.go.y, and make the test relative to the script's position.
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

Isaac wrote: Fri Apr 19, 2019 10:30 am example:

Code: Select all

function itemCheck()
	for x = 14, 16 do
		for y = 14, 16 do
			for obj in map:entitiesAt(x, y) do
				if obj.name == item then
					itemFound = true
					-- added
					break
				end
			end
			
			-- added
			if itemFound then
				break
			end
		end
		
		-- added
		if itemFound then
			break
		end
	end	
Added a few break statements.
I don't know if this will make the code faster in practice, or if its even necessary.

edit:
This would be even better

Code: Select all

function itemCheck()
	local item = "dagger"
	local map = Dungeon.getMap(1)

	for x = 14, 16 do
		for y = 14, 16 do
			for obj in map:entitiesAt(x, y) do
				if obj.name == item then
					return
				end
			end
		end
	end	

	---[[
		--spawn code
		playSound('secret')
		spawn("snake_statue", 1, 15,14,0,0)
	---]]
end

itemCheck()
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

What's the difference between
Champion:modifyBaseStat(name, value)
Champion:upgradeBaseStat(name, value)
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 »

Zo Kath Ra wrote: Fri Apr 19, 2019 10:42 am Added a few break statements.
I don't know if this will make the code faster in practice, or if its even necessary.
This is good to have; it does prevent waste, by not searching the rest of the items after one has been found.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Zo Kath Ra wrote: Fri Apr 19, 2019 1:23 pm What's the difference between
Champion:modifyBaseStat(name, value)
Champion:upgradeBaseStat(name, value)
upgradeBaseStat does an hudPrint saying "Toorum gained Strength +3" or whatever. modifyBaseStat doesn't.
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 an easy way to find out the x,y,z coordinates inside blender ?
I have made several candle models al of different size and height. Now I want to place particle effects (flame) on them, but it is a pain in the ass to find out where exactly to place them?

I have to manually type in the coördinaties in the script definition - load the dungeon inside the editor to check of they are placed at the correct coordinaties, rince and repeat 20 times to place them at the right spot.

I think I am doing it wrong. Anyone have any suggestions on how to do it ?
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 »

In Blender, place an empty at the tip of the wick; (make sure to include it in the export).

In the particle component of the object definition, define the [named] empty as the parent; like this:

Code: Select all

		{
			class = "Particle",
			particleSystem = "candle_flame",
			parentNode = "flame",
		},

Candle FlameShow

Code: Select all

		defineParticleSystem{
	name = "candle_flame",
	emitters = {
				-- flame
		{
			spawnBurst = true,
			maxParticles = 1,
			boxMin = {0.03,-0.16, 0.17},
			boxMax = {0.03,-0.16, 0.17},
			sprayAngle = {0,10},
			velocity = {0, 0},
			texture = "assets/textures/particles/candle_flame.tga",
			frameRate = 32,
			frameSize = 64,
			frameCount = 16,
			lifetime = {1000000, 1000000},
			colorAnimation = false,
			color0 = {1, 1, 1},
			opacity = 1,
			fadeIn = 0.1,
			fadeOut = 0.1,
			size = {0.1, 0.1},
			gravity = {0,0,0},
			airResistance = 1,
			rotationSpeed = 0,
			blendMode = "Additive",
			depthBias = 0.1,
			objectSpace = true,
			randomInitialRotation = false,
		},

				-- glow
		{
			spawnBurst = true,
			emissionRate = 1,
			emissionTime = 0,
			maxParticles = 1,
			boxMin = {0.02,-0.16, 0.18},
			boxMax = {0.02,-0.16, 0.18},
			sprayAngle = {0,30},
			velocity = {0,0},
			texture = "assets/textures/particles/glow.tga",
			lifetime = {1000000, 1000000},
			colorAnimation = false,
			color0 = {0.33, 0.21, 0.18},
			opacity = 1,
			fadeIn = 0.1,
			fadeOut = 0.1,
			size = {0.25, 0.25},
			gravity = {0,0,0},
			airResistance = 1,
			rotationSpeed = 0,
			blendMode = "Additive",
			depthBias = 0.1,
			objectSpace = true,
		},
	}
}
Post Reply