yuhsing

Untitled

Nov 19th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.94 KB | None | 0 0
  1.  
  2. // Last Update : 04:10AM 20/11/2012
  3.  
  4. // Credits to AnnieRuru
  5.  
  6. // ==== TO-DO ====
  7. // - NPC Dialog Lists
  8. // - Add Block User Features ?
  9. // - Clean the Scripts .....
  10.  
  11.  
  12. - script IRC -1,{
  13. function IRC_Create;
  14. function IRC_Join;
  15. function IRC_Broadcast;
  16. function IRC_Add;
  17. function IRC_Remove;
  18. function IRC_List;
  19. function IRC_getSlot;
  20. function IRC_Edit;
  21.  
  22. OnInit:
  23. // Max IRC Room
  24. .MaxRoom = 10;
  25. // Max Users in IRC
  26. .MaxUser = 100;
  27. // Display Time
  28. .DisplayTime = 1;
  29. // Kick when idle X Seconds
  30. .IdleKick = 1800;
  31.  
  32. // IRC Message Colour
  33. .CHAT$ = "0xFFBBFF";
  34. .SYSTEM$ = "0x00EE55";
  35.  
  36. // IRC Commands
  37. .irc_create$ = "create";
  38. .irc_join$ = "join";
  39. .irc_leave$ = "leave";
  40. .irc_list$ = "list";
  41. .irc_kick$ = "kick";
  42. .irc_invite$ = "invite";
  43. .irc_help$ = "help";
  44. .irc_reject$ = "reject";
  45. .irc_edit$ = "edit";
  46.  
  47.  
  48. // IRC Messages ( will add on future )
  49. // .message$[0] = "IRC Room reach limit.";
  50. // .message$[1] = "Please leave your current IRC Room.";
  51. // .message$[2] = "Didnt have any available IRC Room.";
  52. // .message$[3] = "You didnt join any IRC Room";
  53.  
  54. // Delete Data during Test Mode
  55. for ( .@i = 2000000; .@i < 2000003; .@i++ )
  56. if ( attachrid(.@i) )
  57. set @IRC, 0;
  58. end;
  59.  
  60.  
  61. OnWhisperGlobal:
  62. .@Name$ = strcharinfo(0);
  63.  
  64. if( @whispervar0$ == .irc_create$ ){
  65. if( getarraysize( .IRC_Room$ ) >= .MaxRoom ){
  66. dispbottom "Max IRC Channel Reach.";
  67. }else if( @IRC ){
  68. dispbottom "Please leave your current IRC Channel";
  69. }else if( getstrlen(@whispervar1$) < 4 || getstrlen(@whispervar1$) > 24 ){
  70. dispbottom "Usage : '"+.irc_create$+"'#new_irc_name#new_irc_password ( if any )";
  71. dispbottom "irc_name must be between 4 ~ 24";
  72. }else if( getstrlen( @whispervar2$ ) && getstrlen( @whispervar2$ ) < 4 ){
  73. dispbottom "If you gonna add Password for IRC Channel, the Password must not less than 4 characters.";
  74. }else{
  75. @IRC = IRC_Create( @whispervar1$,@whispervar2$ );
  76. if( @IRC ){
  77. dispbottom "Successfully create a Channel.";
  78. IRC_Add( @IRC,.@Name$ );
  79. @Slot = 0;
  80. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0;
  81. deltimer strnpcinfo(0)+"::OnIdleCheck";
  82. addtimer 1000,strnpcinfo(0)+"::OnIdleCheck";
  83.  
  84. // Clear variable ...
  85. @whispervar1$ = "";
  86. @whispervar2$ = "";
  87. }else{
  88. dispbottom "Failed to create a Channel.";
  89. }
  90. }
  91.  
  92. }else if( @whispervar0$ == .irc_join$ ){
  93. if( getarraysize( .IRC_Room$ ) <= 0 ){
  94. dispbottom "Didnt have any available IRC Channel.";
  95. }else if( @IRC ){
  96. dispbottom "Please leave your current IRC Channel";
  97. }else{
  98. @IRC = IRC_Join();
  99. IRC_Add( @IRC,.@Name$ );
  100. @Slot = IRC_getSlot( @IRC,.@Name$ );
  101.  
  102. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0;
  103. deltimer strnpcinfo(0)+"::OnIdleCheck";
  104. addtimer 1000,strnpcinfo(0)+"::OnIdleCheck";
  105. }
  106.  
  107. }else if( @whispervar0$ == .irc_leave$ ){
  108. if( !@IRC ){
  109. dispbottom "You didnt join any IRC Channel.";
  110. }else{
  111. @Slot = IRC_getSlot( @IRC,.@Name$ );
  112. IRC_Remove( @IRC,.@Name$ );
  113. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0;
  114. @IRC = 0;
  115. dispbottom "You have left the IRC Channel";
  116. deltimer strnpcinfo(0)+"::OnIdleCheck";
  117. }
  118.  
  119. }else if( @whispervar0$ == .irc_list$ ){
  120. if( !@IRC ){
  121. dispbottom "You didnt join any IRC Channel.";
  122. }else{
  123. IRC_List( @IRC,.@Name$ );
  124. }
  125.  
  126. }else if( @whispervar0$ == .irc_kick$ ){
  127. if( getd( ".IRC_Room_"+( @IRC - 1 )+"$[0]" ) != .@Name$ ){
  128. dispbottom "Only a MOD of a channel can use '"+.irc_kick$+"' to kick player in this Channel.";
  129. }else if( @whispervar1$ == .@Name$ ){
  130. dispbottom "You cant kick yourself out of the Channel. To quit a channel use '"+.irc_leave$+"' .";
  131. }else{
  132. .@ExpelName$ = @whispervar1$;
  133. if( attachrid( getcharid(3,.@ExpelName$) ) ){
  134. @Slot = IRC_getSlot( @IRC,.@ExpelName$ );
  135. IRC_Remove( @IRC,.@ExpelName$ );
  136. dispbottom "You have been kicked out from the IRC by MOD";
  137.  
  138. deltimer strnpcinfo(0)+"::OnIdleCheck";
  139. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0;
  140. @IRC = 0;
  141. }
  142. attachrid( getcharid( 3,.@Name$ ) );
  143. }
  144.  
  145. }else if( @whispervar0$ == .irc_reject$ ){
  146. @AutoReject = !@AutoReject;
  147. dispbottom ( ( @AutoReject )?"Auto Reject":"Enable" )+" Invitation from other IRC Channel";
  148.  
  149. }else if( @whispervar0$ == .irc_edit$ ){
  150. if( getd( ".IRC_Room_"+( @IRC - 1 )+"$[0]" ) != .@Name$ ){
  151. dispbottom "Only a MOD of a channel can use '"+.irc_edit$+"' to update Channel Name / Password.";
  152. }else if( getstrlen(@whispervar1$) < 4 || getstrlen(@whispervar1$) > 24 ){
  153. dispbottom "Usage : '"+.irc_edit$+"'#new_irc_name#new_irc_password ( if any )";
  154. dispbottom "irc_name must be between 4 ~ 24";
  155. }else if( getstrlen( @whispervar2$ ) && getstrlen( @whispervar2$ ) < 4 ){
  156. dispbottom "If you gonna add Password for IRC Channel, the Password must not less than 4 characters.";
  157. }else{
  158. IRC_Edit( @IRC,@whispervar1$,@whispervar2$,.@Name$ );
  159.  
  160. // Clear variable ...
  161. @whispervar1$ = "";
  162. @whispervar2$ = "";
  163. }
  164.  
  165. }else if( @whispervar0$ == .irc_invite$ ){
  166. if( getd( ".IRC_Room_"+( @IRC - 1 )+"$[0]" ) != .@Name$ ){
  167. dispbottom "Only a MOD of a channel can use '"+.irc_invite$+"' to invite another player into this Channel.";
  168. }else if( @whispervar1$ == .@Name$ ){
  169. dispbottom "You are already inside this Channel.";
  170. }else{
  171.  
  172. .@Channel = @IRC;
  173. .@UserName$ = @whispervar1$;
  174.  
  175. if( attachrid( getcharid( 3,.@UserName$ ) ) )
  176. if( @AutoReject || @IRC ){
  177. .@i = -1;
  178. if( @AutoReject )
  179. dispbottom "Rejected IRC Invitation sent by '"+.@Name$+"'.";
  180. }else{
  181. .@i = @Slot = IRC_Add( .@Channel,.@UserName$ );
  182. addtimer 1000,strnpcinfo(0)+"::OnIdleCheck";
  183. if( @Slot >= 0 )
  184. @IRC = .@Channel;
  185. }
  186.  
  187. attachrid( getcharid( 3,.@Name$ ) );
  188. if( .@i < 0 )
  189. dispbottom "Failed to add this '"+.@UserName$+"' into this Channel.";
  190. }
  191.  
  192. }else if( @IRC <= 0 || @whispervar0$ == .irc_help$ ){
  193. dispbottom "======================= IRC Commands =======================";
  194. dispbottom "To Create a Channel : type '"+.irc_create$+"#irc_name#irc_password' ( if any )";
  195. dispbottom "To Join / View Channel : type '"+.irc_join$+"'";
  196. dispbottom "To Leave Channel : type '"+.irc_leave$+"'";
  197. dispbottom "To Auto Reject / Accept Invitation : type '"+.irc_reject$+"'";
  198. dispbottom "To View Players / Info : type '"+.irc_list$+"'";
  199. dispbottom "==================== IRC [MOD] Commands ====================";
  200. dispbottom "To Invite a Player : type '"+.irc_invite$+"#player_name'";
  201. dispbottom "To Kick a Player : type '"+.irc_kick$+"#player_name'";
  202. dispbottom "To Edit Channel : type '"+.irc_edit$+"#new_irc_name#new_irc_password'";
  203. dispbottom "======================= IRC Commands =======================";
  204.  
  205. }else{
  206. @Slot = IRC_getSlot( @IRC,.@Name$ );
  207. set .@MSG$, .@Name$ +" : "+ @whispervar0$;
  208. IRC_Broadcast( @IRC,.@MSG$,.CHAT$,.@Name$ );
  209.  
  210. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0;
  211. deltimer strnpcinfo(0)+"::OnIdleCheck";
  212. addtimer 1000,strnpcinfo(0)+"::OnIdleCheck";
  213. }
  214. close;
  215.  
  216. OnIdleCheck:
  217. @Slot = IRC_getSlot( @IRC,strcharinfo(0) );
  218. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),( getd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ) + 1 );
  219. if( getd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ) >= .IdleKick ){
  220. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0;
  221. IRC_Remove( @IRC,strcharinfo(0) );
  222. @IRC = 0;
  223. dispbottom "You have keen auto-kicked out from the IRC Channel due to Idled so long.";
  224. }else if( @IRC )
  225. addtimer 1000,strnpcinfo(0)+"::OnIdleCheck";
  226. end;
  227.  
  228. OnPCLogoutEvent:
  229. if( @IRC )
  230. IRC_Remove( @IRC,strcharinfo(0) );
  231. end;
  232.  
  233. // getarg(0) = IRC Channel
  234. // getarg(1) = Player Name
  235. function IRC_Add {
  236. .@channel = getarg(0) - 1;
  237. .@player$ = getarg(1);
  238.  
  239. .@size = getarraysize( getd( ".IRC_Room_"+.@channel+"$" ) );
  240. .@i = 0;
  241.  
  242. while( .@i < .@size ){
  243. if( getd( ".IRC_Room_"+.@channel+"$["+.@i+"]" ) == .@player$ )
  244. return -1;
  245. .@i++;
  246. }
  247.  
  248. setd( ".IRC_Room_"+.@channel+"$["+.@size+"]" ),.@player$;
  249. IRC_Broadcast( ( .@channel + 1 ),"( IRC ) : '"+.@player$+"' joined this channel.",.SYSTEM$,.@player$ );
  250.  
  251. return .@size;
  252. }
  253.  
  254. // getarg(0) = IRC Channel
  255. // getarg(1) = Player Name
  256. function IRC_Remove {
  257. .@channel = getarg(0) - 1;
  258. .@player$ = getarg(1);
  259.  
  260. .@Slot = IRC_getSlot( ( .@channel + 1 ),.@player$ );
  261.  
  262. if( .@Slot >= 0 ){
  263. IRC_Broadcast( ( .@channel + 1 ),"( IRC ) : '"+.@player$+"' left this channel",.SYSTEM$,.@player$ );
  264. deletearray getd( ".IRC_Room_"+.@channel+"$["+.@Slot+"]" ),1;
  265. }
  266.  
  267. // Delete Channel & Password from Channel Lists if empty users
  268. if( getarraysize( getd( ".IRC_Room_"+.@channel+"$" ) ) <= 0 ){
  269. .IRC_Room$[ .@channel ] = "";
  270. .IRC_Pass$[ .@channel ] = "";
  271. }
  272.  
  273. return attachrid( getcharid(3,.@player$ ) );
  274. }
  275.  
  276. // getarg(0) = IRC Channel
  277. function IRC_List {
  278. .@channel = getarg(0) - 1;
  279.  
  280. dispbottom "========= IRC INFORMATION ==========";
  281. dispbottom "IRC Title : "+.IRC_Room$[ .@channel ];
  282. dispbottom "IRC Type : "+( ( getstrlen( .IRC_Pass$[ .@channel ] ) )?"Secured ( '"+.IRC_Pass$[ .@channel ]+"' )":"Public" );
  283. dispbottom "========= IRC USER LIST ===========";
  284.  
  285. .@size = getarraysize( getd( ".IRC_Room_"+.@channel+"$" ) );
  286. .@i = 0;
  287.  
  288. while( .@i < .@size ){
  289. dispbottom " -> "+getd( ".IRC_Room_"+.@channel+"$["+.@i+"]" )+" Idled : "+getd( ".IRC_Idle_"+.@channel+"["+.@i+"]" )+" seconds"+ ( ( .@i == 0 )?" [ MOD ]":"" );
  290. .@i++;
  291. }
  292. dispbottom "========= IRC USER LIST ===========";
  293. dispbottom "Total User : "+.@size;
  294.  
  295. return;
  296. }
  297.  
  298. // getarg(0) = IRC Channel
  299. // getarg(1) = Message
  300. // getarg(2) = Color
  301. // getarg(3) = Attach Target Player
  302. function IRC_Broadcast {
  303. .@channel = getarg(0) - 1;
  304. .@message$ = getarg(1);
  305. .@colour$ = getarg(2);
  306. .@player$ = getarg(3);
  307.  
  308. .@size = getarraysize( getd( ".IRC_Room_"+.@channel+"$" ) );
  309. .@i = 0;
  310.  
  311. while( .@i < .@size ){
  312. if( attachrid( getcharid( 3,getd( ".IRC_Room_"+.@channel+"$["+.@i+"]" ) ) ) )
  313. announce ( ( .DisplayTime )?"[ "+gettimestr("%H:%M",7)+" ] ":"" ) + .@message$,bc_self,.@colour$;
  314. .@i++;
  315. }
  316.  
  317. return attachrid( getcharid( 3,.@player$ ) );
  318. }
  319.  
  320. // getarg(0) = Room Title
  321. // getarg(1) = Room Password if any
  322. function IRC_Create {
  323. .@irc_name$ = getarg(0);
  324. .@irc_password$ = getarg(1);
  325. .@i = 0;
  326.  
  327. while( .@i < .MaxRoom ){
  328. if( .IRC_Room$[.@i] == "" ){
  329. .IRC_Room$[.@i] = .@irc_name$;
  330. .IRC_Pass$[.@i] = .@irc_password$;
  331. return ( .@i + 1 );
  332. }
  333. .@i++;
  334. }
  335.  
  336. return 0;
  337. }
  338.  
  339. // List Channel and Select
  340. function IRC_Join {
  341. .@room_size = getarraysize( .IRC_Room$ );
  342. .@i = 0;
  343.  
  344. while( .@i < .@room_size ){
  345. set .@Menu$,.@Menu$ + ( ( .IRC_Room$[.@i] == "" )?"":"^FF0000[ "+( ( getstrlen( .IRC_Pass$[.@i] ) >= 4 )?"S":"P" )+" ] ^0055FF"+.IRC_Room$[.@i]+" ^FF0000( "+getarraysize( getd( ".IRC_Room_"+.@i+"$") )+" / "+.MaxUser+" Users )^000000" ) +":";
  346. .@i++;
  347. }
  348.  
  349. do{
  350. mes "^0055FF[ S ]^000000 = ^777777Secured Room^000000";
  351. mes "^0055FF[ P ]^000000 = ^777777Public Room^000000";
  352. .@Room = select( .@Menu$ ) - 1;
  353. if( getstrlen( .IRC_Pass$[ .@Room ] ) >= 4 ){
  354. mes "Please enter the IRC Password.";
  355. input .@Pass$;
  356. if( .@Pass$ != .IRC_Pass$[ .@Room ] ){
  357. mes "^FF0000Invalid Password^000000";
  358. next;
  359. }
  360. }
  361. }while( getstrlen( .IRC_Pass$[ .@Room ] ) >= 4 && .@Pass$ != .IRC_Pass$[ .@Room ] );
  362.  
  363. return ( .@Room + 1 );
  364. }
  365.  
  366. // getarg(0) = IRC Channel
  367. // getarg(1) = Player Name
  368. function IRC_getSlot {
  369. .@channel = getarg(0) - 1;
  370. .@player$ = getarg(1);
  371.  
  372. .@size = getarraysize( getd( ".IRC_Room_"+.@channel+"$" ) );
  373. .@i = 0;
  374.  
  375. while( .@i < .@size ){
  376. if( getd( ".IRC_Room_"+.@channel+"$["+.@i+"]" ) == .@player$ )
  377. return .@i;
  378. .@i++;
  379. }
  380.  
  381. return -1;
  382. }
  383.  
  384. // getarg(0) = IRC Channel
  385. // getarg(1) = New IRC Name
  386. // getarg(2) = New IRC Password ( if any )
  387. // getarg(3) = Player Name
  388. function IRC_Edit {
  389. .@channel = getarg(0) - 1;
  390. .@irc_name$ = getarg(1);
  391. .@irc_password$ = getarg(2);
  392. .@player$ = getarg(3);
  393.  
  394. .IRC_Room$[.@channel] = .@irc_name$;
  395. .IRC_Pass$[.@channel] = .@irc_password$;
  396. IRC_Broadcast( ( .@channel + 1 ),"( IRC ) : [MOD] '"+.@player$+"' has updated Channel Name / Password.",.SYSTEM$,.@player$ );
  397.  
  398. return;
  399. }
  400.  
  401. }
Advertisement
Add Comment
Please, Sign In to add comment