ID:270982
 
I am not really sure if there is a way to do it, but how would I go about rewriting Dream Seeker options such as World Reboot?
As a novice programmer in BYOND, I am gonna ask a question which may seem stupid but will help out:

What are you planning to do?



You can make a new procedure or something similar to basically re-route what you want (a work-around basically) or modify Reboot() as how the others stated.


So once again, what do you want done so we can help you.

- GhostAnime
In response to GhostAnime
Basically, overwrite World Reboot. I have seen it done in a few games, but I am not really sure how to begin it myself.
In response to Quest Industries
Quest Industries wrote:
Basically, overwrite World Reboot. I have seen it done in a few games, but I am not really sure how to begin it myself.

I am asking what do you want to "overwrite" it with? Because people are not really overwriting... do you want a countdown?

I am simply asking WHAT you want to ADD/CHANGE the built-in procedure with.

What you replied to me was basically like this:
You: I want a drink.
Myself: Which type of drink? [if you don't get it, I am referring to soft drinks such as 'Cola, Orange, Sprite/7'up]
You: you know, I want a drink.


- GhostAnime
Simply do it as any other function would be done:
world
Reboot()
world << "World is rebooting!"
..() // Do the actual rebooting, without this you can't reboot properly
In response to Nadrew
Yep. You should be able to call the Reboot() with extra arguments and override to make special use of them, like reason and a customized timer time. Example:
world
Reboot(reason as text,secs as num)
if(secs)
if(secs < 3) secs = 3 //no point in 1 or 2 sec timers really, too short
world << "The world will reboot in [secs] seconds! [reason :((reason: [reason])) ? ""]"
while(secs)
sleep(10)
secs--
if(secs && secs < 6) world << "The world will reboot in [secs] seconds!"
for(var/mob/player/P in world)
P.Save() //whatever you use for saving
P << "You've been saved"
world << "<font color=red size=4>The world will now reboot!</font> [reason :((reason: [reason])) ? ""]"
..() //do actual rebooting

Something nice you could do in the time portion, is allow GMs to cancel the reboot (use a global var, and check it). :)
In response to Kaioken
world << "The world will reboot in [secs] seconds! [reason :((reason: [reason])) ? ""]"


You've messed up your syntax there.

world << "The world will reboot in [secs] seconds! [reason?"reason: [reason]":""]"
In response to Nadrew
I believe he wants to 'rewrite' it, such as 'duplicate' that function as an alternate procedure, which, in this case, is impossible.
In response to DivineO'peanut
DivineO'peanut wrote:
I believe he wants to 'rewrite' it, such as 'duplicate' that function as an alternate procedure, which, in this case, is impossible.

Wouldn't something like this work?

proc/Reboot(reason,text_reason) //acts same as reboot, but a reason is provided
var/msg="\red Rebooting world because "
switch(reason)
if(1) msg+="the host pressed the \"Reboot World\" button."
if(2) msg+="a world.Topic() call forced us to."
if(3) msg+="someone sent a SIGUSR1 from UNIX."
else msg+="a piece of coding wanted us to."
if(text_reason) msg+=" Reason: [text_reason]"
world.Reboot(4)

world/Reboot(reason) //reason=4 = called by Reboot() proc
if(reason==4) return ..()
var/text_reason
if(reason==2) //though we can't be sure if the host did this or some person on the shell admin list. sorry.
var/mob/M
for(M in world) if(M.client&&(!M.client.address||M.client.address==world.address||M.client.address=="127.0.0.1") break
if(M)
text_reason=input(M,"Please provide a reason for rebooting.","Reboot World") as null|text
else return
Reboot(reason,text_reason)


Albeit not having the ability to determine who pressed CTRL+R with reason 2, the rest should work.
Quest Industries wrote:
I am not really sure if there is a way to do it, but how would I go about rewriting Dream Seeker options such as World Reboot?

Yes, world/Reboot() allows you to override it. I added an argument to it sometime back that would tell it how it was called, so you could specifically refuse a machine-driven reboot but still allow a user reboot. In Incursion, I tied this into my AreYouSure library so I could ask the host if they wanted to continue.

Lummox JR
In response to Jp
Jp wrote:
world << "The world will reboot in [secs] seconds! [reason :((reason: [reason])) ? ""]"

You've messed up your syntax there.

> world << "The world will reboot in [secs] seconds! [reason?"reason: [reason]":""]"
>


Or better still:
world << "The world will reboot in [secs] second\s![reason && "\n([reason])"]"


In general it's best not to give this warning every second. I'd give it at the 5 minute, 2 minute, 1 minute, 15 second, and 5 second intervals. So even better still:
var/rebootid

world/Reboot(n, reason)
var/id = ++rebootid
var/nexttime
var/saytime
while(secs > 0 && id == rebootid)
saytime=""
if(secs >= 60) saytime = "[round(secs/60)] minute\s"
if(secs % 60) saytime = "[saytime && (saytime+", ")][secs%60] second\s"
// if you warn at 5:01 to 6:00, don't warn again at 5:00 'cause it's redundant
if(secs >= 360) nexttime = 300
else if(secs > 120) nexttime = 120
else if(secs > 60) nexttime = 60
else if(secs > 15) nexttime = 15
else if(secs > 5) nexttime = 5
else nexttime = 0
world << "The server is rebooting in [saytime]![reason && "\n([reason])"]"
sleep((secs - nexttime) * 10)
secs = nexttime
// cancel reboot if ID doen't match
if(id != rebootid) return
..()


To initiate a reboot, just call world.Reboot(0,"because I feel like it") or such. To cancel a reboot, just use ++rebootid and this will stop the current reboot loop in its tracks.

proc/CancelReboot()
++rebootid
world << "The server reboot has been called off."


Lummox JR
In response to Quest Industries
Ah, I see now. Thank you for your help.