• Surface.CreateFont block any command...
    13 replies, posted
Hey Facepunch I want to create a PaintTool with a chatCommand. My PaintTool use Cam3d2d to create HUD in the World. But i have a problem and i dont know why : [CODE] Paint = {} Paint.Active = false function Paint.GetInfo( ply, text, public ) if (string.sub(text, 1, 6) == "!Paint") then local textexplode = string.Explode( " ", text ) local Index = textexplode[2] local Text = textexplode[3] local Size = textexplode[4] local Trace = ply:GetEyeTrace() local Position = Trace.HitPos surface.CreateFont("CV"..tostring(Index), { font = "coolvetica", size = Size, weight = 400, antialias = true, outline = true, } ) RunConsoleCommand("say", Index) RunConsoleCommand("say", Text) RunConsoleCommand("say", Size) RunConsoleCommand("say", tostring(Position)) Paint.AddText(Index, Text, Size, Position) end end hook.Add( "PlayerSay", "SayPaint", Paint.GetInfo) [/CODE] My runConsoleCommand dosent want to execute. Its like if my surface.Create block this command... and i don't understand why... Can you help me plz ? Thx
What console command are you trying to use? You dont have one in the code.
I want when i type : !Paint [INDEX TEXT SIZE] -> !Paint 1 Test 50 My font has to be created and my Console say : Index, Text, Size and Position of my player.
[URL="http://wiki.garrysmod.com/page/GM/PlayerSay"]PlayerSay[/URL] is a server-side hook. Why dont you just make a console command for it?
My problem its just : runConsoleCommand dosent want execut. If i made this : [CODE] function Paint.GetInfo( ply, text, public ) if (string.sub(text, 1, 6) == "!Paint") then local textexplode = string.Explode( " ", text ) local Index = textexplode[2] local Text = textexplode[3] local Size = textexplode[4] local Trace = ply:GetEyeTrace() local Position = Trace.HitPos RunConsoleCommand("say", Index) RunConsoleCommand("say", Text) RunConsoleCommand("say", Size) RunConsoleCommand("say", tostring(Position)) surface.CreateFont("CV"..tostring(Index), { font = "coolvetica", size = Size, weight = 400, antialias = true, outline = true, } ) Paint.AddText(Index, Text, Size, Position) end end [/CODE] My console can speak I think i have an error on my surface.Create but where... I use this : [url]http://wiki.garrysmod.com/page/surface/CreateFont[/url]
You are using 2 functions from different realms. PlayerSay is server-side like I told you, so hooking into it on the client will never get called. surface.CreateFont is client-side, so trying to use it in a server-side hook will error, but since your PlayerSay hook is never called on the client, the code inside is never executed.
Then what is your solution ?
Switch [B]PlayerSay[/B] to [URL="http://wiki.garrysmod.com/page/GM/OnPlayerChat"][B]OnPlayerChat[/B] [/URL]if you want this to be purely [U]clientside[/U]. However, using OnPlayerChat means any serverside admin mods that return a blank string ("") for commands like !command or /command will prevent your OnPlayerChat from ever actually running. Instead,[B] stick with PlayerSay[/B] and put the hook inside of a serverside file. [CODE] -- Serverside file. Example: lua/server/paint.lua function Paint.GetInfo( ply, text, public ) if ( text:sub(1, 6):lower() == "!paint" ) then -- :lower() is so you can type !paint, !Paint, !PAINT, etc local textexplode = string.Explode( " ", text ) local Index = textexplode[2] local Text = textexplode[3] local Size = textexplode[4] net.Start( "AddPaintText" ) net.WriteFloat( Index ) -- net.WriteUInt if you know the amount of bits net.WriteString( Text ) net.WriteFloat( Size ) -- net.WriteUInt if you know the amount of bits net.Send( ply ) end end hook.Add( "PlayerSay", "SayPaint", Paint.GetInfo )[/CODE] Then move this stuff into a clientside file and use net messages to tell the client to run it (alternative, use concommand): [CODE] -- Clientside file. Example: lua/client/paint.lua net.Receive( "AddPaintText", function( bits ) local Index = net.ReadFloat() local Text = net.ReadString() local Size = net.ReadFloat() local Trace = LocalPlayer():GetEyeTrace() local Position = Trace.HitPos RunConsoleCommand("say", Index) RunConsoleCommand("say", Text) RunConsoleCommand("say", Size) RunConsoleCommand("say", tostring(Position)) surface.CreateFont("CV"..tostring(Index), { font = "coolvetica", size = Size, weight = 400, antialias = true, outline = true, } ) Paint.AddText(Index, Text, Size, Position) end[/CODE]
Hooo okay man :) thank you, Really ! I test your code tomorow ! Its Really informative for me, thx again
[QUOTE=Naografix;45413909]Hooo okay man :) thank you, Really ! I test your code tomorow ! Its Really informative for me, thx again[/QUOTE] No problem. I haven't personally tested it, so if you have any further issues, be sure to post here again and we'll try to help. --Edit-- I accidentally left out two [B]end[/B]s in the first code snippet, so make sure to re-copy it when you test it tomorrow. My bad :)
Okay ! Good night ^^
Yep ! Okay, well. I see in your code you said : -- Clientside file. Example: lua/client/paint.lua and server/paint.lua Then i think i can make : if SERVER then ... else ... end But already same [CODE] Paint = {} Paint.Active = false if SERVER then -- Serverside file. Example: lua/server/paint.lua function Paint.GetInfo( ply, text, public ) if ( text:sub(1, 6):lower() == "!paint" ) then -- :lower() is so you can type !paint, !Paint, !PAINT, etc local textexplode = string.Explode( " ", text ) local Index = textexplode[2] local Text = textexplode[3] local Size = textexplode[4] net.Start( "AddPaintText" ) net.WriteFloat( Index ) -- net.WriteUInt if you know the amount of bits net.WriteString( Text ) net.WriteFloat( Size ) -- net.WriteUInt if you know the amount of bits net.Send( ply ) end end hook.Add( "PlayerSay", "SayPaint", Paint.GetInfo ) else -- Clientside file. Example: lua/client/paint.lua net.Receive( "AddPaintText", function( bits ) local Index = net.ReadFloat() local Text = net.ReadString() local Size = net.ReadFloat() local Trace = LocalPlayer():GetEyeTrace() local Position = Trace.HitPos RunConsoleCommand("say", Index) RunConsoleCommand("say", Text) RunConsoleCommand("say", Size) RunConsoleCommand("say", tostring(Position)) surface.CreateFont("CV"..tostring(Index), { font = "coolvetica", size = Size, weight = 400, antialias = true, outline = true, } ) Paint.AddText(Index, Text, Size, Position) end) function Paint.AddText(Index, Text, Size, Position) local Item = {} Item.Index = Index Item.Text = Text Item.Size = Size Item.Position = Position table.insert(Paint.Stored, Item) Paint.Active = true end function Paint.PaintHook() if not Paint.Active then return end for _, Item in pairs(Paint.Stored) do local Text = Item.Text local Position = Item.Position local Angles = Angle(0,0,0) local Size = Item.Size local Index = Item.Index local Alpha = 255 local Color = Color(255,0,0) cam.Start3D2D(Position, Angles, 0.25) draw.DrawText(Text, "CV"..tostring(Index), 0, 0, Color, TEXT_ALIGN_CENTER) cam.End3D2D() end end hook.Add("PostDrawOpaqueRenderables", "Paint.PaintHook", Paint.PaintHook) end [/CODE] I begin the lua language, excuse me ^^' (To test my code i use : lua dev with this command : lua_send_sh Paint.lua)
You are executing the "say" console command too fast. There's a delay before you can use it again.
Woops, I forgot to mention that you need to cache the net message. [CODE] if SERVER then -- Serverside file. Example: lua/server/paint.lua util.AddNetworkString( "AddPaintText" ) -- cache the message name so we can send it function Paint.GetInfo( ply, text, public ) if ( text:sub(1, 6):lower() == "!paint" ) then -- :lower() is so you can type !paint, !Paint, !PAINT, etc local textexplode = string.Explode( " ", text ) local Index = textexplode[2] local Text = textexplode[3] local Size = textexplode[4] net.Start( "AddPaintText" ) net.WriteFloat( Index ) -- net.WriteUInt if you know the amount of bits net.WriteString( Text ) net.WriteFloat( Size ) -- net.WriteUInt if you know the amount of bits net.Send( ply ) end end hook.Add( "PlayerSay", "SayPaint", Paint.GetInfo ) else[/CODE] If you're using those RunConsoleCommand("say",...) parts just for testing, you could switch it to print( Index ), print( Text), print( Position ). If you want it to show up in chat instead, you could use chat.AddText( Index ), etc.
Sorry, you need to Log In to post a reply to this thread.