Я ставлю вывод законов laws он мне изначально выдает такую ошибку:
[lib_plib_v2] addons/lib_plib_v2/lua/plib/extensions/client/surface.lua:150: bad argument #1 to ‘GetTextSize’ (string expected, got table)
- GetTextSize - [C]:-1
- GetTextSize - addons/lib_plib_v2/lua/plib/extensions/client/surface.lua:150
3. v - addons/laws/lua/autorun/client/laws_cl.lua:104
4. unknown - addons/lib_plib_v2/lua/plib/libraries/hook.lua:36 (x453
После чего я добавляю проверку вывод окошко появляется но не работает так как нужно и выдает ошибку:
[laws] addons/laws/lua/autorun/client/laws_cl.lua:121: attempt to call field ‘DrawNonParsedText’ (a nil value) - v - addons/laws/lua/autorun/client/laws_cl.lua:121
- unknown - addons/lib_plib_v2/lua/plib/libraries/hook.lua:36 (x833)
Весь код без проверки
local laws_convar = CreateClientConVar(‘laws’, 1, true)
local scrw, scrh = ScrW(), ScrH()
local color_background = Color(45,45,45,200)
local color_black = Color(0,0,0)
local color_white = Color(255,255,255)
local color_header = Color(26,26,26)
local color_button = Color(230,230,230)
local color_cls = Color(235,122,122)
surface.CreateFont(‘Laws.Header’, {
font = ‘Roboto Regular’,
extended = false,
size = 22,
weight = 800,
})
surface.CreateFont(‘Laws.Content’, {
font = ‘Roboto Regular’,
extended = false,
size = 16,
weight = 800,
})
local standart_laws = [[Денежные Принтеры: Тюрьма
Убийство: Тюрьма
Нелегал оружие: Тюрьма
Не мыть унитазы: Расстрел
Оскорбление госсов : Тюрьма]]
function OpenLawsEditor()
local Frame = vgui.Create(‘DFrame’)
Frame:SetSize(300, 300)
Frame:SetTitle(‘Редактор законов’)
Frame:Center()
Frame:MakePopup()
Frame.Paint = function(self, w, h)
draw.RoundedBox(0, 0, 0, w, h, color_background)
surface.SetDrawColor(color_black)
surface.DrawOutlinedRect(0, 0, w, h)
draw.RoundedBox(0, 0, 0, w, 24, color_header)
surface.SetDrawColor(color_black)
surface.DrawOutlinedRect(0, 0, w, 24)
end
Frame:ShowCloseButton(false)
Frame.cls = vgui.Create('DButton', Frame)
Frame.cls:SetSize(16, 16)
Frame.cls:SetPos(Frame:GetWide() - Frame.cls:GetWide() - 4, 4)
Frame.cls.DoClick = function()
Frame:Close()
end
Frame.cls:SetText('')
Frame.cls.Paint = function(_, w, h)
draw.RoundedBox(100, 0, 0, w, h, color_cls)
end
local text = laws or standart_laws
local TextEntry = vgui.Create('DTextEntry', Frame)
TextEntry:Dock(FILL)
TextEntry:SetText(text)
TextEntry:SetMultiline(true)
local DermaButton = vgui.Create('DButton', Frame)
DermaButton:SetText('Обновить законы')
DermaButton:Dock(BOTTOM)
DermaButton:DockMargin(0, 6, 0, 0)
DermaButton.DoClick = function()
local LawValue = TextEntry:GetValue()
if LawValue == '' then
LawValue = standart_laws
end
net.Start('LawsValue')
net.WriteString(LawValue)
net.SendToServer()
end
DermaButton.Paint = function(self, w, h)
draw.RoundedBox(4, 0, 0, w, h, color_button)
end
end
net.Receive(‘LawsMenu’, OpenLawsEditor)
net.Receive(‘LawsPublic’, function()
laws = net.ReadString()
end)
local mat_law = Material(‘spector_laws/icon.png’)
hook.Add(‘HUDPaint’, ‘DarkFated.SpectorLaws’, function()
if !laws_convar:GetBool() then
return
end
local text = laws or standart_laws
text = text:gsub('//', '\n'):gsub('\\n', '\n')
text = DarkRP.textWrap(text, 'Laws.Content', 290)
local width, height = surface.GetTextSize(text)
draw.RoundedBox(0, scrw - 315, 15, 300, height + 50, color_background)
surface.SetDrawColor(color_black)
surface.DrawOutlinedRect(scrw - 315, 15, 300, height + 50)
draw.RoundedBox(0, scrw - 315, 15, 300, 40, color_header)
surface.SetDrawColor(color_black)
surface.DrawOutlinedRect(scrw - 315, 15, 300, 40)
surface.SetDrawColor(color_white)
surface.SetMaterial(mat_law)
surface.DrawTexturedRect(scrw - 312, 20, 32, 32)
draw.DrawText('Законы города', 'Laws.Header', scrw - 276, 24, color_white, TEXT_ALIGN_LEFT)
draw.DrawText('(F2)', 'Laws.Header', scrw - 24, 24, color_white, TEXT_ALIGN_RIGHT)
draw.DrawNonParsedText(text, 'Laws.Content', scrw - 308, 59, color_white, 0)
end)
hook.Add(‘Think’, ‘DarkFated.SpectorLaws’, function()
if input.IsKeyDown(KEY_F2) and not laws_freeze then
RunConsoleCommand(‘laws’, laws_convar:GetBool() and 0 or 1)
laws_freeze = true
timer.Simple(1, function()
laws_freeze = false
end)
end
end)
Спойлер (c проверкой)
local laws_convar = CreateClientConVar(‘laws’, 1, true)
local scrw, scrh = ScrW(), ScrH()
local color_background = Color(45,45,45,200)
local color_black = Color(0,0,0)
local color_white = Color(255,255,255)
local color_header = Color(26,26,26)
local color_button = Color(230,230,230)
local color_cls = Color(235,122,122)
surface.CreateFont(‘Laws.Header’, {
font = ‘Roboto Regular’,
extended = false,
size = 22,
weight = 800,
})
surface.CreateFont(‘Laws.Content’, {
font = ‘Roboto Regular’,
extended = false,
size = 16,
weight = 800,
})
local standart_laws = [[Денежные Принтеры: Тюрьма
Убийство: Тюрьма
Нелегал оружие: Тюрьма
Не мыть унитазы: Расстрел
Оскорбление госсов : Тюрьма]]
function OpenLawsEditor()
local Frame = vgui.Create(‘DFrame’)
Frame:SetSize(300, 300)
Frame:SetTitle(‘Редактор законов’)
Frame:Center()
Frame:MakePopup()
Frame.Paint = function(self, w, h)
draw.RoundedBox(0, 0, 0, w, h, color_background)
surface.SetDrawColor(color_black)
surface.DrawOutlinedRect(0, 0, w, h)
draw.RoundedBox(0, 0, 0, w, 24, color_header)
surface.SetDrawColor(color_black)
surface.DrawOutlinedRect(0, 0, w, 24)
end
Frame:ShowCloseButton(false)
Frame.cls = vgui.Create('DButton', Frame)
Frame.cls:SetSize(16, 16)
Frame.cls:SetPos(Frame:GetWide() - Frame.cls:GetWide() - 4, 4)
Frame.cls.DoClick = function()
Frame:Close()
end
Frame.cls:SetText('')
Frame.cls.Paint = function(_, w, h)
draw.RoundedBox(100, 0, 0, w, h, color_cls)
end
local text = laws or standart_laws
local TextEntry = vgui.Create('DTextEntry', Frame)
TextEntry:Dock(FILL)
TextEntry:SetText(text)
TextEntry:SetMultiline(true)
local DermaButton = vgui.Create('DButton', Frame)
DermaButton:SetText('Обновить законы')
DermaButton:Dock(BOTTOM)
DermaButton:DockMargin(0, 6, 0, 0)
DermaButton.DoClick = function()
local LawValue = TextEntry:GetValue()
if LawValue == '' then
LawValue = standart_laws
end
net.Start('LawsValue')
net.WriteString(LawValue)
net.SendToServer()
end
DermaButton.Paint = function(self, w, h)
draw.RoundedBox(4, 0, 0, w, h, color_button)
end
end
net.Receive(‘LawsMenu’, OpenLawsEditor)
net.Receive(‘LawsPublic’, function()
laws = net.ReadString()
end)
local mat_law = Material(‘spector_laws/icon.png’)
hook.Add(‘HUDPaint’, ‘DarkFated.SpectorLaws’, function()
if !laws_convar:GetBool() then
return
end
local text = laws or standart_laws
text = text:gsub('//', '\n'):gsub('\\n', '\n')
text = DarkRP.textWrap(text, 'Laws.Content', 290)
local text = "ПРОВЕРКА" -- переменная которую использует метод surface.GetTextSize()
surface.GetTextSize("ПРОВЕРКА")
local width, height = surface.GetTextSize(text)
draw.RoundedBox(0, scrw - 315, 15, 300, height + 50, color_background)
surface.SetDrawColor(color_black)
surface.DrawOutlinedRect(scrw - 315, 15, 300, height + 50)
draw.RoundedBox(0, scrw - 315, 15, 300, 40, color_header)
surface.SetDrawColor(color_black)
surface.DrawOutlinedRect(scrw - 315, 15, 300, 40)
surface.SetDrawColor(color_white)
surface.SetMaterial(mat_law)
surface.DrawTexturedRect(scrw - 312, 20, 32, 32)
draw.DrawText('Законы города', 'Laws.Header', scrw - 276, 24, color_white, TEXT_ALIGN_LEFT)
draw.DrawText('(F2)', 'Laws.Header', scrw - 24, 24, color_white, TEXT_ALIGN_RIGHT)
draw.DrawNonParsedText(text, 'Laws.Content', scrw - 308, 59, color_white, 0)
end)
hook.Add(‘Think’, ‘DarkFated.SpectorLaws’, function()
if input.IsKeyDown(KEY_F2) and not laws_freeze then
RunConsoleCommand(‘laws’, laws_convar:GetBool() and 0 or 1)
laws_freeze = true
timer.Simple(1, function()
laws_freeze = false
end)
end
end)