ID:148374
 
I'm trying to set up an anti-macro code to stop people from training while they are afk. Here is the code I have edited from deadron's close alert boxes:

proc
Train(mob/M)
if(usr.train >= 1000)
usr.train = 0
var/customalert/v = new
sleep(100)
if(usr.stop == 1)
usr <<"Phew, that was close"
else
del v
del(usr)

customalert
New()
spawn() switch(input("To stop from being auto-booted click ok.", "Macro Protection") in list ("Ok"))
if("Ok")
usr.stop = 1


Well, the switch doesn't seem to spawn, but I want some way of telling if they clicked ok or not on the alert. I think there's a way to do it, but I'm not sure how. I tried to use the break proc, but I couldn't figure out how to place it so that I wouldn't get errors lol. If anyone can help me it would be greatly appreciated. :)
No put usr in procs. Ungh.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
No put usr in procs. Ungh.

Lummox JR

uhh sorry, but is that don't put usr in procs?
In response to Jnco904
Jnco904 wrote:
Lummox JR wrote:
No put usr in procs. Ungh.

uhh sorry, but is that don't put usr in procs?

Me use caveman voice so no have to scream at everyone who makes same obvious mistake. Ungh.

Lummox JR
In response to Lummox JR
oh :)


Well, I changed them, but it still doesn't work. Any ideas?
In response to Jnco904
input() assumes usr is the mob to ask, unless you tell it otherwise, so you are still a victim of UsrIsEvil. Make customalert.New() take an argument telling it which mob to query for input.

Also, input() automatically chooses if there is only one choice, so you never see the input pop up as things stand. Change it to an alert(), or give it extra options in the list. I'd give it an extra option, because of my next point.

External macro programs can still be ued to macro with this set up. It triggers the command, passes a moment, then simulates the user pressing the enter key to accept "Ok". You could further prevent macros by making a small list of options and shuffling them before the input, so that the macro program be able to make the correct selection every time.

One more problem, the if() statement may never be true because I don't see anything increasing your train variable.

These changes should help:
proc
Train(mob/M)
train++
if(M.train >= 1000)
M.train = 0
var/customalert/v = new(M)
sleep(100)
if(M.stop == 1)
M <<"Phew, that was close"
else
del v
del(M)

customalert
New(mob/M)
..()
spawn()
var/list/L = list(" Ok", " No, I'm macroing.")

// one random change
var/shuffle = pick(L)
L -= shuffle // remove it from the list
L += shuffle // add it to the end of the list

for(var/x in L)
world << x

switch(input(M,"To stop from being auto-booted click ok.", "Macro Protection") in L)
if(" Ok")
M.stop = 1

Note that the choices both have a leading space. If they didn't, an external macro program could just hit "O" to move to "Ok", then enter to accept the choice.
In response to Shadowdarke
Wow, Thanks. :) All of my training obj/verbs add to the train var.:)


{edit}
Just so you know, it works great now. :)