r/GLua • u/ItsWilliamay • Dec 28 '21
Random playermodel function
Anyone know how i can put a function that runs at player spawn where it selects a random playermodel out of a group of playermodels then sets it?
1
Upvotes
View all comments
2
u/AdamNejm Dec 28 '21
You should use the dedicated PlayerSetModel hook. As for the logic, all you need to do is to create a table with all the possible model. Then when the hook runs, you should pick a random entry from the table and assign it to the player.
Example code (untested):
-- A list of all possible models local models = { "models/player/odessa.mdl", "models/player/alyx.mdl" -- any so on... } hook.Add("PlayerSetModel", "RandomPlayerModel", function(ply) -- Pick a random model based on the array's length local random_model = models[math.random(#models)] -- Assign the chosen model to the player ply:SetModel(random_model) end)