Post new topic    
Slime
Send private message
Location name on screen question 
 PostSat Dec 30, 2017 11:36 pm
Send private message Reply with quote
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!
Metal Slime
Send private message
 
 PostSun Dec 31, 2017 2:31 am
Send private message Reply with quote
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:
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
Metal Slime
Send private message
 
 PostSun Dec 31, 2017 2:54 am
Send private message Reply with quote
Test went pretty well on my end.
Metal King Slime
Send private message
 
 PostSun Dec 31, 2017 6:36 am
Send private message Reply with quote
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.
Metal Slime
Send private message
 
 PostSun Dec 31, 2017 8:38 am
Send private message Reply with quote
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:
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.
Metal Slime
Send private message
 
 PostSun Dec 31, 2017 9:09 am
Send private message Reply with quote
Here we go. Tested, and it works.

Code:
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 (checkzone >= 100 || checkzone < 200) then (
         get zone name (1, checkzone)
         break
      )
   )

   show string at (1, 10, 180) ## Lower left, more or less.
   set timer (1, 3, 18, @hide name zone)   ## 3 second timer before hiding name.
   current zone := checkzone
end

script, hide name zone, begin
   hide string (1)
end


EDIT: Trimmed down the code some, with TMC's input.
Slime
Send private message
 
 PostSun Dec 31, 2017 1:02 pm
Send private message Reply with quote
Thank you so much for your help folks, this is incredibly helpful!

A happy new year to you when it comes!
Metal Slime
Send private message
 
 PostSun Dec 31, 2017 6:13 pm
Send private message Reply with quote
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.
Metal Slime
Send private message
 
 PostSun Dec 31, 2017 6:26 pm
Send private message Reply with quote
Alright, so two things:

Code:
if (checkzone >= 100 || checkzone < 200)

^^ 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:
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) 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 (checkzone >= 100 && checkzone < 200) then (
         get zone name (1, checkzone)
         changed := true
         break
      )
   )
   if (changed) then (
      show string at (1, 10, 180) ## Lower left, more or less.
      set timer (1, 3, 18, @hide name zone)   ## 3 second timer before hiding name.
      current zone := checkzone
   )
end

script, hide name zone, begin
   hide string (1)
end
Metal King Slime
Send private message
 
 PostTue Jan 02, 2018 4:07 am
Send private message Reply with quote
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.
Metal Slime
Send private message
 
 PostTue Jan 02, 2018 7:02 am
Send private message Reply with quote
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:
global variable (1, current zone)

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

   ## 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 (checkzone >= 100 && checkzone < 200) then (
         get zone name (1, checkzone)
         show string at (1, 10, 180) ## Lower left, more or less.
         set timer (1, 3, 18, @hide name zone)   ## 3 second timer before hiding name.
         current zone := checkzone
         break
      )
   )
end

script, hide name zone, begin
   hide string (1)
end
Display posts from previous: