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 »

Haven't tested it yet, but as it works as I think it does I plan to auto disable the trigger after each first map transition so that it doesn't become obnoxious. Just only 1 time when introduced to a new map.

thanks :)
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

I have been using entity.model:setEmissiveColor(vec(0,0,.1)) here and there with varying degrees of success.
it's a quick and dirty way of giving stuff another color and if you keep the values (0.05 - 0.1) low enough then it doesn't look like it's irradiated. It's helpful for giving multiple objects in close proximity another way to look slightly more unique. Trees for example.

Now some quick questions,
1. if I give the model of a monster a different color with entity.model:setEmissiveColor(vec(0,0,.1)) for example. And then proceed to kill this enemy. Will my mod crash later on seeing how it can't find the entity anymore after loading a saved game?

https://ibb.co/bbMJVY0

In this screenshot for example I have given the knight a cold blueish look, I have suspended their animation, so they look like they're frozen solid. You light the campfire so that they get warmer, this triggers a delayed call: entity.animation:enable() so they start moving again.

Now what I want to achieve is for example that their blue color slightly disappears gradually. Is there a script or some way to fadeout the emissiveColor over a period of several seconds back to neutral?
Going from entity.model:setEmissiveColor(vec(0,0,.1)) gradually to entity.model:setEmissiveColor(vec(0,0,0)) over the course of 10 seconds.

Basically in the same way like this script hooked to a timer where i make stuff move up or down
if posY < startHeight then
posY = posY - 0.005

I hope you understand what I'm trying to achieve :)
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 »

Emissive color is emisive. :?

As for the Knight, why not this?

Code: Select all

skeleton_trooper_1.monster:setCondition("frozen", 99999999)

Code: Select all

skeleton_trooper_1.monster:setCondition("frozen", 0)
* If you want it animated, it will have to be a lower duration. The effect seems affected by the condition timer. It's strange. Setting it at up to a million looks good. The 5 million range creates a slideshow framerate, while setting it to math.huge eliminates all shading—flat 2D screenspace.

**The frozen effect only works [well] with single material monsters.
(That's actually the reason that multi-material monsters are immune to freezing.)
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

Well mainly because I don't know how to change colors of things in a better way.

And offcourse setCondition to frozen is indeed a better way of achieving my goal :)

Thanks Isaac :)


However I still want to accomplish my ininital idea of a timer hooked up to something like

if emissivecolor < StartColor then
emissivecolor = emissivecolor - 0.0001

where an object will gradually change it's emissive color.

For example where you heat stuff up and it starts to glow red gradually, overheats and then explodes.
I'm experimenting with a contraption I'm making.
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 »

You can do that with a simple timer calling the function repeatedly.

Something like this (but could be made simpler) :

Code: Select all

snake_statue_1.model:setEmissiveColor(vec(1,0,0))


function fadeColor(objectId, step)
	if type(objectId) == "string" then
		local object = findEntity(objectId)
		if object then
			if not object.model:getEmissiveColor() then 
				object.model:setEmissiveColor(vec())
			end
			if  object.model:getEmissiveColor()[1] < 1 or
				object.model:getEmissiveColor()[2] < 1 or
				object.model:getEmissiveColor()[3] < 1
			 then
				local minimum = 0.001
				local step = step or -.01
				if  object.model:getEmissiveColor()[1] > minimum or
					object.model:getEmissiveColor()[2] > minimum or
					object.model:getEmissiveColor()[3] > minimum 
				 then
					object.model:setEmissiveColor( object.model:getEmissiveColor() + vec(step,step,step) )
				end
			end	
		end
	end
end

function object1()
	fadeColor("snake_statue_1", -.02)  --negative step value darkens, positive value lightens
end
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Remember to scale the change by Time.deltaTime() instead of just changing it by 0.01 each frame! Otherwise it will take longer to fade the lower the framerate is.
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.
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

Sounds great, I'll experiment with this later today :)
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 »

minmay wrote: Sat Feb 02, 2019 12:29 pm Remember to scale the change by Time.deltaTime() instead of just changing it by 0.01 each frame! Otherwise it will take longer to fade the lower the framerate is.
Much better; and I should have remembered that. ;)

_______________

This has turned into a fun experiment. :) —[Which might still have bugs!]
SpoilerShow

Code: Select all


function fadeColor(objectId, step, timer)
	if type(objectId) == "string" then
		local object = findEntity(objectId)		
		if object then 
			local function filter(target)
					for x = 1, 3 do
						if target[x] > 0 and target[x] <= 1 then
						  else target[x] = math.floor(target[x]+0.5)
						end
					end
					return target
				end
										
			if not object.model:getEmissiveColor() then 
				object.model:setEmissiveColor(vec())
			end
					
			local emColor = object.model:getEmissiveColor()	
			step = iff( step, vec(emColor[1]*step,emColor[2]*step,emColor[3]*step) , vec(emColor[1]*.01,emColor[2]*.01,emColor[3]*.01) )			
			object.model:setEmissiveColor( filter(emColor+step*(Time.deltaTime()*10)) )	
			
			emColor = object.model:getEmissiveColor()
			if (emColor[1] < 0.001 or emColor[1] >= 1) and
			   (emColor[2] < 0.001 or emColor[2] >= 1) and 
			   (emColor[3] < 0.001 or emColor[3] >= 1) then
				timer:stop()
			end	
		end
	end
end

--[[Usage:
	Connect timers to any of the example functions below; make more functions (one for each object) as needed.	
	
	For the examples, add three snake_staues to the map, and they will change colors. 
--]]

----------------------------------------------------------------------deletable examples:
-------------------------------------------------------------------------------
if snake_statue_1 and snake_statue_2 and snake_statue_3 then
	snake_statue_1.model:setEmissiveColor(vec(0,0,1))
	snake_statue_2.model:setEmissiveColor(vec(.001,-.9,0))
	snake_statue_3.model:setEmissiveColor(vec(1,1,0))
end
--[[
	To be affected, a color value must be greater or less than zero; zero values are ignored. 
	Non-zero color values will be proportionately incremented either brighter, or darker depending on 
	whether the step value is positive or negative. 
--]]
-------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------

function object1(stop)
	fadeColor("snake_statue_1", -.05, stop)  --negative step value darkens, positive value lightens
end

function object2(stop)
	fadeColor("snake_statue_2", .25, stop)  --negative step value darkens, positive value lightens
end

function object3(stop)
	fadeColor("snake_statue_3", -.1, stop)  --negative step value darkens, positive value lightens
end

Image
Last edited by Isaac on Sun Feb 03, 2019 8:27 am, edited 1 time in total.
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

I'm still not sure how the script entirely works, but I find it interesting that I can achieve intenser colors with it.
Trees on the right are default, the trees on the left I have darkened with the script. Looks pretty sweet.

https://ibb.co/M86yhm1
https://ibb.co/61QF32M

It makes the trees and leaves simply look better and you can bring more variety changing the numbers on each tree individually while running the exact same script :)
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 »

They look good. 8-)

The script is intended for realtime color shifting. It's overkill to use it for static/permanent changes at load time.

Any color you can get with this script, can just be assigned directly, and with just one line.
If you know the color values, then you can place a script with only the adjustment calls, and it should work.
Post Reply