• DrawWorldModel error
    9 replies, posted
I am trying to make a gun that makes you invisible when you click, so to hide the weapon, I am trying to use [CODE]self.Owner:DrawWorldModel() and self.Owner:DrawWorldModel(false)[/CODE] It works, but it always gives me an error. The error always says: [CODE] attempt to call method 'DrawWorldModel' (a nil value) [/CODE] What can I use to properly use the DrawWorldModel without errors?
-bump-
Do an IsValid check on the owner. We could help better if you post more context as to where the code is called from.
There's a bit more to do when setting someone to invisible. In addition to PrePlayerDraw ( return true to hide the player; this is clientside so it can't be trusted as the only thing to hide the player ): [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/gm_functions_and_hooks/gm_preplayerdraw_making_players_invisible.lua.html[/url] You'd need the following calls: [code]_p:SetRenderMode( RENDERMODE_NORMAL ); // Invisible _p:SetColor( Color( 0, 0, 0, 0 ) ); _p:SetNoDraw( true ); _p:DrawWorldModel( false ); // Visible _p:SetColor( Color( 255, 255, 255, 255 ) ) _p:SetNoDraw( false ); _p:DrawWorldModel( true );[/code]
That's the thing, it works great single player, but when I bring it to multiplayer, anytime DrawWorldModel (true/false) is run, it says it is a nil value... It works, which is the weird thing, but it spams console. This is sort of a cloak, so I just set the material of the body to heatwave, but anytime I try to set the weapon material to heatwave, it does weird things.
Those functions need to be ran serverside ( except for PrePlayerDraw ). The reason it works in single-player / listen-server is because client and server are the same meaning the code merges and some can even be overwritten ( which is why it isn't a good idea to dev on a listen-server ) leaving you with unknown effects when run on a dedicated server. Setting up a local SRCDS is EASY. On top of that, if your client crashes, you don't need the server part to re-load. If the server crashes, you don't need to reload the client. So much easier to debug that way. Here's how to set up a local SRCDS ( not all of these are required, just like you don't need to mount all games; but do force-directory as mount.cfg doesn't like the names of the games when they're left to install in other directories ): Server: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_a_server_with_steamcmd.lua.html[/url] FastDL: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/fastdl_setup_instructions.lua.html[/url] Recursive Resource Loader: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_downloads_using_recursive_resource_system.lua.html[/url]
I appreciate your response, but I know how to set up an SRCDS server. I do normally test on just the regular server, but I have no idea how to make the DrawWorldModel() to work without running errors... You said to run it server side, but how would I do that when I have [CODE]function SWEP:Holster() self.Owner:DrawWorldModel( true ) end[/CODE] everytime I holster it it says [CODE] attempt to call method 'DrawWorldModel' (a nil value) [/CODE]
Check self.Owner; it may be invalid / unset..
[QUOTE=Bazoogle;46597140]I appreciate your response, but I know how to set up an SRCDS server. I do normally test on just the regular server, but I have no idea how to make the DrawWorldModel() to work without running errors... You said to run it server side, but how would I do that when I have [CODE]function SWEP:Holster() self.Owner:DrawWorldModel( true ) end[/CODE] everytime I holster it it says [CODE] attempt to call method 'DrawWorldModel' (a nil value) [/CODE] [/QUOTE] Use render mode alpha and set player alpha to 0 or use special materials [code]if IsValid( self.Owner ) then self.Owner:SetRender(RENDERMODE_ALPHA) local oldcl = self.Owner:GetColor() oldcl.a=0 self.Owner:SetColor(oldcl) end[/code]
WOO, I finally got a working version! Thankyou everyone for responding, and especially UnkN because you led me in the right direction! What I did was: [CODE] self.Owner:SetRenderMode( RENDERMODE_TRANSALPHA ) self.Weapon:SetRenderMode( RENDERMODE_TRANSALPHA ) [/CODE] then I just used [CODE] self.Weapon:SetColor(Color(255,255,255,255)) & self.Weapon:SetColor(Color(255,255,255,0))[/CODE]
Sorry, you need to Log In to post a reply to this thread.