(snippet) Custom keyboard shortcuts for testing

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
7Soul
Posts: 95
Joined: Sun Oct 19, 2014 1:56 am

(snippet) Custom keyboard shortcuts for testing

Post by 7Soul » Tue Oct 22, 2019 7:32 am

I made a set of keyboard shortcuts for when testers play my mod (and for me when I'm testing the exported mod too). Some mimic the editor shortcuts and some can help with getting stuck. There's also one for revealing the map and advancing time

Inside the onDrawGui hooK:

Code: Select all

if context.keyDown("shift") and functions.script.keypressDelayGet() == 0 then
-- Shift + U -> Advance day time by 1/6th
if context.keyDown("U") then
	GameMode.setTimeOfDay((GameMode.getTimeOfDay() + 0.33) % 2)
	print("Time of Day set to " .. GameMode.getTimeOfDay())
	functions.script.keypressDelaySet(20)
end

-- Shift + M -> Reveal current map
if context.keyDown("M") then
	functions.script.revealMap()
	print("Map revealed")
	functions.script.keypressDelaySet(20)
end

-- Shift + L -> Level up
if context.keyDown("L") then
	for i = 1,4 do
		party.party:getChampion(i):levelUp()
		functions.script.keypressDelaySet(20)
	end
end

-- Shift + X -> Moves the party 1 square forward
if context.keyDown("X") then
	local dx,dy = getForward(party.facing)
	party:setPosition(party.x + dx, party.y + dy, party.facing, party.elevation, party.level)
	functions.script.keypressDelaySet(20)
end

-- Shift + K -> Kills monster in front of party
if context.keyDown("K") then
	local dx,dy = getForward(party.facing)
	for e in Dungeon.getMap(party.level):entitiesAt(party.x + dx, party.y + dy) do
		if e.monster and e.monster:isAlive() then
			e.monster:die()
		end
	end
	functions.script.keypressDelaySet(20)
end

-- Shift + Z -> Toggles door in front of party
if context.keyDown("Z") then
	functions.script.keypressDelaySet(20)
	local dx,dy = getForward(party.facing)
	for e in Dungeon.getMap(party.level):entitiesAt(party.x, party.y) do
		if e.facing == party.facing and e.door then
			e.door:toggle()
		end
	end
	for e in Dungeon.getMap(party.level):entitiesAt(party.x + dx, party.y + dy) do
		if (e.facing + 2) % 4 == party.facing and e.door then
			e.door:toggle()
		end
	end		
end

-- Shift + H -> Full Heal party
if context.keyDown("H") then
	local negative_conditions = { 
		"cursed",
		"diseased",
		"paralyzed",
		"petrified",
		"poison",
		"slow",
		"chest_wound",
		"feet_wound",
		"head_wound",
		"left_hand_wound",
		"leg_wound",
		"right_hand_wound",
		"blind",
	}

	for i = 1,4 do
		local champion = party.party:getChampion(i)
		for _,v in ipairs(negative_conditions) do
			if champion:getConditionValue(v) ~= 0 then
				champion:setConditionValue(v, 0)
				champion:playHealingIndicator()
			end
		end
		champion:setBaseStat("health", champion:getCurrentStat("max_health"))
		champion:setBaseStat("energy", champion:getCurrentStat("max_energy"))
		playSound("heal_party")
		functions.script.keypressDelaySet(20)
	end
end
end
In a script_entity called "functions":

Code: Select all

function revealMap()
	local startx, starty = party.x, party.y
	for x=0,31 do
		for y=0,31 do
			local zfloor = Dungeon.getMap(party.level):getElevation(x, y)
			
			if not Dungeon.getMap(party.level):isBlocked(x, y, zfloor) then
				party:setPosition(x, y, party.facing, zfloor, party.level)
			end
		end
	end
	party:setPosition(startx, starty, party.facing, party.elevation, party.level)
end
This too:

Code: Select all

keypressDelay = 0
function keypressDelaySet(n)
	keypressDelay = n
end

function keypressDelayGet()
	return keypressDelay
end
In a party timer at 0 timerInterval (here's how to make one)

Code: Select all

functions.script.keypressDelaySet(math.max(functions.script.keypressDelayGet() - 2, 0))
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mod The Old Nexus (wip)

Post Reply