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
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Ask a simple question, get a simple answer

Post by Xardas »

Thank you guys, i knew that the castle walls are higher than the regular ones, but i dind´t knew about the module height.
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!
User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Ask a simple question, get a simple answer

Post by Xardas »

hey guys
i´m currently using an external script as an onThink hook for a custom brain. Is it possible to load a new file to the script, so the trickster "uses a different brain"?. I tried it with loadFile and setSource, but both don´t work properly
Monster Definition for the trickster with custom brain:

Code: Select all

defineObject{ 
name = "trickster_test", 
baseObject = "trickster", 
components = { 
{ 
class = 'Brain', 
onThink = function(self) 
trickster.script.onThink(self) 
end 
} 
} 
}
file i´d like to load to the script for new brain behavior:

Code: Select all

function onThink(self)

local brainaction = braincounter.counter:getValue()
local brain = self.go.brain

if brainaction==1 then
brain:strafeLeft()
delayedCall("trickster", 1, "increment", self.go.id)

elseif brainaction==2 then 
self.go.animation:play("scold")
brain:disable()
delayedCall("trickster", 2.66, "increment", self.go.id)

elseif brainaction==3 then
self:goTo("lever_1") 
if self:goTo("lever_1") then
brain:operate("lever_1")
increment()
end

elseif brainaction==4 then
brain:seek(13,18)
if self.go.x == 13 and self.go.y == 18 then
increment()
end
elseif brainaction==5 then
self:performAction("escape") 
end
end

function increment(self)
braincounter.counter:increment() 
trickster_test_1.brain:enable()
end
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!
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 »

You tell the brain to do nothing, by returning true from your onThink hook; otherwise it uses the built in logic.
User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Ask a simple question, get a simple answer

Post by Xardas »

With the built in logic you mean the normal brainscript right? I just tried returning false and then he does nothing.
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!
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 »

Xardas wrote:With the built in logic you mean the normal brainscript right? I just tried returning false and then he does nothing.
https://github.com/JKos/log2doc/wiki/Co ... -component
When implementing onThinkon a built-in brain, it's possible to override the built-in behaviour in some specific cases while keeping the default implementation for the rest:

The onThink hook should return true when an action is performed (wait() and performXXX() methods already return true, so it's possible to write, for example return self:wait())
If the onThink hook does not return true, the built-in logic kicks in and control for the next action is passed to the built-in brain.

Here is a test project:
Image
https://www.dropbox.com/s/k1r75li191fv4 ... t.zip?dl=1

The script for the above example:

Code: Select all

questEnabled = true

function trapdoor(trigger)

	if trigger then 
		delayedCall(self.go.id, 2, "trapdoor")
	end
	dungeon_pit_trapdoor_1.pit:toggle()
end	

--Trickster

trickster_1.brain:addConnector('onThink', self.go.id, 'onThink')

function onThink(monster)
	local lock = findEntity("lock_gold_1")
		if  questEnabled == true then
		if  monster.go.brain:here(lock.id) then
			monster.go.brain:operate(lock.id) 
			lock.lock:enable()
		 else monster.go.brain:goTo(lock.id)
		end
	end
end

function setQuestEnabled(bool)
	if type(bool) == 'boolean' then questEnabled = bool end
end

function toggleQuestEnabled(lever) 
	 self.setQuestEnabled(lever.go.lever:isActivated())
end
Note that this script doesn't explicitly return a value from the onThink hook for this case.
User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Ask a simple question, get a simple answer

Post by Xardas »

That script was very helpful, thank you. I think i got it now.
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!
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 »

Did they update LoG2 to support a larger file-size for mods, on Steam? (I use the GoG version)

As I recall, the effective size limit for LoG1 Steam mods was stated to be 100mb, (but in practice turned out to be 98mb).
It was a nightmare to get ORRR2 (for LoG1) under 98mb.
User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Ask a simple question, get a simple answer

Post by Xardas »

Hey guys it´s me again
Does anyone know how to generate random numbers?. math.random() just doesn´t do its Job.
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!
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 »

Xardas wrote:Hey guys it´s me again
Does anyone know how to generate random numbers?. math.random() just doesn´t do its Job.
The math.random function does generate it (pseudo-random numbers), but if you use it too early during load, your results could be poor; or perhaps even repeating.

You can set the seed of math.random with math.randomseed(your_number_value), to change its number queue.

There is also the mersenne twister.
https://github.com/JKos/log2doc/wiki/Ob ... nnetwister
http://www.grimrock.net/modding/scripti ... nneTwister

Seeding math.randomseed with the current system time would result in a different stream of numbers from math.random for every second of the day.

math.randomseed(Time.currentTime()) or math.randomseed(Time.systemTime())

math.random()
math.random()
math.random()...

If you are seeding the function in a hook with GUI context, you could salt the seed with the mouse coordinates as well.
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Time.systemTime() returns the number of seconds that the game has been running, with millisecond precision. It tells you nothing about real-world time (and neither does anything else available in the scripting interface). It is probably still the best option for seeding a PRNG, though.

Grimrock calls math.randomseed() when loading a dungeon and when initializing maps (so that tilesets don't provide different results across loads), and whenever the player opens the automap. So if you're using math.random() in your init files it'll always give the same results across loads, and if you're using it during a game you should be aware it could be re-seeded at pretty much any time.
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