Random Cooldowns

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!
Post Reply
User avatar
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Random Cooldowns

Post by David Ward »

Is there a way to randomize the length of a cooldown?

For example, under the code for defineObject { custommonster, code, etc, code }, there is:

Code: Select all

		   class = "MonsterMove",
			name = "move",
			sound = "rat_swarm_walk",
			cooldown = 3,
Instead of a flat 3 cooldown, is there a way to make it randomize, say, 1 to 5? So when the monster moves, sometimes the cooldown will be noticeably quicker (1 or 2 seconds), other times a lot slower (4 or 5 seconds), or the standard 3, depending on how the dice rolls.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Random Cooldowns

Post by minmay »

The cleanest way to do this is probably to add a hidden trait with an onComputeCooldown() hook that returns a random multiplier. Like

Code: Select all

	onComputeCooldown = function(champion, weapon, attack, attackType, level)
		if level > 0 then return 2/3+math.random()*2/3 end
	end,
for a random cooldown multiplier from -33% to +33% (note you might prefer -33% to +50% depending on your statistical goal).

Of course, there is no way to change the item description to show something for the cooldown other than the actual cooldown value, so if you want the item to say "Cooldown: 2.0 to 4.0 seconds" instead of "Cooldown: 3.0 seconds", you're out of luck.
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
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Re: Random Cooldowns

Post by David Ward »

Thank you kindly.
Post Reply