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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Thu Sep 22, 2005 7:28 pm   

%random & #send added question
 
Since no answered me when i posted this as an add-on question to an old topic of mine that had labled *solved* reposting it in it's own topic:

Something that I had been meaning to ask and never got around to.
Code:
#CLASS {PortalShuffle}
#ALIAS Shuffle {
#RESET "portalshuffle"
bo personal
note write Vitae
Maze Portal Switches
#SEND "~@CRoom Vnum: A"
#SEND "~@GPortal reset order~@M"
#4 {
  #VARIABLE A_Index %random( 1, %numitems( @A))
  #VARIABLE A_Shuffle %item( @A, @A_Index)
  #DELNITEM A @A_Index
  #SEND %eval( @A_Shuffle)
}
#SEND "~@CRoom Vnum: B"
#SEND "~@GPortal reset order~@M"
#4 {
  #VARIABLE B_Index %random( 1, %numitems( @B))
  #VARIABLE B_Shuffle %item( @B, @B_Index)
  #DELNITEM B @B_Index
  #SEND %eval( @B_Shuffle)
}
#SEND "~@CRoom Vnum: C"
#SEND "~@GPortal reset order~@M"
#4 {
  #VARIABLE C_Index %random( 1, %numitems( @C))
  #VARIABLE C_Shuffle %item( @C, @C_Index)
  #DELNITEM C @C_Index
  #SEND %eval( @C_Shuffle)
}
#SEND ~@w
#SEND "~@CRoom Vnum: D"
#SEND "~@GPortal reset order~@M"
#4 {
  #VARIABLE D_Index %random( 1, %numitems( @D))
  #VARIABLE D_Shuffle %item( @D, @D_Index)
  #DELNITEM D @D_Index
  #SEND %eval( @D_Shuffle)
}
#SEND "~@CRoom Vnum: E"
#SEND "~@GPortal reset order~@M"
#4 {
  #VARIABLE E_Index %random( 1, %numitems( @E))
  #VARIABLE E_Shuffle %item( @E, @E_Index)
  #DELNITEM E @E_Index
  #SEND %eval( @E_Shuffle)
}
#SEND "~@CRoom Vnum: F"
#SEND "~@GPortal reset order~@M"
#4 {
  #VARIABLE F_Index %random( 1, %numitems( @F))
  #VARIABLE F_Shuffle %item( @F, @F_Index)
  #DELNITEM F @F_Index
  #SEND %eval( @F_Shuffle)
  }
#SEND ~@w
#SEND Thank you.
#SEND end
#SEND p
  }
#VARIABLE A {1|2|3|4} {1|2|3|4}
#VARIABLE B {3|1|5|4} {3|1|5|4}
#VARIABLE C {1|6|3|4} {1|6|3|4}
#VARIABLE D {2|1|3|4} {2|1|3|4}
#VARIABLE E {4|2|3|1} {4|2|3|1}
#VARIABLE F {3|1|7|4} {3|1|7|4}
#VARIABLE A_Index {1}
#VARIABLE A_Shuffle {3}
#VARIABLE B_Index {1}
#VARIABLE B_Shuffle {1}
#VARIABLE C_Index {1}
#VARIABLE C_Shuffle {4}
#VARIABLE D_Index {1}
#VARIABLE D_Shuffle {4}
#VARIABLE E_Index {1}
#VARIABLE E_Shuffle {4}
#VARIABLE F_Index {1}
#VARIABLE F_Shuffle {7}
#CLASS 0
OutPut:
Code:
Room Vnum: A
Portal reset order
4
3
2
1
Room Vnum: B
Portal reset order
3
5
1
4
Room Vnum: C
Portal reset order
1
6
3
4
Room Vnum: D
Portal reset order
1
2
4
3
Room Vnum: E
Portal reset order
2
4
3
1
Room Vnum: F
Portal reset order
3
7
1
4


(the ~@C ~@G ~@M are Aards color codes)
The thing is, in each room only one portal needs to be shuffled. The one that needs to be shuffled is the one that ALWAYS needs to be shuffled. The other 3 all lead to the same room and don't need to be moved except to be replaced by the correct one. So basically, I think the whole loop part is useless.

If in room A #4 is the one that needs to be shuffled then when i run it again (for at least the next 2 times) what would it look like to have it just change that.
The other #'s in each vnum are of no concern but cost gold to change and hence a waste of gold.
So if the current sort is 1 2 3 4 with 4 being the correct one, the next time i shuffle, if i can have 1 4 3 2, and then the next 4 1 3 2 type of thing...not sure how to go about it. 3 hasn't moved which is right.
I'm assuming this is a whole store the room vnum/portal id to a var and compare with an %ismember but honestly aint sure and not even 75% sure what the heck this code even does :-) for example why is *_Index ALWAYS 1. don't matter what i put as room vnum or portal, not even if i delete it. it comes out to 1...wth?

Thanks for any help
*bow*

Original topic: http://forums.zuggsoft.com/phpbb/viewtopic.php?t=20114&highlight=portal+shuffle
_________________
http://www.Aardwolf.com
Reply with quote
billaben
Wanderer


Joined: 02 Sep 2005
Posts: 60

PostPosted: Thu Sep 22, 2005 7:41 pm   
 
HUmm.... set the code aside for a minute. Before I can really think about this one I need a clearer picture of what exactly this shuffle concept is intended to do.
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Thu Sep 22, 2005 8:17 pm   
 
well, ya can start by reading the posts in the link i provided.
But in a nut shell
lets say I have 4 portals
1
2
3
4

My clan gets raided and they figure out portal 4 is the one that leads into the next part of the maze. I request a resort of the portals so that portal 4 is now actually in the 2nd slot
1
4
3
2

Next time a raid party comes in they try portal 4 (which is really now portal 2) and they go to the jail room
i'm using 1 2 3 4, but in reality it's portal vnums. like 55467 55465 55462 55469
_________________
http://www.Aardwolf.com
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Wed May 31, 2006 12:59 pm   
 
Well, still looking for some help on this :-)
Basically, whichever leader(s) has/have the responsibility of keeping the maze portals up to date after raids runs this script and it writes a note to the imms with a new sorted order of portals.
The only thing is that it does a COMPLETE shuffle.
Normally there are 4 portals in a room. 1 leads to the next part of the maze, and the other 3 lead to the jail (or something).
The problem here is that I could never figure out how to get just the ONE room to change places with just ONE of the jail portals. So of course there is always the extra cost (unless you got an imm that knew what they were doing and could just shuffle on thier own the 2 rooms.
You have portals 1, 2, 3 & 4 in room A. You get raided and the raiders see that Portal 4 is the right one. After the Raid you do shuffle command and it asks that portals be set as 1, 4, 3, 2. (well thats the way I WISH it was rather than winding up with 2, 4, 1, 3 or other variations.)

Code:
#CLASS {PortalShuffle}
#ALIAS Shuffle {
  #RESET "portalshuffle"
  bo upgrades
  note write imm
  Maze Portal Switches
  #SEND "~@@CRoom Vnum: A"
  #SEND "~@@GPortal reset order~@@M"
  #LOOP 4 {
    #VARIABLE A_Index %random( 1, %numitems( @@A))
    #VARIABLE A_Shuffle %item( @@A, @@A_Index)
    #DELNITEM A @@A_Index
    #SEND %eval( @@A_Shuffle)
    }
  #SEND ~@@w
  #SEND "~@@CRoom Vnum: B"
  #SEND "~@@GPortal reset order~@@M"
  #LOOP 4 {
    #VARIABLE B_Index %random( 1, %numitems( @@B))
    #VARIABLE B_Shuffle %item( @@B, @@B_Index)
    #DELNITEM B @@B_Index
    #SEND %eval( @@B_Shuffle)
    }
  #SEND ~@@w
  #SEND "~@@CRoom Vnum: C"
  #SEND "~@@GPortal reset order~@@M"
  #LOOP 4 {
    #VARIABLE C_Index %random( 1, %numitems( @@C))
    #VARIABLE C_Shuffle %item( @@C, @@C_Index)
    #DELNITEM C @@C_Index
    #SEND %eval( @@C_Shuffle)
    }
  #SEND ~@@w
  #SEND "~@@CRoom Vnum: D"
  #SEND "~@@GPortal reset order~@@M"
  #LOOP 4 {
    #VARIABLE D_Index %random( 1, %numitems( @@D))
    #VARIABLE D_Shuffle %item( @@D, @@D_Index)
    #DELNITEM D @@D_Index
    #SEND %eval( @@D_Shuffle)
    }
  #SEND ~@@w
  #SEND "~@@CRoom Vnum: E"
  #SEND "~@@GPortal reset order~@@M"
  #LOOP 4 {
    #VARIABLE E_Index %random( 1, %numitems( @@E))
    #VARIABLE E_Shuffle %item( @@E, @@E_Index)
    #DELNITEM E @@E_Index
    #SEND %eval( @@E_Shuffle)
    }
  #SEND ~@@w
  #SEND "~@@CRoom Vnum: F"
  #SEND "~@@GPortal reset order~@@M"
  #LOOP 4 {
    #VARIABLE F_Index %random( 1, %numitems( @@F))
    #VARIABLE F_Shuffle %item( @@F, @@F_Index)
    #DELNITEM F @@F_Index
    #SEND %eval( @@F_Shuffle)
    }
  #SEND ~@@w
  #SEND Thank you.
  #SEND end
  #SEND p
  }
#VARIABLE A {} {1|2|3|4}
#VARIABLE B {} {3|1|5|4}
#VARIABLE C {} {1|6|3|4}
#VARIABLE D {} {2|1|3|4}
#VARIABLE E {} {4|2|3|1}
#VARIABLE F {} {3|1|7|4}
#VARIABLE A_Index {1}
#VARIABLE A_Shuffle {4}
#VARIABLE B_Index {1}
#VARIABLE B_Shuffle {5}
#VARIABLE C_Index {1}
#VARIABLE C_Shuffle {4}
#VARIABLE D_Index {1}
#VARIABLE D_Shuffle {2}
#VARIABLE E_Index {1}
#VARIABLE E_Shuffle {2}
#VARIABLE F_Index {1}
#VARIABLE F_Shuffle {4}
#CLASS 0
_________________
http://www.Aardwolf.com
Reply with quote
dbsexton
Newbie


Joined: 19 Mar 2006
Posts: 6

PostPosted: Wed May 31, 2006 10:05 pm   
 
Well, here is a really dirty example I did on my lunch break

Assumptions:

1.) You can extract the vnum of the room that links to the maze into the variable goodvnum. For the example below to be able to run "as is", I gave it a vnum of 102.

2.) It assumes that you can extract all the vnums for the looping rooms and the maze into the string list roomvnumlist. What you would consider the 1st doorway is the first entry, the second door is the second entry and so on. For the example below to be able to run "as is", I made the 1st, 2nd, 3rd, and 4th doors as 103, 101, 104, and 102 respectively. This means that the 1st, 2nd and 3rd doors loop and the 4th door goes to the maze.

3.) It also assumes that there are 4 total doorways. I couldn't find a "what is the length of the list" function, or I would have used that instead of the 4's below in the random functions.


Basic concept:

Stuff you need to do:
1.) Extract the maze vnum into goodvnum.
2.) Extract all of the room vnums into a string list where the room vnum is added to the list in the order that you would count them. In other words, the first rooms vnum would be added first, the second room added second, etc.

Stuff the script does:
3.) Find the index of goodvnum in roomvnumlist.
3.) If the value is 0, then goodvnum is not in the room list and the script is aborted.
4.) Get a random number from 1 to 4 (or ideally from 1 to length of the string list).
5.) while the random number is equal to our maze vnumindex, get a new random number.
6.) Get the value of the string item that is in our random number slot.
7.) Loop through our roomvnumlist. If the item matches the maze vnum, then add the vnum of the switching room to the new list, else if the item matches the switching room vnum, then add the maze vnum to the new list, else add the item to the new string list.


In layman's terms, find the maze room, pick one random room that is not the maze room, walk through the room list switching only the maze room and the chosen random room. You should be able to then do whatever you need with the new string list. This example is set so you can run it multiple times to ensure that the rooms orders are switching correctly. You'll need to write the support code to get it to work in your situation. It could also use some code refactoring and cleanup.

Code:

#var goodvnum 102
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#if (@roomvnumlist = "") {
   #var roomvnumlist "103|101|104|102"
}
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {
   #say Aborting. None of the roomlinks match the good vnum link
} {
  switchvnumindex = %random( 1, 4)
  #while (@switchvnumindex == @vnumindex) {
   switchvnumindex = %random( 1, 4)
  }
  switchvnum = %item( @roomvnumlist, @switchvnumindex)
  #FORALL @roomvnumlist {
   #if (%i = @goodvnum) {
      #ADDITEM newroomvnumlist @switchvnum
   } {
      #if (%i = @switchvnum) {
         #ADDITEM newroomvnumlist @goodvnum
      } {
         #ADDITEM newroomvnumlist %i
      }
   }
  }
}
#say @newroomvnumlist
roomvnumlist = @newroomvnumlist
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Thu Jun 01, 2006 3:30 pm   
 
Each Room & Portal Vnum are already known.
I am not talking about anything on the MAP btw, dunno if I mentioned that.
A clan leader knows the Vnums of everything in the clan. Every portal, every room. Zmud maps have nothing to do with it.
The Room Vnums lets pretend are
12345, 23456, 34567
the portal vnums lets pretend in room 12345 are
98765, 87654, 76543, 65432
Portal 76543 is the portal that leads to Room 23456

The clan gets raided.
After the raid a leader runs the script, and it posts a note asking to change the order of each and every rooms portals

98765, 87654, 76543, 65432 is changed to 98765, 76543, 87654, 65432
etc etc for all the rooms
Note: 76543 is the only portal that works in that room, and there is NO duplicate of 76543 ANYWHERE in any other room
98765, 87654, 65432 all lead to another part of the maze, 9 outta 10 times the Jail room.
Any one of those portals can be in any other part of the maze.

What will be done is that the leaders will simply type in the vnums for the vars. The note itself contains the room vnum becuase the Imm's that change it need to know what room to go to and typing goto A is all they need to do.

Basically all i need is for someway to have JUST 76543 moved with another portal vnum.
What it's doing now is moving everything, with the off chance that the move of the correct portal isnt even happening.
98765, 87654, 76543, 65432 can just as easily become 65432, 87654, 76543, 98765 which is of NO benefit at all, because 10mil in gold is wasted on a portal move that was not needed since they both lead to the same jail, and the portal that WAS needed to move didnt.

Not sure if I am even being clear after all this typing cause I only had one cup of coffee today and battling a migraine.

1, 2, 3, 4
3 is the MAIN one.
move 3 to another spot.
move replaced Portal to 3's original spot.


---
Also, i noted that I posted the code badly on here, I had extra @'s all over the place from a posting I did on the note board on Aard
Code:
#RESET "portalshuffle"
bo upgrade
note write imm
Maze Portal Switches
#SEND "~@CRoom Vnum: A"
#SEND "~@GPortal reset order~@M"
#LOOP 4 {
  #VARIABLE A_Index %random( 1, %numitems( @A))
  #VARIABLE A_Shuffle %item( @A, @A_Index)
  #DELNITEM A @A_Index
  #SEND %eval( @A_Shuffle)
  }
#SEND ~@w
#SEND "~@CRoom Vnum: B"
#SEND "~@GPortal reset order~@M"
#LOOP 4 {
  #VARIABLE B_Index %random( 1, %numitems( @B))
  #VARIABLE B_Shuffle %item( @B, @B_Index)
  #DELNITEM B @B_Index
  #SEND %eval( @B_Shuffle)
  }
#SEND ~@w
#SEND "~@CRoom Vnum: C"
#SEND "~@GPortal reset order~@M"
#LOOP 4 {
  #VARIABLE C_Index %random( 1, %numitems( @C))
  #VARIABLE C_Shuffle %item( @C, @C_Index)
  #DELNITEM C @C_Index
  #SEND %eval( @C_Shuffle)
  }
#SEND ~@w
#SEND "~@CRoom Vnum: D"
#SEND "~@GPortal reset order~@M"
#LOOP 4 {
  #VARIABLE D_Index %random( 1, %numitems( @D))
  #VARIABLE D_Shuffle %item( @D, @D_Index)
  #DELNITEM D @D_Index
  #SEND %eval( @D_Shuffle)
  }
#SEND ~@w
#SEND "~@CRoom Vnum: E"
#SEND "~@GPortal reset order~@M"
#LOOP 4 {
  #VARIABLE E_Index %random( 1, %numitems( @E))
  #VARIABLE E_Shuffle %item( @E, @E_Index)
  #DELNITEM E @E_Index
  #SEND %eval( @E_Shuffle)
  }
#SEND ~@w
#SEND "~@CRoom Vnum: F"
#SEND "~@GPortal reset order~@M"
#LOOP 4 {
  #VARIABLE F_Index %random( 1, %numitems( @F))
  #VARIABLE F_Shuffle %item( @F, @F_Index)
  #DELNITEM F @F_Index
  #SEND %eval( @F_Shuffle)
  }
#SEND ~@w
#SEND Thank you.
#SEND end
#SEND p
_________________
http://www.Aardwolf.com
Reply with quote
dbsexton
Newbie


Joined: 19 Mar 2006
Posts: 6

PostPosted: Thu Jun 01, 2006 4:50 pm   
 
If you run my code, you will see that what you are asking is exactly what it does.
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Thu Jun 01, 2006 6:10 pm   
 
?, I got say 10 rooms with 4 portals, 1 portal in each room is a good one. So I got 10 good vnums for portals
What do I do with this part?
#var goodvnum 102
Do i incorporate that into the loop somehow?
_________________
http://www.Aardwolf.com
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Thu Jun 01, 2006 6:45 pm   
 
So, intergrating your script into mine I got these results
for the record these are what my roomvnumlist vars are for each room:
1|2|3|4
5|2|3|4
6|2|3|4
7|2|3|4
8|2|3|4
9|2|3|4

I run the script and these are the output results:
4|2|3|1
4|2|5|1
6|2|5|1
6|7|5|1
8|7|5|1
9|7|5|1

Not even close to being correct

Here's what the code looks like with your code put in:

Code:
#RESET "shuffle2"
bo upgrade
note write imm
Maze Portal Switches
#SEND "~@CRoom Vnum: A"
#SEND "~@GPortal reset order~@M"
#var goodvnum 1
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#if (@roomvnumlist = "") {#var roomvnumlist "1|2|3|4"}
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
  switchvnumindex = %random( 1, 4)
  #while (@switchvnumindex == @vnumindex) {switchvnumindex = %random( 1, 4)}
  switchvnum = %item( @roomvnumlist, @switchvnumindex)
  #FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
  }
#say @newroomvnumlist
roomvnumlist = @newroomvnumlist
#SEND ~@w
#SEND "~@CRoom Vnum: B"
#SEND "~@GPortal reset order~@M"
#var goodvnum 5
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#if (@roomvnumlist = "") {#var roomvnumlist "5|2|3|4"}
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
  switchvnumindex = %random( 1, 4)
  #while (@switchvnumindex == @vnumindex) {switchvnumindex = %random( 1, 4)}
  switchvnum = %item( @roomvnumlist, @switchvnumindex)
  #FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
  }
#say @newroomvnumlist
roomvnumlist = @newroomvnumlist
#SEND ~@w
#SEND "~@CRoom Vnum: C"
#SEND "~@GPortal reset order~@M"
#var goodvnum 6
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#if (@roomvnumlist = "") {#var roomvnumlist "6|2|3|4"}
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
  switchvnumindex = %random( 1, 4)
  #while (@switchvnumindex == @vnumindex) {switchvnumindex = %random( 1, 4)}
  switchvnum = %item( @roomvnumlist, @switchvnumindex)
  #FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
  }
#say @newroomvnumlist
roomvnumlist = @newroomvnumlist
#SEND ~@w
#SEND "~@CRoom Vnum: D"
#SEND "~@GPortal reset order~@M"
#var goodvnum 7
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#if (@roomvnumlist = "") {#var roomvnumlist "7|2|3|4"}
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
  switchvnumindex = %random( 1, 4)
  #while (@switchvnumindex == @vnumindex) {switchvnumindex = %random( 1, 4)}
  switchvnum = %item( @roomvnumlist, @switchvnumindex)
  #FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
  }
#say @newroomvnumlist
roomvnumlist = @newroomvnumlist
#SEND ~@w
#SEND "~@CRoom Vnum: E"
#SEND "~@GPortal reset order~@M"
#var goodvnum 8
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#if (@roomvnumlist = "") {#var roomvnumlist "8|2|3|4"}
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
  switchvnumindex = %random( 1, 4)
  #while (@switchvnumindex == @vnumindex) {switchvnumindex = %random( 1, 4)}
  switchvnum = %item( @roomvnumlist, @switchvnumindex)
  #FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
  }
#say @newroomvnumlist
roomvnumlist = @newroomvnumlist
#SEND ~@w
#SEND "~@CRoom Vnum: F"
#SEND "~@GPortal reset order~@M"
#var goodvnum 9
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#if (@roomvnumlist = "") {#var roomvnumlist "9|2|3|4"}
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
  switchvnumindex = %random( 1, 4)
  #while (@switchvnumindex == @vnumindex) {switchvnumindex = %random( 1, 4)}
  switchvnum = %item( @roomvnumlist, @switchvnumindex)
  #FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
  }
#say @newroomvnumlist
roomvnumlist = @newroomvnumlist
#SEND ~@w
#SEND Thank you.
#SEND end
#SEND p
_________________
http://www.Aardwolf.com
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Jun 01, 2006 8:42 pm   
 
dbsexton's code does do what you need. The problem is that when you tried to integrate it with what you had in order to do the same thing multiple times, you just put the same code over and over again just after the last copy. This means that the variables are being reused and weird stuff starts to happen.

However, we can make use of one small detail that you mentioned before. The correct portal number only appears in the list of portal numbers for just one room, and not any other room. The idea then is to build a list of valid portal numbers and check each list of room portal numbers against the "good list". If we find a match, then we swap the number that matched with another randomly selected one.

Also, to avoid repeating code, let's store all of the room portal number lists inside a record variable. This way, we can relate each room vnum with its corresponding portal number list.

#VAR randPortal {}
#VAR randPortalIndex {}
#VAR currPortalList {}
#VAR validPortals {1|5|6|7|8|9}
#ADDKEY portals {A=(1|2|3|4)|B=(5|2|3|4)|C=(6|2|3|4)|D=(7|2|3|4)|E=(8|2|3|4)|F=(9|2|3|4)}
#ALIAS shuffle {bo upgrade;note write imm;Maze Portal Switches;#LOOPDB @portals {#SEND ~@CRoom Vnum: %key;#SEND ~@GPortal reset order~@M;#FORALL @validportals {#IF (%ismember(%i, %val)) {#VAR currPortalList {%val};#VAR randPortalIndex {%random(1, %numitems(%val))};#WHILE (@randPortalIndex = %ismember(%i, %val)) {#VAR randPortalIndex {%random(1, %numitems(%val))}};#VAR randPortal {%item(%val, @randPortalIndex)};#VAR currPortalList {%replaceitem(%i, @randPortalIndex, %replaceitem(@randPortal, %ismember(%i, %val), %val))};#VAR portals {%addkey(@portals, %key, @currPortalList)}}};#FORALL %db(@portals, %key) {#SEND %i}};#SEND ~@w;#SEND Thank you.;#SEND end;#SEND p}

In the @portals record variable, the keys are the room vnums (A, B, C, D, E, and F, in this case) and the value for each key is the list of numbers for the portals in that room. As mentioned previously, the @validPortals variable contains the list of portals that are the "good ones" and which we want to shuffle around when the alias is called. It is very important that each of these room portal numbers appears in just one of the portal lists and that within that portal list it appears only once.

By the way, this script is to be entered into the command line.
_________________
Kjata
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Thu Jun 01, 2006 8:55 pm   
 
for simplicity I made 2|3|4 for all of them, but at times there could lets say a 10 in one of them that are the jail portals.
Your script don't matter with that correct?

#ADDKEY portals {A=(1|2|3|4)|B=(5|2|3|4)|C=(6|2|3|4)|D=(7|2|3|4)|E=(8|2|3|4)|F=(9|12|33|54)}
would work just as well?
_________________
http://www.Aardwolf.com
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Jun 01, 2006 9:55 pm   
 
That's correct. The script will still work with those numbers.
_________________
Kjata
Reply with quote
dbsexton
Newbie


Joined: 19 Mar 2006
Posts: 6

PostPosted: Thu Jun 01, 2006 10:18 pm   
 
I guess another assumption that I made would be that you would strip out the code that is useful for your particular sitation. I am not familiar with your mud or it's output, so I wrote code that was generic that could be adapted to your situation. The first two things I did was strip out the "if the room list is blank" line and just assigned the value. I also removed the line where the new recordlist is assigned to the starting recordlist. This allowed the code to be run multiple times without having to pick a random starting order. Obviously since that is not what you are doing, and it was only in for demonstrational purposes, it was removed.

Here is some updated code that shows the old string list and the new string list. It's up to you to take that new string list and format it to your specific mud implementation. I would *guess* that instead of doing the forall loop below that creates a new string list, you would send either the goodvnum, the switchvnum or both.

I also did some code re-arranging to bypass a bug, or my not knowing something, that caused the While loop to be bypassed.

#RESET "shuffle2"
bo upgrade
note write imm
Maze Portal Switches
#SEND "~@CRoom Vnum: A"
#SEND "~@GPortal reset order~@M"
#var goodvnum 1
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#var roomvnumlist "1|2|3|4"
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
switchvnumindex = @vnumindex
#until (%eval( @switchvnumindex <> @vnumindex)) {switchvnumindex=%random( 1, 4)}
switchvnum = %item( @roomvnumlist, @switchvnumindex)
#FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
}
#say "Previous List: " @roomvnumlist
#say " New list: " @newroomvnumlist
#say ***********************
#SEND ~@w
#SEND "~@CRoom Vnum: B"
#SEND "~@GPortal reset order~@M"
#var goodvnum 5
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#var roomvnumlist "5|2|3|4"
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
switchvnumindex = @vnumindex
#until (%eval( @switchvnumindex <> @vnumindex)) {switchvnumindex=%random( 1, 4)}
switchvnum = %item( @roomvnumlist, @switchvnumindex)
#FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
}
#say "Previous List: " @roomvnumlist
#say " New list: " @newroomvnumlist
#say ***********************
#SEND ~@w
#SEND "~@CRoom Vnum: C"
#SEND "~@GPortal reset order~@M"
#var goodvnum 6
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#var roomvnumlist "6|2|3|4"
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
switchvnumindex = @vnumindex
#until (%eval( @switchvnumindex <> @vnumindex)) {switchvnumindex=%random( 1, 4)}
switchvnum = %item( @roomvnumlist, @switchvnumindex)
#FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
}
#say "Previous List: " @roomvnumlist
#say " New list: " @newroomvnumlist
#say ***********************
#SEND ~@w
#SEND "~@CRoom Vnum: D"
#SEND "~@GPortal reset order~@M"
#var goodvnum 7
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#var roomvnumlist "7|2|3|4"
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
switchvnumindex = @vnumindex
#until (%eval( @switchvnumindex <> @vnumindex)) {switchvnumindex=%random( 1, 4)}
switchvnum = %item( @roomvnumlist, @switchvnumindex)
#FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
}
#say "Previous List: " @roomvnumlist
#say " New list: " @newroomvnumlist
#say ***********************
#SEND ~@w
#SEND "~@CRoom Vnum: E"
#SEND "~@GPortal reset order~@M"
#var goodvnum 8
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#var roomvnumlist "8|2|3|4"
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
switchvnumindex = @vnumindex
#until (%eval( @switchvnumindex <> @vnumindex)) {switchvnumindex=%random( 1, 4)}
switchvnum = %item( @roomvnumlist, @switchvnumindex)
#FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
}
#say "Previous List: " @roomvnumlist
#say " New list: " @newroomvnumlist
#say ***********************
#SEND ~@w
#SEND "~@CRoom Vnum: F"
#SEND "~@GPortal reset order~@M"
#var goodvnum 9
#var switchvnum 0
#var vnumindex 0
#var switchvnumindex 0
#var newroomvnumlist ""
#var roomvnumlist "9|2|3|4"
vnumindex = %ismember( @goodvnum, @roomvnumlist)
#if (vnumindex = 0) {#say Aborting. None of the roomlinks match the good vnum link} {
switchvnumindex = @vnumindex
#until (%eval( @switchvnumindex <> @vnumindex)) {switchvnumindex=%random( 1, 4)}
switchvnum = %item( @roomvnumlist, @switchvnumindex)
#FORALL @roomvnumlist {#if (%i = @goodvnum) {#ADDITEM newroomvnumlist @switchvnum} {#if (%i = @switchvnum) {#ADDITEM newroomvnumlist @goodvnum} {#ADDITEM newroomvnumlist %i}}}
}
#say "Previous List: " @roomvnumlist
#say " New list: " @newroomvnumlist
#say ***********************
#SEND ~@w
#SEND Thank you.
#SEND end
#SEND p
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Mon Jun 05, 2006 1:00 pm   
 
Kjata & dbsexton,
Thank you both for your input.
For simplicity sake I am going with Kjata's version. It's much shorter and for me shorter is better....well, my wife don't believe that, but that isn't the board of that. Twisted Evil
Kjata, I had to make a SLIGHT change to your script:
Code:
#LOOPDB @portals {
  #SEND {~@CRoom Vnum: %key}
  #SEND {~@GPortal reset order~@M}
  #FORALL @validportals {

Without the {} for the send's it wasnt sending the text.
Thanks a ton :-)
_________________
http://www.Aardwolf.com
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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