Arena style room [source]

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Arena style room [source]

Post by Blichew »

I found out how to implement some kind of arena system to LoG, haven't found anything similar on forums so I thought I'd share it with you :)

In my case it let player choose one of 4 types of skeletons (warrior, archer, 2 archers and 4 warriors - so nothing really new here)


1. I've created a small room with various stuff in it, something like that:

Image
2. Instruction text:

Code: Select all

Press higher button
to change contestant type

Press lower button 
to engage the chosen contestant
3. Two gates - in my example I used dungeon_portcullis (or whatever the name is)

4. Spawner - empty, no CD, no selected entity to be spawned

5. Two buttons:
Image
Upper type is: dungeon_secret_button_large - connects with skTypeNext() function from Lua script
Lower type is: wall_button - connects with skSpawn() function from Lua script

6. Timer -this one works in 1 sec interval and runs skTick() function from Lua script

Now for the script:
SpoilerShow

Code: Select all

sk_types = { "skeleton_archer", "skeleton_warrior", "skeleton_archer_patrol", "skeleton_patrol" } -- define skeleton types (asset names)
sk_types_n = { "Skeleton Archer", "Skeleton Warrior", "Two Skeleton Archers", "Four Skeleton Warriors" } -- define skeleton descriptions for hudPrint
sk_index = 0 -- type index, for above arrays
sk_ticker = 0 -- counter/ticker that increments every second when timer starts
sk_inProgress = false -- is encounter in progress ? (helps to prevent spawning another monsters during encounter/messing with timer/counter, etc.)
lights = false -- if lights (fx) has been spawned

function skTypeNext() -- kinda self-explanatory
	if sk_inProgress == false then
		if sk_index == 4 then
			sk_index = 1
		else
			sk_index = sk_index + 1
		end
	end
	msg() -- if encounter not in progress spawn a line with chosen monster type
end

function skSpawn()
	if sk_inProgress == false then --is event in progress ? 
		if sk_index == 0 then -- if monster type wasn't chosen yet
			hudPrint("Choose your contestant with the upper button first.")
		else
			T_arena:activate() -- let's roll
			hudPrint("\n\n\n\n") -- clear hud text
			hudPrint("Preparing next contestant: "..sk_types_n[sk_index]..". Ready yourselves !")
			sk_inProgress = true
		end
	else
		msg() -- if encounter is in progress spawn info msg
	end
end

function msg()
	if sk_inProgress == false then
		hudPrint("Contestant type chosen: "..sk_types_n[sk_index].."")
	else
		hudPrint("Encounter in progress. Kill "..sk_types_n[sk_index].." before choosing next enemy.")
	end
end

function skTick()
	if sk_ticker == 1 then			--after 1 sec: play gong (custom sound)
		playSound("gong_1")
		changeLights()				--and spawn fx with green light in the middle of the room and another red one behind the gate (on spawner)
	elseif sk_ticker == 2 then 		--after 2 sec close south door (entrance)
		D_arena_S:close()
	elseif sk_ticker == 3 then 		--after 3 sec spawn monster
		SP_arena:setSpawnedEntity(sk_types[sk_index]) -- set spawned entity using array from the start
		SP_arena:activate()
	elseif sk_ticker == 4 then 		--after 4 sec: release monster
		D_arena_N:open()
	elseif sk_ticker ~= 0 then		--after each next 1-sec tick: check if monster is killed
		if checkArea(sk_types[sk_index],2,15,4,20) then 		--it is killed - clean up
			hudPrint(""..sk_types_n[sk_index].." defeated. Congratulations !")
			sk_ticker = 0
			D_arena_N:close() --close cage
			D_arena_S:open() -- open entrance
			sk_inProgress = false
			T_arena:deactivate()
			changeLights() -- destroy lights in the area
			return
		end
	end
	sk_inProgress = true
	sk_ticker = sk_ticker + 1
end

function checkArea(what,minX,minY,maxX,maxY)
	if what == "skeleton_patrol" then
		what = "skeleton_warrior"
	elseif what == "skeleton_archer_patrol" then
		what ="skeleton_archer"
	end
	for x = minX,maxX do
		for y = minY,maxY do
			for object in entitiesAt(party.level,x,y) do
            	if object.name == what then
            		return false
            	end
			end
		end
	end
	return true
end

function changeLights()
	if lights == false then -- if lights are not spawned, spawn them, one per each square
		--greens
		local i = 0
		for x = 2,4 do
			for y = 17,19 do
				spawn("fx",1,x,y,3,"skFxRoom"..i)
				findEntity("skFxRoom"..i):setLight(0,0.9,0,20,5,3600,true)
				findEntity("skFxRoom"..i):translate(0,1.5,0)
				i = i + 1
			end
		end
		--red
		spawn("fx",1,3,15,3,"skFxRoom"..i)
		findEntity("skFxRoom"..i):setLight(0.9,0,0,20,10,3600,true)
		findEntity("skFxRoom"..i):translate(0,1.5,0)
		i = i + 1
		lights = true --lights are spawned
	else -- if lights are spawned
		local i = 0
		-- destroy each fx in the area (greens)
		for x = 2,4 do
			for y = 17,19 do
				findEntity("skFxRoom"..i):destroy()
				i = i + 1
			end
		end
		-- destroy the red one
		findEntity("skFxRoom"..i):destroy()
		lights = false	-- lights are out again
	end
en
And that's it. I know the script could be more optimized but I wanted to implement it asap.
NOTE: There's no special reward (like spawn the reward in an alcove or grant additional xp) beside the xp from kills.

NOTE2: As for possible reward, I was thinking about spawning a coin in the alcove after each fight. There's no coin asset in the game afaik and I have absolutely no idea how to implement it (don't send me back to grimrock.net/modding please as I've read all of the articles).

If anyone with some patience and free time could make a step-by-step tutorial for dummies he/she would earn my (and not only mine i think) endless gratitude :D


Blichew
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Arena style room [source]

Post by Komag »

I probably won't have any arena in my dungeon(s) but I'm sure others will love this idea and run with it - maybe you go somewhere and are locked in until you have five victories or something like that. Cool stuff, thanks for the invention :)

PS - this is totally worthy to go in the script repository, you should put it there once it's finalized (or now, and you can edit and change later):
USEFUL SCRIPTS REPOSITORY
Finished Dungeons - complete mods to play
Post Reply