Advertisement
Guest User

Untitled

a guest
Mar 18th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.79 KB | None | 0 0
  1. //===== eAthena Script =======================================
  2. //= PvP SQL Ladder
  3. //===== By: ==================================================
  4. //= HaSuKrOnOs
  5. //===== Current Version: =====================================
  6. //= 0.93
  7. //===== Compatible With: =====================================
  8. //= Tested in eAthena 14927
  9. //===== Description: =========================================
  10. //= PVP Ladder with sql table
  11. //===== Additional Comments: =================================
  12. //= It's Time to PVP GO!
  13. //============================================================
  14.  
  15. prontera,164,124,4 script Party Versus Party::partyladder 483,{
  16. if (getgmlevel() >= 99)goto GmMenuRequest;
  17. goto Main;
  18.  
  19.  
  20. ///////////////////////////////////
  21. // ON INIT //
  22. // CONFIGURATION //
  23. ///////////////////////////////////
  24. OnInit:
  25.  
  26. set $@bTableName$,"pvp_ladder_arena"; //MySQL Table Name
  27. set $@bMapName$,"guild_vs2"; // Map name
  28. set $@bReturnMapName$,"prontera"; // Return Map
  29. set $@bTeam1X,8; // Team 1 X Coord
  30. set $@bTeam1Y,50; // Team 1 Y Coord
  31. set $@bTeam2X,90; // Team 2 X Coord
  32. set $@bTeam2Y,50; // Team 2 Y Coord
  33. set $@bReturnMapX,89; // Return map X Coord
  34. set $@bReturnMapY,86; // Return map Y Coord
  35. set $@bTeam1XLimit,13; // Limit that team 1 can't go before the match starts
  36. set $@bTeam2XLimit,86; // Limit that team 2 can't go before the match starts
  37. set $@bQParty,2; // Quantity of players by party
  38. set $@bPointsWins,1; // Point by game win
  39. set $@bPointsLose,1; // Point by game lose
  40. set .NpcName$,"[ "+$@bQParty+"v"+$@bQParty+" Ladder Announcer ]"; // NPC Title name
  41. set $@bSQL_Enable,1; // Enable SQL Database
  42.  
  43.  
  44. //DONT EDIT THIS!!
  45. set $@bTableName$,escape_sql($@bTableName$); // Escape Table name
  46. OnResetNpc:
  47. set $@bMatchStatus,0; // 0: Wating, 1: Match in progress
  48. set $@bTeam1,0; // Team Variable, stores the party id of Team1
  49. set $@bTeam2,0; // Team Variable, stores the party id of Team2
  50. set $@bScore1,0; // Team 1 Score
  51. set $@bScore2,0; // Team 2 Score
  52. set $@bCounter,0; // Countdown variable
  53. end;
  54.  
  55. //|||||||||||||||||||||||||||||||//
  56.  
  57. ///////////////////////////////////
  58. // GM MENU //
  59. ///////////////////////////////////
  60. GmMenuRequest:
  61. mes "SELECT OPTION:";
  62. menu "Config Database",OnCreateDatabase,"Normal Menu",Main;
  63. end;
  64.  
  65. //Creando base de datos
  66. OnCreateDatabase:
  67. query_sql("CREATE TABLE IF NOT EXISTS `"+$@bTableName$+"` (`id` int(100) NOT NULL AUTO_INCREMENT,`char0` int(11) NOT NULL,`char1` int(11) NOT NULL,`char2` int(11) NOT NULL,`char3` int(11) NOT NULL,`char4` int(11) NOT NULL,`char5` int(11) NOT NULL,`char6` int(11) NOT NULL,`charname0` varchar(30) NOT NULL,`charname1` varchar(30) NOT NULL,`charname2` varchar(30) NOT NULL,`charname3` varchar(30) NOT NULL,`charname4` varchar(30) NOT NULL,`charname5` varchar(30) NOT NULL,`charname6` varchar(30) NOT NULL,`points` int(5) NOT NULL,`games_played` int(5) NOT NULL DEFAULT '0',`games_wins` int(5) NOT NULL DEFAULT '0',`games_lost` int(5) NOT NULL DEFAULT '0',PRIMARY KEY (`id`));");
  68. query_sql("CREATE TABLE IF NOT EXISTS `"+$@bTableName$+"_log` (`id` INT( 255 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`id_winner` INT( 11 ) NOT NULL ,`id_loser` INT( 11 ) NOT NULL ,`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);");
  69. mes "The database tables has been created.";
  70. close;
  71. end;
  72. ///////////////////////////////////
  73. // MAIN //
  74. ///////////////////////////////////
  75. Main:
  76. //CHECKING MATCH IN PROGRESS
  77. if($@bMatchStatus)goto OnMatchInProgress;
  78.  
  79. //CHECKING PARTY LEADER
  80. if(getpartyleader(getcharid(1),2) != getcharid(0))goto OnPartyLeaderError;
  81.  
  82. //CHECKING INSCRIPTION
  83. if($@bTeam1==getcharid(1) || $@bTeam2==getcharid(1))goto OnAlreadySign;
  84. //NPC MENU SAY
  85. mes .NpcName$;
  86. mes "Welcome to "+$@bQParty+"vs"+$@bQParty+" Ladder";
  87. mes "---------Team Signed--------";
  88. if(!$@bTeam1 && !$@bTeam2) mes "No team has already signed.";
  89. else{
  90. if($@bTeam1) mes "^0066FF- "+getpartyname($@bTeam1);
  91. if($@bTeam2) mes "^CC0000- "+getpartyname($@bTeam2);
  92. }
  93. mes "^000000-----------------------------------";
  94. mes "You want to sign up?";
  95. if (select("Yes,sign me in.:No, exit")!=1) goto OnSelectNo;
  96. //CHECK DUPLICATE JOBS
  97. if ( callfunc("party_has_duplicate_job") ) {
  98. mes "It seems that someone in the party has the same class than another member. Please check again the requirements...";
  99. close;
  100. end;
  101. }
  102. //CHECKING PARTY MEMBERS COUNT
  103. getpartymember(getcharid(1));
  104. set @partymembercount,$@partymembercount;
  105. copyarray @partymembername$[0],$@partymembername$[0],$@bQParty;
  106. if(@partymembercount!=$@bQParty)goto OnPartyQError;
  107.  
  108. //CHECKING ALL MEMBERS ONLINE
  109. getpartymember(getcharid(1)),1;
  110. getpartymember(getcharid(1)),2;
  111. copyarray @partymembercid[0],$@partymembercid[0],$@bQParty;
  112. copyarray @partymemberaid[0],$@partymemberaid[0],$@bQParty;
  113.  
  114. for(set .@i,0; .@i<$@members; set .@i,.@i+1){
  115. if(!isloggedin($@partymemberaid[.@i],$@partymembercid[.@i])) goto OnNoAllOnlineError;
  116. }
  117.  
  118. //INSCRIBIR EQUIPO
  119.  
  120. if(!$@bTeam1){
  121. set $@bTeam1,getcharid(1);
  122. copyarray $@bParty1MemberCharId[0],@partymembercid[0],$@bQParty;
  123. copyarray $@bParty1MemberName$[0],@partymembername$[0],$@bQParty;
  124. }
  125. else if(!$@bTeam2){
  126. set $@bTeam2,getcharid(1);
  127. copyarray $@bParty2MemberCharId[0],@partymembercid[0],$@bQParty;
  128. copyarray $@bParty2MemberName$[0],@partymembername$[0],$@bQParty;
  129. }
  130. else goto OnLateSignUp;
  131.  
  132. if(!$@bTeam1 || !$@bTeam2)goto OnPleaseWait;
  133. else goto OnMatchStart;
  134.  
  135. end;
  136. //|||||||||||||||||||||||||||||||//
  137.  
  138.  
  139. ///////////////////////////////////
  140. // MATCH START //
  141. ///////////////////////////////////
  142. OnMatchStart:
  143. set $@bMatchStatus,1;
  144. warpparty $@bMapName$,$@bTeam1X,$@bTeam1Y,$@bTeam1;
  145. warpparty $@bMapName$,$@bTeam2X,$@bTeam2Y,$@bTeam2;
  146. initnpctimer 0;
  147. end;
  148. //|||||||||||||||||||||||||||||||//
  149.  
  150. ///////////////////////////////////
  151. // TIMERS //
  152. ///////////////////////////////////
  153.  
  154. OnTimer1000:
  155. if($@bMatchStatus==1){
  156. //CHECK USERS TEAM 1
  157. for(set .@i,0; .@i<$@bQParty; set .@i,.@i+1) {
  158. if (getmapxy(.@mapname$,.@mapx,.@mapy,0,$@bParty1MemberName$[.@i])==0){
  159. if(.@mapname$!=$@bMapName$ || .@mapx>$@bTeam1XLimit) warpchar $@bMapName$,$@bTeam1X,$@bTeam1Y,$@bParty1MemberCharId[.@i];
  160. }
  161. }
  162. //CHECK USERS TEAM 2
  163. for(set .@i,0; .@i<$@bQParty; set .@i,.@i+1) {
  164. if (getmapxy(.@mapname$,.@mapx,.@mapy,0,$@bParty2MemberName$[.@i])==0){
  165. if(.@mapname$!=$@bMapName$ || .@mapx<$@bTeam2XLimit) warpchar $@bMapName$,$@bTeam2X,$@bTeam2Y,$@bParty2MemberCharId[.@i];
  166. }
  167. }
  168.  
  169. set $@bCounter,$@bCounter+1;
  170. if($@bCounter>=20)mapannounce $@bMapName$,"Start in "+(30-$@bCounter),bc_blue;
  171. if($@bCounter>=30){
  172. set $@bMatchStatus,2;
  173. mapannounce $@bMapName$,"Game Start!!",bc_blue;
  174.  
  175. //GET SCORE 1
  176. for(set .@i,0; .@i<$@bQParty; set .@i,.@i+1) {
  177. if (getmapxy(.@mapname$,.@mapx,.@mapy,0,$@bParty1MemberName$[.@i])==0){
  178. if(.@mapname$==$@bMapName$) set $@bScore1,$@bScore1+1;
  179. }
  180. }
  181. //GET SCORE 2
  182. for(set .@i,0; .@i<$@bQParty; set .@i,.@i+1) {
  183. if (getmapxy(.@mapname$,.@mapx,.@mapy,0,$@bParty2MemberName$[.@i])==0){
  184. if(.@mapname$==$@bMapName$) set $@bScore2,$@bScore2+1;
  185. }
  186. }
  187.  
  188. if(!$@bScore1 || !$@bScore2) goto onMatchEnd;
  189. }
  190.  
  191. stopnpctimer;
  192. initnpctimer 0;
  193. }
  194. end;
  195.  
  196. OnTimer100000:
  197. mapannounce $@bMapName$,getpartyname($@bTeam1)+" "+$@bScore1+" - "+$@bScore2+" "+getpartyname($@bTeam2),bc_blue;
  198. end;
  199. OnTimer300000:
  200. mapannounce $@bMapName$,"Times Up!!!",bc_blue;
  201. goto onMatchEnd;
  202. end;
  203. ///////////////////////////////////
  204. // ON DIE //
  205. ///////////////////////////////////
  206. OnPCDieEvent:
  207. OnPCLogoutEvent:
  208. if($@bMatchStatus==2){
  209. if($@bTeam1==getcharid(1))set $@bScore1,$@bScore1-1;
  210. if($@bTeam2==getcharid(1))set $@bScore2,$@bScore2-1;
  211. if(!$@bScore1 || !$@bScore2) goto onMatchEnd;
  212. mapannounce $@bMapName$,getpartyname($@bTeam1)+" "+$@bScore1+" - "+$@bScore2+" "+getpartyname($@bTeam2),bc_blue;
  213. }
  214. end;
  215. //|||||||||||||||||||||||||||||||//
  216.  
  217. ///////////////////////////////////
  218. // MATCH END //
  219. ///////////////////////////////////
  220. OnMatchEnd:
  221.  
  222. mapannounce $@bMapName$,"Game End",bc_blue;
  223. mapannounce $@bMapName$,getpartyname($@bTeam1)+" "+$@bScore1+" - "+$@bScore2+" "+getpartyname($@bTeam2),bc_blue;
  224.  
  225. mapwarp $@bMapName$,$@bReturnMapName$,$@bReturnMapX,$@bReturnMapY;
  226.  
  227. if($@bSQL_Enable && ($@bScore1!=$@bScore2)) goto SqlProcess;
  228.  
  229. OnMatchEndContinue:
  230.  
  231. goto OnResetNpc;
  232.  
  233. end;
  234. //|||||||||||||||||||||||||||||||//
  235.  
  236.  
  237.  
  238. //:::::::::::ERRORS::::::::::://
  239.  
  240. ///////////////////////////////////
  241. // MATCH IN PROGRESS //
  242. ///////////////////////////////////
  243. OnMatchInProgress:
  244. mes .NpcName$;
  245. mes "A game is in progress.";
  246. mes "Please wait the game end to sign up.";
  247. close;
  248. end;
  249. //|||||||||||||||||||||||||||||||//
  250.  
  251.  
  252. ///////////////////////////////////
  253. // PARTY PLAYERS ERROR //
  254. ///////////////////////////////////
  255. OnPartyQError:
  256. mes .NpcName$;
  257. mes "You need "+$@bQParty+" players to play.";
  258. mes "Please organize your team.";
  259. close;
  260. end;
  261. //|||||||||||||||||||||||||||||||//
  262.  
  263.  
  264. ///////////////////////////////////
  265. // PARTY LEADER ERROR //
  266. ///////////////////////////////////
  267. OnPartyLeaderError:
  268. mes .NpcName$;
  269. mes "Hey! you are not the leader.";
  270. mes "Only leaders can talk with me.";
  271. close;
  272. end;
  273. //|||||||||||||||||||||||||||||||//
  274.  
  275.  
  276. ///////////////////////////////////
  277. // NO ALL ONLINE //
  278. ///////////////////////////////////
  279. OnNoAllOnlineError:
  280. mes .NpcName$;
  281. mes "You are not signed up.";
  282. mes "All yours teammates need be online";
  283. close;
  284. end;
  285. //|||||||||||||||||||||||||||||||//
  286.  
  287.  
  288. ///////////////////////////////////
  289. // NO INSCRIBIR //
  290. ///////////////////////////////////
  291. OnSelectNo:
  292. mes "We'll be waiting for you.";
  293. close;
  294. end;
  295. //|||||||||||||||||||||||||||||||//
  296.  
  297. ///////////////////////////////////
  298. // SIGN UP TOO LATE //
  299. ///////////////////////////////////
  300. OnLateSignUp:
  301. mes "All teams are ready.";
  302. mes "You need to be quick with your decisions.";
  303. close;
  304. end;
  305. //|||||||||||||||||||||||||||||||//
  306.  
  307. ///////////////////////////////////
  308. // PLEASE WAIT //
  309. ///////////////////////////////////
  310. OnPleaseWait:
  311. mes "Your team has sign up.";
  312. mes "your team has already been registered.";
  313. close;
  314. end;
  315. //|||||||||||||||||||||||||||||||//
  316.  
  317.  
  318. ///////////////////////////////////
  319. // ALREADY SIGN //
  320. ///////////////////////////////////
  321.  
  322. OnAlreadySign:
  323. mes "You are already sign up.";
  324. close;
  325. end;
  326.  
  327. OnWhisperGlobal:
  328. set @input$,@whispervar0$;
  329. //debugmes "Input : " + @input$;
  330. if(@input$=="topten"){
  331. //debugmes "Prueba";
  332. set .@TheSqlQuery$,"SELECT charname0,charname1,charname2,charname3,charname4,charname5,charname6,points FROM "+$@bTableName$+" ORDER BY points DESC";
  333. set .@nb, query_sql(.@TheSqlQuery$,.@charname0$,.@charname1$,.@charname2$,.@charname3$,.@charname4$,.@charname5$,.@charname6$,.@points);
  334. for(set .@i,0; .@i<.@nb; set .@i,.@i+1)dispbottom (.@i+1)+" )"+.@charname0$[.@i]+" "+.@charname1$[.@i]+" "+.@charname2$[.@i]+" "+.@charname3$[.@i]+" "+.@charname4$[.@i]+" "+.@charname5$[.@i]+" "+.@charname6$[.@i]+" || Puntos: "+.@points[.@i];
  335. }//else debugmes "No entro";
  336. end;
  337.  
  338. ///////////////////////////////////
  339. // SQL PROCESS //
  340. ///////////////////////////////////
  341. SqlProcess:
  342. //SELECT CHAR_ID SORTED
  343. set .@TheSqlQuery$,"SELECT char_id,name FROM `char` WHERE ";
  344. set .@TheSqlQuery$,.@TheSqlQuery$+"char_id = "+(($@Score1>$@Score2)?$@bParty1MemberCharId[0]:$@bParty2MemberCharId[0])+" ";
  345. for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1) set .@TheSqlQuery$,.@TheSqlQuery$+"OR char_id = "+(($@Score1>$@Score2)?$@bParty1MemberCharId[.@i]:$@bParty2MemberCharId[.@i])+" ";
  346. set .@TheSqlQuery$,.@TheSqlQuery$+"ORDER BY char_id ASC";
  347. //announce .@TheSqlQuery$,bc_all,0x00FF00; //DEBUG
  348. set .@nb, query_sql(.@TheSqlQuery$,.@TheCharId,.@TheCharName$);
  349.  
  350. //announce "Cantidad de jugadores encontrados: "+.@nb,bc_all,0x00FF00; //DEBUG
  351. //CHECK IF PARTY EXISTS
  352. CheckPartyExists:
  353. set .@TheSqlQuery$,"SELECT id FROM "+$@bTableName$+" WHERE";
  354. set .@WhereQuery$," char0 = "+.@TheCharId[0]+" ";
  355. for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1) set .@WhereQuery$,.@WhereQuery$+"AND char"+.@i+" = "+.@TheCharId[.@i]+" ";
  356. //announce .@TheSqlQuery$+.@WhereQuery$,bc_all,0x00FF00; //DEBUG
  357. set .@nb, query_sql(.@TheSqlQuery$+.@WhereQuery$,.@ThePartyLadderId);
  358.  
  359. //IF PARTY NOT EXISTS
  360. if(!.@nb){
  361. set .@TheSqlQuery$,"INSERT INTO "+$@bTableName$;
  362. set .@TheFields$," (char0,charname0";
  363. set .@TheValues$," VALUES("+.@TheCharId[0]+",'"+escape_sql(.@TheCharName$[0])+"'";
  364. for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1){
  365. set .@TheFields$,.@TheFields$+",char"+.@i+",charname"+.@i;
  366. set .@TheValues$,.@TheValues$+","+.@TheCharId[.@i]+",'"+escape_sql(.@TheCharName$[.@i])+"'";
  367. }
  368. set .@TheFields$,.@TheFields$+")";
  369. set .@TheValues$,.@TheValues$+")";
  370.  
  371. //announce .@TheSqlQuery$+.@TheFields$+.@TheValues$,bc_all,0x00FF00; //DEBUG
  372.  
  373. query_sql(.@TheSqlQuery$+.@TheFields$+.@TheValues$);
  374. goto CheckPartyExists;
  375. }
  376.  
  377. query_sql("UPDATE "+$@bTableName$+" SET points = (points + "+$@bPointsWins+"), games_played = (games_played +1), games_wins = (games_wins + 1) WHERE id = "+.@ThePartyLadderId[0]);
  378.  
  379. //SELECT CHAR_ID SORTED
  380. set .@TheSqlQuery$,"SELECT char_id,name FROM `char` WHERE ";
  381. set .@TheSqlQuery$,.@TheSqlQuery$+"char_id = "+(($@Score1>$@Score2)?$@bParty2MemberCharId[0]:$@bParty1MemberCharId[0])+" ";
  382. for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1) set .@TheSqlQuery$,.@TheSqlQuery$+"OR char_id = "+(($@Score1>$@Score2)?$@bParty2MemberCharId[.@i]:$@bParty1MemberCharId[.@i])+" ";
  383. set .@TheSqlQuery$,.@TheSqlQuery$+"ORDER BY char_id ASC";
  384. //announce .@TheSqlQuery$,bc_all,0x00FF00; //DEBUG
  385. set .@nb, query_sql(.@TheSqlQuery$,.@TheCharId,.@TheCharName$);
  386.  
  387. //announce "Cantidad de jugadores encontrados: "+.@nb,bc_all,0x00FF00; //DEBUG
  388. //CHECK IF PARTY EXISTS
  389. CheckPartyExists2:
  390. set .@TheSqlQuery$,"SELECT id FROM "+$@bTableName$+" WHERE";
  391. set .@WhereQuery$," char0 = "+.@TheCharId[0]+" ";
  392. for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1) set .@WhereQuery$,.@WhereQuery$+"AND char"+.@i+" = "+.@TheCharId[.@i]+" ";
  393. //announce .@TheSqlQuery$+.@WhereQuery$,bc_all,0x00FF00; //DEBUG
  394. set .@nb, query_sql(.@TheSqlQuery$+.@WhereQuery$,.@ThePartyLadderId2);
  395.  
  396. //IF PARTY NOT EXISTS
  397. if(!.@nb){
  398. set .@TheSqlQuery$,"INSERT INTO "+$@bTableName$;
  399. set .@TheFields$," (char0,charname0";
  400. set .@TheValues$," VALUES("+.@TheCharId[0]+",'"+escape_sql(.@TheCharName$[0])+"'";
  401. for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1){
  402. set .@TheFields$,.@TheFields$+",char"+.@i+",charname"+.@i;
  403. set .@TheValues$,.@TheValues$+","+.@TheCharId[.@i]+",'"+escape_sql(.@TheCharName$[.@i])+"'";
  404. }
  405. set .@TheFields$,.@TheFields$+")";
  406. set .@TheValues$,.@TheValues$+")";
  407.  
  408. //announce .@TheSqlQuery$+.@TheFields$+.@TheValues$,bc_all,0x00FF00; //DEBUG
  409.  
  410. query_sql(.@TheSqlQuery$+.@TheFields$+.@TheValues$);
  411. goto CheckPartyExists2;
  412. }
  413.  
  414. query_sql("UPDATE "+$@bTableName$+" SET points = (points - "+$@bPointsLose+"), games_played = (games_played +1), games_lost = (games_lost + 1) WHERE id = "+.@ThePartyLadderId2[0]);
  415.  
  416. query_sql("INSERT INTO "+$@bTableName$+"_log (id_winner,id_loser) VALUES("+.@ThePartyLadderId[0]+","+.@ThePartyLadderId2[0]+")");
  417.  
  418. goto OnMatchEndContinue;
  419. end;
  420. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement