• Draw a square where a player executed a command
    7 replies, posted
Hello, I have this code in [u]lua/server[/u] (3 is the taxi team) [CODE]concommand.Add( "callTaxi", function( ply, cmd, args ) -- Creates a console command if ply:Team() == 3 then -- Tests if the player is in the team ply:PrintMessage( HUD_PRINTTALK, "You can't call a taxi while being a taxi." ) elseif ply:Team() != 3 then if team.NumPlayers( 3 ) != 0 then -- If there is players in the team taxiTeam = team.GetPlayers( 3 ) -- Gets all the players in the team taxiTeamPlayer = table.Random( taxiTeam ) -- Choose a random player from the team taxiTeamPlayer:PrintMessage( HUD_PRINTTALK, "A player need you." ) -- Draw a square where the player who executed the command is -- elseif team.NumPlayers( 3 ) == 0 then ply:PrintMessage( HUD_PRINTTALK, "No taxi in the city." ) end end end ) [/CODE] And I want to draw a square where the player executed the command "callTaxi" and removes it when the "taxiTeamPlayer" as came close to the destination. (Kind of GPS) I know I can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/DrawQuadEasy]render.DrawQuadEasy[/url] but I don't know how to do what I want.
-Snip- misread
You've got various options here. You can either use the 3D option and follow the example of the wiki on render.DrawQuadEasy or use the 2D option, getting a vectors 2D position on the screen with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/ToScreen]Vector:ToScreen[/url] and drawing it with the draw library and via [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/HUDPaint]GM:HUDPaint[/url] If you want to continue by any of the two, you should set some sort of local variable clientside and use the [URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]net library[/URL] to send to the client the Player that he requires to go to and maybe even any other params you want to pass, and also a Think hook that checks the distance of the LocalPlayer with the other player and when there is less than a certain distance, stop the thing from appearing to that player locally. [editline]4th October 2017[/editline] [QUOTE=MelonShooter;52746218]Inside, put a HUDPaint hook that does surface.DrawRect() and remove the HUDPaint hook when you don't need it drawn anymore.[/QUOTE] That is a 3D rendering hook. HUDPaint is a 2D rendering hook. That answer is just out of context.
[QUOTE=geferon;52746235]You've got various options here. You can either use the 3D option and follow the example of the wiki on render.DrawQuadEasy or use the 2D option, getting a vectors 2D position on the screen with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/ToScreen]Vector:ToScreen[/url] and drawing it with the draw library and via [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/HUDPaint]GM:HUDPaint[/url][/QUOTE] I've done this (in [U]lua/client[/U]) : [CODE]playerPos = LocalPlayer():GetPos() hook.Add( "PostDrawTranslucentRenderables", "mapPoint", function() render.DrawQuadEasy( Vector( playerPos ), Vector( playerPos ), 64, 64, Color( 255, 255, 255, 200 ), 0) end )[/CODE] But it follows the player and rotate when the player is moving, and it has a strange texture that change. (That is really strange, I can't describe it) [QUOTE=geferon;52746235]If you want to continue by any of the two, you should set some sort of local variable clientside and use the [URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]net library[/URL] to send to the client the Player that he requires to go to and maybe even any other params you want to pass, and also a Think hook that checks the distance of the LocalPlayer with the other player and when there is less than a certain distance, stop the thing from appearing to that player locally..[/QUOTE] Wow that seems hard, I don't understand.
Store the var outside the hook.
I changed my code to use [img]https://wiki.garrysmod.com/favicon.ico[/img] [URL=https://wiki.garrysmod.com/page/cam/Start3D]cam.Start3D[/URL] with the given exemple because this is easier and this do not glitch like the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/DrawQuadEasy]render.DrawQuadEasy[/url] [QUOTE=Quozul;52749440]But it follows the player and rotate when the player is moving, and it has a strange texture that change. (That is really strange, I can't describe it)[/QUOTE] [CODE]hook.Add( "HUDPaint", "drawPlayer", function() cam.Start3D() ply:DrawModel() cam.End3D() end )[/CODE] But how can I execute it when the player executed a command (or from the server, but I don't understand how to use [img]https://wiki.garrysmod.com/favicon.ico[/img] [URL=http://wiki.garrysmod.com/page/Net_Library_Usage]net library[/URL]) ? I've tried this : [CODE]function drawPlayer( ply ) cam.Start3D() ply:DrawModel() cam.End3D() end concommand.Add( "drawAPlayer", drawPlayer)[/CODE] But it doesn't work. And how can I undraw the model (is it even possible) ?
[QUOTE=Quozul;52758465]I changed my code to use [img]https://wiki.garrysmod.com/favicon.ico[/img] [URL=https://wiki.garrysmod.com/page/cam/Start3D]cam.Start3D[/URL] with the given exemple because this is easier and this do not glitch like the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/DrawQuadEasy]render.DrawQuadEasy[/url] [CODE]hook.Add( "HUDPaint", "drawPlayer", function() cam.Start3D() ply:DrawModel() cam.End3D() end )[/CODE] But how can I execute it when the player executed a command (or from the server, but I don't understand how to use [img]https://wiki.garrysmod.com/favicon.ico[/img] [URL=http://wiki.garrysmod.com/page/Net_Library_Usage]net library[/URL]) ? I've tried this : [CODE]function drawPlayer( ply ) cam.Start3D() ply:DrawModel() cam.End3D() end concommand.Add( "drawAPlayer", drawPlayer)[/CODE] But it doesn't work. And how can I undraw the model (is it even possible) ?[/QUOTE] It has to be isnide a hook, you can't just do it once. It has to be done for every frame.
[QUOTE=Quozul;52749440] But it follows the player and rotate when the player is moving, and it has a strange texture that change. (That is really strange, I can't describe it)[/QUOTE] Probably because you didn't add any specific texture before RenderQuadEasy. Try using render.SetTexture() directly before and it should work fine...
Sorry, you need to Log In to post a reply to this thread.