General > Developers Corner

Admin sounds, tools and other code chat.

<< < (30/31) > >>

jay209015:
Lol, I'm just wanting this to learn and it would be useful for those rare occasions where you may accidentally spam due to a bad timer on a prop spawner ect.

jay209015:
How do I get the vgui to display ply.warn?

cl_init:

--- Code: ---function ServerVGUI()
local ply = LocalPlayer()
         local DermaPanel = vgui.Create( "DFrame" )
         DermaPanel:SetPos( 0,0 )
         DermaPanel:SetSize( 150, 0 )
         DermaPanel:SetTitle( "Warning lvl:" ..ply.warn )
DermaPanel:SetVisible(true)
DermaPanel:ShowCloseButton( false )

end
concommand.Add( "vguitest", ServerVGUI )
--- End code ---

init:

--- Code: ---AddCSLuaFile("cl_init.lua");
--- End code ---

ASpam:

--- Code: ---// Potentially Harmful props have a longer delay in spawn time
dlist = { "crane_frame.mdl", "models/props_phx/ball.mdl", "models/props_phx/oildrum001_explosive.mdl", "models/props_phx/mk-82.mdl", "models/props_phx/torpedo.mdl", "models/props_phx/ww2bomb.mdl", "models/props_phx/misc/flakshell_big.mdl", "models/props_junk/gascan001a.mdl", "models/props_junk/propane_tank001a.mdl", "models/props_c17/oildrum001_explosive.mdl", "models/props_phx/huge/tower.mdl", "models/props_phx/huge/evildisc_corp.mdl", "models/props_phx/playfield.mdl", "models/props_c17/utilitypole01d.mdl", "models/props_buildings/building_002a.mdl", "models/props_buildings/collapsedbuilding02b.mdl", "models/props_buildings/collapsedbuilding02c.mdl", "models/props_buildings/project_building01.mdl", "models/props_buildings/project_building02.mdl", "models/props_buildings/project_building03.mdl", "models/props_buildings/project_destroyedbuildings01.mdl", "models/props_buildings/row_church_fullscale.mdl", "models/props_buildings/row_corner_1_fullscale.mdl", "models/props_buildings/row_res_1_fullscale.mdl", "models/props_buildings/row_res_2_ascend_fullscale.mdl", "models/props_canal/canal_bridge01.mdl", "models/props_canal/canal_bridge02.mdl", "models/props_canal/canal_bridge03a.mdl", "models/props_canal/canal_bridge03b.mdl" }
Delay = 0.3 // Delay for normal props
XDelay = 1  // Delay for the props in the dlist
Warn_Player = 5 // After what warning lvl should the player be warned?
Max_Warn = 10 // Max number of times a player can be warned before getting kicked

//==============================DO NOT EDIT BELOW THIS POINT===================================//
module( "ASpam", package.seeall )

function setup_propspawn(ply)
ply.denied = false
ply.d_time = 0
ply.t_time = 0
ply.warn = 0
ply:ConCommand("vguitest")
end
hook.Add( "PlayerInitialSpawn", "Setup_PropSpawn", setup_propspawn );
function propspawn(ply, mdl)
if CurTime() < ply.d_time then
wait_time = ply.d_time - math.Round(CurTime(),2)
ply:PrintMessage(HUD_PRINTTALK, "You must wait " ..wait_time.. " second(s) before spawning another prop")
ply.warn = ply.warn + 1
timer.Create( ply:Nick().. "cooldown", 60, 0, CoolDown, ply)
timer.Simple( 0, Spammer_Kick, ply )
return false
end
for k, v in pairs( dlist ) do
if string.find( mdl, v, 1, true ) then
if ply.whitelist then
ply.d_time = 0
else
ply.d_time = math.Round(CurTime()) + XDelay
return
end
else
if ply.whitelist then
ply.d_time = 0
else
ply.d_time = math.Round(CurTime()) + Delay
end
end
end
end
hook.Add( "PlayerSpawnProp", "PropSpawn", propspawn )
function gettool(ply, tr, toolmode)
if CurTime() > ply.t_time then
if toolmode == "adv_duplicator" or toolmode == "duplicator" then
ply.t_time = math.Round(CurTime(),1) + Delay
timer.Create( ply:Nick().. "timer", 0, 0, remove_delay, ply)
timer.Create( ply:Nick().. "whitelist", 10, 0, timerreset, ply)
else
if toolmode == "ol_stacker" or toolmode == "dynamite" then
ply.t_time = math.Round(CurTime(), 2) + XDelay
else
ply.t_time = 0
end
end
else
t_wait_time = ply.t_time - math.Round(CurTime(), 2)
ply:PrintMessage(HUD_PRINTTALK, "You must wait " ..t_wait_time.. " second(s) before using another tool")
ply.whitelist = false
return false
end
end
hook.Add( "CanTool", "GetTool", gettool)
function timerreset( ply )
ply.d_time = CurTime() + Delay
timer.Destroy( ply:Nick().. "timer" )
timer.Destroy( ply:Nick().. "whitelist" )
ply.whitelist = false
end
function remove_delay( ply )
if !ply.whitelist then
ply.whitelist = true
end
end
function CoolDown( ply )
if ply.warn > 0 then
ply.warn = ply.warn - 1
else
timer.Destroy( ply:Nick().. "cooldown" )
ply.warn = 0
end
end
function Timer_Remove( ply )
if timer.IsTimer( ply:Nick().. "cooldown" ) then
timer.Destroy( ply:Nick().. "cooldown" )
end
if timer.IsTimer( ply:Nick().. "timer" ) then
timer.Destroy( ply:Nick().. "timer" )
end
if timer.IsTimer( ply:Nick().. "whitelist" ) then
timer.Destroy( ply:Nick().. "whitelist" )
end
end
hook.Add( "PlayerDisconnected", "Remove_Timers_Hook", Timer_Remove )
function Spammer_Kick( ply )
if ply.warn >= Warn_Player then
ply:PrintMessage(HUD_PRINTTALK, "If you continue to Spam, you will be kicked!")
Warn_Left = Max_Warn - ply.warn
game.ConsoleCommand( "ulx asay Player " ..ply:Nick().. " is spamming, and has a warn level of " ..ply.warn.. ". Kicking them after " ..Warn_Left.. " more warnings \n")
end
if ply.warn >= Max_Warn then
ULib.kick(ply, "Quit Spamming")
end
end




--- End code ---

Error I get with the cl_init:

--- Code: ---autorun/cl_init.lua:11: attempt to concatenate field 'warn' (a nil value)
--- End code ---

Megiddo:
You need to send the 'warn' variable to the client somehow. Networked vars or usermessages are your options. Look 'em up on the wiki.

jay209015:
The warning lvl doesn't update now.

cl_init:

--- Code: ---function ServerVGUI()
local ply = LocalPlayer()
         local DermaPanel = vgui.Create( "DFrame" )
         DermaPanel:SetPos( 0,0 )
         DermaPanel:SetSize( 150, 25 )
DermaPanel:SetTitle( "Warning lvl:" ..ply:GetNetworkedInt( "warn" ) )
DermaPanel:SetVisible(true)
DermaPanel:ShowCloseButton( false )
DermaPanel:SetDraggable( false )
end
concommand.Add( "vguitest", ServerVGUI )
--- End code ---

ASpam:

--- Code: ---// Potentially Harmful props have a longer delay in spawn time
dlist = { "crane_frame.mdl", "models/props_phx/ball.mdl", "models/props_phx/oildrum001_explosive.mdl", "models/props_phx/mk-82.mdl", "models/props_phx/torpedo.mdl", "models/props_phx/ww2bomb.mdl", "models/props_phx/misc/flakshell_big.mdl", "models/props_junk/gascan001a.mdl", "models/props_junk/propane_tank001a.mdl", "models/props_c17/oildrum001_explosive.mdl", "models/props_phx/huge/tower.mdl", "models/props_phx/huge/evildisc_corp.mdl", "models/props_phx/playfield.mdl", "models/props_c17/utilitypole01d.mdl", "models/props_buildings/building_002a.mdl", "models/props_buildings/collapsedbuilding02b.mdl", "models/props_buildings/collapsedbuilding02c.mdl", "models/props_buildings/project_building01.mdl", "models/props_buildings/project_building02.mdl", "models/props_buildings/project_building03.mdl", "models/props_buildings/project_destroyedbuildings01.mdl", "models/props_buildings/row_church_fullscale.mdl", "models/props_buildings/row_corner_1_fullscale.mdl", "models/props_buildings/row_res_1_fullscale.mdl", "models/props_buildings/row_res_2_ascend_fullscale.mdl", "models/props_canal/canal_bridge01.mdl", "models/props_canal/canal_bridge02.mdl", "models/props_canal/canal_bridge03a.mdl", "models/props_canal/canal_bridge03b.mdl" }
Delay = 0.3 // Delay for normal props
XDelay = 1  // Delay for the props in the dlist
Warn_Player = 5 // After what warning lvl should the player be warned?
Max_Warn = 10 // Max number of times a player can be warned before getting kicked

//==============================DO NOT EDIT BELOW THIS POINT===================================//


function setup_propspawn(ply)
ply.denied = false
ply.d_time = 0
ply.t_time = 0
ply.warn = 0
ply:SetNetworkedInt( "warn", ply.warn )
ply:ConCommand("vguitest")
end
hook.Add( "PlayerInitialSpawn", "Setup_PropSpawn", setup_propspawn );
function propspawn(ply, mdl)
if CurTime() < ply.d_time then
wait_time = ply.d_time - math.Round(CurTime(),2)
ply:PrintMessage(HUD_PRINTTALK, "You must wait " ..wait_time.. " second(s) before spawning another prop")
ply.warn = ply.warn + 1
ply:SetNetworkedInt( "warn", ply.warn )
timer.Create( ply:Nick().. "cooldown", 60, 0, CoolDown, ply)
timer.Simple( 0, Spammer_Kick, ply )
return false
end
for k, v in pairs( dlist ) do
if string.find( mdl, v, 1, true ) then
if ply.whitelist then
ply.d_time = 0
else
ply.d_time = math.Round(CurTime()) + XDelay
return
end
else
if ply.whitelist then
ply.d_time = 0
else
ply.d_time = math.Round(CurTime()) + Delay
end
end
end
end
hook.Add( "PlayerSpawnProp", "PropSpawn", propspawn )
function gettool(ply, tr, toolmode)
if CurTime() > ply.t_time then
if toolmode == "adv_duplicator" or toolmode == "duplicator" then
ply.t_time = math.Round(CurTime(),1) + Delay
timer.Create( ply:Nick().. "timer", 0, 0, remove_delay, ply)
timer.Create( ply:Nick().. "whitelist", 10, 0, timerreset, ply)
else
if toolmode == "ol_stacker" or toolmode == "dynamite" then
ply.t_time = math.Round(CurTime(), 2) + XDelay
else
ply.t_time = 0
end
end
else
t_wait_time = ply.t_time - math.Round(CurTime(), 2)
ply:PrintMessage(HUD_PRINTTALK, "You must wait " ..t_wait_time.. " second(s) before using another tool")
ply.whitelist = false
return false
end
end
hook.Add( "CanTool", "GetTool", gettool)
function timerreset( ply )
ply.d_time = CurTime() + Delay
timer.Destroy( ply:Nick().. "timer" )
timer.Destroy( ply:Nick().. "whitelist" )
ply.whitelist = false
end
function remove_delay( ply )
if !ply.whitelist then
ply.whitelist = true
end
end
function CoolDown( ply )
if ply.warn > 0 then
ply.warn = ply.warn - 1
ply:SetNetworkedInt( "warn", ply.warn )
ply:ConCommand("vguitest")
else
timer.Destroy( ply:Nick().. "cooldown" )
ply.warn = 0
ply:SetNetworkedInt( "warn", ply.warn )
ply:ConCommand("vguitest")
end
end
function Timer_Remove( ply )
if timer.IsTimer( ply:Nick().. "cooldown" ) then
timer.Destroy( ply:Nick().. "cooldown" )
end
if timer.IsTimer( ply:Nick().. "timer" ) then
timer.Destroy( ply:Nick().. "timer" )
end
if timer.IsTimer( ply:Nick().. "whitelist" ) then
timer.Destroy( ply:Nick().. "whitelist" )
end
end
hook.Add( "PlayerDisconnected", "Remove_Timers_Hook", Timer_Remove )
function Spammer_Kick( ply )
if ply.warn >= Warn_Player then
ply:PrintMessage(HUD_PRINTTALK, "If you continue to Spam, you will be kicked!")
Warn_Left = Max_Warn - ply.warn
game.ConsoleCommand( "ulx asay Player " ..ply:Nick().. " is spamming, and has a warn level of " ..ply.warn.. ". Kicking them after " ..Warn_Left.. " more warnings \n")
end
if ply.warn >= Max_Warn then
ULib.kick(ply, "Quit Spamming")
end
end
function Vgui_Updater( ply )
ply:ConCommand("vguitest")
end
--- End code ---

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given

[0] Board index

Go to full version