Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
teion
Wanderer


Joined: 03 May 2005
Posts: 72

PostPosted: Mon Nov 22, 2010 6:29 pm   

speedwalk to closest room in a string list
 
I have mapped a favorite mud of mine and Have a string list variable called @Healerlist that contains the room vnums of healers on the mud I play.
I would like to be able to run an the alias Goheal to #walk to the closest room in the list @Healerlist

I'm assuming I should have to use some sort of #if statement to accomplish this task

any help is appreciated
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Nov 22, 2010 9:10 pm   
 
Ah, a fun one. I've done a couple things similar, let me see if I can recall how...
It would be something like this, but I don't guarantee this will work without testing:
[edited to correct the code a bit]
Code:

#LOCAL $pathlength $curpathlength $closest
$curpathlength = 99999999999
#FORALL @healerlist {
  $pathlength = %numitems(%pathexpand(%pathfrom(,%i)))
  #IF ($pathlength < $curpathlength) {
    $closest = %i
    $curpathlength = $pathlength
  }
}
#show Closest healer room is: $closest, $pathlength rooms away
Reply with quote
Scarn
Apprentice


Joined: 24 Jul 2005
Posts: 137

PostPosted: Mon Feb 24, 2014 10:25 am   
 
I have this exact feature, you will need the following alias for this to function correctly.

Code:
#ALIAS mark {#VAR MarkedRoom %roomvnum}


Here is my script for running to the closest healer.

Code:
#UNVAR Healers
mark
{#ADDKEY Healers  %len(%pathexpand(%pathfrom(,healer1))) healer1} {}
{#ADDKEY Healers  %len(%pathexpand(%pathfrom(,healer2)))  healer2} {}
#SORT Healers numeric


The above adds healer1 and healer2 (they are room nicknames) to a variable and sorts them by length.
Therefore you just need to run to the following, and it will run to the closest healer.

Code:
#WALK %item(Healers,1)


Hope this helps, this is the code cut down a lot. I have features that allow me to disable
healers from the list if they are exhausted etc...
Reply with quote
Llohr
Apprentice


Joined: 17 May 2005
Posts: 108

PostPosted: Wed Feb 26, 2014 8:04 pm   
 
One note, though it wouldn't matter to this script, using %len(%pathexpand(some path)) returns the length of the path, in addition to all of the separator characters (pipes} between the steps, so %len(%pathexpand(3ne)) would return 7, rather than 4. %numitems(%pathexpand(some path)) will give the correct number of steps.
Reply with quote
Scarn
Apprentice


Joined: 24 Jul 2005
Posts: 137

PostPosted: Wed Feb 26, 2014 8:24 pm   
 
Ah, thanks. I will modify my script.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Feb 27, 2014 12:37 am   
 
Door commands are included in paths given via mapper commands/functions. This will throw off your step count.
_________________
EDIT: I didn't like my old signature
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot 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

© 2009 Zugg Software. Hosted by Wolfpaw.net