Tables and Arguments

What I’m trying to do is pick a player model out of a table, and then set the material for that model.

So a short inaccurate example would be:
[lua]function PlayerModel( pl, args )
local playermodels = {}
playermodels[1] = {“models/player/roflplayer”, “materials/models/player/roflplayer”}
playermodels[2] = {“models/player/lolplayer”, “materials/models/player/lolplayer”}

local Rand = math.random(1, #(self.playermodels))
Mdl = self.playermodels[Rand] --Use First Argument
Mtrl = self.playermodels[Rand] --Use Second Argument
pl:SetModel(Mdl)
pl:SetMaterial(Mtrl)

end[/lua]
I don’t know how to use args correctly for this type of thing.
E: For further concerns, I know I’m not adding any hooks in this as that’s not my problem.

Any help would be appreciated,
Bastinka

I still can’t figure out how to get the first or second argument of the random number. Would I need to use a for loop?

the first and second arguemnt to math.random(number,number) just outputs a random number betweent hose ranges if you do math.random(1,3) you could get 1 2 or 3 as a possible out put. also try changing Mdl = self.playermodels[Rand] and Mtrl = self.playermodels[Rand] to


Mdl = self.playermodels[Rand][1]
 Mtrl = self.playermodels[Rand][2]

[lua]

local playermodels = {}
playermodels[1] = {“models/player/roflplayer”, “materials/models/player/roflplayer”}
playermodels[2] = {“models/player/lolplayer”, “materials/models/player/lolplayer”}

function PlayerModel( pl, args )
local mdlmat = table.Random(playermodels)
pl:SetModel(mdlmat[1])
pl:SetMaterial(mdlmat[2])
end[/lua]

Optimized for you :eng101:

Playermodel is defined outside of the function, table.Random function is used, and significantly fewer lines. Hope it makes sense when you read it.

-Snip- FIXED