Author Topic: Spray Control Help Needed  (Read 2279 times)

0 Members and 1 Guest are viewing this topic.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Spray Control Help Needed
« on: August 03, 2013, 02:56:32 PM »
So I am trying to make a mod of SprayMon so that it can actually help manage players sprays but here is an error I am running into...

Code: [Select]
L 08/03/2013 - 16:43:25: FAdmin Action: Tenshi (STEAM_0:1:68223774) Removed all decals
L 08/03/2013 - 16:43:25: "[LG] Taco Cliff<178><STEAM_0:1:37219778><>" disconnected (reason "Client 3 overflowed reliable channel.")
L 08/03/2013 - 16:43:25: [LG] Taco Cliff  (STEAM_0:1:37219778) Disconnected
L 08/03/2013 - 16:43:25: "Jeralynn<170><STEAM_0:1:44915738><>" disconnected (reason "Client 4 overflowed reliable channel.")
L 08/03/2013 - 16:43:25: Jeralynn (STEAM_0:1:44915738) Disconnected
L 08/03/2013 - 16:43:25: "(KGC) Nyht Gunner<179><STEAM_0:0:28465605><>" disconnected (reason "Client 5 overflowed reliable channel.")
L 08/03/2013 - 16:43:25: (KGC) Nyht Gunner (STEAM_0:0:28465605) Disconnected
L 08/03/2013 - 16:43:25: "Nyht Shadow<180><STEAM_0:0:42251730><>" disconnected (reason "Client 6 overflowed reliable channel.")
L 08/03/2013 - 16:43:25: Nyht Shadow (STEAM_0:0:42251730) Disconnected
L 08/03/2013 - 16:43:25: "Elite_Matai<174><STEAM_0:0:59753662><>" disconnected (reason "Client 7 overflowed reliable channel.")
L 08/03/2013 - 16:43:25: Elite_Matai (STEAM_0:0:59753662) Disconnected

This is my current code...

Code: [Select]
-- CLIENT SIDE LUA --

local sprays = {}
local vOnce = true
local vOnceB = true

net.Receive("vAddSpray", function()
local ply = net.ReadEntity()
if ply.SteamID then
local normal = Vector(net.ReadFloat(), net.ReadFloat(), net.ReadFloat())
local ang = normal:Angle()
local vec = ang:Forward() * .001 + (ang:Right() + ang:Up()) * 32
local pos = Vector(net.ReadFloat(), net.ReadFloat(), net.ReadFloat()) + ang:Up() * 4
sprays[ply:SteamID()] = {name = ply:Name(), pos1 = pos - vec, pos2 = pos + vec, normal = normal, clears = 0}
end
end)

local function clear()
for k, v in pairs(sprays) do
v.clears = v.clears + 1
if v.clears >= 2 then
sprays[k] = nil
end
end
end
net.Receive("vClearDecals", clear)

local old = RunConsoleCommand
RunConsoleCommand = function(cmd, ...)
if cmd == "r_cleardecals" then
clear()
end
return old(cmd, ...)
end

local function isin(num, num1, num2)
return (num >= num1 and num <= num2) or (num <= num1 and num >= num2)
end

surface.CreateFont("vSpray", {font = "Trebuchet MS", size = 24, weight = 900})

local first = true

function isSpray( ply )
todraw = {}
local trace = ply:GetEyeTrace()
for k, v in pairs(sprays) do
if v.normal == trace.HitNormal and isin(trace.HitPos.x, v.pos1.x, v.pos2.x) and isin(trace.HitPos.y, v.pos1.y, v.pos2.y) and isin(trace.HitPos.z, v.pos1.z, v.pos2.z) then
table.insert(todraw, k)
end
end
if #todraw > 0 then
return true
end
end

hook.Add("HUDPaint", "vPrintSprays", function()
local todraw = {}
local trace = LocalPlayer():GetEyeTrace()
for k, v in pairs(sprays) do
if v.normal == trace.HitNormal and isin(trace.HitPos.x, v.pos1.x, v.pos2.x) and isin(trace.HitPos.y, v.pos1.y, v.pos2.y) and isin(trace.HitPos.z, v.pos1.z, v.pos2.z) then
table.insert(todraw, k)
end
end
if #todraw > 0 then
LocalPlayer().CanSpray = false

if(vOnce) then
if not(LocalPlayer().CanSpray) then
net.Start("vSprayBlock")
net.SendToServer()
vOnceB = true
vOnce = false
end
end

if first then
chat.AddText(Color(128, 128, 128), "You can view SteamID of spray owner by holding ALT while looking at it.")
first = false
end
local y = ScrH() / 2 - #todraw * 12
draw.SimpleText("Sprayed by:", "vSpray", 10, y, Color(0, 63.75, 255), 0, 1)
for k, v in pairs(todraw) do
y = y + 24
draw.SimpleText(sprays[v].name .. (input.IsKeyDown(KEY_LALT) and (": " .. v) or ""), "vSpray", 10, y, Color(0, 63.75, 255), 0, 1)
end
else
LocalPlayer().CanSpray = true
if(LocalPlayer().CanSpray and vOnceB) then
net.Start("vSprayAllow")
net.SendToServer()
vOnce = true
vOnceB = false
end
end
end)

hook.Add("PlayerBindPress", "vNoSprayDelay", function( ply, cmd )
local canspray = false
if( string.find(cmd, "impulse 201") ) then
if not(ply:IsSuperAdmin()) then
if not( LocalPlayer().CanSpray ) then
net.Start("vSprayBlock")
canspray = false
chat.AddText(Color(255,0,0,255), "[SprayMon] ", Color(255,0,0,255), "You can not place a spray here!")
return true
else
net.Start("vSprayAllow")
net.SendToServer()
canspray = true
end
else
net.Start("vSprayAllow")
net.SendToServer()
canspray = true
end

if( canspray ) then
net.Start("vSpray")
net.SendToServer()
else
chat.AddText(Color(255,0,0,255), "[SprayMon] ", Color(255,0,0,255), "You can not place a spray here!")
return true
end
end
end)

Code: [Select]
-- SERVER SIDE LUA --

util.AddNetworkString("vSprayBlock")
util.AddNetworkString("vSprayAllow")
util.AddNetworkString("vSpray")
util.AddNetworkString("vAddSpray")
util.AddNetworkString("vClearDecals")
util.AddNetworkString("vSpray")

CreateConVar("spraymon_nodelay", 1, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE}, "no delay for 0:nobody | 1:admins | 2:superadmins")

hook.Add("PlayerSpray", "vSendSpray", function(ply)
local trace = ply:GetEyeTrace()
net.Start("vAddSpray")
net.WriteEntity(ply)
net.WriteFloat(trace.HitNormal.x)
net.WriteFloat(trace.HitNormal.y)
net.WriteFloat(trace.HitNormal.z)
net.WriteFloat(trace.HitPos.x)
net.WriteFloat(trace.HitPos.y)
net.WriteFloat(trace.HitPos.z)
net.Broadcast()
end)

local plymeta = FindMetaTable("Player")
local old = plymeta.ConCommand
plymeta.ConCommand = function(self, cmd, ...)
if string.find(cmd, "r_cleardecals") then
old(self, cmd, ...)
net.Start("vClearDecals")
net.Send(self)
end
return old(self, cmd, ...)
end

net.Receive("vSpray", function(_, ply)
if GetConVarNumber("spraymon_nodelay") > 0 and (GetConVarNumber("spraymon_nodelay") > 1 and ply:IsSuperAdmin() or ply:IsAdmin()) then
ply:AllowImmediateDecalPainting()
end
end)

net.Receive("vSprayBlock", function(_, ply)
ply:ChatPrint("Spraying Blocked")
ply.SCanSpray = false
end)

net.Receive("vSprayAllow", function(_, ply)
ply:ChatPrint("Spraying Allowed")
ply.SCanSpray = true
end)

hook.Add("PlayerSpray", "vNoSprayBlock", function( ply )
if not( ply.SCanSpray == nil ) then
if not( ply.SCanSpray ) then
ply:SendLua([[chat.AddText(Color(255,0,0,255), "[SprayMon] ", Color(255,0,0,255), "You can not place a spray here!")]])
return true
end
end
end)

Help with cleaning up the code an fixing the error will be greatly appreciated.

Special thanks to VigiFyre for making SprayMon in the first place!
« Last Edit: August 03, 2013, 03:00:39 PM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Spray Control Help Needed
« Reply #1 on: August 03, 2013, 05:39:28 PM »
It generally means you're sending too much data or creating too many cvars somehow... but that's really all the help I can offer, sorry.
Experiencing God's grace one day at a time.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Spray Control Help Needed
« Reply #2 on: August 04, 2013, 12:37:14 AM »
It generally means you're sending too much data or creating too many cvars somehow... but that's really all the help I can offer, sorry.

Turns out the error happened because I was updating the code live, after a server restart the problem disappeared.
I cry every time I see that I am not a respected member of this community.