ID:1634189
 
Adapted from the "Are You Sure?" library by Lummox JR. It is available here: http://www.byond.com/developer/LummoxJR/AreYouSure?tab=index

The intention is to provide the functionality provided in that library, and more. Not really big, though, so I don't think it needs its own library.

/client

var/timed_alert/timed_alert

proc/timed_alert(question, title, default, time = 300, choice1, choice2, choice3)

if(timed_alert) del(timed_alert)
var/timed_alert/ref_alert = new
timed_alert = ref_alert

var/ref_result

ref_result = ref_alert.timed_alert(src, question, title, time, choice1, choice2, choice3)
if (!ref_result) ref_result = default

if (ref_alert) del(ref_alert)

return ref_result

/timed_alert

proc/timed_alert(client/ref_client, question, title, time, choice1, choice2, choice3)
if (!ref_client) return
spawn (time) del src

var/ref_answer
ref_answer = alert(ref_client, question, title, choice1, choice2, choice3)

if(!ref_client || !ref_answer) return
else return ref_answer


Example:

/mob
verb/delete_save()
var/delete = timed_alert("Do you really want to delete it?", "Deleting Save", "No", 100, "Yes", "No")
if (delete == "Yes")
remove_player_save()

else
src << "Lucky you."


If you'd like to make this a proc for mobs, too-- So that it may be used like the regular alert, you can add in this quick snippet:

/mob
proc/timed_alert(question, title, default, time, choice1, choice2, choice3)

if (client) client.timed_alert(question, title, default, time, choice1, choice2, choice3)
return


By adding the above to the code, you are capable of using timed alerts. Specifically, a procedure based on the alert() proc which has a default answer and a timer-- If the timer elapses, then the alert closes of its own accord and the default is returned to the person who was using the alert.

This may have issues, because it has not been extensively tested in a large number of instances, but from the tests performed it hasn't failed.

Any recommendations, improvements, suggestions, requests, and critiques are completely welcome.

I'd like to add that one can replicate a fair bit of the function of the provided snippet by using built in procs.

var/reference
reference = spawn (0) alert(usr, question, title, choice1, choice2, choice3)
sleep (wait_time)

if (reference == null)
do default thing


However, that does not cause the window to close automatically, and will cause it to wait the amount before doing anything. If you don't need the auto-window-closing function, and you don't need an immediate result, you could use the method shown here instead.