yuhsing

Untitled

Nov 18th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.33 KB | None | 0 0
  1.  
  2. // Last Update : 10:20AM 19/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.  
  21. OnInit:
  22. // Max IRC Room
  23. .MaxRoom = 10;
  24. // Max Users in IRC
  25. .MaxUser = 100;
  26. // Display Time
  27. .DisplayTime = 1;
  28. // Kick when idle X Seconds
  29. .IdleKick = 600;
  30.  
  31. // IRC Message Colour
  32. .CHAT$ = "0xFFBBFF";
  33. .SYSTEM$ = "0x00EE55";
  34.  
  35. // IRC Commands
  36. .irc_create$ = "create";
  37. .irc_join$ = "join";
  38. .irc_leave$ = "leave";
  39. .irc_list$ = "list";
  40. .irc_kick$ = "kick";
  41. .irc_invite$ = "invite";
  42. // .irc_help$ = "help";
  43. .irc_reject$ = "reject";
  44.  
  45.  
  46. // IRC Messages ( will add on future )
  47. // .message$[0] = "IRC Room reach limit.";
  48. // .message$[1] = "Please leave your current IRC Room.";
  49. // .message$[2] = "Didnt have any available IRC Room.";
  50. // .message$[3] = "You didnt join any IRC Room";
  51.  
  52. // Delete Data during Test Mode
  53. for ( .@i = 2000000; .@i < 2000003; .@i++ )
  54. if ( attachrid(.@i) )
  55. set @IRC, 0;
  56. end;
  57.  
  58.  
  59. OnWhisperGlobal:
  60. .@OriginalUser$ = strcharinfo(0);
  61.  
  62. if( @whispervar0$ == .irc_create$ ){
  63. if( getarraysize( .IRC_Room$ ) >= .MaxRoom ){
  64. dispbottom "Max IRC Room Reach.";
  65. }else if( @IRC ){
  66. dispbottom "Please leave your current IRC Room";
  67. }else if( getstrlen(@whispervar1$) < 4 || getstrlen(@whispervar1$) > 24 ){
  68. dispbottom "Usage : create#irc_name#irc_password ( if any password )";
  69. dispbottom "irc_name must be between 4 ~ 24";
  70. }else if( getstrlen( @whispervar2$ ) && getstrlen( @whispervar2$ ) < 4 ){
  71. dispbottom "If you gonna add Password for IRC Room, the Password must not less than 4 characters.";
  72. }else{
  73. @IRC = IRC_Create( @whispervar1$,@whispervar2$ );
  74. if( @IRC ){
  75. dispbottom "Successfully create a Room.";
  76. IRC_Add( ( @IRC - 1 ),strcharinfo(0) );
  77. @Slot = 0;
  78. setd( ".IRC_Idle_"+@IRC+"["+@Slot+"]" ),0;
  79. deltimer strnpcinfo(0)+"::OnIdleCheck";
  80. addtimer 1000,strnpcinfo(0)+"::OnIdleCheck";
  81.  
  82. // Clear variable ...
  83. @whispervar1$ = "";
  84. @whispervar2$ = "";
  85. }else{
  86. dispbottom "Failed to create a Room.";
  87. }
  88. }
  89.  
  90. }else if( @whispervar0$ == .irc_join$ ){
  91. if( getarraysize( .IRC_Room$ ) <= 0 ){
  92. dispbottom "Didnt have any available IRC Room.";
  93. }else if( @IRC ){
  94. dispbottom "Please leave your current IRC Room";
  95. }else{
  96. @IRC = IRC_Join();
  97. IRC_Add( ( @IRC - 1 ),strcharinfo(0) );
  98. @Slot = IRC_getSlot( ( @IRC - 1 ),strcharinfo(0) );
  99. setd( ".IRC_Idle_"+@IRC+"["+@Slot+"]" ),0;
  100. deltimer strnpcinfo(0)+"::OnIdleCheck";
  101. addtimer 1000,strnpcinfo(0)+"::OnIdleCheck";
  102. }
  103.  
  104. }else if( @whispervar0$ == .irc_leave$ ){
  105. if( !@IRC ){
  106. dispbottom "You didnt join any IRC Room.";
  107. }else{
  108. @Slot = IRC_getSlot( ( @IRC - 1 ),strcharinfo(0) );
  109. IRC_Remove( ( @IRC - 1 ),strcharinfo(0),@Slot );
  110. setd( ".IRC_Idle_"+@IRC+"["+@Slot+"]" ),0;
  111. @IRC = 0;
  112. dispbottom "You have left the IRC Channel";
  113. deltimer strnpcinfo(0)+"::OnIdleCheck";
  114. }
  115.  
  116. }else if( @whispervar0$ == .irc_list$ ){
  117. if( !@IRC ){
  118. dispbottom "You didnt join any IRC Room.";
  119. }else{
  120. IRC_List( ( @IRC - 1 ),strcharinfo(0) );
  121. }
  122.  
  123. }else if( @whispervar0$ == .irc_kick$ ){
  124. if( getd( ".IRC_Room_"+( @IRC - 1 )+"$[0]" ) != strcharinfo(0) ){
  125. dispbottom "Only a MOD of a channel can use this to kick player in this Channel.";
  126. }else{
  127.  
  128. .@ExpelName$ = @whispervar1$;
  129. if( attachrid( getcharid(3,.@ExpelName$) ) ){
  130. @Slot = IRC_getSlot( ( @IRC - 1 ),.@ExpelName$ );
  131. IRC_Remove( ( @IRC - 1 ),.@ExpelName$ );
  132. dispbottom "You have been kicked out from the IRC by MOD";
  133. deltimer strnpcinfo(0)+"::OnIdleCheck";
  134. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0;
  135. @IRC = 0;
  136. }
  137. attachrid( getcharid( 3,.@OriginalUser$ ) );
  138. }
  139.  
  140. }else if( @whispervar0$ == .irc_reject$ ){
  141. @AutoReject = !@AutoReject;
  142. dispbottom ( ( @AutoReject )?"Auto Reject":"Enable" )+" Invitation from other IRC Channel";
  143.  
  144. }else if( @whispervar0$ == .irc_invite$ ){
  145. if( getd( ".IRC_Room_"+( @IRC - 1 )+"$[0]" ) != strcharinfo(0) ){
  146. dispbottom "Only a MOD of a channel can invite another player into this Channel.";
  147. }else{
  148.  
  149. .@Channel = @IRC;
  150. .@Name$ = @whispervar1$;
  151. if( attachrid( getcharid(3,.@Name$) ) ){
  152. if( @AutoReject || @IRC ){
  153. .@i = 0;
  154. if( @AutoReject )
  155. dispbottom "Rejected IRC Invitation from "+.@OriginalUser$+".";
  156. }else{
  157. .@i = @Slot = IRC_Add( ( .@Channel - 1 ),.@Name$ );
  158. addtimer 1000,strnpcinfo(0)+"::OnIdleCheck";
  159. if( @Slot >= 0 ) @IRC = .@Channel;
  160. }
  161. }
  162. attachrid( getcharid( 3,.@OriginalUser$ ) );
  163. if( .@i < 0 ) dispbottom "Failed to add this Player into this Channel.";
  164. }
  165.  
  166. }else if( @IRC <= 0 ){
  167. dispbottom "You didnt join any IRC Room.";
  168. dispbottom "To Create a Channel : type 'create#irc_name#irc_password' ( if any )";
  169. dispbottom "To Join a Channel : type 'join'";
  170.  
  171. }else{
  172. @Slot = IRC_getSlot( ( @IRC - 1 ),strcharinfo(0) );
  173. set .@MSG$, strcharinfo(0) +" : "+ @whispervar0$;
  174. IRC_Broadcast( ( @IRC - 1 ),.@MSG$,.CHAT$,strcharinfo(0) );
  175.  
  176. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0;
  177. deltimer strnpcinfo(0)+"::OnIdleCheck";
  178. addtimer 1000,strnpcinfo(0)+"::OnIdleCheck";
  179. }
  180. close;
  181.  
  182. OnIdleCheck:
  183. @Slot = IRC_getSlot( ( @IRC - 1 ),strcharinfo(0) );
  184. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),( getd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ) + 1 );
  185. if( getd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ) >= .IdleKick ){
  186. setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0;
  187. IRC_Remove( ( @IRC - 1 ),strcharinfo(0) );
  188. @IRC = 0;
  189. dispbottom "You have keen auto-kicked out from the IRC Channel due to Idled so long.";
  190. }else if( @IRC )
  191. addtimer 1000,strnpcinfo(0)+"::OnIdleCheck";
  192. end;
  193.  
  194. OnPCLogoutEvent:
  195. if( @IRC )
  196. IRC_Remove( ( @IRC - 1 ),strcharinfo(0) );
  197. end;
  198.  
  199. // getarg(0) = Room
  200. // getarg(1) = Player Name
  201. function IRC_Add {
  202. .@size = getarraysize( getd( ".IRC_Room_"+getarg(0)+"$" ) );
  203. for( .@i = 0; .@i < .@size; .@i++ )
  204. if( getd( ".IRC_Room_"+getarg(0)+"$["+.@i+"]" ) == getarg(1) )
  205. return -1;
  206. setd( ".IRC_Room_"+getarg(0)+"$["+.@size+"]" ),getarg(1);
  207. IRC_Broadcast( getarg(0),"( IRC ) : '"+getarg(1)+"' joined this room",.SYSTEM$,getarg(1) );
  208. return .@size;
  209. }
  210.  
  211. // getarg(0) = Room
  212. // getarg(1) = Player Name
  213. function IRC_Remove {
  214. .@Slot = IRC_getSlot( getarg(0),getarg(1) );
  215. if( .@Slot >= 0 ){
  216. IRC_Broadcast( getarg(0),"( IRC ) : '"+getarg(1)+"' left this room",.SYSTEM$,getarg(1) );
  217. deletearray getd( ".IRC_Room_"+getarg(0)+"$["+.@Slot+"]" ),1;
  218. }
  219.  
  220. // Delete Room & Password from Room Lists if empty users
  221. if( getarraysize( getd( ".IRC_Room_"+getarg(0)+"$" ) ) <= 0 ){
  222. .IRC_Room$[ getarg(0) ] = "";
  223. .IRC_Pass$[ getarg(0) ] = "";
  224. }
  225.  
  226. return attachrid( getcharid(3,getarg(1) ) );
  227. }
  228.  
  229. // getarg(0) = Room
  230. function IRC_List {
  231. dispbottom "========= IRC INFORMATION ==========";
  232. dispbottom "IRC Name : "+.IRC_Room$[ getarg(0) ];
  233. dispbottom "IRC Type : "+( ( getstrlen( .IRC_Pass$[ getarg(0) ] ) )?"Secured ( '"+.IRC_Pass$[ getarg(0) ]+"' )":"Public" );
  234. dispbottom "========= IRC USER LIST ===========";
  235.  
  236. .@size = getarraysize( getd( ".IRC_Room_"+getarg(0)+"$" ) );
  237. for( .@i = 0; .@i < .@size; .@i++ )
  238. dispbottom " -> "+getd( ".IRC_Room_"+getarg(0)+"$["+.@i+"]" )+" Idled : "+getd( ".IRC_Idle_"+getarg(0)+"["+.@i+"]" )+" seconds"+ ( ( .@i == 0 )?" [ MOD ]":"" );
  239. dispbottom "========= IRC USER LIST ===========";
  240. dispbottom "Total User : "+.@size;
  241. return;
  242. }
  243.  
  244. // getarg(0) = Room
  245. // getarg(1) = Message
  246. // getarg(2) = Color
  247. // getarg(3) = Attach Target Player
  248. function IRC_Broadcast {
  249. freeloop(1);
  250. for( .@i = 0; .@i < getarraysize( getd( ".IRC_Room_"+getarg(0)+"$" ) ); .@i++ )
  251. if( attachrid( getcharid( 3,getd( ".IRC_Room_"+getarg(0)+"$["+.@i+"]" ) ) ) ){
  252. announce ( ( .DisplayTime )?"[ "+gettimestr("%H:%M",7)+" ] ":"" ) + getarg(1),bc_self,getarg(2);
  253. }
  254. freeloop(0);
  255. return attachrid( getcharid( 3,getarg(3) ) );
  256. }
  257.  
  258. // getarg(0) = Room Title
  259. // getarg(1) = Room Password if any
  260. function IRC_Create {
  261. for( .@i = 0; .@i < .MaxRoom; .@i++ )
  262. if( .IRC_Room$[.@i] == "" ){
  263. .IRC_Room$[.@i] = getarg(0);
  264. .IRC_Pass$[.@i] = getarg(1);
  265. return ( .@i + 1 );
  266. }
  267. return 0;
  268. }
  269.  
  270. // List Channel and Select
  271. function IRC_Join {
  272. for( .@i = 0; .@i < getarraysize( .IRC_Room$ ); .@i++ )
  273. 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" ) +":";
  274. do{
  275. mes "^0055FF[ S ]^000000 = ^777777Secured Room^000000";
  276. mes "^0055FF[ P ]^000000 = ^777777Public Room^000000";
  277. .@Room = select( .@Menu$ );
  278. if( getstrlen( .IRC_Pass$[(.@Room - 1)] ) >= 4 ){
  279. mes "Please enter the IRC Password.";
  280. input .@Pass$;
  281. if( .@Pass$ != .IRC_Pass$[(.@Room - 1)] ){
  282. mes "^FF0000Invalid Password^000000";
  283. next;
  284. }
  285. }
  286. }while( getstrlen( .IRC_Pass$[(.@Room - 1)] ) >= 4 && .@Pass$ != .IRC_Pass$[(.@Room - 1)] );
  287. return .@Room;
  288. }
  289.  
  290. // getarg(0) = IRC Channel
  291. // getarg(1) = Player Name
  292. function IRC_getSlot {
  293. .@size = getarraysize( getd( ".IRC_Room_"+getarg(0)+"$" ) );
  294. for( .@i = 0; .@i < .@size; .@i++ )
  295. if( getd( ".IRC_Room_"+getarg(0)+"$["+.@i+"]" ) == getarg(1) )
  296. return .@i;
  297. return -1;
  298. }
  299.  
  300. }
Advertisement
Add Comment
Please, Sign In to add comment