Shutdown

For everything NOT server specific support. Do NOT ask for connectivity help here!.

Moderator: Moderators

Message
Author
setsunaseiei
Human
Human
Posts: 38
Joined: 17 May 2011, 07:09
Noob?: No

Shutdown

#1 Post by setsunaseiei »

Is it possible to shutdown the pc using macro?

Like for instance, I have already completed my hunting items or when I leveled up.

Thank you.
オペンコレ!

EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Shutdown

#2 Post by EternalHarvest »


James1987
Noob
Noob
Posts: 5
Joined: 17 Jan 2013, 08:28
Noob?: No

Re: Shutdown

#3 Post by James1987 »

Before I get yelled at for dredging this from ye old days, I have a very valid reason to do so. This is the first hit that comes up on google when you search for openkore shutdown computer. So I believe this solution should be available here for anyone who wishes to do this.

I will go through the process of modifying the Macro plugin to add a new macro command to shut down a PC. This works on Windows 7. You should be able to modify it yourself to make it work on Linux etc. Read all the steps before you attempt it. Also if your PC blows up then that is not my fault, you do this modification at your own risk.

Step 1: Get the macro plugin if you do not have it already. I am not going to hold your hand with this. You should figure this out, there are plenty of other topics and threads on how to install the macro plugin. (Wiki link to the macro plugin installation is here > http://www.openkore.com/index.php/Macro ... stallation)

Step 2: Get yourself a decent text editing program. "Notepad" is not good enough. Get yourself "Notepad++" (http://notepad-plus-plus.org/)

Step 3: From this point on wards I am going to assume that your macro plugin is working and you already know how to make macros. I am not going to spoon feed you everything.

From the root folder of Openkore: Open the file /plugins/macro/Macro/Script.pm inside Notepad++

Notepad++ will look like a programming interface and show you the basic syntax and structure of perl.

Search (CTRL+F in Notepad++) for this line "sub-routine command" (or you can look for this as well "} elsif ($line =~ /^(?:\w+)\s*\(.*?\)/) {") it will be around lines 490 inside this file. If you look around you will notice that this is near the end of a massive set of "else if" perl statements.

The magic code you need to add directly ABOVE that line is this:

Code: Select all

	##########################################
	# Custom shutdown macro command. Woot woot.
	} elsif ($line =~ /^shutdown/) {	# Regex to match ANY string starting with the word "shutdown". Ie: "shutdown start"
		if ($line =~ /^shutdown\s+start$/) {
			message "[macro log] Shutdown Initiated\n", "macro";
			system('shutdown -s -f -t 180 -c "OpenKore wants to shut down ze PC"');	# Simple, yet effective.
			# -t 180 means that in 180 seconds from when the message pops up, the computer will shut down.
		} else {
			message "[macro log] Shutdown Aborted\n", "macro";
			system('shutdown -a'); # Abort scheduled shutdown.
		}
		$self->{line}++;
		$self->{timeout} = $self->{macro_delay}
		# you can abort a shutdown by quickly running windows command prompt and entering "shutdown /a"
Save and close that file. Just look around and notice how the opening { have a matching closing } if something is wrong in this structure your macro plugin (and probably openkore) will fail to start up.

That's it, you have just added a command called "shutdown" to your macro plugin. This command has one expected input. From the macro code in macros.txt if you do "shutdown start" then it will start the shutdown process. Your computer will shut down in 3 minutes (180 seconds), you can set this time to whatever you want. It will also add another option which would be "shutdown <stop/abort/kill me now/don't do it/plz stop/omfgbbq>" which will stop the shutdown sequence. (I added this extra option just for the sake of it, who knows. Maybe your bot runs across an MVP after it's been scheduled to shut down *shrugs*)

Step 4: Now I will show you some example macro code on how to make this awesome thing work. This is pulled from one of the macros powering one of my accounts. As found in config/macros.txt:

Code: Select all

macro storageDo {
	do c @storage
	pause 1
	do storage add Treasure Box
	do storage add Old Blue Box
	do storage add Old Purple Box
	do storage add Old Violet Box
	pause 1
	if (@storamount(Treasure Box) < 1000) goto one	# If less than 1000 treasure boxes collected then just close the storage and proceed to warping back to dungeon
		shutdown start		# This line only gets processed if the above if statement does not go through, so when there are more than 1000 treasure boxes. Then this will be triggered
		do quit			# This command will make OpenKore log out cleanly in preparation for the computer shutdown.
	stop
	:one
		do storage close
		pause 1
		do c @warp abyss_03
	stop

}

macro stopShutDownPlz {
	shutdown abort		# This will stop any previous shutdown that was scheduled by openkore. Call this macro from any other automacro or macro which detects a reason NOT to shut down the pc. Obviously this will only work if you did not do "do quit" in the block which started the shutdown process.
}
And there we go folks. That's all there is to it. Very simple modification. If you are on another operating system then obviously change the "system()" function in the perl bit of the code to what suits your system. Google is your best friend.

Happy botting.

PS: For those that don't know what's going on, I pasted the entire contents of my Script.pm at this link http://pastebin.com/raw.php?i=SgmwWqyF. You could just open Script.pm in a Text editor and copy paste the whole bit of code from that page and it should work, no 100% guarantee it will work with the SVN version you are running.

For anyone looking at this post months/years in the future, probably not a good idea copy pasting that PasteBin code. It's bound to be outdated by now. Hope you figure out how to add it manually.

Final notes: This is not a very elegant way of disconnecting and shutting down. If you do not do "do quit" after the shutdown process was initiated. Then OpenKore will be END TASKED before the computer shuts down. The ragnarok server will disconnect you from it's end when the sync packets stop being sent back and forth so there is no reason to worry about this too much.

I also believe that by using @eval you are probably able to do the same thing but in a much easier and less convoluted way. But I like making permanent mods in my code so this is what I did.
Last edited by James1987 on 24 Jan 2013, 11:22, edited 1 time in total.

rocknroll
Been there done that!
Been there done that!
Posts: 118
Joined: 19 Sep 2011, 07:30
Noob?: Yes

Re: Shutdown

#4 Post by rocknroll »

nice post :D
the cmd command :D
Sorry, my english is very bad !

James1987
Noob
Noob
Posts: 5
Joined: 17 Jan 2013, 08:28
Noob?: No

Re: Shutdown

#5 Post by James1987 »

Thank you :) hope it becomes useful for some other users. I'm definitely using it!

And yup, it is the CMD command to shutdown windows :) that's what the system() function does :D

Post Reply