• Hail, we're RedGuides. We want you to play six (yes, 6!) EverQuest characters at once. We have scripts and a friendly community to help, please join our playstyle and say hello! 👋
  • We've added LLM sections to our Terms & Rules and Resource Rules, for everyone's sanity & in-game safety.
    Read more
    a. Do not replace your voice with an LLM. This goes for your posts and your scripts. Drafting and editing with a tool is fine, but don't take you out of what you share.
    b. Do not replace your EQ character's voice with an LLM. We don't want scripts that speak over /ooc, /shout or other public channels. This has been an unwritten rule that's kept casino scripts off the site for decades, but we're now compelled to make it clear: keep automated communication private.

    Why Does RG Review Scripts?
    Nearly every LLM-written Lua script we see is making your character do impossible things, and rarely in a way that's beneficial to you. We've seen heavy server hammering, /target over impossible distances when /nav spawn would passively accomplish the same thing, a spawn search that fires 20+ times per second, and other pointless actions that are likely annoying GMs.

    You are welcome to use LLMs as a tool to structure, draft, and edit your work, but please read critically before hitting /lua run

Question - Is there any way to randomly pull a variable from an array? (1 Viewer)

Screwing around with the Bazaar.mac and I've done very little in regards to programming using macro language but I've got a fair amount of experience with programming in general. I was wondering, if I declare an array (which hopefully I did right) is there any way to randomly choose a value from that array?

For example, say I wanted my determinant percentage that calculates my items price to be chosen from 3 different values:

Array
INI:
    /declare pricePercentage[3]  float     outer
    /varset  pricePercentage[1]  0.92
    /varset  pricePercentage[2]  0.95
    /varset  pricePercentage[3]  0.97
Would be my arrays declaration (I think), how would I randomly choose a value to throw in to the equation calculating the items price, something like a misc.random?

Or is there a better way to do this?

Thanks! :)
 
Code:
/declare randomInt int outer 0
could be created as an outer variable.

and according to mq2 wiki for math TLO.
Code:
  /echo ${Math.Rand[500]}
Echoes a random number between 1 and 500

So then we can then
Code:
/varset randomInt ${Math.Rand[3].Int}
/echo ${pricePercentage[${randomInt}]} is the value stored at ${randomInt}

Hope this helps.
 
Code:
/declare randomInt int outer 0
could be created as an outer variable.

and according to mq2 wiki for math TLO.
Code:
  /echo ${Math.Rand[500]}
Echoes a random number between 1 and 500

So then we can then
Code:
/varset randomInt ${Math.Rand[3].Int}
/echo ${pricePercentage[${randomInt}]} is the value stored at ${randomInt}

Hope this helps.
It looks like Math.Rand uses 0 which ends up being null. :( I'll toy around with it, but anyone know any way to fix this? Pic for reference, works great otherwise!

Edit:
Whipped up a simple fix:
Null fix
INI:
            /varset percentagePicker ${Math.Rand[3]}
                    /if (${percentagePicker}<1) {
                        /varcalc percentagePicker ${percentagePicker}+1
                        /echo Null avoided!
                    }
Threw this before the varcalc on the percentage. Essentially just sets the variable, checks if it's 0 and if it is sets it to 1 then does the varcalc and now it's working like a charm! Thanks again! :)

Edit 2:
Realized Math.Rand can take a min argument so I kept the exception catcher in there just in case but instead used:
Math.Rand
INI:
/varset percentagePicker ${Math.Rand[1,5]}
so 1 is the minimum and 5 is the maximum (increased array size to 5)

Hopefully last edit! Thanks again! :)
 

Attachments

  • bazerror.png
    bazerror.png
    18.2 KB · Views: 13
Last edited:
Question - Is there any way to randomly pull a variable from an array?

Users who are viewing this thread

Back
Top
Cart