Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //===== eAthena Script =======================================
- //= PvP SQL Ladder
- //===== By: ==================================================
- //= HaSuKrOnOs
- //===== Current Version: =====================================
- //= 0.93
- //===== Compatible With: =====================================
- //= Tested in eAthena 14927
- //===== Description: =========================================
- //= PVP Ladder with sql table
- //===== Additional Comments: =================================
- //= It's Time to PVP GO!
- //============================================================
- prontera,164,124,4 script Party Versus Party::partyladder 483,{
- if (getgmlevel() >= 99)goto GmMenuRequest;
- goto Main;
- ///////////////////////////////////
- // ON INIT //
- // CONFIGURATION //
- ///////////////////////////////////
- OnInit:
- set $@bTableName$,"pvp_ladder_arena"; //MySQL Table Name
- set $@bMapName$,"guild_vs2"; // Map name
- set $@bReturnMapName$,"prontera"; // Return Map
- set $@bTeam1X,8; // Team 1 X Coord
- set $@bTeam1Y,50; // Team 1 Y Coord
- set $@bTeam2X,90; // Team 2 X Coord
- set $@bTeam2Y,50; // Team 2 Y Coord
- set $@bReturnMapX,89; // Return map X Coord
- set $@bReturnMapY,86; // Return map Y Coord
- set $@bTeam1XLimit,13; // Limit that team 1 can't go before the match starts
- set $@bTeam2XLimit,86; // Limit that team 2 can't go before the match starts
- set $@bQParty,2; // Quantity of players by party
- set $@bPointsWins,1; // Point by game win
- set $@bPointsLose,1; // Point by game lose
- set .NpcName$,"[ "+$@bQParty+"v"+$@bQParty+" Ladder Announcer ]"; // NPC Title name
- set $@bSQL_Enable,1; // Enable SQL Database
- //DONT EDIT THIS!!
- set $@bTableName$,escape_sql($@bTableName$); // Escape Table name
- OnResetNpc:
- set $@bMatchStatus,0; // 0: Wating, 1: Match in progress
- set $@bTeam1,0; // Team Variable, stores the party id of Team1
- set $@bTeam2,0; // Team Variable, stores the party id of Team2
- set $@bScore1,0; // Team 1 Score
- set $@bScore2,0; // Team 2 Score
- set $@bCounter,0; // Countdown variable
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // GM MENU //
- ///////////////////////////////////
- GmMenuRequest:
- mes "SELECT OPTION:";
- menu "Config Database",OnCreateDatabase,"Normal Menu",Main;
- end;
- //Creando base de datos
- OnCreateDatabase:
- 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`));");
- 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);");
- mes "The database tables has been created.";
- close;
- end;
- ///////////////////////////////////
- // MAIN //
- ///////////////////////////////////
- Main:
- //CHECKING MATCH IN PROGRESS
- if($@bMatchStatus)goto OnMatchInProgress;
- //CHECKING PARTY LEADER
- if(getpartyleader(getcharid(1),2) != getcharid(0))goto OnPartyLeaderError;
- //CHECKING INSCRIPTION
- if($@bTeam1==getcharid(1) || $@bTeam2==getcharid(1))goto OnAlreadySign;
- //NPC MENU SAY
- mes .NpcName$;
- mes "Welcome to "+$@bQParty+"vs"+$@bQParty+" Ladder";
- mes "---------Team Signed--------";
- if(!$@bTeam1 && !$@bTeam2) mes "No team has already signed.";
- else{
- if($@bTeam1) mes "^0066FF- "+getpartyname($@bTeam1);
- if($@bTeam2) mes "^CC0000- "+getpartyname($@bTeam2);
- }
- mes "^000000-----------------------------------";
- mes "You want to sign up?";
- if (select("Yes,sign me in.:No, exit")!=1) goto OnSelectNo;
- //CHECK DUPLICATE JOBS
- if ( callfunc("party_has_duplicate_job") ) {
- mes "It seems that someone in the party has the same class than another member. Please check again the requirements...";
- close;
- end;
- }
- //CHECKING PARTY MEMBERS COUNT
- getpartymember(getcharid(1));
- set @partymembercount,$@partymembercount;
- copyarray @partymembername$[0],$@partymembername$[0],$@bQParty;
- if(@partymembercount!=$@bQParty)goto OnPartyQError;
- //CHECKING ALL MEMBERS ONLINE
- getpartymember(getcharid(1)),1;
- getpartymember(getcharid(1)),2;
- copyarray @partymembercid[0],$@partymembercid[0],$@bQParty;
- copyarray @partymemberaid[0],$@partymemberaid[0],$@bQParty;
- for(set .@i,0; .@i<$@members; set .@i,.@i+1){
- if(!isloggedin($@partymemberaid[.@i],$@partymembercid[.@i])) goto OnNoAllOnlineError;
- }
- //INSCRIBIR EQUIPO
- if(!$@bTeam1){
- set $@bTeam1,getcharid(1);
- copyarray $@bParty1MemberCharId[0],@partymembercid[0],$@bQParty;
- copyarray $@bParty1MemberName$[0],@partymembername$[0],$@bQParty;
- }
- else if(!$@bTeam2){
- set $@bTeam2,getcharid(1);
- copyarray $@bParty2MemberCharId[0],@partymembercid[0],$@bQParty;
- copyarray $@bParty2MemberName$[0],@partymembername$[0],$@bQParty;
- }
- else goto OnLateSignUp;
- if(!$@bTeam1 || !$@bTeam2)goto OnPleaseWait;
- else goto OnMatchStart;
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // MATCH START //
- ///////////////////////////////////
- OnMatchStart:
- set $@bMatchStatus,1;
- warpparty $@bMapName$,$@bTeam1X,$@bTeam1Y,$@bTeam1;
- warpparty $@bMapName$,$@bTeam2X,$@bTeam2Y,$@bTeam2;
- initnpctimer 0;
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // TIMERS //
- ///////////////////////////////////
- OnTimer1000:
- if($@bMatchStatus==1){
- //CHECK USERS TEAM 1
- for(set .@i,0; .@i<$@bQParty; set .@i,.@i+1) {
- if (getmapxy(.@mapname$,.@mapx,.@mapy,0,$@bParty1MemberName$[.@i])==0){
- if(.@mapname$!=$@bMapName$ || .@mapx>$@bTeam1XLimit) warpchar $@bMapName$,$@bTeam1X,$@bTeam1Y,$@bParty1MemberCharId[.@i];
- }
- }
- //CHECK USERS TEAM 2
- for(set .@i,0; .@i<$@bQParty; set .@i,.@i+1) {
- if (getmapxy(.@mapname$,.@mapx,.@mapy,0,$@bParty2MemberName$[.@i])==0){
- if(.@mapname$!=$@bMapName$ || .@mapx<$@bTeam2XLimit) warpchar $@bMapName$,$@bTeam2X,$@bTeam2Y,$@bParty2MemberCharId[.@i];
- }
- }
- set $@bCounter,$@bCounter+1;
- if($@bCounter>=20)mapannounce $@bMapName$,"Start in "+(30-$@bCounter),bc_blue;
- if($@bCounter>=30){
- set $@bMatchStatus,2;
- mapannounce $@bMapName$,"Game Start!!",bc_blue;
- //GET SCORE 1
- for(set .@i,0; .@i<$@bQParty; set .@i,.@i+1) {
- if (getmapxy(.@mapname$,.@mapx,.@mapy,0,$@bParty1MemberName$[.@i])==0){
- if(.@mapname$==$@bMapName$) set $@bScore1,$@bScore1+1;
- }
- }
- //GET SCORE 2
- for(set .@i,0; .@i<$@bQParty; set .@i,.@i+1) {
- if (getmapxy(.@mapname$,.@mapx,.@mapy,0,$@bParty2MemberName$[.@i])==0){
- if(.@mapname$==$@bMapName$) set $@bScore2,$@bScore2+1;
- }
- }
- if(!$@bScore1 || !$@bScore2) goto onMatchEnd;
- }
- stopnpctimer;
- initnpctimer 0;
- }
- end;
- OnTimer100000:
- mapannounce $@bMapName$,getpartyname($@bTeam1)+" "+$@bScore1+" - "+$@bScore2+" "+getpartyname($@bTeam2),bc_blue;
- end;
- OnTimer300000:
- mapannounce $@bMapName$,"Times Up!!!",bc_blue;
- goto onMatchEnd;
- end;
- ///////////////////////////////////
- // ON DIE //
- ///////////////////////////////////
- OnPCDieEvent:
- OnPCLogoutEvent:
- if($@bMatchStatus==2){
- if($@bTeam1==getcharid(1))set $@bScore1,$@bScore1-1;
- if($@bTeam2==getcharid(1))set $@bScore2,$@bScore2-1;
- if(!$@bScore1 || !$@bScore2) goto onMatchEnd;
- mapannounce $@bMapName$,getpartyname($@bTeam1)+" "+$@bScore1+" - "+$@bScore2+" "+getpartyname($@bTeam2),bc_blue;
- }
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // MATCH END //
- ///////////////////////////////////
- OnMatchEnd:
- mapannounce $@bMapName$,"Game End",bc_blue;
- mapannounce $@bMapName$,getpartyname($@bTeam1)+" "+$@bScore1+" - "+$@bScore2+" "+getpartyname($@bTeam2),bc_blue;
- mapwarp $@bMapName$,$@bReturnMapName$,$@bReturnMapX,$@bReturnMapY;
- if($@bSQL_Enable && ($@bScore1!=$@bScore2)) goto SqlProcess;
- OnMatchEndContinue:
- goto OnResetNpc;
- end;
- //|||||||||||||||||||||||||||||||//
- //:::::::::::ERRORS::::::::::://
- ///////////////////////////////////
- // MATCH IN PROGRESS //
- ///////////////////////////////////
- OnMatchInProgress:
- mes .NpcName$;
- mes "A game is in progress.";
- mes "Please wait the game end to sign up.";
- close;
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // PARTY PLAYERS ERROR //
- ///////////////////////////////////
- OnPartyQError:
- mes .NpcName$;
- mes "You need "+$@bQParty+" players to play.";
- mes "Please organize your team.";
- close;
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // PARTY LEADER ERROR //
- ///////////////////////////////////
- OnPartyLeaderError:
- mes .NpcName$;
- mes "Hey! you are not the leader.";
- mes "Only leaders can talk with me.";
- close;
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // NO ALL ONLINE //
- ///////////////////////////////////
- OnNoAllOnlineError:
- mes .NpcName$;
- mes "You are not signed up.";
- mes "All yours teammates need be online";
- close;
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // NO INSCRIBIR //
- ///////////////////////////////////
- OnSelectNo:
- mes "We'll be waiting for you.";
- close;
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // SIGN UP TOO LATE //
- ///////////////////////////////////
- OnLateSignUp:
- mes "All teams are ready.";
- mes "You need to be quick with your decisions.";
- close;
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // PLEASE WAIT //
- ///////////////////////////////////
- OnPleaseWait:
- mes "Your team has sign up.";
- mes "your team has already been registered.";
- close;
- end;
- //|||||||||||||||||||||||||||||||//
- ///////////////////////////////////
- // ALREADY SIGN //
- ///////////////////////////////////
- OnAlreadySign:
- mes "You are already sign up.";
- close;
- end;
- OnWhisperGlobal:
- set @input$,@whispervar0$;
- //debugmes "Input : " + @input$;
- if(@input$=="topten"){
- //debugmes "Prueba";
- set .@TheSqlQuery$,"SELECT charname0,charname1,charname2,charname3,charname4,charname5,charname6,points FROM "+$@bTableName$+" ORDER BY points DESC";
- set .@nb, query_sql(.@TheSqlQuery$,.@charname0$,.@charname1$,.@charname2$,.@charname3$,.@charname4$,.@charname5$,.@charname6$,.@points);
- 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];
- }//else debugmes "No entro";
- end;
- ///////////////////////////////////
- // SQL PROCESS //
- ///////////////////////////////////
- SqlProcess:
- //SELECT CHAR_ID SORTED
- set .@TheSqlQuery$,"SELECT char_id,name FROM `char` WHERE ";
- set .@TheSqlQuery$,.@TheSqlQuery$+"char_id = "+(($@Score1>$@Score2)?$@bParty1MemberCharId[0]:$@bParty2MemberCharId[0])+" ";
- for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1) set .@TheSqlQuery$,.@TheSqlQuery$+"OR char_id = "+(($@Score1>$@Score2)?$@bParty1MemberCharId[.@i]:$@bParty2MemberCharId[.@i])+" ";
- set .@TheSqlQuery$,.@TheSqlQuery$+"ORDER BY char_id ASC";
- //announce .@TheSqlQuery$,bc_all,0x00FF00; //DEBUG
- set .@nb, query_sql(.@TheSqlQuery$,.@TheCharId,.@TheCharName$);
- //announce "Cantidad de jugadores encontrados: "+.@nb,bc_all,0x00FF00; //DEBUG
- //CHECK IF PARTY EXISTS
- CheckPartyExists:
- set .@TheSqlQuery$,"SELECT id FROM "+$@bTableName$+" WHERE";
- set .@WhereQuery$," char0 = "+.@TheCharId[0]+" ";
- for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1) set .@WhereQuery$,.@WhereQuery$+"AND char"+.@i+" = "+.@TheCharId[.@i]+" ";
- //announce .@TheSqlQuery$+.@WhereQuery$,bc_all,0x00FF00; //DEBUG
- set .@nb, query_sql(.@TheSqlQuery$+.@WhereQuery$,.@ThePartyLadderId);
- //IF PARTY NOT EXISTS
- if(!.@nb){
- set .@TheSqlQuery$,"INSERT INTO "+$@bTableName$;
- set .@TheFields$," (char0,charname0";
- set .@TheValues$," VALUES("+.@TheCharId[0]+",'"+escape_sql(.@TheCharName$[0])+"'";
- for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1){
- set .@TheFields$,.@TheFields$+",char"+.@i+",charname"+.@i;
- set .@TheValues$,.@TheValues$+","+.@TheCharId[.@i]+",'"+escape_sql(.@TheCharName$[.@i])+"'";
- }
- set .@TheFields$,.@TheFields$+")";
- set .@TheValues$,.@TheValues$+")";
- //announce .@TheSqlQuery$+.@TheFields$+.@TheValues$,bc_all,0x00FF00; //DEBUG
- query_sql(.@TheSqlQuery$+.@TheFields$+.@TheValues$);
- goto CheckPartyExists;
- }
- query_sql("UPDATE "+$@bTableName$+" SET points = (points + "+$@bPointsWins+"), games_played = (games_played +1), games_wins = (games_wins + 1) WHERE id = "+.@ThePartyLadderId[0]);
- //SELECT CHAR_ID SORTED
- set .@TheSqlQuery$,"SELECT char_id,name FROM `char` WHERE ";
- set .@TheSqlQuery$,.@TheSqlQuery$+"char_id = "+(($@Score1>$@Score2)?$@bParty2MemberCharId[0]:$@bParty1MemberCharId[0])+" ";
- for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1) set .@TheSqlQuery$,.@TheSqlQuery$+"OR char_id = "+(($@Score1>$@Score2)?$@bParty2MemberCharId[.@i]:$@bParty1MemberCharId[.@i])+" ";
- set .@TheSqlQuery$,.@TheSqlQuery$+"ORDER BY char_id ASC";
- //announce .@TheSqlQuery$,bc_all,0x00FF00; //DEBUG
- set .@nb, query_sql(.@TheSqlQuery$,.@TheCharId,.@TheCharName$);
- //announce "Cantidad de jugadores encontrados: "+.@nb,bc_all,0x00FF00; //DEBUG
- //CHECK IF PARTY EXISTS
- CheckPartyExists2:
- set .@TheSqlQuery$,"SELECT id FROM "+$@bTableName$+" WHERE";
- set .@WhereQuery$," char0 = "+.@TheCharId[0]+" ";
- for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1) set .@WhereQuery$,.@WhereQuery$+"AND char"+.@i+" = "+.@TheCharId[.@i]+" ";
- //announce .@TheSqlQuery$+.@WhereQuery$,bc_all,0x00FF00; //DEBUG
- set .@nb, query_sql(.@TheSqlQuery$+.@WhereQuery$,.@ThePartyLadderId2);
- //IF PARTY NOT EXISTS
- if(!.@nb){
- set .@TheSqlQuery$,"INSERT INTO "+$@bTableName$;
- set .@TheFields$," (char0,charname0";
- set .@TheValues$," VALUES("+.@TheCharId[0]+",'"+escape_sql(.@TheCharName$[0])+"'";
- for(set .@i,1; .@i<$@bQParty; set .@i,.@i+1){
- set .@TheFields$,.@TheFields$+",char"+.@i+",charname"+.@i;
- set .@TheValues$,.@TheValues$+","+.@TheCharId[.@i]+",'"+escape_sql(.@TheCharName$[.@i])+"'";
- }
- set .@TheFields$,.@TheFields$+")";
- set .@TheValues$,.@TheValues$+")";
- //announce .@TheSqlQuery$+.@TheFields$+.@TheValues$,bc_all,0x00FF00; //DEBUG
- query_sql(.@TheSqlQuery$+.@TheFields$+.@TheValues$);
- goto CheckPartyExists2;
- }
- query_sql("UPDATE "+$@bTableName$+" SET points = (points - "+$@bPointsLose+"), games_played = (games_played +1), games_lost = (games_lost + 1) WHERE id = "+.@ThePartyLadderId2[0]);
- query_sql("INSERT INTO "+$@bTableName$+"_log (id_winner,id_loser) VALUES("+.@ThePartyLadderId[0]+","+.@ThePartyLadderId2[0]+")");
- goto OnMatchEndContinue;
- end;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement