Garry's Mod

Garry's Mod

View Stats:
The Battler Aug 16, 2024 @ 10:44pm
Replacing an NPC's model with a different and random model (Lua Script)
I'm trying to replace an NPC's base model with a random model from a file directory (Eg: models/npcs/etc) via a lua script.
The base script I am attempting to use is this:

function replacement()

for k, v in pairs( ents.FindByModel( "models/combine_soldier.mdl" ) ) do
if v:IsNPC() then
v:SetModel(math.random(#"models/npc/hostile/*"))

Unfortunately, it doesn't work and the NPC's model is still default and isn't any of the models that I want it replaced with. I'm not trying to replace the NPC with just one model, but rather a chance of it appearing with multiple and different models I have in a model file. Is there an easy solution to this?
Date Posted: Aug 16, 2024 @ 10:44pm
Posts: 0