yuhsing

Untitled

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