Advertisement
Capuche

Total_time_online

May 8th, 2013
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.58 KB | None | 0 0
  1. //===== rAthena Script =======================================
  2. //= Total time online
  3. //===== By: ==================================================
  4. //= Capuche
  5. //===== Current Version: =====================================
  6. //= 1.0
  7. //===== Compatible With: =====================================
  8. //= rAthena SVN
  9. //===== Description: =========================================
  10. //= Rank of player/account online since the beginning.
  11. //= Give reward by mail each week to the xY top online.
  12. //------------------------------------------------------
  13. //= Another version at the end of the script with a sql table.
  14. //= Choose your version.
  15. //============================================================
  16.  
  17. prontera,149,129,5 script TotalTimeOnline 857,{
  18.  
  19. mes "^FF6600Time device^000000";
  20. mes "My Game's Time.";
  21. mes "- Account online since: ^777777"+ callfunc( "timeleft__", #secs_online + gettimetick(2) - @login_time ) +"^000000.";
  22. mes "-----------------------------------";
  23. mes "- Character online since: ^777777"+ callfunc( "timeleft__", time_online + gettimetick(2) - @login_time ) +"^000000.";
  24. next;
  25. if ( select( "^777777~ Top 5 accounts online.", ( getgmlevel() > 10 ? "~ Reset Ranking" : "" ), "~ Cancel^000000" ) == 3 ) close;
  26. else if( @menu == 2 ) {
  27. if( select( "Reset The character ranking.", "Reset The account time", "Cancel" ) == 3 ) close;
  28. else if( @menu == 2 ) {
  29. .@choice_reset$ = "account time";
  30. .@var_name$ = "#secs_online";
  31. }
  32. else {
  33. .@choice_reset$ = "character ranking";
  34. .@var_name$ = "time_online";
  35. }
  36. mes "^FF6600Time device^000000";
  37. mes "Are you sure to reset the "+ .@choice_reset$ +" ?";
  38. mes "The players must be ^FF0000offline^000000 otherwise the update doesn't work.";
  39. next;
  40. if( select( "No", "Yes" ) == 1 ) close;
  41. mes "^FF6600Time device^000000";
  42. mes .@choice_reset$ +" reset.";
  43. query_sql "DELETE FROM `global_reg_value` WHERE `global_reg_value`.`str` = '"+ escape_sql( .@var_name$ ) +"'";
  44. close;
  45. }
  46. .@size = query_sql( "SELECT `char`.`name`, `value` FROM `global_reg_value` LEFT JOIN `char` ON `global_reg_value`.`char_id` = `char`.`char_id` WHERE global_reg_value.`str` = 'time_online' ORDER BY `value` DESC LIMIT 5", .@name$, .@value );
  47. if( .@size ) {
  48. .@origin = getcharid(3);
  49. mes "^FF6600Time device^000000";
  50. for( .@i = 0; .@i < .@size; .@i++ ) {
  51. if( attachrid( getcharid( 3,.@name$[.@i] ) ) ) {
  52. .@value[.@i] = time_online + gettimetick(2) - @login_time;
  53. attachrid( .@origin );
  54. }
  55. mes "^777777"+ ( .@i +1 ) +"/^000000 "+ .@name$[.@i] +": ^FF0000"+ callfunc( "timeleft__", .@value[.@i] ) +"^000000";
  56. }
  57. }
  58. close;
  59.  
  60. OnPCLoginEvent:
  61. // if( getgmlevel() > 10 ) end;
  62. set @login_time, gettimetick(2);
  63. end;
  64. OnPCLogoutEvent:
  65. // if ( @login_time && getgmlevel() < 10 ) {// @login_time must be empty for gm but just in case
  66. set #secs_online, #secs_online + (gettimetick(2)-@login_time);
  67. time_online = time_online + gettimetick(2) - @login_time;
  68. // }
  69. end;
  70. OnSun0000:
  71. OnTue2310:
  72. .@size = query_sql( "SELECT `char`.`char_id`, `char`.`account_id` FROM `char` LEFT JOIN `global_reg_value` ON `global_reg_value`.`char_id` = `char`.`char_id` WHERE global_reg_value.`str` = 'time_online' ORDER BY `value` DESC LIMIT "+ getarraysize( .reward_ID ), .@char_id, .@account_id );
  73. for( .@i = 0; .@i < .@size; .@i++ ) {
  74. query_sql("INSERT INTO `mail` (send_name,dest_id,title,message,nameid,amount,identify,zeny,time) "+
  75. "VALUES ('no-reply',"+ .@char_id[.@i] +",'Reward Online',"+
  76. "'"+ escape_sql( .message$ ) +"',"+ .reward_ID[.@i] +","+ .reward_amount[.@i] +",0,"+ .reward_zeny[.@i] +",UNIX_TIMESTAMP(NOW()))");
  77. if ( isloggedin( .@account_id[.@i], .@char_id[.@i] ) )
  78. message rid2name( .@account_id[.@i] ),"You've got mail! Please re-login to update your mailing list.";
  79. }
  80. end;
  81. OnInit:
  82. .message$ = "Here your reward for being in the top 5 of the character online this week !";
  83. setarray .reward_ID, 501, 502, 503;
  84. setarray .reward_amount, 1, 1, 1;
  85. setarray .reward_zeny, 0, 0, 0;
  86. end;
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. /*
  96. CREATE TABLE IF NOT EXISTS `time_online` (
  97. `char_id` int(11) unsigned NOT NULL DEFAULT '0',
  98. `value` varchar(1000) NOT NULL DEFAULT '0',
  99. `account_id` int(11) unsigned NOT NULL DEFAULT '0',
  100. PRIMARY KEY (`char_id`,`account_id`),
  101. KEY `account_id` (`account_id`),
  102. KEY `char_id` (`char_id`)
  103. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  104. */
  105.  
  106. function script timeleft__ {
  107. function s;
  108. if ( ( .@left = getarg(0) ) <= 0 ) return getarg(0);
  109. .@week = .@left / 86400 * 7;
  110. .@day = .@left / 86400;
  111. .@hour = .@left % 86400 / 3600;
  112. .@min = .@left % 3600 / 60;
  113. .@sec = .@left % 60;
  114. if( .@week )
  115. return .@week +" week"+ s( .@week ) + .@day +" day"+ s( .@day ) + .@hour +" hour"+ s( .@hour );
  116. else if ( .@day )
  117. return .@day +" day"+ s( .@day ) + .@hour +" hour"+ s( .@hour );
  118. else if ( .@hour )
  119. return .@hour +" hour"+ s(.@hour) + .@min +" min" +s( .@min );
  120. else if ( .@min )
  121. return .@min +" min"+ s( .@min ) + .@sec +" sec"+ s( .@sec );
  122. else
  123. return .@sec +" sec"+ s( .@sec );
  124.  
  125. function s { return ( getarg(0) > 1 ? "s " : " " ); }
  126. }
  127.  
  128. prontera,149,129,5 script TotalTimeOnline 857,{
  129. query_sql "SELECT value FROM time_online WHERE char_id = "+ getcharid(0) +" LIMIT 1", .@time_char;
  130. query_sql "SELECT value FROM time_online WHERE account_id = "+ getcharid(3) +" LIMIT 1", .@time_account;
  131.  
  132. mes "^FF6600Time device^000000";
  133. mes "My Game's Time.";
  134. mes "- Account online since: ^777777"+ callfunc( "timeleft__", .@time_account + gettimetick(2) - @login_time ) +"^000000.";
  135. mes "-----------------------------------";
  136. mes "- Character online since: ^777777"+ callfunc( "timeleft__", .@time_char + gettimetick(2) - @login_time ) +"^000000.";
  137. next;
  138. if ( select( "^777777~ Top 5 accounts online.", ( getgmlevel() > 10 ? "~ Reset Ranking" : "" ), "~ Cancel^000000" ) == 3 ) close;
  139. else if( @menu == 2 ) {
  140. if( select( "^777777~ Reset The character ranking.", "~ Reset The account time", "~ Cancel^000000" ) == 3 ) close;
  141. else if( @menu == 2 ) {
  142. .@choice_reset$ = "account time";
  143. .@var_name$ = "account_id";
  144. }
  145. else {
  146. .@choice_reset$ = "character ranking";
  147. .@var_name$ = "char_id";
  148. }
  149. mes "^FF6600Time device^000000";
  150. mes "Are you sure to reset the "+ .@choice_reset$ +" ?";
  151. next;
  152. if( select( "^777777~ No", "~ Yes^000000" ) == 1 ) close;
  153. mes "^FF6600Time device^000000";
  154. mes .@choice_reset$ +" reset.";
  155. query_sql "DELETE FROM `time_online` WHERE `time_online`."+ escape_sql( .@var_name$ ) +" > 0";
  156. close;
  157. }
  158. .@size = query_sql( "SELECT `char`.`name`, `value` FROM `time_online` LEFT JOIN `char` ON `time_online`.`char_id` = `char`.`char_id` WHERE time_online.`char_id` > 0 ORDER BY `value` DESC LIMIT 5", .@name$, .@value );
  159. if( .@size ) {
  160. .@origin = getcharid(3);
  161. mes "^FF6600Time device^000000";
  162. for( .@i = 0; .@i < .@size; .@i++ ) {
  163. if( attachrid( getcharid( 3,.@name$[.@i] ) ) ) {
  164. .@value[.@i] = .@value[.@i] + gettimetick(2) - @login_time;
  165. attachrid( .@origin );
  166. }
  167. mes "^777777"+ ( .@i +1 ) +"/^000000 "+ .@name$[.@i] +": ^FF0000"+ callfunc( "timeleft__", .@value[.@i] ) +"^000000";
  168. }
  169. }
  170. close;
  171.  
  172. OnPCLoginEvent:
  173. if( getgmlevel() >= 5) end;
  174. set @login_time, gettimetick(2);
  175. end;
  176. OnPCLogoutEvent:
  177. if ( @login_time && getgmlevel() < 5 ) {// @login_time must be empty for gm but just in case
  178. query_sql "INSERT INTO `time_online` VALUES ( "+ getcharid(0) +", 1, 0 ) ON DUPLICATE KEY UPDATE value = value + "+ ( gettimetick(2) - @login_time );
  179. query_sql "INSERT INTO `time_online` VALUES ( 0, 1, "+ getcharid(3) +" ) ON DUPLICATE KEY UPDATE value = value + "+ ( gettimetick(2) - @login_time );
  180. }
  181. end;
  182. OnSun0000:
  183. .@size = query_sql( "SELECT `char`.`char_id`, `char`.`account_id` FROM `char` LEFT JOIN `time_online` ON `time_online`.`char_id` = `char`.`char_id` WHERE time_online.`char_id` > 0 ORDER BY `value` DESC LIMIT "+ getarraysize( .reward_ID ), .@char_id, .@account_id );
  184. for( .@i = 0; .@i < .@size; .@i++ ) {
  185. query_sql("INSERT INTO `mail` (send_name,dest_id,title,message,nameid,amount,identify,zeny,time) "+
  186. "VALUES ('no-reply',"+ .@char_id[.@i] +",'Reward Online',"+
  187. "'"+ escape_sql( .message$ ) +"',"+ .reward_ID[.@i] +","+ .reward_amount[.@i] +",0,"+ .reward_zeny[.@i] +",UNIX_TIMESTAMP(NOW()))");
  188. if ( isloggedin( .@account_id[.@i], .@char_id[.@i] ) )
  189. message rid2name( .@account_id[.@i] ),"You've got mail! Please re-login to update your mailing list.";
  190. }
  191. end;
  192. OnInit:
  193. .message$ = "Here your reward for being in the top 5 of the character online this week !";
  194. setarray .reward_ID, 501, 502, 503;
  195. setarray .reward_amount, 1, 1, 1;
  196. setarray .reward_zeny, 0, 0, 0;
  197. end;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement