Advertisement
johnlol

PvP Recruiter v1.6

May 27th, 2019
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 13.99 KB | None | 0 0
  1. // ------------------------------------------------------------------------------------------
  2. // ------ rAthena Script Release
  3. // Title: PvP [4v4] Rewrite
  4. // Author: jezznar
  5. // Version: 1.0 Jezznar
  6. //      - Initial Release
  7. // Version: 1.1 PandaLovesHamster
  8. //      - Player Logoff Detection
  9. //      - Team change on recruitment stage
  10. // Version: 1.2 Jezznar
  11. //      - Renamed to "PvP Recruiter"
  12. //      - Changed @4v4 to @pvprecruitment
  13. //      - Added flexibility on number of parcipants (set .NumPlayers)
  14. //      - Fixed and improved free slot checking algorithm
  15. //      - Fixed and improved registration checking and team transfer algorithm
  16. //      - Added Player Variable @MyTeam for easier checkings:
  17. //          [0] Team number ( 0 for No Team Yet | 1 for Odin | 2 for Freya)
  18. //          [1] Slot number of his team
  19. //      - Fixed Clear event
  20. //      - Fixed Menu not closing on registration
  21. //      - Added a variable to indicate if the session is on-going (set .started)
  22. //      - Check if the event is already running when player begins to talk to the npc
  23. // Version: 1.3 Jezznar
  24. //      - Quick fix for event not being able to function correctly
  25. //      - Optimized OnEventStart algorithm
  26. //      - Optimized and Improved Logged in/Logged Off Checking
  27. //      - Takes off logged off players from the roster instead of resetting the whole recruitment process
  28. //      - Took off OnFailLack
  29. //      - Added OnPCLoginEvent and OnPCLogoutEvent
  30. //      - Added GM Safe failcheck
  31. // Version: 1.4 Jezznar
  32. //      - Thoroughly fixed a lot of logical and symmantic errors
  33. //      - Optimized a lot of codes
  34. //      - Fixed a lot of exploits and bugs
  35. //      - Made it functionally working
  36. //      - Demo video uploaded [posting soon]
  37. // Version: 1.5 Jezznar
  38. //      - Will be tagged as stable if noone complains about any bug
  39. //      - Fixed the "fatal error: player not attached problem" caused by @MyTeam
  40. //      - Participant will be taken as a casualty if he logs out when the session is on-going
  41. //      - Added mapflags and can be modified through .@mapflags
  42. //      - Tested without errors, bugs, and exploits.
  43. // Version: 1.6 Jezznar [Will be tagged as stable if noone complains about anything]
  44. //      - Changed Line up view to PlayerName instead of CharID
  45. // Search for "getitem" to change rewards and their quantity
  46. // ------------------------------------------------------------------------------------------
  47. prontera,147,149,6  script  PvP Recruiter   416,{
  48. function CheckSessionProgress;
  49. set .@n$,"[^FF0000Party Battle Recruiter^000000]";
  50. set .@charid,getcharid(0);
  51. set .@rid,getcharid(3);
  52. mes .@n$;
  53. mes "Your Charname:"+rid2name(.@rid);
  54. mes "==============================";
  55. mes "Current Line up";
  56. mes "==============================";
  57. if ($OdinR[.@x] == 0 && $FreyaR[.@x] == 0)
  58.         mes "None Yet.";
  59. else
  60.     for(set .@x,0; .@x < .NumPlayers; set .@x, .@x + 1)
  61.         if ($OdinR[.@x] != 0 || $FreyaR[.@x] != 0)
  62.             mes "Odin: "+($OdinR[.@x]==0?" Free ":rid2name($OdinR[.@x]))+" | Freya: "+($FreyaR[.@x]==0?" Free ":rid2name($FreyaR[.@x]));
  63.    
  64.  
  65. next;
  66.  
  67.  
  68. if (getmapusers("guild_vs3") > 0 || .started == 1) { // Check if there is an on-going session
  69.     mes .@n$;
  70.     mes "There appears to be a match currently in session. Check back momentarily.";
  71.     close;
  72. }
  73.  
  74. //Check for free slots
  75. set .free, 0;
  76. for (set .@x, 0; .@x < .NumPlayers && .free == 0 ; set .@x, .@x + 1){
  77.     if ($Odin[.@x] == 0){
  78.         set .free, 1;
  79.     } else if ($Freya[.@x] == 0){
  80.         set .free, 1;
  81.     }
  82. }
  83.    
  84.    
  85. // if (getarraysize($Odin) >= .NumPlayers && getarraysize($Freya) >= .NumPlayers) {
  86. if (!.free){
  87.     mes .@n$;
  88.     mes "Sorry, there are no slots available right now. Please come back again later.";
  89.     close;
  90. }
  91. // }
  92.  
  93.  
  94.  
  95. //Check if character is already registered
  96. set .@registered, 0;
  97. for (set .@x, 0; .@x < .NumPlayers && .@registered == 0 ; set .@x, .@x + 1) {
  98.     if ($Odin[.@x] == .@charid){
  99.         set .@registered, 1;
  100.         set .@MyTeam$, "Odin";  //NPC temp var to contain current team
  101.     } else if ($Freya[.@x] == .@charid){
  102.         set .@registered, 1;
  103.         set .@MyTeam$, "Freya";  //NPC temp var to contain current team
  104.     }
  105. }
  106.  
  107.  
  108.  
  109. if (.@registered == 1){
  110.         set .@prev, .@x - 1;
  111.         mes .@n$;
  112.         mes "You are already registered in slot "+(.@prev+1)+" of the "+.@MyTeam$+" Team.";
  113.         mes "Do You want to transfer to the other side?";
  114.         Switch(Select("Yes:No")){
  115.             case 1:
  116.                 if (.@MyTeam$ == "Odin"){ // The guy is from the Odin Team
  117.                     //Check for possible unfilled slot
  118.                     for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1){
  119.                         if ($Freya[.@x] == 0){ // Slot found, Change team
  120.                             set .@MyTeam$, "Freya";
  121.                             cleararray $Odin[.@prev], 0, 1; // free up the slot
  122.                             cleararray $OdinR[.@prev], 0, 1; // free up the slot
  123.                             for (;.@prev < (.NumPlayers); set .@prev, .@prev+1){
  124.                                 set $Odin[.@prev], $Odin[.@prev+1];
  125.                                 set $OdinR[.@prev], $OdinR[.@prev+1];
  126.                             }
  127.                             // cleararray $Odin[.NumPlayers], 0, 1;
  128.                             // cleararray $OdinR[.NumPlayers], 0, 1;
  129.                             set $Freya[.@x], .@charid; // set free slot
  130.                             set $FreyaR[.@x], .@rid; // set free slot
  131.                             npctalk strcharinfo(0)+" transferred to Freya's Side";
  132.                             //successful transfer
  133.                             mes .@n$;
  134.                             mes "You have been successfully transferred to the "+.@MyTeam$+" Team's slot #"+(.@x+1);
  135.                             close;                     
  136.                         }
  137.                     }
  138.                     mes "Sorry, The other team is full.";
  139.                     close;
  140.                    
  141.                
  142.                 } else if (.@MyTeam$ == "Freya"){ // The guy is from the Freya Team
  143.                     for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1){
  144.                         if ($Odin[.@x] == 0){ // Slot found, Change team
  145.                             set .@MyTeam$, "Odin";
  146.                             cleararray $Freya[.@prev], 0, 1; // free up the slot
  147.                             cleararray $FreyaR[.@prev], 0, 1; // free up the slot
  148.                             for (;.@prev < (.NumPlayers); set .@prev, .@prev+1){
  149.                                 set $Freya[.@prev], $Freya[.@prev+1];
  150.                                 set $FreyaR[.@prev], $FreyaR[.@prev+1];
  151.                             }  
  152.                             // cleararray $Freya[.NumPlayers], 0, 1;
  153.                             // cleararray $FreyaR[.NumPlayers], 0, 1;                          
  154.                             set $Odin[.@x], .@charid; // set slot
  155.                             set $OdinR[.@x], .@rid; // set slot
  156.                             npctalk strcharinfo(0)+" transferred to Odin's Side";
  157.                             //successful transfer
  158.                             mes .@n$;
  159.                             mes "You have been successfully transferred to the "+.@MyTeam$+" Team's slot #"+(.@x+1);
  160.                             close;                     
  161.                         }
  162.                     }
  163.                     mes "Sorry, The other team is full.";
  164.                     close;
  165.                 }      
  166.                 break;
  167.             case 2:
  168.                 mes "Alright. See You around.";
  169.                 close;
  170.                 break;         
  171.         }
  172. }
  173.  
  174. mes .@n$;
  175. mes "Would you like to register for a "+.NumPlayers+" versus "+.NumPlayers+" Party Battle?";
  176.  
  177. Switch(Select("Yes:No")) {
  178.     case 2:
  179.         mes .@n$;
  180.         mes "Alright, See you around.";
  181.         close;
  182.     default:
  183.         mes .@n$;
  184.         mes "Which side are you going to play for?";
  185.         break;
  186. }
  187.  
  188.  
  189.    
  190. switch(select("Odin ("+(getarraysize($Odin))+"/"+.NumPlayers+"):Freya ("+(getarraysize($Freya))+"/"+.NumPlayers+")")) {
  191.     case 1:
  192.         if (getarraysize($Odin) < .NumPlayers) {
  193.             if (getarraysize($Odin) == 0 && getarraysize($Freya) == 0 && .OnGMStart == 0) { // Check if he is the first one to register & not manually started by a GM
  194.                 initnpctimer;
  195.                 announce "The PvP["+.NumPlayers+"v"+.NumPlayers+"] Event has been triggered by "+strcharinfo(0)+"! Join now!",bc_all;
  196.             }
  197.             for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1){
  198.                 if ($Odin[.@x] == 0) { // Slot found, assign team
  199.                     set .@MyTeam$, "Odin";
  200.                     set $Odin[.@x], .@charid; // set slot
  201.                     set $OdinR[.@x], .@rid; // set slot
  202.                     mes "You have been successfully assigned to the "+.@MyTeam$+" Team's slot #"+(.@x+1);
  203.                     break;
  204.                 }
  205.             }
  206.         } else {
  207.             mes "This team is full.";
  208.             close;
  209.         }
  210.         break;
  211.     case 2:
  212.         if (getarraysize($Freya) < .NumPlayers) {
  213.             if (getarraysize($Odin) == 0 && getarraysize($Freya) == 0 && .OnGMStart == 0) { // Check if he is the first one to register & not manually started by a GM
  214.                 initnpctimer;
  215.                 announce "The PvP["+.NumPlayers+"v"+.NumPlayers+"] Event has been triggered by "+strcharinfo(0)+"! Join now!",bc_all;
  216.             }              
  217.             for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1){
  218.                 if ($Freya[.@x] == 0) { // Slot found, assign team
  219.                     set .@MyTeam$, "Freya";
  220.                     set $Freya[.@x], .@charid; // set slot
  221.                     set $FreyaR[.@x], .@rid; // set slot
  222.                     mes "You have been successfully assigned to the "+.@MyTeam$+" Team's slot #"+(.@x+1);
  223.                     break;
  224.                 }
  225.             }
  226.         } else {
  227.             mes "This team is full.";
  228.             close;
  229.         }
  230.         break;
  231. }
  232.  
  233.  
  234. if((getarraysize($Odin)) >= .NumPlayers && (getarraysize($Freya)) >= .NumPlayers) {  
  235.     stopnpctimer;
  236.     npctalk "Both teams have been filled. All participants currently logged in will be transferred to the arena in ten seconds.";
  237.     initnpctimer;
  238.     set .started,1;
  239.     close; 
  240. }
  241.    
  242. close;
  243. end;
  244.  
  245.  
  246. OnEventStart:
  247. // For OnPCKillEvent's Player Counter for each side
  248. set $OdinCount, getarraysize($Odin);
  249. set $FreyaCount, getarraysize($Freya);
  250.  
  251. //Check if all Players are online and take off Players who are not
  252. for(set .@x,0; .@x < (2*.NumPlayers); set .@x, .@x + 1){
  253.     if(!attachrid($FreyaR[.@x])) {
  254.         set $Freya[.@x], 0;
  255.         set $FreyaR[.@x], 0;
  256.     }
  257.     detachrid;
  258.     if(!attachrid($OdinR[.@x])) {
  259.         set $Odin[.@x], 0;
  260.         set $OdinR[.@x], 0;
  261.     }
  262.     detachrid;
  263. }
  264. //If all players are online then warp all participants to the event place - guild_vs3
  265. if (getarraysize($Odin) == .NumPlayers && getarraysize($Freya) == .NumPlayers){
  266.     for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1) {
  267.         warpchar "guild_vs3",18,50,$Odin[.@x];
  268.         warpchar "guild_vs3",83,50,$Freya[.@x];
  269.     }
  270. } else {
  271.         announce .NumPlayers+" vs "+.NumPlayers+" Event has failed due to a missing participant.",bc_all;
  272.         sleep 2000;
  273.         announce "Waiting for more participants.",bc_all;
  274.         set .OnGMStart, 0;
  275.         set .started, 0;
  276.         initnpctimer;
  277. }
  278.  
  279. end;   
  280.    
  281. OnTimer10000:
  282.     if (.started == 1){
  283.         stopnpctimer;
  284.         callsub OnEventStart;
  285.         end;
  286.     } else  {
  287.         npctalk "Ten seconds have passed. Entry to the round ends in 20 seconds.";
  288.         end;
  289.     }
  290. OnTimer20000:
  291.     npctalk "Twenty seconds have passed. Entry to the round ends in 10 seconds.";
  292.     end;
  293. OnTimer30000:
  294.     npctalk "Thirty seconds have passed and thus I have canceled the round.";
  295.     stopnpctimer;
  296. OnEventReset:
  297.     cleararray $Odin,0,getarraysize($Odin);
  298.     cleararray $OdinR,0,getarraysize($OdinR);
  299.     cleararray $Freya,0,getarraysize($Freya);
  300.     cleararray $FreyaR,0,getarraysize($FreyaR);
  301.     stopnpctimer;
  302.     set .started,0;
  303.     set .OnGMStart, 0;
  304. end;
  305.  
  306. OnAtCommand:
  307.     if (.@atcmd_parameters$[0] == "on"){
  308.         if (.started == 0){ // fail safe check
  309.             initnpctimer;
  310.             announce "A GM has started a PvP["+.NumPlayers+"v"+.NumPlayers+"] Event! Join now!",bc_all;
  311.             set .OnGMStart, 1;
  312.         } else {
  313.             dispbottom "A session is already in-progress.";
  314.         }
  315.     } else if (.@atcmd_parameters$[0] == "off"){
  316.         if (.started == 0){
  317.             dispbottom "No PvP Recruitment Session to stop. Can only interrupt when PvP is already on-going.";
  318.             end;
  319.         }
  320.         stopnpctimer;
  321.         announce "A GM has stopped a PvP["+.NumPlayers+"v"+.NumPlayers+"] Event!",bc_all;
  322.         for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1) { // warp all characters out if a session was on-going
  323.             mapwarp "guild_vs3","prontera",156,191;
  324.         }  
  325.         callsub OnEventReset;      
  326.     }
  327. end;
  328.  
  329.  
  330. OnInit:
  331.     bindatcmd "pvprecruitment", strnpcinfo(0)+"::OnAtCommand";
  332.     set .OnGMStart, 0;
  333.     set .NumPlayers, 2;
  334.     set .started, 0;
  335.     cleararray $Odin,0,getarraysize($Odin);
  336.     cleararray $OdinR,0,getarraysize($OdinR);
  337.     cleararray $Freya,0,getarraysize($Freya);
  338.     cleararray $FreyaR,0,getarraysize($FreyaR);
  339.     removemapflag "guild_vs3", mf_gvg;
  340.     setarray .@mapflags[0], mf_pvp, mf_nocommand, mf_nosave, mf_noexppenalty, mf_nomemo;
  341.     for (set .@x, 0; .@x < getarraysize(.@mapflags); set .@x, .@x + 1) {
  342.         setmapflag "guild_vs3", .@mapflags[.@x], 99;
  343.     }
  344.     end;
  345.    
  346. OnPCDieEvent:
  347.     if(strcharinfo(3) == "guild_vs3") {
  348.         sleep2 3000;
  349.         warp "SavePoint", 0, 0;
  350.     }
  351. end;
  352.  
  353.  
  354. OnPCKillEvent:
  355. if( strcharinfo(3) == "guild_vs3") {
  356.     mapannounce "guild_vs3","PvP["+.NumPlayers+"v"+.NumPlayers+"] Event:"+strcharinfo(0)+" has killed "+rid2name(killedrid)+".",1,0xD6A4E6;
  357.     Getitem 607, 5; //Reward for killing a member of the other team
  358.     for (set .@x, 0; .@x < 4; set .@x, .@x + 1) { // Decrease Team Alive Player Counter
  359.     if ($OdinR[.@x] == killedrid)
  360.         set $OdinCount, $OdinCount - 1;
  361.     else if ($FreyaR[.@x] == killedrid)
  362.         set $FreyaCount, $FreyaCount - 1;
  363.     }
  364.     mapannounce "guild_vs3","PvP["+.NumPlayers+"v"+.NumPlayers+"] Event: Odin:"+$OdinCount+" Freya:"+$FreyaCount,1,0xD6A4E6;
  365.     CheckSessionProgress();
  366. }
  367. end;
  368.  
  369. function CheckSessionProgress {
  370.     if (getarraysize($OdinCount) <= 0){ // Check if Team Odin is all dead
  371.         mapannounce "guild_vs3","PvP[4v4] Event: The Odin Team has dominated this round!",1,0xD6A4E6;
  372.         //Reward all of Team Freya for kill of Team Odin
  373.         for (set .@x, 0; .@x < getarraysize($FreyaR); set .@x, .@x + 1){
  374.             attachrid($FreyaR[.@x]);
  375.             getitem 608, 50; //reward for winning the round
  376.             sleep2 3000;
  377.             warpchar "prontera",156,191,getcharid(0);
  378.             detachrid;         
  379.         }
  380.         set .started,0;
  381.         callsub OnEventReset;
  382.     } else if (getarraysize($FreyaCount) <= 0){ // Check if Team Freya is all dead
  383.         mapannounce "guild_vs3","PvP["+.NumPlayers+"v"+.NumPlayers+"] Event: The Freya Team has dominated this round!",1,0xD6A4E6;
  384.         //Reward all of Team Freya for kill of Team Odin
  385.         for (set .@x, 0; .@x < getarraysize($OdinR); set .@x, .@x + 1){
  386.             attachrid($OdinR[.@x]);
  387.             getitem 608, 50; //reward for winning the round
  388.             sleep2 3000;
  389.             warpchar "prontera",156,191,getcharid(0);
  390.             detachrid;         
  391.         }  
  392.         set .started,0;
  393.         callsub OnEventReset;
  394.     }  
  395. return;
  396. }
  397.  
  398. OnPCLogoutEvent:
  399. if(.started == 1){
  400.     for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1){
  401.         if ($Odin[.@x] == getcharid(0)){
  402.             set $Odin[.@x], 0;
  403.             set $OdinR[.@x], 0;
  404.             set $OdinCount, $OdinCount - 1;
  405.         } else if ($Freya[.@x] == getcharid(0)){
  406.             set $Freya[.@x], 0;
  407.             set $FreyaR[.@x], 0;
  408.             set $FreyaCount, $FreyaCount - 1;
  409.         }
  410.     }
  411.     mapannounce "guild_vs3","PvP["+.NumPlayers+"v"+.NumPlayers+"] Event: "+strcharinfo(0)+" has logged out during the round! His team just had a casualty!",1,0xD6A4E6;
  412.     mapannounce "guild_vs3","PvP["+.NumPlayers+"v"+.NumPlayers+"] Event: Odin:"+$OdinCount+" Freya:"+$FreyaCount,1,0xD6A4E6;
  413.     CheckSessionProgress();
  414. }
  415. end;
  416.  
  417.  
  418. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement