General > Developers Corner
Admin sounds, tools and other code chat.
JamminR:
Quick dirty way .. place your script in lua/ULib/modules (or better as an addon, virtually ... addons/<yourscriptfoldername>/lua/ULib/modules/)
Best practice way .. place your script in lua/<yourscriptfoldername>/blah.lua (again, addons are recommended)
Then place an init in ULib/modules/ that loads.
Take a look at how Umotd loads from the addons.. it places an init file in an addons virtual ULib's modules folder.
jay209015:
I got it all worked out. Here's the script. Btw I used it in addon format :D
--- Code: ---if SERVER then
Msg("////////////////////////\n")
Msg("// Ajoin // \n")
Msg("////////////////////////\n")
Msg("// Rules.lua Loaded // \n")
Msg("// Setting Rules // \n")
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
for k,v in pairs( RulesT.rules ) do
RulesT.rules[tonumber(k)]=v
end
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules," "))
Msg("// Rules Set // \n")
Msg("////////////////////////\n")
function AddRule( ply, command, RuleA )
if ply:IsValid() then
if ply:IsAdmin() then
Rule = table.concat(RuleA)
if table.HasValue(RulesT.rules, "<li>" ..Rule) then
ULib.tsay(ply,"Rule Already Exist",false)
else
table.insert( RulesT.rules,"<li>" ..Rule )
file.Write("Umotd/rulest.txt", ULib.makeKeyValues(RulesT))
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules," "))
end
else
end
else
Msg("Can't execute from console \n")
end
end
concommand.Add( "AddRule", AddRule )
function RemoveRule( ply, command, RuleB )
if ply:IsValid() then
if ply:IsAdmin() then
RuleN = (tonumber(table.concat(RuleB)))
if RuleN <= table.Count(RulesT.rules) && RuleN > 1 then
table.remove( RulesT.rules, (RuleN) )
file.Write("Umotd/rulest.txt", ULib.makeKeyValues(RulesT))
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules," "))
else
if RuleN == 1 then
table.remove( RulesT.rules, 2 )
file.Write("Umotd/rulest.txt", ULib.makeKeyValues(RulesT))
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules," "))
else
ULib.tsay(ply,"Couldn't find Rule " ..RuleN.. "\nplease check !rules and try again.",false)
end
end
else
end
else
Msg("Can't run from console \n")
end
end
concommand.Add( "RemoveRule", RemoveRule )
else
Msg("Not Server, Ending Script")
end
--- End code ---
==EDIT==
With the help of Megiddo
jay209015:
Now, I'm trying to make an afk module. I am having some difficulties though.It's not working at all all. I'm not even getting Msg(view_old).
--- Code: ---function ajoin_afk()
for _,ply in pairs(player.GetAll()) do
function afk()
old_time = 1
local afk_status = nil
if ply:IsValid() then
view_old = ply:EyeAngles( )
old_time = tonumber(CurTime())
Msg(view_old)
end
end
function afk_check()
if tonumber(CurTime()) > (CurTime() + 10) then
if view_old == ply:EyeAngles() then
local afk_status = "AFK"
Msg("AFK SET")
end
end
if afk_status == "AFK" then
Msg("AFK")
game.ConsoleCommand("say Player " ..ply:Nick().. " Is AFK \n")
end
end
end
end
hook.Add("Think", "Afk_Check", afk_check)
--- End code ---
jay209015:
New Code, still nothing. The only change here, is that I change it to ply.._afk_status because before I only had one variable for all the players in the server. The code still doesn't work sadly enough. It's not even printing the messages past the start of the function.
--- Code: ---Msg("////////////////////\n")
Msg("// Module:AFK //\n")
Msg("////////////////////\n")
function ajoin_afk()
for _,ply in pairs(player.GetAll()) do
function afk()
old_time = 1
if ply:IsValid() then
view_old = ply:EyeAngles( )
old_time = tonumber(CurTime())
Msg(view_old)
end
end
function afk_check()
if tonumber(CurTime()) > (CurTime() + 10) then
if view_old == ply:EyeAngles() then
ply:Nick()_afk_status = "AFK"
Msg("AFK SET")
else
ply:Nick()_afk_status = "ACTIVE"
Msg("Active Set")
end
end
if ply:Nick().."afk_status" == "AFK" then
Msg("AFK")
game.ConsoleCommand("say Player " ..ply:Nick().. " Is AFK \n")
end
end
end
end
hook.Add("Think", "Afk_Check", afk_check)
--- 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