ID:1596035
 
Keywords: afk, afkcheck, help, pick, pickproc
(See the best response by TheDracheX1.)
Code:
proc
AutoCheck()
set background=1
sleep(pick(18000,24000,27000,30000,36000))//sleep a random amount of time so players can't predict when the next check is
for(var/mob/M in world)
M.AFK=1
usr.colour=pick("Red","Green","Blue")
if(usr.colour = "Red")
usr << "Please Press The Red Button In the Next 30 Seconds, Or You Will Be Booted!"
if(usr.colour = "Blue")
usr << "Please Press The Blue Button In the Next 30 Seconds, Or You Will Be Booted!"
if(usr.colour = "Green")
usr << "Please Press The Green Button In the Next 30 Seconds, Or You Will Be Booted!"
sleep(300)
for(var/mob/M in world)
if(M.AFK)
world<< "<b>[M] was booted!"
del(M)

mob
var
colour = ""

mob
verb
.PressRed()
if(usr.colour == "Red")
usr << "Thank You For Choosing the Right Color!"
usr << "Here Is A Reward For Not Being AFK!"
usr.exp += usr.level*25
usr.AFK = 0
else
usr.AFK = 1
usr << "You Have Picked the Wrong Color! You Will Now Be Booted! :)"
for(var/mob/M in world)
if(M.AFK)
world<< "<b>[M] was booted!"
del(M)
mob
verb
.PressBlue()
if(usr.colour == "Blue")
usr << "Thank You For Choosing the Right Color!"
usr << "Here Is A Reward For Not Being AFK!"
usr.exp += usr.level*25
usr.AFK = 0
else
usr.AFK = 1
usr << "You Have Picked the Wrong Color! You Will Now Be Booted! :)"
for(var/mob/M in world)
if(M.AFK)
world<< "<b>[M] was booted!"
del(M)
mob
verb
.PressGreen()
if(usr.colour == "Green")
usr << "Thank You For Choosing the Right Color!"
usr << "Here Is A Reward For Not Being AFK!"
usr.exp += usr.level*25
usr.AFK = 0
else
usr.AFK = 1
for(var/mob/M in world)
if(M.AFK)
world<< "<b>[M] was booted!"
del(M)


Problem description:
I have been trying to figure this out for about an hour now, and to no avail I have not figured out how to fix this! I get two error messages,
Codes\AFK.dm:66:error: pick: undefined proc
Codes\AFK.dm:67:error: : invalid expression
Any Ideas on how to fix this?

You should probably define the picked number above and outside of the sleep proc.
How would I go about changing that?
Just create a variable to store that value, as seen below.

var/the_picked_number=pick(18000,24000,27000,30000,36000)
sleep(the_picked_number)


I would personally use spawn() but eh, we all are different I guess.
Your system won't function very well with multiple players at all.

If you hit the wrong color before I get to hit the right color I will be booted as well as you.

Please revise your code.
Ok, I should have stated this but, the problem is not with the sleep part, the problem is with picking the Color. My fault for not stating that
Try removing the "." in all those verbs.
Oh nevermind rofl, I see what you mean
Your code is like this:

proc
AutoCheck()
set background=1
sleep(pick(18000,24000,27000,30000,36000))//sleep a random amount of time so players can't predict when the next check is
for(var/mob/M in world)
M.AFK=1
usr.colour=pick("Red","Green","Blue")
if(usr.colour = "Red")
usr << "Please Press The Red Button In the Next 30 Seconds, Or You Will Be Booted!"
if(usr.colour = "Blue")
usr << "Please Press The Blue Button In the Next 30 Seconds, Or You Will Be Booted!"
if(usr.colour = "Green")
usr << "Please Press The Green Button In the Next 30 Seconds, Or You Will Be Booted!"
sleep(300)
for(var/mob/M in world)
if(M.AFK)
world<< "<b>[M] was booted!"
del(M)


when it should be like this

proc
AutoCheck()
set background=1
sleep(pick(18000,24000,27000,30000,36000))//sleep a random amount of time so players can't predict when the next check is
for(var/mob/M in world)
M.AFK=1
usr.colour=pick("Red","Green","Blue")
if(usr) //i put this here because I didn't want to unspace all your spaces. Please use tabs, it's more convenient for me.
if(usr.colour = "Red")
usr << "Please Press The Red Button In the Next 30 Seconds, Or You Will Be Booted!"
if(usr.colour = "Blue")
usr << "Please Press The Blue Button In the Next 30 Seconds, Or You Will Be Booted!"
if(usr.colour = "Green")
usr << "Please Press The Green Button In the Next 30 Seconds, Or You Will Be Booted!"
sleep(300)
for(var/mob/M in world)
if(M.AFK)
world<< "<b>[M] was booted!"
del(M)
Awesome lol, now I don't have problems with the picking of the colors, but now I have 3 errors for the if statements for the color
yeah, when using statements, the expression for "=" is actually "=="

So rather than using

if(usr.colour = "Red")


Use

if(usr.colour == "Red")
Although those if statements are pointless, I would just do this:

        if(usr) //i put this here because I didn't want to unspace all your spaces.  Please use tabs, it's more convenient for me.
usr << "Please Press The [usr.colour] Button In the Next 30 Seconds, Or You Will Be Booted!"
sleep(300)
for(var/mob/M in world)
if(M.AFK)
world<< "<b>[M] was booted!"
del(M)
Oh! Thanks lol, I was over complicating it
Just remember, there are various ways to get the same results, always ask yourself which is the quickest and most efficient.

Best of luck.
Best response
BYOND actually has a 'inactivity' variable in the client. http://www.byond.com/docs/ref/info.html#/client/var/ inactivity

So you could create a controller which goes through the clients and if they are over a certain treshhold, it kicks them, and even warn them maybe a minute before they get kicked.
#define AFK_TRESHHOLD 6000 //10 minutes
/datum/afk_kicker
proc/process()
set background = 1
sleep(600) //loop every minute
for(var/client/C in world)
if(C.inactivity >= AFK_TRESHHOLD)
del(C)
else if(C.inactivity + 600 >= AFK_TRESHHOLD)
alert(C.mob, "You will be kicked in one minute.", "Alert")


Or something similar to that.
Here is SS13's code for an AFK kicker, it works fine, I use it too to preserve bandwidth and whatnot;

#define INACTIVITY_KICK 9000    //15 minutes in ticks (approx.)
/world/proc/KickInactiveClients()
spawn(-1)
while(1)
sleep(INACTIVITY_KICK)
for(var/client/C in clients)
if(C.is_afk(INACTIVITY_KICK))
if(!istype(C.mob, /mob/dead))
if(!C in admins && !is_donator(C))
log_access("AFK: [key_name(C)]")
C << "\red You have been inactive for more than 15 minutes and have been disconnected."
del(C)
#undef INACTIVITY_KICK


Does need slight indentation fixes, though.