• 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

Problem - Problems with Math.Rand

I am trying to implement a randomizer so the script randomly picks one of the group members to cast a particular spell.

I got the following code:

Code:
local RandomIndex = mq.TLO.Math.Rand(1, 6) --- Generate a random number from 1 to 6
local RandomMember = "Character1" --- This is just a default to declare the varible

if RandomIndex == 1 then
    RandomMember = "Character1"
elseif RandomIndex == 2 then
    RandomMember = "Character2"
elseif RandomIndex == 3 then
    RandomMember = "Character3"
elseif RandomIndex == 4 then
    RandomMember = "Character4"
elseif RandomIndex == 5 then
    RandomMember = "Character5"
elseif RandomIndex == 6 then
    RandomMember = "Character6"     
end

print(RandomIndex)
print(RandomMember)

The problem I am having is that print(RandomIndex) does indeed print a random number from 1 to 6, but print(RandomMember) always prints the default "Character1". That means that the If / Elseif rules are ignored altogether. I cannot figure out where my syntax is wrong.

Any insights please? Thanks!
 
oh no dont use TLO.Math in a Lua, use the Lua math library

you gonna much happier

 
The core issue is is that you are comparing a string to a number, and Lua is strongly typed so that comparison will always fail. First, do what kaen says to get an actual number, but also remember to always close your datatypes with () to get an actual usable Lua type.
 
I am trying to implement a randomizer so the script randomly picks one of the group members to cast a particular spell.

I got the following code:

Code:
local RandomIndex = mq.TLO.Math.Rand(1, 6) --- Generate a random number from 1 to 6
local RandomMember = "Character1" --- This is just a default to declare the varible

if RandomIndex == 1 then
    RandomMember = "Character1"
elseif RandomIndex == 2 then
    RandomMember = "Character2"
elseif RandomIndex == 3 then
    RandomMember = "Character3"
elseif RandomIndex == 4 then
    RandomMember = "Character4"
elseif RandomIndex == 5 then
    RandomMember = "Character5"
elseif RandomIndex == 6 then
    RandomMember = "Character6"     
end

print(RandomIndex)
print(RandomMember)

The problem I am having is that print(RandomIndex) does indeed print a random number from 1 to 6, but print(RandomMember) always prints the default "Character1". That means that the If / Elseif rules are ignored altogether. I cannot figure out where my syntax is wrong.

Any insights please? Thanks!

Since Math.Rand is a TLO you need terminate it with a () to make it a number

edit: lol everybody replied at exactly the same time :D
 
for your character name, just do
Lua:
mq.TLO.Group.Member(RandomIndex - 1).CleanName()  -- -1 because group is from 0 to 5

that gets you that person in group
 
math.randomseed (x)

Sets x as the "seed" for the pseudo-random generator: equal seeds produce equal sequences of numbers.

This is how I do it most of the time:

math.randomseed(os.time()*mq.TLO.Me.ID())
 
math.randomseed (x)

Sets x as the "seed" for the pseudo-random generator: equal seeds produce equal sequences of numbers.

This is how I do it most of the time:

math.randomseed(os.time()*mq.TLO.Me.ID())
This. The benefit of using the time from your os is that it is always changing. If you don't seed (or seed with the same number all the time), then your 'random' sequence will always be the same every time you start it.
 
Thanks everybody for the suggestions, very kind. I think I got the right code based on the responses in this thread, see code below:

Code:
math.randomseed(os.clock())
local RandomIndex = mq.TLO.Math.Rand(1, 6)()
local RandomMember = mq.TLO.Group.Member(RandomIndex - 1).CleanName()  --- This gives me the name of the character
print(RandomMember)

This snippet of code is embedded within a larger code that I must run for all characters. The new problem I am observing is that each character is printing a different RandomMember, whereas I would need them all to be "in sync", meaning that every time the script runs in each of the clients (characters), the same RandomMember should be printed for all.

How do you sync up a Math.Rand across all clients within the dannet?
 
Anyone? is it even possible?
if you provide the same seed, the same results will occur :) but only if you do the same random calls on each toon.

But you need to describe what exactly you want to accomplish...

"I need all of my 6 toons to target the same random group member" probably best solved by doing the random on one, then telling the other members whom to target
 
Problem - Problems with Math.Rand

Users who are viewing this thread

Back
Top
Cart