ID:160941
 
Here is what my "goal" is.

I want a 'AFK' Check that is constantly updating. So, I decided to use stat() in this case. I've tried (client.inactivity/10) but that is not what Im looking for. For example, a player can stand at one location, continuously use a verb, and make client.inactivity invalid in my case. I need something that focuses on the mob's movement.

To make long story short, here is an example of a code that I did, turned out to be a failure.

if(!src.meditating&&src.loggedin)
var/* = src.loc
sleep(*)
if(src.loc == Zzz)
if(!src.pafk)
src.overlays += 'AFK.dmi'
src.pafk = 1
src<<"<b>I would move if I was you"
if(src.pafk)
src.firing = 1
src.doing = 1


My problem lies within var/* = src.loc I need another method that does the same function. Hope Im clear enough :)
mob/New()
AFKCheck()
..()

mob/proc/AFKCheck()
set background=1
var/loc1=src.loc
spawn(600)
if(loc1==src.loc)
src.AFK=1
//the rest of the stuff here
spawn(10) AFKCheck()

mob/Move()
if(src.AFK)
AFK=0
..()
else ..()


Hope that's simple to understand.
Instead of using Stat(), you should create a loop dedicated to checking if they're afk. Also, why are you trying to use a turf for sleep()'s arg? And why create a var when loc would work perfectly? You should read the DM guide before you go any further.
In response to Jeff8500
Jeff Sorry, I was in a hurry and I typed that out on the top of my head.

When loc would work perfectly? One of us are not understanding each other.

What Im trying to do is, find your previous location, after a certain set of time, check if your previous location matches up with your current location. And then from then on. Im still an amateur, and I'm getting my basics down before I do anything else. I do realize what a loop is. But, I'm not an expert, or not sure how to use it yet.

For example, I can use for() and etc, but I dont know how to apply it to this situation.
In response to Generation
Generation wrote:
What Im trying to do is, find your previous location, after a certain set of time, check if your previous location matches up with your current location. And then from then on.

The answer is located here: [link]
In response to Andre-g1
Andre-g1 wrote:
> mob/New()
> AFKCheck()
> ..()
>
> mob/proc/AFKCheck()
> set background=1
> var/loc1=src.loc
> spawn(600)
> if(loc1==src.loc)
> src.AFK=1
> //the rest of the stuff here
> spawn(10) AFKCheck()
>
> mob/Move()
> if(src.AFK)
> AFK=0
> ..()
> else ..()
>

Hope that's simple to understand.


____________________________________________________________


Good one Andre-g1 but the problem there is even if the mob is already AFK, when it calls again AFKCheck() and the mob still haven't move, it still assigns AFK to 1 or does the code below it.

You can also try this one:

var/AFK_TIME = 100 // put time for afk here, example 100 for 10 sec.

mob
var
AFK = 0

New()
..()
spawn() src.AFK_Check()

proc
AFK_Check()
set background = 1
var/tmpLoc = src.loc
sleep(global.AFK_TIME)
if(src.loc == tmpLoc && !src.AFK)
src.overlays += 'AFK.dmi'
src.AFK = 1
src << "You are now AFKing"
//some code here
spawn(10) src.AFK_Check()

Move()
if(src.AFK)
src.overlays -= 'AFK.dmi'
src.AFK = 0
src << "Thank God You Moved!"
//some code here
..()


So it only makes the mob AFK, if he is still at the same location after global.AFK_TIME (10 sec.) and the mob is not yet AFKing. I hope this helps... :)