Page 1 of 1

Modification: automatic logout after x min playtime

Posted: Mon Jun 22, 2009 12:01 pm
by d003232
Here a modification for automatic logout after x minutes botting.

Insert in bot.lua line 27 after '__RPL = nil; -- Return Point List'

Code: Select all

__RPL = nil; -- Return Point List

hf_bot_start = os.time();	--  start time of the bot
and at the end in bot.lua after line 306

Code: Select all

		end
		
		player:logout_check();	-- automatic logout check   <<< INSTERT THAT LINE
	end
	
end
startMacro(main);
Define your logout-key: Insert in settings.xml after line 10 and change the key="VK_C" to your logout key:

Code: Select all

		<hotkey description="LOGOUT" key="VK_C" modifier="" />
Create a ingame macro 'logout' with following code:

Code: Select all

/script Logout();
.

Assign that macro to your before defined logout key.

Insert the new function 'function CPlayer:logout_check(hf_logout)' in player.lua:

Code: Select all

-- function for automatic logout checking
-- you can also use it with logout_check(true) for logout whitout timer
function CPlayer:logout_check(hf_logout)

	if( settings.profile.options.LOGOUT_TIME == nil ) then settings.profile.options.LOGOUT_TIME = 0; end;
	if( settings.profile.options.LOGOUT_SHUTDOWN == nil ) then settings.profile.options.LOGOUT_SHUTDOWN = false; end;	

	if( self.Battling == true  or		-		-- no logout if aggro
	    settings.profile.options.LOGOUT_TIME == 0  ) then	-- no logout if timer = 0
		return;						-- go back
	end;
	
	if( (os.difftime(os.time(), hf_bot_start)/60) > settings.profile.options.LOGOUT_TIME ) then
		hf_logout = true;
	end;

	if( hf_logout == true ) then
		printf("automatic logout after %s min playtime\n", (os.difftime(os.time(), hf_bot_start)/60) );
		keyboardPress(settings.hotkeys.LOGOUT.key);
		yrest(12000);
		if( settings.profile.options.LOGOUT_SHUTDOWN == true ) then 
			printf("automatic shutdown in 30 sec\n" );
			os.execute("\"%windir%\\system32\\shutdown.exe -s -t 30\" ");	-- shutdown after 30 sec
		end;	
		stopPE();
	end;
end
And last, define two new options in your profile file ?charname?.xml

Code: Select all

	<option name="LOGOUT_TIME" value="120" />	
	<option name="LOGOUT_SHUTDOWN" value="true" />	
In 'LOGOUT_TIME' you can set the time in minutes until automatic logout. Setting '0' means no automatic logout. And with 'LOGOUT_SHUTDOWN' you can define if you want to shutdown your system after logout (true or false).

EDIT: add an option for shutdown.

Re: Modification: automatic logout after x min playtime

Posted: Mon Jun 22, 2009 1:24 pm
by kumpel100
that looks very great i will test it i used same in my Bot in a other Game with the special Feature " Shut down your machine after xx hours" that is an important Part !!!
something like:

Code: Select all

   
<option name="LOGOUT_TIME" value="120" />  
<option name="SHUT_DOWN_PC" value="true" />  
<option name="SHUT_DOWN_PC_ON_DEATH" value="true" />

this will save alot of Money in Germany the Power is Expensive :)

in my Bot the Function was looking like:

Code: Select all

if (Shutdownxx = true)
{
sleep 3000
;Logoff  	0
;Shutdown 	1
;Reboot 	2
;Force 	4
;Power down 	8
; Force a Power down (Power down + force + Shutdown = 8 + 4 + 1 = 13)
Shutdown, 13  ;13
;Works for XP, Vista
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
sleep 5000
pause
}
if (Shutdownxx = false)
{
Gosub save
sleep 1000
pause  ; pause while Death !!!!
}
}
}
}
Return

Re: Modification: automatic logout after x min playtime

Posted: Mon Jun 22, 2009 3:34 pm
by kumpel100
should we insert indeet of that:
end

player:logout_check(); -- automatic logout check <<< INSTERT THAT LINE
end

end
startMacro(main);

better this:

Code: Select all

end
if( settings.profile.options.USE_LOGOUT == true ) then     
                player:logout_check();   -- automatic logout check   <<< INSTERT THAT LINE                                          
                end 
  end 
end
startMacro(main);[/quote]
and in Profil:

<option name="LOGOUT_TIME" value="120" />
<option name="USE_LOGOUT" value="false" />


so we can set a true or a false.

Re: Modification: automatic logout after x min playtime

Posted: Mon Jun 22, 2009 3:43 pm
by d003232
kumpel100 wrote: <option name="LOGOUT_TIME" value="120" />
<option name="USE_LOGOUT" value="false" />


so we can set a true or a false.
You can allready set:

Code: Select all

<option name="LOGOUT_TIME" value="0" />
if you dont want to use automatic logout.

Re: Modification: automatic logout after x min playtime

Posted: Mon Jun 22, 2009 4:06 pm
by kumpel100
AHHHH ok :)

Re: Modification: automatic logout after x min playtime

Posted: Mon Jun 22, 2009 4:21 pm
by 3cmSailorfuku
How about using the winmessage shutdown to close a window instead of making a macro? :)

Anyway, Elverion posted similiar code already once but instead of making fancy XML settings, it would be fit into onleavecombat.
In my opinion that makes the code more simple, I have a great sense of Original Code <-> Modifications.

Re: Modification: automatic logout after x min playtime

Posted: Mon Jun 22, 2009 5:05 pm
by d003232
kumpel100 wrote:... with the special Feature " Shut down your machine after xx hours" that is an important Part !!!
I added one more option for shuting down the machine after logout. See the starting post.
3cmSailorfuku wrote:How about using the winmessage shutdown to close a window instead of making a macro? :)
Not really sure what you mean? I hope to save all RoM settings by using the macro ingame.
3cmSailorfuku wrote:it would be fit into onleavecombat.
In my opinion that makes the code more simple, I have a great sense of Original Code <-> Modifications.
My onleavecombat would be to big! :-) And I had some strange behaivor with, I think, the xml parser. So I dont really like it for 'bigger' things. And you are right. I allway say to my customers 'pls pls , don't modify the system ... use the standard' :-). But thats so boring ! :lol:

Re: Modification: automatic logout after x min playtime

Posted: Mon Jun 22, 2009 9:54 pm
by Administrator
I am about to commit this (and other changes by d003232) to SVN. The code I used is highly based on what was posted here, but was modified for simplicity, cleanliness, and includes some extra features.

Those features are (and it's not anything too fancy, so relax):
  • Options are set by default to false (do not use)
    Use either logout-macro or forcefully close client if logout-macro isn't set
    Reports (language specific) what is happening
    Exits the script entirely rather than just pausing the protected environment
    Timer is updated in the event that you pause/resume the bot
[50] = "Automatisch Ausloggen.\n",
[51] = "Herunterfahren des Systems.\n"
Can somebody verify if these are correct? I'm quite certain 50 is fine (maybe the A needs an umlaut?), the second one I'm unsure of.


I've also rennamed the hotkey "LOGOUT" to "LOGOUT_MACRO". Again, it works fine if this is not set; it will just close the client for you.

Re: Modification: automatic logout after x min playtime

Posted: Tue Jun 23, 2009 7:11 am
by 3cmSailorfuku
Administrator wrote:I am about to commit this (and other changes by d003232) to SVN. The code I used is highly based on what was posted here, but was modified for simplicity, cleanliness, and includes some extra features.

Those features are (and it's not anything too fancy, so relax):
  • Options are set by default to false (do not use)
    Use either logout-macro or forcefully close client if logout-macro isn't set
    Reports (language specific) what is happening
    Exits the script entirely rather than just pausing the protected environment
    Timer is updated in the event that you pause/resume the bot
[50] = "Automatisch Ausloggen.\n",
[51] = "Herunterfahren des Systems.\n"
Can somebody verify if these are correct? I'm quite certain 50 is fine (maybe the A needs an umlaut?), the second one I'm unsure of.


I've also rennamed the hotkey "LOGOUT" to "LOGOUT_MACRO". Again, it works fine if this is not set; it will just close the client for you.
Automatisches Ausloggen

Rest is fine.