• Print

Author Topic: Admin sounds, tools and other code chat.  (Read 95065 times)

0 Members and 1 Guest are viewing this topic.

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #90 on: April 30, 2008, 06:15:21 pm »
Now I'm having a problem with concommand.Add

I typed this ingame.
Code: [Select]
AddRule "Test"

and got this in server console.
Code: [Select]
autorun/Ajoin.lua:48: attempt to concatenate local 'args' (a table value)
This is Line:48
Code: [Select]
if string.find( Rules, "<li>" ..args, 1, true ) then
==EDIT==
Got it :D
Code: [Select]
function AddRule( ply, command, RuleA )
Rules = file.Read( "Umotd/rules.txt" )
if ply:IsValid() then
if ply:IsAdmin() then
Rule = table.concat(RuleA)
if string.find( Rules, "<li>" ..Rule, 1, true ) then
Rules = Rules
else
Rules = Rules.. "<li>" ..Rule
file.Write( "Umotd/rules.txt", Rules )
end
else

end
else
print("Can't execute from console \n")
end
end
concommand.Add( "AddRule", AddRule )
« Last Edit: April 30, 2008, 07:55:13 pm by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #91 on: May 01, 2008, 05:41:00 pm »
Code: [Select]
Unknown command: AddRule
Code: [Select]
Unknown command: RemoveRuleErrors above.

Code: [Select]
Rules = file.Read( "Umotd/rulest.txt" )
RulesT = util.KeyValuesToTable( Rules )
for k,v in pairs( RulesT.rules ) do
RulesT.rules[tonumber(k)]=v
end
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules, " ") )
function AddRule( ply, command, RuleA )
if ply:IsValid() then
if ply:IsAdmin() then
Rule = table.concat(RuleA)
if string.find( table.concat(RulesT.rules), "<li>" ..Rule, 1, true ) then
Msg("Rule already exists \n")
else
table.insert( RulesT.rules, "<li>" ..Rule )
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules, " ") )
file.Write( "Umotd/rulest.txt", util.TableToKeyValues(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 = table.concat(RuleB)
if tonumber(RuleN) < table.Count(RulesT.rules)+1 && tonumber(RuleN) > 1 then
table.remove( RulesT.rules, RuleN )
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules, " ") )
file.Write( "Umotd/rulest.txt", util.TableToKeyValues(RulesT.rules))
else
Msg("Couldn't find the rule mentioned \n")
end
else

end
else
Msg("Can't run from console \n")
end
end
concommand.Add( "RemoveRule", RemoveRule )

rulest.txt below

Code: [Select]
"Out"
{
"1" "<ol>"
"2" "<li>Test2"
"3" "<li>Test5"
"4" "<li>Test6"
}

BTW I'm trying to make it handle the table like Uteam does with the Uteam.txt file in the data folder, so my rulest.txt should look like this below, but the rulest.txt was written by the script.


Code: [Select]
"Out"
{
     "rules"
     {
     "1" "<ol>"
     "2" "<li>Test2"
     "3" "<li>Test5"
     "4" "<li>Test6"
     }
}
« Last Edit: May 02, 2008, 01:50:37 pm by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #92 on: May 02, 2008, 02:16:10 pm »
Not Setting RulesT for somereason.

Code: [Select]
if SERVER then
timer.Create( RulesTimer, 1, 0, SetRules )
function SetRules()
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
end
function AddRule( ply, command, RuleA )
if ply:IsValid() then
if ply:IsAdmin() then
Rule = table.concat(RuleA)
if  table.HasValue(RulesT, "<li>" ..Rule) then
Msg("Rule already exists \n")
else
table.insert( RulesT, "<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, " ") )
end
else

end
else
Msg("Can't execute from console \n")
end
end
concommand.Add( "AddRule", AddRule )
Msg("p4")
function RemoveRule( ply, command, RuleB )
if ply:IsValid() then
if ply:IsAdmin() then
RuleN = table.concat(RuleB)
if tonumber(RuleN) < table.Count(RulesT)+1 && tonumber(RuleN) > 1 then
table.remove( RulesT, (tonumber(RuleN)+1) )
file.Write("Umotd/rulest.txt", ULib.makeKeyValues(RulesT))
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
file.Write( "Umotd/rules2.txt", table.concat(RulesT, " ") )
else
Msg("Couldn't find the rule # mentioned \n")
end
else

end
else
Msg("Can't run from console \n")
end
end
concommand.Add( "RemoveRule", RemoveRule )
Msg("p5")
else
Msg("Not Server, Ending Script")
timer.Destroy( RulesTimer )
end

My rulest.txt
Code: [Select]
"1" "<ol>"
"2" "<li>Test1"
"3" "<li>Test2"
"4" "<li>Test3"
"5" "<li>Test4"
« Last Edit: May 03, 2008, 08:54:05 am by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #93 on: May 04, 2008, 08:51:18 pm »
No one see anything wrong I guess?
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #94 on: May 10, 2008, 08:55:01 pm »
Ok, after looking through the console I found the problem.

Code: [Select]
autorun/Rules.lua:2: attempt to index global 'ULib' (a nil value)
======== Installing Table (De)Serialiser Module | ver: 1.4 ========
///////////////////////////////
//      Ulysses Library      //
///////////////////////////////
// Loading...                //
//  shared/defines.lua       //
//  server/hook.lua          //
//  server/gamemode_hooks.lua//
//  shared/misc.lua          //
//  shared/util.lua          //
//  shared/table.lua         //
//  shared/player.lua        //
//  server/player.lua        //
//  shared/messages.lua      //
//  shared/concommand.lua    //
//  server/concommand.lua    //
//  server/util.lua          //
//  shared/sh_ucl.lua        //
//  server/ucl.lua           //
//  server/phys.lua          //
//  server/player_ext.lua    //
//  server/entity_ext.lua    //
// Load Complete!            //
///////////////////////////////
[ULIB] Loading SHARED module: ulx_init.lua
///////////////////////////////
//       ULX Admin Mod       //
///////////////////////////////
// Loading...                //
//  sh_defines.lua           //
//  lib.lua                  //
//  base.lua                 //
//  log.lua                  //
//  MODULE: chat.lua         //
//  MODULE: fun.lua          //
//  MODULE: menus.lua        //
//  MODULE: rcon.lua         //
//  MODULE: slots.lua        //
//  MODULE: teleport.lua     //
//  MODULE: toolmode.lua     //
//  MODULE: user.lua         //
//  MODULE: util.lua         //
//  MODULE: vote.lua         //
//  MODULE: votemap.lua      //
//  MODULE: Umotd_helper.lua //
//  MODULE: userhelp.lua     //
//  end.lua                  //
// Load Complete!            //
///////////////////////////////
[ULIB] Loading SHARED module: umotd_init.lua
///////////////////////////////
//    Ulysses MOTD Revived   //
//        Version 2.A6       //
///////////////////////////////
// Umotd Loaded. Thanks!     //
///////////////////////////////

Code: [Select]
if SERVER then
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
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
Msg("Rule already exists \n")
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 = table.concat(RuleB)
if tonumber(RuleN) < table.Count(RulesT.rules)+1 && tonumber(RuleN) > 1 then
table.remove( RulesT.rules, (tonumber(RuleN)+1) )
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
Msg("Couldn't find the rule # mentioned \n")
end
else

end
else
Msg("Can't run from console \n")
end
end
concommand.Add( "RemoveRule", RemoveRule )
else
Msg("Not Server, Ending Script")
end

Is there a way to make it so that my script doesn't run until after ULib has been loaded?
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #95 on: May 10, 2008, 09:02:55 pm »
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.
« Last Edit: May 10, 2008, 09:04:59 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #96 on: May 11, 2008, 12:22:22 am »
I got it all worked out. Here's the script. Btw I used it in addon format :D

Code: [Select]
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

==EDIT==
With the help of Megiddo
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #97 on: May 14, 2008, 05:21:17 pm »
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: [Select]
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)
« Last Edit: May 14, 2008, 06:22:47 pm by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #98 on: May 18, 2008, 06:22:05 am »
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: [Select]
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)
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Admin sounds, tools and other code chat.
« Reply #99 on: May 18, 2008, 09:18:13 am »
First off, indent your code properly. It makes it much easier to understand what's going on. You should indent at the start of every new block, and dedent when you end that block.
Code: Lua
  1. Msg("////////////////////\n")
  2. Msg("//  Module:AFK    //\n")
  3. Msg("////////////////////\n")
  4. function ajoin_afk()
  5.         for _,ply in pairs(player.GetAll()) do
  6.                 function afk()
  7.                         old_time = 1
  8.                         if ply:IsValid() then
  9.                                 view_old = ply:EyeAngles( )
  10.                                 old_time = tonumber(CurTime())
  11.                                 Msg(view_old)
  12.                         end
  13.                 end
  14.                 function afk_check()
  15.                         if tonumber(CurTime()) > (CurTime() + 10) then
  16.                                 if view_old == ply:EyeAngles() then
  17.                                         ply:Nick()_afk_status = "AFK"
  18.                                         Msg("AFK SET")
  19.                                 else
  20.                                         ply:Nick()_afk_status = "ACTIVE"
  21.                                         Msg("Active Set")
  22.                                 end
  23.                         end
  24.                         if ply:Nick().."afk_status" == "AFK" then
  25.                                 Msg("AFK")
  26.                                 game.ConsoleCommand("say Player " ..ply:Nick().. " Is AFK \n")
  27.                         end
  28.                 end
  29.         end
  30. end
  31. hook.Add("Think", "Afk_Check", afk_check)

Lets look at it line by line shall we?
Code: Lua
  1. Msg("////////////////////\n") --\
  2. Msg("//  Module:AFK    //\n") -- | Prints out a message saying we're loading the module. No problems here.
  3. Msg("////////////////////\n") --/
  4. function ajoin_afk() -- Defunes a new function ajoin_afk(). Matching end on line 30. Warning: This function is never called.
  5.         for _,ply in pairs(player.GetAll()) do -- Loop through all players. Matching end on line 29.
  6.                 function afk() -- Defines a new GLOBAL function afk(). Matching end on line 13. Warning: Function is overwritten on each iteration of loop. Warning: Function is never called.
  7.                         old_time = 1 -- Sets GLOBAL old_time to be 1. Warning: This variable is never read.
  8.                         if ply:IsValid() then -- Matching end on line 12.
  9.                                 view_old = ply:EyeAngles( ) -- Sets GLOBAL view_old to the player's current view angle.
  10.                                 old_time = tonumber(CurTime()) -- Sets GLOBAL old_time to the Current Time. Warning: Useless call of tonumber on a number.
  11.                                 Msg(view_old) -- Prints out value of view_old.
  12.                         end -- end if ply:IsValid() then
  13.                 end -- end function afk()
  14.                 function afk_check() -- Defines a new GLOBAL function afk_check(). Matching end on line 28. Warning: Function in overwritten on each iteration of loop.
  15.                         if tonumber(CurTime()) > (CurTime() + 10) then -- Warning: Useless call of tonumber on a number. Warning: Will never be true.
  16.                                 if view_old == ply:EyeAngles() then  -- Matching else on line 19. Warning: view_old is not defined.
  17.                                         ply:Nick()_afk_status = "AFK" -- Error: Invalid syntax.
  18.                                         Msg("AFK SET") -- Prints "AFK SET"
  19.                                 else -- Matching end on line 22.
  20.                                         ply:Nick()_afk_status = "ACTIVE" -- Error: Invalid syntax.
  21.                                         Msg("Active Set") -- Prints "Active Set"
  22.                                 end -- end else of if view_old == ply:EyeAngles() then
  23.                         end -- end if tonumber(CurTime()) > (CurTime() + 10) then
  24.                         if ply:Nick().."afk_status" == "AFK" then -- If ply:Nick() concatenated with "afk_status" == "AFK". (ie. "bob" .. "afk_status" => "bobafk_status" == "AFK"). Matching end on line 27. Warning: Will never be true.
  25.                                 Msg("AFK") -- Prints "AFK"
  26.                                 game.ConsoleCommand("say Player " ..ply:Nick().. " Is AFK \n") -- Console: Player bob Is AFK
  27.                         end -- end if ply:Nick().."afk_status" == "AFK" then
  28.                 end -- end function afk_check()
  29.         end -- end for _,ply in pairs(player.GetAll()) do
  30. end -- end function ajoin_afk()
  31. hook.Add("Think", "Afk_Check", afk_check) -- Error: afk_check is not defined.

If you need more explination on any specific ask.

If you want to store data on the player themselves you can do so by accessing the player directly, treating it like a table.
Code: Lua
  1. ply.afk_status = true
  2. if ply.afk_status then
  3.     --do something here
  4. end
I also recommend using a boolean (true or false) to store the player's afk status. Takes less memory, and you don't have to compare it to anything to use it in an if statement.
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #100 on: May 18, 2008, 09:48:37 am »
Code: Lua
  1. Msg("////////////////////\n")
  2. Msg("//  Module:AFK    //\n")
  3. Msg("////////////////////\n")
  4. afk_time = 10
  5. function ajoin_afk()
  6.         for _,ply in pairs(player.GetAll()) do
  7.                 function afk()
  8.                         old_time = 1
  9.                         if ply:IsValid() then
  10.                                 view_old = ply:EyeAngles( )
  11.                                 ply.old_time = CurTime()
  12.                                 Msg(view_old)
  13.                         end
  14.                 end
  15.                 function afk_check()
  16.                         if CurTime() > (ply.old_time + afk_time) then --Never True
  17.                                 if view_old == ply:EyeAngles() then
  18.                                         ply.afk_status = true
  19.                                         Msg("AFK SET")
  20.                                 else
  21.                                         ply.afk_status = false
  22.                                         Msg("Active Set")
  23.                                 end
  24.                         end
  25.                         if ply.afk_status then
  26.                                 Msg("AFK")
  27.                                 game.ConsoleCommand("say Player " ..ply:Nick().. " Is AFK \n")
  28.                         end
  29.                 end
  30.         end
  31. end
  32. hook.Add("Think", "Afk_Check", ajoin_afk)

I made the changes you suggested, now I see the new problem. I need to set ply.old_time only if they aren't moving, because now it's setting ply.old_time every frame so Curtime() is never greater than ply.old_time + 10.
« Last Edit: May 18, 2008, 09:52:27 am by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #101 on: May 18, 2008, 10:58:36 am »
Ok, I think I took care of the ply.old_time problem.

Code: Lua
  1. Msg("////////////////////\n")
  2. Msg("//  Module:AFK    //\n")
  3. Msg("////////////////////\n")
  4. afk_time = 10
  5. function ajoin_afk(ply)
  6.                 function afk()
  7.                         if ply:IsValid() then
  8.                                 view_old = ply:EyeAngles( )
  9.                                 ply.old_time = CurTime()
  10.                                 Msg(ply.view_old)
  11.                         end
  12.                 end
  13.                 function afk_check()
  14.                         if CurTime() > (ply.old_time + afk_time) then
  15.                                 if view_old == ply:EyeAngles() then
  16.                                         ply.afk_status = true
  17.                                         Msg("AFK SET")
  18.                                 else
  19.                                         ply.afk_status = false
  20.                                         Msg("Active Set")
  21.                                 end
  22.                         end
  23.                                 if ply.afk_status then
  24.                                         Msg("AFK")
  25.                                         game.ConsoleCommand("say Player " ..ply:Nick().. " Is AFK \n")
  26.                                 end
  27.                 end
  28. end
  29. hook.Add("Think", "AFK_Check", afk_check)
  30. hook.Add("PlayerSpawn", "Ajoin_AFK", ajoin_afk)

==EDIT==
Faild, none of the messages are being printed.
« Last Edit: May 18, 2008, 11:11:11 am by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: Admin sounds, tools and other code chat.
« Reply #102 on: May 18, 2008, 04:36:10 pm »
Then start doing something easier.

Code: Lua
  1. function ajoin_afk(ply)
  2.  
  3.         Msg("function ajoin_afk(" .. tostring(ply) .. ") was called\n")
  4.  
  5.         function afk()
  6.                 Msg("function afk() was called\n")
  7.         end
  8.  
  9.         function afk_check()
  10.                 Msg("function afk_check() was called\n")
  11.         end
  12.  
  13. end
  14.  
  15. hook.Add("Think", "AFK_Check", afk_check)
  16. hook.Add("PlayerSpawn", "Ajoin_AFK", ajoin_afk)

If this doesn't print anything, search why and try things. For example, moving the function afk_check() outside of function ajoin_afk(ply) .

Just a question: do you look the console for Lua error/warning messages?
« Last Edit: May 18, 2008, 04:44:00 pm by Kyzer »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #103 on: May 18, 2008, 04:44:12 pm »
His main problem from what I've seen the past few posts, and spbogie even comments on it in his assist attempt, is that he's creating two functions every think frame, which get overwritten except for the last player in GetAll(), and still yet those functions are never called by any other block. (Unless we're just seeing the think statement)

Code: [Select]
hook.Add("Think", "AFK_Check", afk_check)

That line will bomb on server startup, because Think attempts to run at server startup, or client connect if it's running on client.
The hook would get removed, because afk_check hasn't yet been created (and, even if it had, in it's current configuration, would only have one player, the last one of the loop.

[edit] - Also, why cycle through every player when one joins... though in theory you could have a think statement cycle through all players, having it cycle through all each player join would most likely reset 'afk' players.

I see where you're wanting to go with this, but you have a bit to travel.
All being said and done, besides a learning experience, you know that MrPresident has a nice AntiAFK script in our releases section, right? (Just trying to help prevent re-inventing the wheel, if you didn't know)
« Last Edit: May 18, 2008, 05:06:26 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #104 on: May 18, 2008, 07:11:52 pm »
I see what your are all saying, and yes I know MrPresident has an antiAFk module. This is for a learning experience, and I would like to work on vgui's after getting afk_status checks working.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

  • Print