 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Onlyoneinall Bug finder
Joined: 16 Jul 2005 Posts: 746
|
Posted: Tue Jul 10, 2007 1:55 am Post subject: Range detection |
|
|
I'm pretty sure I saw this before somewhere, but I've searched and can't seem to find the answer.
How would I work a script so that when a hero and NPC are within certain # of tiles near each other, something different happens? I'm not even sure how I would have to word it to get it to work. _________________ http://www.castleparadox.com/gamelist-display.php?game=750 Bloodlust Demo 1.00
 |
|
Back to top |
|
 |
jabbercat Composer

Joined: 04 Sep 2003 Posts: 823 Location: Oxford
|
Posted: Tue Jul 10, 2007 2:25 am Post subject: |
|
|
you'd need to check the location of every tile within a certain radius of the hero. take the hero's x&y and offset it according to the number of tiles you want to check, you'll have to work out how to do diagonals too though. _________________ Moogle no longer owes prizes. |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
|
Back to top |
|
 |
Onlyoneinall Bug finder
Joined: 16 Jul 2005 Posts: 746
|
Posted: Wed Jul 11, 2007 12:20 am Post subject: |
|
|
Thanks!
But, could you explain to me how to use it? I tried but it doesn't seem to be working successfully. I want it so that a moving NPC will change speed once you are within say, 5 tiles of it. How would I do this?
Code: | script,NPC in range,hero,NPC,range,begin
variable(difference)
# by default, the result is false
return(false)
# check vertically
difference:=NPC Y(NPC) -- Hero Y(hero)
if(difference<=range,and,difference>=range*-5) then(
# yes, the NPC is in range vertically
# now check horizontally
difference:=NPC X(NPC) -- Hero X(hero)
if(difference<=range,and,difference>=range*-5) then(
return(true)
)
)
if (return(false))
then, begin
alter NPC (4,NPCstat:move speed,1)
end
else,begin
alter NPC (4,NPCstat:move speed,10)
end
end |
I don't think I did it right. _________________ http://www.castleparadox.com/gamelist-display.php?game=750 Bloodlust Demo 1.00
 |
|
Back to top |
|
 |
Calehay ...yeah. Class B Minstrel

Joined: 07 Jul 2004 Posts: 549
|
Posted: Wed Jul 11, 2007 2:32 am Post subject: |
|
|
What's happening when you try it?
I know what it is. "difference>=range*-5" is not the amount of tiles, it's just a statment used to make the "range" variable negative so that you can find out if the "difference" value is reporting a negative instead of a positive.
So what you need to do is change all of the fives back to negative ones. You'll notice in James' Paige's script that range is set up in this line:
Code: | define script(autonumber,NPC in range,3,0,0,0) |
That 3 is the one you need to change to a five.
Of course, I'm somewhat new to arguments, so I might be quoting the wrong one, but I'm 95% sure that's what the problem is. _________________ Calehay |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Wed Jul 11, 2007 7:01 am Post subject: |
|
|
Onlyoneinall wrote: | Thanks!
But, could you explain to me how to use it? I tried but it doesn't seem to be working successfully. I want it so that a moving NPC will change speed once you are within say, 5 tiles of it. How would I do this? |
Nah. This is supposed to be used as a function. Remove the stuff you added to the end. (by the way "if(return(false))" is totally bogus and will never do what you intend). Anyway, you want want to call "NPC in rage" from a loop that checks the NPC over and over. Maybe something like this:
Code: | script,endless loop,begin
variable(NPC)
NPC := NPC reference(7) # use the first copy of NPC ID 7
while(true) do, begin
if (NPC in range (me, NPC, 5)) then, begin
set NPC speed(NPC, 10) # go fast
end, else, begin
set NPC speed(NPC, 4) # go normal speed
end
wait (1)
end
end |
|
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Wed Jul 11, 2007 7:04 am Post subject: |
|
|
Onlyoneinall wrote: |
Code: |
if (return(false))
then, begin
alter NPC (4,NPCstat:move speed,1)
end
else,begin
alter NPC (4,NPCstat:move speed,10)
end
end |
I don't think I did it right. |
Did both of you miss this part? This is completely wrong.
Use the script as originally written and call it from something like James wrote. _________________
|
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Wed Jul 11, 2007 7:05 am Post subject: |
|
|
Moogle1 wrote: |
Did both of you miss this part? This is completely wrong.
|
Yes, I did miss it, and I edited my post after I saw it. |
|
Back to top |
|
 |
Onlyoneinall Bug finder
Joined: 16 Jul 2005 Posts: 746
|
Posted: Wed Jul 11, 2007 8:42 am Post subject: |
|
|
Thanks. Do I set the endless loop script as an Autorun Script?
Also, the NPC gets stuck in between tiles. I tried to do add if(NPC is walking), but for some reason it freezes the game from moving. What should I do to make it so the NPC doesn't get stuck if the script activates while it's moving? _________________ http://www.castleparadox.com/gamelist-display.php?game=750 Bloodlust Demo 1.00
 |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Wed Jul 11, 2007 8:49 am Post subject: |
|
|
Those are both good questions. I would recommend setting it as a map autorun script and changing this line Code: | while(true) do, begin | to this: Code: | while(current map == map:My Map Name) do, begin | (using the actual map name from your HSI file, of course).
As for your second question, I think you can avoid any errors by changing this line to This will change the script so that it checks how far the NPC is from you after each time the NPC takes a step.
So the final script looks like this:
Code: | script,endless loop,begin
variable(NPC)
NPC := NPC reference(7) # use the first copy of NPC ID 7
while(current map == map:My Map Name) do, begin
if (NPC in range (me, NPC, 5)) then, begin
set NPC speed(NPC, 10) # go fast
end, else, begin
set NPC speed(NPC, 4) # go normal speed
end
wait for NPC (NPC)
end
end |
And you can call it as a map autorun script, as long as it's on just the one map. _________________
|
|
Back to top |
|
 |
Onlyoneinall Bug finder
Joined: 16 Jul 2005 Posts: 746
|
Posted: Wed Jul 11, 2007 10:36 am Post subject: |
|
|
Thanks for the help! The script works perfectly now.
As my way of saying thanks, let me show you the creature I intend the script for.
(That's the walkabout pic, battle pic, and backdrop pic from left to right)
Plus extra image:
 _________________ http://www.castleparadox.com/gamelist-display.php?game=750 Bloodlust Demo 1.00
 |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Wed Jul 11, 2007 2:49 pm Post subject: |
|
|
Beware of script overload when trying to use loops in map autorun scripts. If you have doors that go from this map to itself (stairs are the first example that springs to mind for me), then you will re-call the autorun script every time you use one of these doors. But since you never left the current map, the loop never stopped, so you have a new loop on top of the old one, and if you do this several times, you will have several such loops sitting on each other. It can also cause a problem if your map is set to remember its state upon leaving, because you will call the script and all of your commands will be run from where the NPC is currently standing.
The easiest solution I can think of (if this is even an issue for you; it was for me) is to have a tag that is turned on when the loop is running, and turned off if it is completed. The following is untested, I'm afraid:
Code: | script, mapautorun, begin
if(check tag (tag:loop running)==false),then
begin
set tag (tag:loop running, on)
while (currentmap==map:My map),do
begin
#all your stuff
end
set tag (tag:loop running, off)
end
end |
Something like this can help in many 'infinite loop' situations. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
Onlyoneinall Bug finder
Joined: 16 Jul 2005 Posts: 746
|
Posted: Wed Jul 11, 2007 2:53 pm Post subject: |
|
|
Thanks. Fortunately, this current map doesn't have any doors except out of the map itself, so the loops shouldn't be a problem. However, I am planning to use the script again in maps that will have doors leading around such most likely, so your input is appreciated and I will let you know whether or not it works in the near future.  _________________ http://www.castleparadox.com/gamelist-display.php?game=750 Bloodlust Demo 1.00
 |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Wed Jul 11, 2007 3:03 pm Post subject: |
|
|
Actually, this will be a problem if you go from one map that uses the script to another that uses a looping autorun script. The script msw posted will keep you from having any problems with stack overflow.
If you want to use that script on multiple maps, you can do something like this:
Code: | while (current map==map:My map,or,current map==map:My other map,or,current map==map:A more different map),do |
etc. _________________
|
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|