Total players online: 7



Take the Tour | Site Map

It is currently Tue Dec 12, 2017 12:38 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Mon Apr 03, 2017 6:43 pm 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 12/23/2003 03:27
Posts: 1144
Location: Seige Perilous

I'd like to take a list of items found with FindItem and randomize it. I'm working on a mining script, and will eventually have enough marked locations that by the time my character cycles through all of them, they will all be ready to mine again. I'm also going to do this in 2 sections of runes, so the 1st half will always have time to respawn ore before the 2nd half is completed, so there won't be any situations where the character mines runespot #100 close to the end of the list and on a list reset runespot #100 then gets put at the begining of the new list. It'll be listA randomly done then listB randomly done.
But Only way I have thought of to make a randomized list from the finditem list is: :bounce:
Code:
  1. for %a 1 100
  2. set %List . %a null
  3. Finditem %RuneType C_ , %RuneStorage
  4. {
  5. GetRandomNumber:
  6. set %x #random % 100 + 1
  7. if %List . %x <> null
  8. goto GetRandomNumber
  9. set %List . %x #findid
  10. }


The GetRandomNumber loop can get rather long as %List 1 - 100 gets more <> null values

_________________
While a = a
{
Scanjournal 1
If Daemon_is_attacking_you in #journal || ( you_are_attacking in #journal && Daemon in #journal )
Terminate UO
}


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Thu Apr 20, 2017 2:25 pm 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 07/10/2004 17:11
Posts: 2123

Just generate a random number between 1 and #findcnt, set #findcnt to that randomly generated number, and boom. You have all the info in the corresponding system vars for that finditem. If the #findcnt was 22 items for your %runeType search, and you generated a random number between 1 and 22, and that number was 8, all you have to do is set #findindex to 8 and it would populate all the system vars on the right of EUO with the 8th found item...

_________________
Image


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Mon May 08, 2017 10:37 pm 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 12/23/2003 03:27
Posts: 1144
Location: Seige Perilous

What I am doing with that code, is making an array list of all the runes, in a randomized order. This is so that other players cannot anticipate seeing my characters recalling. There are places where I've marked a rune for every 8x8 resource grid, so locations can be right next to each other and right after one another in their order. This can lead to a player seeing my character recall to one spot then another, and later seeing my character repeat the same 2 spots in the same order. I'd like to randomize the order of the runes each time I run script on the whole set of them. I have 100 runes, hence the %List . %a being 1 to 100. I should have set the random generated number from 1 to #findcnt, but typed in 100 knowing that #findcnt was 100 runes.

_________________
While a = a
{
Scanjournal 1
If Daemon_is_attacking_you in #journal || ( you_are_attacking in #journal && Daemon in #journal )
Terminate UO
}


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Tue May 09, 2017 1:22 pm 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 07/10/2004 17:11
Posts: 2123

So change it to #findcnt. ;) There is a command for generating random numbers in EUO. It's pretty easy to understand. Did you figure it out?

_________________
Image


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Wed May 10, 2017 2:22 pm 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 12/23/2003 03:27
Posts: 1144
Location: Seige Perilous

OMG, I'm using that command, and in an advanced manner to randomize a number from 1 to 100 already.
Code:
  1. Finditem %RuneType C_ , %RuneStorage
  2. set %List . %a null
  3. {
  4. GetRandomNumber:
  5. set %x #random % 100 + 1
  6. if %List . %x <> null
  7. goto GetRandomNumber
  8. set %List . %x #findid
  9. }

_________________
While a = a
{
Scanjournal 1
If Daemon_is_attacking_you in #journal || ( you_are_attacking in #journal && Daemon in #journal )
Terminate UO
}


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Wed May 10, 2017 2:36 pm 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 07/10/2004 17:11
Posts: 2123

Ok I reread your garbled text that isn't 100% clear, and the way I understand it, is you want to randomize 100 runes, then randomize 100 other runes. Going to each one in turn in each group of 100. So do it by their x_y location. And use my pseudoIgnore sub to ignore each x_y location and create a new list of runes each time ignoring the one you randomly selected, and creating a new list of the runes by their x_y location. So that rune is ignored and won't be used again until you reset it after rune 100. So it's not "ignored" anymore by my sub. Since you're proficient with the #random function, I'm sure you can figure out how to do that with my sub. ;) Let me know how it works for ya.

_________________
Image


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Wed May 10, 2017 11:16 pm 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 12/23/2003 03:27
Posts: 1144
Location: Seige Perilous

The code I'm using is working correctly. Once it's finished I have an array with %List . %Index which is from 1 to 100. The 100 runes are added to the list in order of their #findindex, but with a random index value. I was hoping there would be a way to do this w/o running a loop from 1 - 100 for each and every rune. Running the loop over and over 'til it generates a number not used as %Index in %List . %Index starts out short. Inly need to run it once when there are no current values. but when 90 out of 100 values are taken, it can take the loop well over 100 cycles to produce a number not already used. All in all, with this code you can see that exponential growth can produce a situation where the last few positions in the list can take many thousands of cycles to complete the list.
Code:
  1. for %a 1 100
  2. set %Total %Total + %a
  3. display %Total

Running this produces a final %Total of 5050
That means a final total of over 5k cycles and that's based on a steady rate of progression.

_________________
While a = a
{
Scanjournal 1
If Daemon_is_attacking_you in #journal || ( you_are_attacking in #journal && Daemon in #journal )
Terminate UO
}


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Thu May 11, 2017 10:41 am 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 07/10/2004 17:11
Posts: 2123

It shouldn't. The list should only get shorter and shorter as you start weeding out runes you've used. Plus, you use #lpc to bump up the speed of execution to make the loop nearly instant. If it's 100 entries and 2 lines of code for the for loop an #lpc of 200 would execute it instantly.

_________________
Image


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Thu May 11, 2017 12:59 pm 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 12/23/2003 03:27
Posts: 1144
Location: Seige Perilous

I'm doing a loop inside of a for loop of 1 to 100. The For loop is going through the runes, the other loop inside of it is randomly generating a number from 1 to 100, but has to repeat itself if the random number has already been used.
You just can't comprehend what it is I'm doing...
Try this, roll a set of dice... see how many times it takes for you to roll one of each number...
from 2 to 12, should be 11 right??? Is this what you would think???
Try it and then post the outcome...

_________________
While a = a
{
Scanjournal 1
If Daemon_is_attacking_you in #journal || ( you_are_attacking in #journal && Daemon in #journal )
Terminate UO
}


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Thu May 11, 2017 2:24 pm 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 07/10/2004 17:11
Posts: 2123

That's your problem. You're resuing numbers. If you just remake the list every time, and exclude the rune you used already... it gets faster and faster. And every time you decrease your loop, you decrease the random number you generate by 1.

_________________
Image


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Sun May 14, 2017 1:49 am 
Offline
Novice Scripter
Novice Scripter

Joined: 02/04/2017 02:31
Posts: 36
Location: Turkiye
Daemon wrote:
Code:
  1. for %a 1 100
  2. set %List . %a null
  3. Finditem %RuneType C_ , %RuneStorage
  4. {
  5. GetRandomNumber:
  6. set %x #random % 100 + 1
  7. if %List . %x <> null
  8. goto GetRandomNumber
  9. set %List . %x #findid
  10. }



That is not the way doing this.

Consider that;
you have N runes and you randomize numbers, then your list will go on like,

%List1 setted
%List2 setted
%List3 N/A
%List4 setted
. setted
. setted
. setted
%ListN setted

all list array setted except %List3,
in this example, you have to wait GetRandomNumber loop to randomize number 3, it might never randomize. Script might go in endless loop. When u randomize the numbers u have;

RuneCount/RuneCount chance for ListX is N/A at first randomize.
RuneCount-1/RuneCount chance for ListX is N/A at second randomize.
.
.
.
When you left one number to randomize, you have 1/RuneCount chance for ListX is N/A at every randomize. It may never randomize the number you need.

Try to make something like lotto(tombola). You have N balls in a Bag with random numbers up to BallCount. Every random pull of a ball decreases ballCount and discards the number it has. So at every pull of a ball, u have 100% chance that the ball randomized number X is N/A at %ListX.

I think, you have to use something other than randomizing between 1 and RuneCount.

_________________
There is no code that does not work. There is code that does not work as expected...


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Sun May 14, 2017 4:47 am 
Offline
Novice Scripter
Novice Scripter

Joined: 02/04/2017 02:31
Posts: 36
Location: Turkiye
First, you have to variables to consider about. A random List Number and A random #findIndex.
So the script can set #findIndex %RandomIndex
and set %List[RandomListNumber] #findID

Create two Arrays like;
NumberArray _1_2_3_4_5_6_7_8_9_10_11_........................................._96_97_98_99_100_
IndexArray _1_2_3_4_5_6_7_8_9_10_11_........................................._96_97_98_99_100_

Randomize a number between 1 to Count of UnderScores for each Array.
Pull the number between Randomized underscore and the next one for each Array and set to RandomNumber and RandomIndex.
Replace the _number_ with _ in each Array, so the count of underscores reduces.
When underscore count became 1, means List[RandomNumber] Array has finished.

Code:
  1.  
  2. findItem %RuneType
  3. gosub CreateNumberArray
  4. gosub CreateIndexArray
  5. str Count %NumberArray _
  6. set %UnderScoreCount #strres
  7. while %UnderScoreCount > 1
  8. {
  9.     gosub RandomizeNumberAndIndex
  10.     set #findIndex %RandomIndex
  11.     set %List . %RandomNumber #findID
  12.     str Count %NumberArray _
  13.     set %UnderScoreCount #strres
  14. }
  15. ; At the end of while loop, here is your random List Array
  16. sub CreateNumberArray
  17. {
  18.     set %NumberArray _
  19.     for %a 1 #findCnt
  20.     {
  21.         set %NumberArray %NumberArray , %a , _
  22.     }
  23.     return
  24. }
  25. sub CreateIndexArray
  26. {
  27.     set %IndexArray _
  28.     for %a 1 #findCnt
  29.     {
  30.         set %IndexArray %IndexArray , %a , _
  31.     }
  32.     return
  33. }
  34. sub RandomizeNumberAndIndex
  35. {
  36.     ; Pull a random underscore from Number array, set it to RandomNumber
  37.     set %RandomUnderScore #random % %UnderScoreCount + 1
  38.     if %RandomUnderScore = %UnderScoreCount
  39.         set %RandomUnderScore %UnderScoreCount - 1
  40.     str Pos %NumberArray _ %RandomUnderScore
  41.     set %NumberStart #strres + 1
  42.     set %Temp %RandomUnderScore + 1
  43.     str Pos %NumberArray _ %Temp
  44.     set %NumberEnd #strres
  45.     set %NumberLen %NumberEnd - %NumberStart
  46.     str Mid %NumberArray %NumberStart %NumberLen
  47.     set %RandomNumber #strres
  48.     ; after setting RandomNumber, Replace _number_ with _ in NumberArray, so script wont use the same Number again.
  49.     str Ins %NumberArray _ %NumberEnd
  50.     set %NumberArray #strres
  51.     set %Temp %NumberStart - 1
  52.     set %DelLen %NumberLen + 2
  53.     str Del %NumberArray %Temp %DelLen
  54.     set %NumberArray #strres
  55.     ; Do it again for RandomIndex
  56.     ; Pull a random underscore from Index Array, set it to RandomIndex
  57.     set %RandomUnderScore #random % %UnderScoreCount + 1
  58.     if %RandomUnderScore = %UnderScoreCount
  59.         set %RandomUnderScore %UnderScoreCount - 1
  60.     str Pos %IndexArray _ %RandomUnderScore
  61.     set %NumberStart #strres + 1
  62.     set %Temp %RandomUnderScore + 1
  63.     str Pos %IndexArray _ %Temp
  64.     set %NumberEnd #strres
  65.     set %NumberLen %NumberEnd - %NumberStart
  66.     str Mid %IndexArray %NumberStart %NumberLen
  67.     set %RandomIndex #strres
  68.     ; after setting the RandomIndex, Replace _Index_ with _ in IndexArray, so script wont use the same Index again.
  69.     str Ins %IndexArray _ %NumberEnd
  70.     set %IndexArray #strres
  71.     set %Temp %NumberStart - 1
  72.     set %DelLen %NumberLen + 2
  73.     str Del %IndexArray %Temp %DelLen
  74.     set %IndexArray #strres
  75.     return
  76. }
  77.  

_________________
There is no code that does not work. There is code that does not work as expected...


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Sun May 14, 2017 5:02 am 
Offline
Novice Scripter
Novice Scripter

Joined: 02/04/2017 02:31
Posts: 36
Location: Turkiye
Example above is very complex.
For ease, you may use just one Array and one #random.
And set List[RandomNumber] #findID in #findIndex order.

Code:
  1.  
  2. findItem %RuneType
  3. gosub CreateNumberArray
  4. {
  5.     gosub RandomizeNumber
  6.     set %List . %RandomNumber #findID
  7. }
  8. ; At the end of for loop, here is your random List Array
  9. sub CreateNumberArray
  10. {
  11.     set %NumberArray _
  12.     for %a 1 #findCnt
  13.     {
  14.         set %NumberArray %NumberArray , %a , _
  15.     }
  16.     return
  17. }
  18. sub RandomizeNumber
  19. {
  20.     str Count %NumberArray _
  21.     set %UnderScoreCount #strres
  22.     ; Pull a random underscore from Number array, set it to RandomNumber
  23.     set %RandomUnderScore #random % %UnderScoreCount + 1
  24.     if %RandomUnderScore = %UnderScoreCount
  25.         set %RandomUnderScore %UnderScoreCount - 1
  26.     str Pos %NumberArray _ %RandomUnderScore
  27.     set %NumberStart #strres + 1
  28.     set %Temp %RandomUnderScore + 1
  29.     str Pos %NumberArray _ %Temp
  30.     set %NumberEnd #strres
  31.     set %NumberLen %NumberEnd - %NumberStart
  32.     str Mid %NumberArray %NumberStart %NumberLen
  33.     set %RandomNumber #strres
  34.     ; after setting RandomNumber, Replace _number_ with _ in NumberArray, so script wont use the same Number again.
  35.     str Ins %NumberArray _ %NumberEnd
  36.     set %NumberArray #strres
  37.     set %Temp %NumberStart - 1
  38.     set %DelLen %NumberLen + 2
  39.     str Del %NumberArray %Temp %DelLen
  40.     set %NumberArray #strres
  41.     return
  42. }
  43.  

_________________
There is no code that does not work. There is code that does not work as expected...


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Sun May 14, 2017 6:14 am 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 07/10/2004 17:11
Posts: 2123

I think it's hilarious you said "I just can't comprehend what you're doing." What is really happening, is you're not comprehending what I'm saying. I understand what you are saying absolutely and completely. You're just not doing what I said. ;)

  1. finditem %runes c_ , #backpackid
  2. {
  3.   set %random #random % #findcnt + 1
  4.   set #findindex %random
  5.   set %runeToRecallFrom #findid
  6. }
  7. ; DO ALL YOUR CODE UNTIL #FINDCNT = 1
  8.   ignoreitem reset

_________________
Image


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Sun May 14, 2017 7:18 am 
Offline
Novice Scripter
Novice Scripter

Joined: 02/04/2017 02:31
Posts: 36
Location: Turkiye
Scripty wrote:
I think it's hilarious you said "I just can't comprehend what you're doing." What is really happening, is you're not comprehending what I'm saying. I understand what you are saying absolutely and completely. You're just not doing what I said. ;)

  1. finditem %runes c_ , #backpackid
  2. {
  3.   set %random #random % #findcnt + 1
  4.   set #findindex %random
  5.   set %runeToRecallFrom #findid
  6. }
  7. ; DO ALL YOUR CODE UNTIL #FINDCNT = 1
  8.   ignoreitem reset


This is not true, in this way, %random may become the same number twice or more. Not True...

_________________
There is no code that does not work. There is code that does not work as expected...


Top
  ProfileShow poster's scripts in the public script library 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours


Who is online

Users browsing this forum: ickmanuriardri, Yahoo [Bot] and 12 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Hosted by CalWeb Internet Services, Inc.