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!
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Re: Ask a simple question, get a simple answer

Post by trancelistic »

I"m nto sure of LoG2 has it like Log 1, other floors goes way slower in 1. so also the timer.

If log 2 has it as well, I guess you can put a timer some where emty on the map far deep somewhere. So the timer runs the same all over. ( you just have to calculate the difference then with it being slower then real time)
User avatar
THOM
Posts: 1280
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

well, I need the timer and it's triggering just in one level. My qustion is, if it's absolutely neccessary to stop it, when the party leaves this level or is it enough to set it on "current level only"... ??
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

:shock: This is scripted for LoG1... (my mistake; I will convert it when I get a chance sometime later on tonight, or tomorrow ;) .)
________________________________________________________________________
You don't have to use a timer for this.

You could use the game's internal play_time statistic to track time.

Code: Select all

--object.lua
defineObject{
	name = "party",
	class = "Party",
	editorIcon = 32,
	onDrawGui = function(self) 
				if lightSwitch.needed then
					lightSwitch:check()
				end	
			    end,
}

Code: Select all

--script name: lightSwitch

time_delay = 4   --
needed = true
lights_on = true
last_time = getStatistic("play_time")

function floorPlate(caller)
	if needed then
		needed = false
	else
		needed = true
	end
	
	print("Checking time: ",needed) --=----------[debug comment]-
	
end

function check()
	if getStatistic("play_time") >= last_time + time_delay then
		last_time = getStatistic("play_time")	
		if lights_on then
			lights_on = false
		else
			lights_on = true
		end	
		lights(lights_on)
	end	
end

function setTimeDelay(num)
	if type(num) == "number" then
		time_delay = num
	end
end

function setNeeded(bool)
	if type(bool) == "boolean" then
		needed = bool
	end
end

function setLightsOn(bool)
	if type(bool) == "boolean" then
		lights_on = bool
		lights(bool)
	end
end

function lights(bool)  -- add your own custom light controller here.
	
	-- this one is just for the example map.
	if lamp_1 then
	 lamp_1:destroy() 
	end
	
	if bool then
		spawn("temple_ceiling_lamp", self.level, self.x, self.y, self.facing,"lamp_1")
	end
	--
	
end
https://www.dropbox.com/s/79m9n0rmxgvr1 ... k.zip?dl=0
Last edited by Isaac on Sun Jul 05, 2015 10:41 pm, edited 3 times in total.
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

If you want the time of day you should use GameMode.getTimeOfDay(). Time of day in Grimrock does not actually correspond to time, it changes when the party moves and turns, and while they're resting.
Also consider using Time.currentTime() instead of the play_time statistic, depending on your needs.
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.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:If you want the time of day you should use GameMode.getTimeOfDay(). Time of day in Grimrock does not actually correspond to time, it changes when the party moves and turns, and while they're resting.
Also consider using Time.currentTime() instead of the play_time statistic, depending on your needs.
I recall using that for the town clock bell in one mod, but it was a nightmare to check accurately.
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

What do you mean? Getting the hour from the scale is very easy:

Code: Select all

local hour = (GameMode.getTimeOfDay()*12+9)%24
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.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:What do you mean? Getting the hour from the scale is very easy:

Code: Select all

local hour = (GameMode.getTimeOfDay()*12+9)%24
The problem I had was under/ or overshooting the hour when checking the time, and the bell was off. (IIRC, the problem came of not wanting a constant high-speed test going on all the time during the game. This was compounded by variant time speed during rest ~which still rang on the hour, and no time speed, when the party was stationary.)
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

Is there any way to make a champion use a UsableItem in a script (automatically, without the player right clicking on it) ?
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

AndakRainor wrote:Is there any way to make a champion use a UsableItem in a script (automatically, without the player right clicking on it) ?
How exactly do you mean then? (Please invent a gameplay example.)
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Isaac wrote:
AndakRainor wrote:Is there any way to make a champion use a UsableItem in a script (automatically, without the player right clicking on it) ?
How exactly do you mean then? (Please invent a gameplay example.)
Using the item like when the player right-clicks on it or drops it on a champion's portrait, but without actually requiring the player to right-click on it or drop it on a champion's portrait.
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