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
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

shayologo wrote: Thu Apr 11, 2019 9:00 am It's a possibility to add in my mod custom portrait or player must download it from external link and add it manualy?
If you add the portrait image files into your project folder, you can assign them to the PCs via script.

You should definitely put a warning in the mod's description if you intend to implement a custom party.

The script command to assign a portrait is this:

Code: Select all

champion:setPortrait( —path to your portrait file, ending in .tga— )
An example usage is:

Code: Select all

--[[
	For this example, the portrait images must be placed in the path:
		mod_assets/textures/portraits/

	The files must be in the .dds image format.
	 eg. "barbarian.dds" "sorceress.dds" "wookie.dds" "thief.dds"
	
	Various image editors can convert pictures to .dds format; one is Paint.Net. ( https://getpaint.net )
	
	Portrait images are 128x128 pixels.
	
	Of course you can change the example portrait names to whatever you wish.
--]]

for x = 1, 4 do
	local portrait = {"barbarian", "sorceress", "wookie", "thief"}  
	local champion = party.party:getChampion(x)
	if champion:getEnabled() and portrait[x] then champion:setPortrait("mod_assets/textures/portraits/"..portrait[x]..".tga") 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 »

What's the correct code to "fade in" a light and particle component from a lightsource instead of just turning it on instantly?
If that is even remotely possible. So that it takes 5 seconds before the light and particle is at 100% after 5 seconds?

start situation:
g1_darkelf_temple_ceiling_lantern.light = disabled
g1_darkelf_temple_ceiling_lantern.particle = disabled

a floor trigger triggers a script that's supposed to:

fadeIn:particle’s fade in time in seconds.
fadeOut:particle’s fade out time in seconds.

g1_darkelf_temple_ceiling_lantern_5.light:fadeIn5() ?
g1_darkelf_temple_ceiling_lantern_5.particle:fadeIn5() ?
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 »

It shouldn't be :fadeIn (5)

Maybe It won't work if you have disabled the component. Can't check that out ATM.
Then you should fade out the components at the beginning of the game.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

That's it! Makes total sense as well. Looks nice :)

Is there a command to instantly set it at for example 30 % intensity?

I have now skeleton knights walking around holding torches in their hands that light up coal based lightsources that increase intensity over the course of 1 minute once lit up.
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 »

Not sure if this has been answered yet but ill ask. Is there a way to make an emissiveMap on a material fluctuate opacity? or even randomly?
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

check page 278 of this topic

Maybe Isaac's script can be helpful.
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 »

Pompidom wrote: Sat Apr 13, 2019 1:27 am check page 278 of this topic

Maybe Isaac's script can be helpful.
Can this be run on a material or just an object? I basically just want to randomly change the opacity on the emissive within the material it self. So that way I don't have to deal with objects. I'm creating giant mushrooms that have an emissive glow on a small part of it that I want to fluctuate in and out randomly.

thanks btw :)
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 »

I have run into another problem, when I run my base.lua that has auto spawns it will re run them again upon load. On my stairs up and stairs down I do have them removing supports, pillars and the ground slope. But when I save and load all the things are reloaded because of my auto spawning in the base.lua. How would get the the following script to only run once or have the stairs remove them every time? Would I have to make all the objects local?

Code: Select all

do
-- Automatically make floor dirt if on solid ground and dirt is not already
-- present. Platforms are not considered floor!
local autoDecoEdgeCave = function(self)
	local g = self.go	
	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
	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_01b")
		elseif choice >= 0.7 then
			g:spawn("rc_edge_support_02b")
		elseif choice >= 0.55 then
			g:spawn("rc_edge_support_03b")
		elseif choice >= 0.4 then
			g:spawn("rc_edge_support_04b")
		end
	end
	if g.map:getElevation(g.x,g.y) == g.elevation then
		local choice = math.random()
		if choice >= 0.8 then
			g:spawn("rc_rocks_trim_01")
		elseif choice >= 0.6 then
			g:spawn("rc_rocks_trim_02")
		elseif choice >= 0.4 then
			g:spawn("rc_rocks_trim_03")
		else
			g:spawn("rc_wall_slope",g.level,g.x,g.y,math.random(0,3),g.elevation)
		end
	end
end	

local autoDecoFloorDetailAll = function(self)
	local g = self.go
	local choice = math.random()
	local choice2 = math.random()
	local choice3 = math.random()
	
	if choice >= 0.6 then
	  spawn("rc_grass_01a",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice >= 0.4 then
	  spawn("rc_grass_01b",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice >= 0.2 then
	  spawn("rc_grass_01c",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
	if choice2 >= 0.94 then
	  spawn("rc_ground_tiles_01",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice2 >= 0.88 then
	  spawn("rc_ground_tiles_02",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice2 >= 0.82 then
	  spawn("rc_ground_tiles_03",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice2 >= 0.76 then
	  spawn("rc_ground_tiles_04",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice2 >= 0.7 then
	  spawn("rc_ground_tiles_05",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
	if choice3 >= 0.8 then
	  spawn("rc_ground_pebbles_04",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice3 >= 0.6 then
	  spawn("rc_ground_pebbles_01",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice3 >= 0.4 then
	  spawn("rc_ground_pebbles_02",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice3 >= 0.2 then
	  spawn("rc_ground_pebbles_03",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
   
end
defineObject{
	name = "base_cave_wall",
	baseObject = "base_wall",
	components = {
		{
			class = "Null",
			onInit = autoDecoEdgeCave,
		},
	},
	minimalSaveState = true,
}

defineObject{
	name = "base_cave_ground",
	baseObject = "base_floor",
	components = {
		{
			class = "Null",
			onInit = autoDecoFloorDetailAll,
		},
	},
	minimalSaveState = true,
}
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 »

I wonder if there might be a way to tell the objects that spawn randomly that if it detects stairs in its proximity to just simply not spawn.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Pompidom wrote: Sat Apr 13, 2019 1:27 amcheck page 278 of this topic
This is not a very useful answer if you don't include a link, since different users have different settings for how many posts appear per page.

In general, no, you can't adjust the intensity of the emissive map. You can add uniform RGB values to entire models with ModelComponent:setEmissiveColor() or the emissiveColor field in the component definition, but this is additive rather than multiplicative so it is nothing like changing the "opacity" of the emissive map. Also in the Mac version it only works on materials with lighting or materials with the "crystal" shader, which means no blendModes other than Opaque.

Maybe you can do something with the "additive" shader's "intensity" parameter, but I think that shader just ignores the emissive map altogether.
vanblam wrote: Sat Apr 13, 2019 3:31 am I have run into another problem, when I run my base.lua that has auto spawns it will re run them again upon load. On my stairs up and stairs down I do have them removing supports, pillars and the ground slope. But when I save and load all the things are reloaded because of my auto spawning in the base.lua. How would get the the following script to only run once or have the stairs remove them every time? Would I have to make all the objects local?

Code: Select all

do
-- Automatically make floor dirt if on solid ground and dirt is not already
-- present. Platforms are not considered floor!
local autoDecoEdgeCave = function(self)
	local g = self.go	
	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
	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_01b")
		elseif choice >= 0.7 then
			g:spawn("rc_edge_support_02b")
		elseif choice >= 0.55 then
			g:spawn("rc_edge_support_03b")
		elseif choice >= 0.4 then
			g:spawn("rc_edge_support_04b")
		end
	end
	if g.map:getElevation(g.x,g.y) == g.elevation then
		local choice = math.random()
		if choice >= 0.8 then
			g:spawn("rc_rocks_trim_01")
		elseif choice >= 0.6 then
			g:spawn("rc_rocks_trim_02")
		elseif choice >= 0.4 then
			g:spawn("rc_rocks_trim_03")
		else
			g:spawn("rc_wall_slope",g.level,g.x,g.y,math.random(0,3),g.elevation)
		end
	end
end	

local autoDecoFloorDetailAll = function(self)
	local g = self.go
	local choice = math.random()
	local choice2 = math.random()
	local choice3 = math.random()
	
	if choice >= 0.6 then
	  spawn("rc_grass_01a",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice >= 0.4 then
	  spawn("rc_grass_01b",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice >= 0.2 then
	  spawn("rc_grass_01c",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
	if choice2 >= 0.94 then
	  spawn("rc_ground_tiles_01",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice2 >= 0.88 then
	  spawn("rc_ground_tiles_02",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice2 >= 0.82 then
	  spawn("rc_ground_tiles_03",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice2 >= 0.76 then
	  spawn("rc_ground_tiles_04",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice2 >= 0.7 then
	  spawn("rc_ground_tiles_05",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
	if choice3 >= 0.8 then
	  spawn("rc_ground_pebbles_04",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice3 >= 0.6 then
	  spawn("rc_ground_pebbles_01",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice3 >= 0.4 then
	  spawn("rc_ground_pebbles_02",g.level,g.x,g.y,math.random(0,3),g.elevation)
	elseif choice3 >= 0.2 then
	  spawn("rc_ground_pebbles_03",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
   
end
defineObject{
	name = "base_cave_wall",
	baseObject = "base_wall",
	components = {
		{
			class = "Null",
			onInit = autoDecoEdgeCave,
		},
	},
	minimalSaveState = true,
}

defineObject{
	name = "base_cave_ground",
	baseObject = "base_floor",
	components = {
		{
			class = "Null",
			onInit = autoDecoFloorDetailAll,
		},
	},
	minimalSaveState = true,
}
end
Remember, minimalSaveState objects only save their name, id, level, x, y, facing, and elevation, they don't store any data about the components. So when they are spawned again upon loading, they create all their components again based on the definition, and all those components will run their onInit hooks again.
I would strongly recommend you make your autoDecoEdgeCave and autoDecoFloorDetailAll functions destroy the object when they're done. Even without this issue, there's no reason to keep the base_cave_ground, base_cave_wall, etc. objects around when they no longer do anything useful.
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