Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i pick a random mesh and textureid from table?

Asked by 5 years ago

to elaborate, how would i get the missile to use a random mesh and texture id from an table i really dont know where to start, ive read the wiki, tried googling for a solution and probably some more. this is what i have right now

local mesh = {55,33,16,4}
local texture = {22,6,11,5}

so yeah i want the meshid to match the textureid lets say that the meshid is 55, then i want the textureid to be 22 meshid is 33, textureid is 6 and so on

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

One really simple way to do this is to use a numeric for loop:

local mesh = {55, 33, 16, 4}
local texture = {22, 6, 11, 5}
local Storage = {} -- Make a table to store patterns
for i = 1, #mesh do -- This doesn't really matter because I'm assuming that your tables are going to have equal lengths anyway
    table.insert(Storage, mesh[i])
    table.insert(Storage, texture[i])
end

If you otherwise want it to be completely randomized, I would use math.random():

local mesh = {55, 33, 16, 4}
local texture = {22, 6, 11, 5}
local Storage = {} -- Make a table to store randomized patterns
local ChosenMesh = mesh[math.random(1, #mesh)]
local ChosenTexture = texture[math.random(1, #texture)]
table.insert(Storage, ChosenMesh)
table.insert(Storage, ChosenTexture)

Using a for loop to get the values by index places them in a table so that for every 2 values in a table the pattern is mesh[i] followed by texture[i]. Using math.random() randomly selects them from the tables and stores them in random patterns.

0
alright, ill try that prohax1234 2 — 5y
0
how would i get the id to "MeshId = id from table" prohax1234 2 — 5y
0
The MeshId is always an odd number index in the storage table if you did it the first way. TextureIDs are even number indices. DeceptiveCaster 3761 — 5y
0
So that means Storage[1], Storage[3], Storage[5] and Storage[7] are all MeshIds. DeceptiveCaster 3761 — 5y
Ad

Answer this question