Location name on screen question

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
robcurrie
Slime
Posts: 5
Joined: Wed Jul 01, 2015 9:58 am

Location name on screen question

Post by robcurrie »

Hi everyone.

I'm working on a game just now which has a fairly large overworld map (150sq x 80sqx), and what I'm hoping to be able to do is have the in-game name of areas within that map appear in the corner of the screen for a moment, then disappear (if you've played Breath of the Wild you might know the kind of effect I'm hoping to achieve - in fact, you can see it in this video in case you aren't familiar with BOTW)

I'm not sure if this is possible, and I'm not very experienced with scripting in the OHRRPGCE, but I'm keen to give it a bash if people think it can be done.

Many thanks!
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

See if you can work with this, set it as your on-step script for your map and fill the different areas with appropriate zones. Of course, edit the names and numbers as you see fit.

Code: Select all

global variable (1, current zone)

plotscript, check name zone, begin
	variable (newzone)
	
	## Making sure we aren't re-displaying the same zone we're already in.
	newzone := zone at spot (hero x(me), hero y(me))
	if (newzone == current zone) then (exit script)

	## Put numbered zones inside areas, or just at the perimeter of areas.
	switch (newzone) do (
		case (1) $1="Plains"
		case (2) $1="Forest"
		case (3) $1="Mountains"
		case (4) $1="Seaside"
		## etc...
		case (else) exit script
	)
	
	
	show string at (1, 10, 180) ## Lower left, more or less?
	set timer (1, 5, 18, @hide name zone)	## 5 second timer before hiding area name.
	current zone := newzone
end

script, hide name zone, begin
	hide string (1)
end
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Test went pretty well on my end.
Image
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

That's a pretty nice script, so I put link to it on the wiki (no reason it couldn't have it own article).

You can simplify the script by using the name of the zone as the name of area (simply replace the 'switch' block with the line "get zone name(1, newzone)").

Also, that script won't work if you use zones for other purposes too and they overlap. So I suggest reserving a certain range of zone IDs, like 100-200 for region names. You'll then need to modify the script to check all the zones on a tile, and ignore other IDs.
Last edited by TMC on Sun Dec 31, 2017 6:36 am, edited 1 time in total.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Ah right, thanks for reminding me. This'll add a bit more to the script, but I have a simple method of looking through overlapped zones:

Code: Select all

variable (i, z)
	z := zone at spot (hero x(me), hero y(me), get count)
	
	if (z > 0) then (
		for (i, 0, z) do (
			if (zone at spot (hero x(me), hero y(me), i) == 1) then (
				## Do stuff based on zone 1
			)
		)
	)
Unfortunately working this in with the current script is going to get messy and awkward very quickly.
Last edited by Foxley on Sun Dec 31, 2017 8:41 am, edited 1 time in total.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Here we go. Tested, and it works.

Code: Select all

global variable (1, current zone)

plotscript, check name zone, begin
	variable (checkzone, z, i, changed)

	## Loop through all potentially overlapping zones
	z := zone at spot (hero x(me), hero y(me), get count)
	for (i, 0, z--1) do (
		## Making sure we aren't re-displaying the name zone we're already in.
		checkzone := zone at spot (hero x(me), hero y(me), i)
		if (checkzone == current zone) then (exit script)

		## Checking for zones between 100-199, and storing the zone's
		## name in string 1 if it's there.
		if &#40;checkzone >= 100 || checkzone < 200&#41; then &#40;
			get zone name &#40;1, checkzone&#41;
			break
		&#41;
	&#41;

	show string at &#40;1, 10, 180&#41; ## Lower left, more or less.
	set timer &#40;1, 3, 18, @hide name zone&#41;	## 3 second timer before hiding name.
	current zone &#58;= checkzone
end

script, hide name zone, begin
	hide string &#40;1&#41;
end
EDIT: Trimmed down the code some, with TMC's input.
Last edited by Foxley on Sun Dec 31, 2017 9:40 am, edited 3 times in total.
robcurrie
Slime
Posts: 5
Joined: Wed Jul 01, 2015 9:58 am

Post by robcurrie »

Thank you so much for your help folks, this is incredibly helpful!

A happy new year to you when it comes!
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

No worries, it was kind of fun doing a script to warm up. Hope it helps.

I'm finding that this only works if entire areas are filled with contiguous zones; if there are gaps, it starts behaving erratically. Still trying to figure out why that is.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Alright, so two things:

Code: Select all

if &#40;checkzone >= 100 || checkzone < 200&#41;
^^ This wasn't catching zones, it was actually doing jack squat because it can be over 100 or below 200, which essentially translates to "any zone". I've changed the || to &&.

I also brought back the "changed" variable, because as I expected, stepping between a zone with a name and a tile with no zone repeatedly kept re-triggering the "show string at" and the timer, so the text never went away as long as I kept moving.

Should be working just dandy now!

Code: Select all

global variable &#40;1, current zone&#41;

plotscript, check name zone, begin
	variable &#40;checkzone, z, i, changed&#41;

	## Loop through all potentially overlapping zones
	z &#58;= zone at spot &#40;hero x&#40;me&#41;, hero y&#40;me&#41;, get count&#41;
	for &#40;i, 0, z&#41; do &#40;
		## Making sure we aren't re-displaying the name zone we're already in.
		checkzone &#58;= zone at spot &#40;hero x&#40;me&#41;, hero y&#40;me&#41;, i&#41;
		if &#40;checkzone == current zone&#41; then &#40;exit script&#41;

		## Checking for zones between 100-199, and storing the zone's
		## name in string 1 if it's there.
		if &#40;checkzone >= 100 && checkzone < 200&#41; then &#40;
			get zone name &#40;1, checkzone&#41;
			changed &#58;= true
			break
		&#41;
	&#41;
	if &#40;changed&#41; then &#40;
		show string at &#40;1, 10, 180&#41; ## Lower left, more or less.
		set timer &#40;1, 3, 18, @hide name zone&#41;	## 3 second timer before hiding name.
		current zone &#58;= checkzone
	&#41;
end

script, hide name zone, begin
	hide string &#40;1&#41;
end
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I see you uploaded an example game! Best to link to that here: Show zone names

Oops, I think I was to blame for the ||.

"for (i, 0, z) do (" should be "for (i, 0, z -- 1) do ("

What I meant by getting rid of 'changed' was to move everything in the "if (changed)" block into the for loop. But it only saves you two lines of code, so never mind.
Last edited by TMC on Tue Jan 02, 2018 4:09 am, edited 1 time in total.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Wow, I can't believe I didn't notice that earlier. Fixed that up, added the --1 back to the for loop, and it should now be good.

Code: Select all

global variable &#40;1, current zone&#41;

plotscript, check name zone, begin
	variable &#40;checkzone, z, i&#41;

	## Loop through all potentially overlapping zones
	z &#58;= zone at spot &#40;hero x&#40;me&#41;, hero y&#40;me&#41;, get count&#41;
	for &#40;i, 0, z--1&#41; do &#40;
		## Making sure we aren't re-displaying the name zone we're already in.
		checkzone &#58;= zone at spot &#40;hero x&#40;me&#41;, hero y&#40;me&#41;, i&#41;
		if &#40;checkzone == current zone&#41; then &#40;exit script&#41;

		## Checking for zones between 100-199, and storing the zone's
		## name in string 1 if it's there.
		if &#40;checkzone >= 100 && checkzone < 200&#41; then &#40;
			get zone name &#40;1, checkzone&#41;
			show string at &#40;1, 10, 180&#41; ## Lower left, more or less.
			set timer &#40;1, 3, 18, @hide name zone&#41;	## 3 second timer before hiding name.
			current zone &#58;= checkzone
			break
		&#41;
	&#41;
end

script, hide name zone, begin
	hide string &#40;1&#41;
end
Last edited by Foxley on Tue Jan 02, 2018 7:05 am, edited 1 time in total.
Post Reply