get_nearest_char

Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /var/www/pied-piper.ermarian.net/includes/common.inc).
AuthorTopic: get_nearest_char
The Establishment
Member # 6
Profile #0
It seems when the get_nearest_char commands are called in a creature script, it returns its own number for its value. The creature running the script was created using the place_monster call.

Is anyone else having problems with this?

--------------------
Your flower power is no match for my glower power!
Posts: 3726 | Registered: Tuesday, September 18 2001 07:00
Agent
Member # 2820
Profile #1
You're right! get_nearest_char() and get_nearest_good_char() always return the creature for which the script is running. I think those were mainly for use with terrain scripts, though. But that is unfortunate because then this would be the only good alternative:

i = 0;
closest = dist_to_char(i);
i = i +1;
while (i < 120) {
if (dist_to_char(i) < closest)
closest = i;
}


--------------------
Thuryl: I mean, most of us don't go around consuming our own bodily fluids, no matter how delicious they are.
====
Alorael: War and violence would end if we all had each other's babies!
====
Drakefyre: Those are hideous mangos.
Posts: 1415 | Registered: Thursday, March 27 2003 08:00
Post Navel Trauma ^_^
Member # 67
Profile Homepage #2
I assume you mean closest = dist_to_char(i), not closest = i

--------------------
Barcoorah: I even did it to a big dorset ram.

New Mac BoE
Posts: 1798 | Registered: Thursday, October 4 2001 07:00
Off With Their Heads
Member # 4045
Profile Homepage #3
No, because the idea is to get the nearest character number, not the distance to the nearest character.

--------------------
Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens.
Smoo: Get ready to face the walls!
Ephesos: In conclusion, yarr.

Kelandon's Pink and Pretty Page!!: the authorized location for all things by me
The Archive of all released BoE scenarios ever
Posts: 7968 | Registered: Saturday, February 28 2004 08:00
Shock Trooper
Member # 4154
Profile #4
Creature scripts perplex me beyond belief... And if I'm not baffled more than I think I am, I'll allow myself to point out that 'while' doesn't seem necessary there. Wouldn't an 'if' work the same? Or am I just creature-script-inept?

--------------------
You're a moron if you think I'm not.
Posts: 213 | Registered: Friday, March 26 2004 08:00
Off With Their Heads
Member # 4045
Profile Homepage #5
The idea of the "while" is to check the distance of every single possible living monster and keep track of which one is the lowest. An "if" wouldn't really do that.

Although, looking at it again, I realize that the "i = i + 1" part is misplaced. It should be inside the "while," or else the thing will loop infinitely.

--------------------
Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens.
Smoo: Get ready to face the walls!
Ephesos: In conclusion, yarr.

Kelandon's Pink and Pretty Page!!: the authorized location for all things by me
The Archive of all released BoE scenarios ever
Posts: 7968 | Registered: Saturday, February 28 2004 08:00
Shock Trooper
Member # 4154
Profile #6
Ahhh, that makes more sense then. I still don't get what's going on, but it makes more sense.

--------------------
You're a moron if you think I'm not.
Posts: 213 | Registered: Friday, March 26 2004 08:00
Agent
Member # 2820
Profile #7
Oh yes, there are many problems with my code.

i = 0;
closest = i;
while (i < 120) {
if (dist_to_char(i) < dist_to_char(closest));
closest = i;
i = i + 1;
}


--------------------
Thuryl: I mean, most of us don't go around consuming our own bodily fluids, no matter how delicious they are.
====
Alorael: War and violence would end if we all had each other's babies!
====
Drakefyre: Those are hideous mangos.
Posts: 1415 | Registered: Thursday, March 27 2003 08:00