Author Topic: AFK Manager  (Read 9876 times)

0 Members and 1 Guest are viewing this topic.

Offline Terminal58

  • Newbie
  • *
  • Posts: 41
  • Karma: 1
AFK Manager
« on: November 02, 2006, 03:14:36 PM »
Code: [Select]
maxafktime = 45
maxafkkicktime = 300
ulib = 1
--Also you can't get kicked if it is listen server and your host.
--Originally for SAM

--SAM REDO STARTED
t58 = {}

if ulib == 1 then
assert( _file.Exists( "lua/ULib/init.lua" ), "Optional Ulib support needs Ulib *duh*" )
_OpenScript( "ULib/init.lua" )
assert( ULib.VERSION >= 1, "AFK Mod requires 1.0 +" )
local ucl = ULib.mainUcl
end

function t58.createSVar( svarname , var )
t58[svarname] = {}
t58[svarname].var = var
end

function t58.svar( svarname )
local svartemp = t58[svarname].var
return svartemp
end

--SAM REDO ENDED

t58.createSVar( "maxafktime" , maxafktime ); --Svars measured in seconds
t58.createSVar( "maxafkkicktime" , maxafkkicktime ); --5 Minutes

afkon = true

afk = {}

for i=1, _MaxPlayers() do
afk[i] = {};
afk[i].time = 0
afk[i].active = 0
afk[i].run = 0 --Made for my rule display, feel free to use it in any of yours
end

--Thanks to foszor!
--http://gmod.foszor.com/luabin/?snip=2

nextthink = _CurTime();

function afkthinktimer()
if ( _CurTime() < nextthink ) then return; end
nextthink = nextthink + 1; --Don't get the guys FPS involved
afk.tick()
end

AddThinkFunction( afkthinktimer );

function afk.tick()
for i=1, _MaxPlayers() do
afk[i].time = afk[i].time + 1
if afk[i].time == t58.svar("maxafktime") then -- It equals it
afk[i].active = 1 --3rd Party mod support. Read it I'm nice lol make sure to do a nil check to make sure the script is on.
afk.initgui(i) -- No more flashy screen
afk.gui(i) --They need that one secound.
elseif afk[i].time >= t58.svar("maxafktime") then -- What will most likely happen
afk.gui(i) -- Call de GUI!
if afk[i].time >= t58.svar("maxafkkicktime") then --Eeek hes gonna get kicked!
afk.kick(i) -- WHY JUDGE WHY!
end end end end


function afk.kick(Client)
if ulib == 0 then
if ( not _IsDedicatedServer() ) then
 if Client >= 1 then
_ServerCommand("kickid ".._PlayerInfo(Client,"networkid").."\n")
end
if ulib == 1 then
  if ULib.mainUcl:query(Client, ACCESS_IMMUNITY) == false then
_ServerCommand("kickid ".._PlayerInfo(Client,"networkid").."\n")
end end end end end

function afk.initgui(Client)
   _GModRect_Start("gmod/white")
   _GModRect_SetPos(0, 0, 1, 1)
   _GModRect_SetColor(52, 52, 52, 200)
   _GModRect_SetTime(99999, 0, 0)
   _GModRect_Send(Client,1005)
end

function afk.gui(Client)
   _GModText_Start("ImpactMassive")
   _GModText_SetPos(0.40 , 0.45)
   _GModText_SetColor(000, 180, 255, 255)
   _GModText_SetTime(99999, 0, 0)
   _GModText_SetText("You have been afk for "..afk[Client].time.." seconds.")
   _GModText_AllowOffscreen( false );
   _GModText_Send(Client,1004)
   
erg = t58.svar( maxafkkicktime ) - afk[Client].time
   
_GModText_Start("TargetID");
_GModText_SetEntityOffset(vector3(0,0,50))
_GModText_SetEntity(Client)
_GModText_SetColor(000, 180, 255, 255)
_GModText_SetTime(99999,1,1);
_GModText_SetText("AFK/nKick in:/n"..erg.."");
_GModText_Send(0, 1006+Client);
end

function afk.zip(Client)
afk[Client].time = 0
if afk[Client].active == 1 then
afk[Client].active = 0
_GModRect_Hide(Client,1005,1,0);
_GModText_Hide(Client,1004);
_GModText_Hide(Client,1006+Client);
end end

HookEvent("eventKeyPressed",afk.zip)

Originally made for SAM so it has SAM in the back.



Or save as
http://www.l-games.com/released/afkmod.lua
If you did the download line 3 edit it to 1.

Ulib support barely tested.
« Last Edit: November 04, 2006, 01:41:07 PM by Terminal58 »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: AFK Manager
« Reply #1 on: November 02, 2006, 03:26:26 PM »
I can tell just by looking at it that it's not going to work right. You called ucl:query(), you need to call an instantiation of ucl, not ucl itself. (IE, ULib.mainUcl:query())

I was just thinking the other day that something like this might be useful in ULX, though. :)
Experiencing God's grace one day at a time.

Offline Terminal58

  • Newbie
  • *
  • Posts: 41
  • Karma: 1
Re: AFK Manager
« Reply #2 on: November 02, 2006, 03:42:45 PM »
Fixed it I think also fixed variables.

Erg fixed it again if theres another issue watch this post.

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: AFK Manager
« Reply #3 on: November 02, 2006, 06:00:09 PM »
You still did not fix the ucl problem that megiddo stated above.
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 Terminal58

  • Newbie
  • *
  • Posts: 41
  • Karma: 1
Re: AFK Manager
« Reply #4 on: November 02, 2006, 08:46:00 PM »
Code: [Select]
maxafktime = 45
maxafkkicktime = 300
ulib = 0
--Also you can't get kicked if it is listen server and your host.
--Originally for SAM

--SAM REDO STARTED
t58 = {}

if ulib == 1 then
assert( _file.Exists( "lua/ULib/init.lua" ), "Optional Ulib support needs Ulib *duh*" )
_OpenScript( "ULib/init.lua" )
assert( ULib.VERSION >= 1, "AFK Mod requires 1.0 +" )
local ucl = ULib.mainUcl
end

function t58.createSVar( svarname , var )
t58[svarname] = {}
t58[svarname].var = var
end

function t58.svar( svarname )
local svartemp = t58[svarname].var
return svartemp
end

--SAM REDO ENDED

t58.createSVar( "maxafktime" , maxafktime ); --Svars measured in seconds
t58.createSVar( "maxafkkicktime" , maxafkkicktime ); --5 Minutes

afkon = true

afk = {}

for i=1, _MaxPlayers() do
afk[i] = {};
afk[i].time = 0
afk[i].active = 0
afk[i].run = 0 --Made for my rule display, feel free to use it in any of yours
end

--Thanks to foszor!
--http://gmod.foszor.com/luabin/?snip=2

nextthink = 0;

function afkthinktimer()
if ( _CurTime() < nextthink ) then return; end
nextthink = nextthink + 1; --Don't get the guys FPS involved
afk.tick()
end

AddThinkFunction( afkthinktimer );

function afk.tick()
for i=1, _MaxPlayers() do
afk[i].time = afk[i].time +1
if afk[i].time == t58.svar("maxafktime") then -- It equals it
afk[i].active = 1 --3rd Party mod support. Read it I'm nice lol make sure to do a nil check to make sure the script is on.
afk.initgui(i) -- No more flashy screen
afk.gui(i) --They need that one secound.
elseif afk[i].time >= t58.svar("maxafktime") then -- What will most likely happen
afk.gui(i) -- Call de GUI!
if afk[i].time >= t58.svar("maxafkkicktime") then --Eeek hes gonna get kicked!
afk.kick(i) -- WHY JUDGE WHY!
end end end end


function afk.kick(Client)
if ulib == 0 then
if ( not _IsDedicatedServer() ) then
 if Client >= 1 then
_ServerCommand("kickid ".._PlayerInfo(Client,"networkid").."\n")
end
if ulib == 1 then
  if ucl:query( Client, ACCESS_IMMUNITY ) == false then
_ServerCommand("kickid ".._PlayerInfo(Client,"networkid").."\n")
end
end
end
end
end

function afk.initgui(Client)
   _GModRect_Start("gmod/white")
   _GModRect_SetPos(0, 0, 1, 1)
   _GModRect_SetColor(52, 52, 52, 200)
   _GModRect_SetTime(99999, 0, 0)
   _GModRect_Send(Client,1005)
   
_GModText_Start("TargetID");
_GModText_SetEntityOffset(vector3(0,0,50))
_GModText_SetEntity(Client)
_GModText_SetColor(000, 180, 255, 255)
_GModText_SetTime(99999,1,1);
_GModText_SetText("AFK");
_GModText_Send(0, 1006+Client);
end

function afk.gui(Client)
   _GModText_Start("ImpactMassive")
   _GModText_SetPos(0.40 , 0.45)
   _GModText_SetColor(000, 180, 255, 255)
   _GModText_SetTime(99999, 0, 0)
   _GModText_SetText("You have been afk for "..afk[Client].time.." seconds.")
   _GModText_AllowOffscreen( false );
   _GModText_Send(Client,1004)
end

function afk.zip(Client)
afk[Client].time = 0
if afk[Client].active == 1 then
afk[Client].active = 0
_GModRect_Hide(Client,1005,1,0);
_GModText_Hide(Client,1004);
_GModText_Hide(Client,1006+Client);
end
end

HookEvent("eventKeyPressed",afk.zip)
I can't find anything on Main UCL in the file besides
ULib.mainUcl = ULib.ucl:newFromFile( ULib.DEFAULT_UCL_FILE )
« Last Edit: November 02, 2006, 08:50:59 PM by Terminal58 »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: AFK Manager
« Reply #5 on: November 02, 2006, 09:36:04 PM »
From http://ulyssesmod.net/docs/files/ucl_public-lua.html :

Quote
mainUcl

    ULib.mainUcl

This holds the default user access list, from the file “lua/ULib/users.ini”
Experiencing God's grace one day at a time.

Offline Terminal58

  • Newbie
  • *
  • Posts: 41
  • Karma: 1
Re: AFK Manager
« Reply #6 on: November 04, 2006, 12:50:26 PM »
Code: [Select]
maxafktime = 45
maxafkkicktime = 300
ulib = 1
--Also you can't get kicked if it is listen server and your host.
--Originally for SAM

--SAM REDO STARTED
t58 = {}

if ulib == 1 then
assert( _file.Exists( "lua/ULib/init.lua" ), "Optional Ulib support needs Ulib *duh*" )
_OpenScript( "ULib/init.lua" )
assert( ULib.VERSION >= 1, "AFK Mod requires 1.0 +" )
local ucl = ULib.mainUcl
end

function t58.createSVar( svarname , var )
t58[svarname] = {}
t58[svarname].var = var
end

function t58.svar( svarname )
local svartemp = t58[svarname].var
return svartemp
end

--SAM REDO ENDED

t58.createSVar( "maxafktime" , maxafktime ); --Svars measured in seconds
t58.createSVar( "maxafkkicktime" , maxafkkicktime ); --5 Minutes

afkon = true

afk = {}

for i=1, _MaxPlayers() do
afk[i] = {};
afk[i].time = 0
afk[i].active = 0
afk[i].run = 0 --Made for my rule display, feel free to use it in any of yours
end

--Thanks to foszor!
--http://gmod.foszor.com/luabin/?snip=2

nextthink = _CurTime();

function afkthinktimer()
if ( _CurTime() < nextthink ) then return; end
nextthink = nextthink + 1; --Don't get the guys FPS involved
afk.tick()
end

AddThinkFunction( afkthinktimer );

function afk.tick()
for i=1, _MaxPlayers() do
afk[i].time = afk[i].time + 1
if afk[i].time == t58.svar("maxafktime") then -- It equals it
afk[i].active = 1 --3rd Party mod support. Read it I'm nice lol make sure to do a nil check to make sure the script is on.
afk.initgui(i) -- No more flashy screen
afk.gui(i) --They need that one secound.
elseif afk[i].time >= t58.svar("maxafktime") then -- What will most likely happen
afk.gui(i) -- Call de GUI!
if afk[i].time >= t58.svar("maxafkkicktime") then --Eeek hes gonna get kicked!
afk.kick(i) -- WHY JUDGE WHY!
end end end end


function afk.kick(Client)
if ulib == 0 then
if ( not _IsDedicatedServer() ) then
 if Client >= 1 then
_ServerCommand("kickid ".._PlayerInfo(Client,"networkid").."\n")
end
if ulib == 1 then
  if ULib.mainUcl:query(Client, ACCESS_IMMUNITY) == false then
_ServerCommand("kickid ".._PlayerInfo(Client,"networkid").."\n")
end end end end end

function afk.initgui(Client)
   _GModRect_Start("gmod/white")
   _GModRect_SetPos(0, 0, 1, 1)
   _GModRect_SetColor(52, 52, 52, 200)
   _GModRect_SetTime(99999, 0, 0)
   _GModRect_Send(Client,1005)
end

function afk.gui(Client)
   _GModText_Start("ImpactMassive")
   _GModText_SetPos(0.40 , 0.45)
   _GModText_SetColor(000, 180, 255, 255)
   _GModText_SetTime(99999, 0, 0)
   _GModText_SetText("You have been afk for "..afk[Client].time.." seconds.")
   _GModText_AllowOffscreen( false );
   _GModText_Send(Client,1004)
   
erg = t58.svar( maxafkkicktime ) - afk[Client].time
   
_GModText_Start("TargetID");
_GModText_SetEntityOffset(vector3(0,0,50))
_GModText_SetEntity(Client)
_GModText_SetColor(000, 180, 255, 255)
_GModText_SetTime(99999,1,1);
_GModText_SetText("AFK/nKick in:/n"..erg.."");
_GModText_Send(0, 1006+Client);
end

function afk.zip(Client)
afk[Client].time = 0
if afk[Client].active == 1 then
afk[Client].active = 0
_GModRect_Hide(Client,1005,1,0);
_GModText_Hide(Client,1004);
_GModText_Hide(Client,1006+Client);
end end

HookEvent("eventKeyPressed",afk.zip)
1.03