Undo SetNoDraw

Hey,

So I’m working on a script, which requires weapons to be hidden then reappear. I’ve searched the Wiki and these forums to do that, and found the SetNoDraw command.

So I’ve come up with this:

[lua]
if SERVER then
ply:DrawViewModel( false )
else
local ViewModel = LocalPlayer():GetViewModel()
if not ViewModel:IsValid() then return end
LocalPlayer():GetViewModel():SetNoDraw(true)
end
[/lua]

which works, the weapon doesn’t show up.

then when I want the gun to reappear, I was trying this:

[lua]
if SERVER then
ply:DrawViewModel( true )
else
local ViewModel = LocalPlayer():GetViewModel()
if not ViewModel:IsValid() then return end
LocalPlayer():GetViewModel():SetNoDraw(false)
end
[/lua]

This doesn’t work, apparently it isn’t catching the view model, since there isn’t something to view.

How would I get this to reappear?

Thanks!

Uh, I dunno, but you could try this:


if SERVER then    ply:DrawViewModel( false ) else    local ViewModel = LocalPlayer():GetViewModel()     if ( !ViewModel:IsValid() ) then return end    LocalPlayer():GetViewModel():SetNoDraw(true)  end

[editline]8th January 2011[/editline]

Seriously, that’s all I could think of.

Thanks for the reply.

That just throws an error out, because it’s basically saying, if it can’t find an entity, draw that entity… it doesn’t know what it is drawing…

-snip- shit messed up

Any Lua Kings would like to pitch in?

I was thinking and I guess I can do it clientside if all else fails.

ply is nil, use for k, v in pairs(player.GetAll()) do then v:Method() instead of ply

Can’t you just make the SetNoDraw a boolean

Or SetNoDraw(false)

Just a random suggestion/question/something to think about, but here is my theory

SetNoDraw( true ) MIGHT make the entity nil/null/invalid, by looking at your code that’s the only way it looks like it broke, I could be wrong, look into it.

You could always re-initialize the entity…I think =S.

Wow! Thanks everyone for responding!

I don’t understand, you’re just telling me to execute a command to all players?

Tried, the thing is, is how it selects the entity is by GetViewModel(), so when you do SetNoDraw(), you’re getting rid of how it selects it, through no longer drawing the model view.

That’s not a half bad idea about re-initializing, i’ll try that and get back to you.

No, I’m saying that ply is nil( undefined, non existent) so instead of using ply use a for loop. Here is an example:

[lua]
for k, v in pairs(player.GetAll()) do
v:Method() – the method you are trying to use, such as SetColor(), IsAdmin(), etc.
end
[/lua]

Have you tried setting the color to 255, 255, 255, 0, I’ve heard SetNoDraw() is a hacky/unreliable function

Aren’t you the one who said that it’s impossible to set the alpha on the player? And that SetNoDraw() is better?

[editline]10th January 2011[/editline]

you also facepalmed me

[editline]10th January 2011[/editline]

i hope you feel dumb

I’m assuming it didn’t work because someone told me it didn’t work(forgot who, either Grea$eMonkey, jakedgadget, or Silverlan, I dunno lol) and apparently you said it works, so now I’m assuming it does work, I haven’t tried it yet.

Oh, I see what you are getting at, however, I am actually trying to do individual commands since this script is intended to be a holster. The ply is actually not nil, i’m just having issues with the clientside draws.

That’s not a half bad idea, I’ll try that tomorrow.

I’ve just stumbled across these:

ply:DrawWorldModel(bool) and ply:DrawViewModel(bool)

I bumped cause you didn’t say if it’s resolved or not =/

In Andrikos case you put 1 or 0 for the bool. lo0l