ply:SetModel("model/path/here.mdl") works, but ply:SetModel(playermodel) with "playermodel" set to "
4 replies, posted
Okay, sorry about the confusing title, but that's the only way I could think to describe whatever's going on, here.
I know exactly where the problem is, but not WHAT the problem is, because it makes no logical sense to me at all whatsoever.
I have this line in my code, and it's properly passing along "model" as it should:
[lua]
RunConsoleCommand("changeplayermodel", model)
[/lua]
It's running the console command properly, and everything works just fine. In fact here's the function for the console command:
[lua]
function SetPlyModel(ply, ignore, ignore2, model)
if not CheckIsMember(ply) then return false end //Ignore this.
if CheckRoundState() == "active" then//Ignore this.
ply:ChatPrint("You can't change your model during the round!")//Ignore this.
return false//Ignore this.
end//Ignore this.
//local playermodel = model //We're going to refer to this as Variable Line A - it inherits "model" which was passed along from the RunConsoleCommand() line above.
local playermodel = "models/Batman/slow/jamis/mkvsdcu/batman/slow_pub_v2.mdl" //We're going to refer to this as Variable Line B
Msg("Changing model to: "..playermodel.."\n") //This just prints to the console that you're changing your model
ply:SetModel(playermodel) //Obviously, this sets the player's model to "playermodel"
end
[/lua]
Here's where it gets confusing...
If Variable Line A is commented out, and Variable Line B isn't, then it changes the player's model to the defined model (in this case, a Batman playermodel).
HOWEVER, if Variable Line B is commented out, and Variable Line A isn't, then it changes the model to whatever's stored in "playermodel" which is defined by the RunConsoleCommand() line, as I've already stated, which in this case is exactly the same string as what's in Variable Line B - and for some seemingly inexplicable reason the console says that the model is missing, and sure enough the player (me) is the big red ERROR model.
So yeah, I know WHERE the problem is, but not what it is, and I have no fucking clue how to fix it. Regardless of which Variable Line is commented out, Msg() works just fine.
(Before anyone says anything, I'm aware that it's pretty redundant to set "playermodel" to "model" at all, when I can just run SetModel(model) instead. I just added those two lines for debugging purposes.
Does ANYONE know what's going on or how to fix it? Because I'm completely fucking stumped.
Thanks in advance.
I'm assuming you have concommand.Add("changeplayermodel", SetPlyModel) ?
[lua]function SetPlyModel(ply, command, args)[/lua]
[lua]//variable line a
local playermodel = args[1][/lua]
Yeah, the console command itself works fine.
If you have exactly
[lua]concommand.Add("changeplayermodel", SetPlyModel)[/lua] then the function definition is set up wrong then replace your code with the lines I supplied
...holy crap I'm an idiot. Thank you, I never would've figured that out!
Sorry, you need to Log In to post a reply to this thread.