Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------------------------------------------------------------------------------------------
- // ------ rAthena Script Release
- // Title: PvP [4v4] Rewrite
- // Author: jezznar
- // Version: 1.0 Jezznar
- // - Initial Release
- // Version: 1.1 PandaLovesHamster
- // - Player Logoff Detection
- // - Team change on recruitment stage
- // Version: 1.2 Jezznar
- // - Renamed to "PvP Recruiter"
- // - Changed @4v4 to @pvprecruitment
- // - Added flexibility on number of parcipants (set .NumPlayers)
- // - Fixed and improved free slot checking algorithm
- // - Fixed and improved registration checking and team transfer algorithm
- // - Added Player Variable @MyTeam for easier checkings:
- // [0] Team number ( 0 for No Team Yet | 1 for Odin | 2 for Freya)
- // [1] Slot number of his team
- // - Fixed Clear event
- // - Fixed Menu not closing on registration
- // - Added a variable to indicate if the session is on-going (set .started)
- // - Check if the event is already running when player begins to talk to the npc
- // Version: 1.3 Jezznar
- // - Quick fix for event not being able to function correctly
- // - Optimized OnEventStart algorithm
- // - Optimized and Improved Logged in/Logged Off Checking
- // - Takes off logged off players from the roster instead of resetting the whole recruitment process
- // - Took off OnFailLack
- // - Added OnPCLoginEvent and OnPCLogoutEvent
- // - Added GM Safe failcheck
- // Version: 1.4 Jezznar
- // - Thoroughly fixed a lot of logical and symmantic errors
- // - Optimized a lot of codes
- // - Fixed a lot of exploits and bugs
- // - Made it functionally working
- // - Demo video uploaded [posting soon]
- // Version: 1.5 Jezznar
- // - Will be tagged as stable if noone complains about any bug
- // - Fixed the "fatal error: player not attached problem" caused by @MyTeam
- // - Participant will be taken as a casualty if he logs out when the session is on-going
- // - Added mapflags and can be modified through .@mapflags
- // - Tested without errors, bugs, and exploits.
- // Version: 1.6 Jezznar [Will be tagged as stable if noone complains about anything]
- // - Changed Line up view to PlayerName instead of CharID
- // Search for "getitem" to change rewards and their quantity
- // ------------------------------------------------------------------------------------------
- prontera,147,149,6 script PvP Recruiter 416,{
- function CheckSessionProgress;
- set .@n$,"[^FF0000Party Battle Recruiter^000000]";
- set .@charid,getcharid(0);
- set .@rid,getcharid(3);
- mes .@n$;
- mes "Your Charname:"+rid2name(.@rid);
- mes "==============================";
- mes "Current Line up";
- mes "==============================";
- if ($OdinR[.@x] == 0 && $FreyaR[.@x] == 0)
- mes "None Yet.";
- else
- for(set .@x,0; .@x < .NumPlayers; set .@x, .@x + 1)
- if ($OdinR[.@x] != 0 || $FreyaR[.@x] != 0)
- mes "Odin: "+($OdinR[.@x]==0?" Free ":rid2name($OdinR[.@x]))+" | Freya: "+($FreyaR[.@x]==0?" Free ":rid2name($FreyaR[.@x]));
- next;
- if (getmapusers("guild_vs3") > 0 || .started == 1) { // Check if there is an on-going session
- mes .@n$;
- mes "There appears to be a match currently in session. Check back momentarily.";
- close;
- }
- //Check for free slots
- set .free, 0;
- for (set .@x, 0; .@x < .NumPlayers && .free == 0 ; set .@x, .@x + 1){
- if ($Odin[.@x] == 0){
- set .free, 1;
- } else if ($Freya[.@x] == 0){
- set .free, 1;
- }
- }
- // if (getarraysize($Odin) >= .NumPlayers && getarraysize($Freya) >= .NumPlayers) {
- if (!.free){
- mes .@n$;
- mes "Sorry, there are no slots available right now. Please come back again later.";
- close;
- }
- // }
- //Check if character is already registered
- set .@registered, 0;
- for (set .@x, 0; .@x < .NumPlayers && .@registered == 0 ; set .@x, .@x + 1) {
- if ($Odin[.@x] == .@charid){
- set .@registered, 1;
- set .@MyTeam$, "Odin"; //NPC temp var to contain current team
- } else if ($Freya[.@x] == .@charid){
- set .@registered, 1;
- set .@MyTeam$, "Freya"; //NPC temp var to contain current team
- }
- }
- if (.@registered == 1){
- set .@prev, .@x - 1;
- mes .@n$;
- mes "You are already registered in slot "+(.@prev+1)+" of the "+.@MyTeam$+" Team.";
- mes "Do You want to transfer to the other side?";
- Switch(Select("Yes:No")){
- case 1:
- if (.@MyTeam$ == "Odin"){ // The guy is from the Odin Team
- //Check for possible unfilled slot
- for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1){
- if ($Freya[.@x] == 0){ // Slot found, Change team
- set .@MyTeam$, "Freya";
- cleararray $Odin[.@prev], 0, 1; // free up the slot
- cleararray $OdinR[.@prev], 0, 1; // free up the slot
- for (;.@prev < (.NumPlayers); set .@prev, .@prev+1){
- set $Odin[.@prev], $Odin[.@prev+1];
- set $OdinR[.@prev], $OdinR[.@prev+1];
- }
- // cleararray $Odin[.NumPlayers], 0, 1;
- // cleararray $OdinR[.NumPlayers], 0, 1;
- set $Freya[.@x], .@charid; // set free slot
- set $FreyaR[.@x], .@rid; // set free slot
- npctalk strcharinfo(0)+" transferred to Freya's Side";
- //successful transfer
- mes .@n$;
- mes "You have been successfully transferred to the "+.@MyTeam$+" Team's slot #"+(.@x+1);
- close;
- }
- }
- mes "Sorry, The other team is full.";
- close;
- } else if (.@MyTeam$ == "Freya"){ // The guy is from the Freya Team
- for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1){
- if ($Odin[.@x] == 0){ // Slot found, Change team
- set .@MyTeam$, "Odin";
- cleararray $Freya[.@prev], 0, 1; // free up the slot
- cleararray $FreyaR[.@prev], 0, 1; // free up the slot
- for (;.@prev < (.NumPlayers); set .@prev, .@prev+1){
- set $Freya[.@prev], $Freya[.@prev+1];
- set $FreyaR[.@prev], $FreyaR[.@prev+1];
- }
- // cleararray $Freya[.NumPlayers], 0, 1;
- // cleararray $FreyaR[.NumPlayers], 0, 1;
- set $Odin[.@x], .@charid; // set slot
- set $OdinR[.@x], .@rid; // set slot
- npctalk strcharinfo(0)+" transferred to Odin's Side";
- //successful transfer
- mes .@n$;
- mes "You have been successfully transferred to the "+.@MyTeam$+" Team's slot #"+(.@x+1);
- close;
- }
- }
- mes "Sorry, The other team is full.";
- close;
- }
- break;
- case 2:
- mes "Alright. See You around.";
- close;
- break;
- }
- }
- mes .@n$;
- mes "Would you like to register for a "+.NumPlayers+" versus "+.NumPlayers+" Party Battle?";
- Switch(Select("Yes:No")) {
- case 2:
- mes .@n$;
- mes "Alright, See you around.";
- close;
- default:
- mes .@n$;
- mes "Which side are you going to play for?";
- break;
- }
- switch(select("Odin ("+(getarraysize($Odin))+"/"+.NumPlayers+"):Freya ("+(getarraysize($Freya))+"/"+.NumPlayers+")")) {
- case 1:
- if (getarraysize($Odin) < .NumPlayers) {
- if (getarraysize($Odin) == 0 && getarraysize($Freya) == 0 && .OnGMStart == 0) { // Check if he is the first one to register & not manually started by a GM
- initnpctimer;
- announce "The PvP["+.NumPlayers+"v"+.NumPlayers+"] Event has been triggered by "+strcharinfo(0)+"! Join now!",bc_all;
- }
- for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1){
- if ($Odin[.@x] == 0) { // Slot found, assign team
- set .@MyTeam$, "Odin";
- set $Odin[.@x], .@charid; // set slot
- set $OdinR[.@x], .@rid; // set slot
- mes "You have been successfully assigned to the "+.@MyTeam$+" Team's slot #"+(.@x+1);
- break;
- }
- }
- } else {
- mes "This team is full.";
- close;
- }
- break;
- case 2:
- if (getarraysize($Freya) < .NumPlayers) {
- if (getarraysize($Odin) == 0 && getarraysize($Freya) == 0 && .OnGMStart == 0) { // Check if he is the first one to register & not manually started by a GM
- initnpctimer;
- announce "The PvP["+.NumPlayers+"v"+.NumPlayers+"] Event has been triggered by "+strcharinfo(0)+"! Join now!",bc_all;
- }
- for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1){
- if ($Freya[.@x] == 0) { // Slot found, assign team
- set .@MyTeam$, "Freya";
- set $Freya[.@x], .@charid; // set slot
- set $FreyaR[.@x], .@rid; // set slot
- mes "You have been successfully assigned to the "+.@MyTeam$+" Team's slot #"+(.@x+1);
- break;
- }
- }
- } else {
- mes "This team is full.";
- close;
- }
- break;
- }
- if((getarraysize($Odin)) >= .NumPlayers && (getarraysize($Freya)) >= .NumPlayers) {
- stopnpctimer;
- npctalk "Both teams have been filled. All participants currently logged in will be transferred to the arena in ten seconds.";
- initnpctimer;
- set .started,1;
- close;
- }
- close;
- end;
- OnEventStart:
- // For OnPCKillEvent's Player Counter for each side
- set $OdinCount, getarraysize($Odin);
- set $FreyaCount, getarraysize($Freya);
- //Check if all Players are online and take off Players who are not
- for(set .@x,0; .@x < (2*.NumPlayers); set .@x, .@x + 1){
- if(!attachrid($FreyaR[.@x])) {
- set $Freya[.@x], 0;
- set $FreyaR[.@x], 0;
- }
- detachrid;
- if(!attachrid($OdinR[.@x])) {
- set $Odin[.@x], 0;
- set $OdinR[.@x], 0;
- }
- detachrid;
- }
- //If all players are online then warp all participants to the event place - guild_vs3
- if (getarraysize($Odin) == .NumPlayers && getarraysize($Freya) == .NumPlayers){
- for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1) {
- warpchar "guild_vs3",18,50,$Odin[.@x];
- warpchar "guild_vs3",83,50,$Freya[.@x];
- }
- } else {
- announce .NumPlayers+" vs "+.NumPlayers+" Event has failed due to a missing participant.",bc_all;
- sleep 2000;
- announce "Waiting for more participants.",bc_all;
- set .OnGMStart, 0;
- set .started, 0;
- initnpctimer;
- }
- end;
- OnTimer10000:
- if (.started == 1){
- stopnpctimer;
- callsub OnEventStart;
- end;
- } else {
- npctalk "Ten seconds have passed. Entry to the round ends in 20 seconds.";
- end;
- }
- OnTimer20000:
- npctalk "Twenty seconds have passed. Entry to the round ends in 10 seconds.";
- end;
- OnTimer30000:
- npctalk "Thirty seconds have passed and thus I have canceled the round.";
- stopnpctimer;
- OnEventReset:
- cleararray $Odin,0,getarraysize($Odin);
- cleararray $OdinR,0,getarraysize($OdinR);
- cleararray $Freya,0,getarraysize($Freya);
- cleararray $FreyaR,0,getarraysize($FreyaR);
- stopnpctimer;
- set .started,0;
- set .OnGMStart, 0;
- end;
- OnAtCommand:
- if (.@atcmd_parameters$[0] == "on"){
- if (.started == 0){ // fail safe check
- initnpctimer;
- announce "A GM has started a PvP["+.NumPlayers+"v"+.NumPlayers+"] Event! Join now!",bc_all;
- set .OnGMStart, 1;
- } else {
- dispbottom "A session is already in-progress.";
- }
- } else if (.@atcmd_parameters$[0] == "off"){
- if (.started == 0){
- dispbottom "No PvP Recruitment Session to stop. Can only interrupt when PvP is already on-going.";
- end;
- }
- stopnpctimer;
- announce "A GM has stopped a PvP["+.NumPlayers+"v"+.NumPlayers+"] Event!",bc_all;
- for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1) { // warp all characters out if a session was on-going
- mapwarp "guild_vs3","prontera",156,191;
- }
- callsub OnEventReset;
- }
- end;
- OnInit:
- bindatcmd "pvprecruitment", strnpcinfo(0)+"::OnAtCommand";
- set .OnGMStart, 0;
- set .NumPlayers, 2;
- set .started, 0;
- cleararray $Odin,0,getarraysize($Odin);
- cleararray $OdinR,0,getarraysize($OdinR);
- cleararray $Freya,0,getarraysize($Freya);
- cleararray $FreyaR,0,getarraysize($FreyaR);
- removemapflag "guild_vs3", mf_gvg;
- setarray .@mapflags[0], mf_pvp, mf_nocommand, mf_nosave, mf_noexppenalty, mf_nomemo;
- for (set .@x, 0; .@x < getarraysize(.@mapflags); set .@x, .@x + 1) {
- setmapflag "guild_vs3", .@mapflags[.@x], 99;
- }
- end;
- OnPCDieEvent:
- if(strcharinfo(3) == "guild_vs3") {
- sleep2 3000;
- warp "SavePoint", 0, 0;
- }
- end;
- OnPCKillEvent:
- if( strcharinfo(3) == "guild_vs3") {
- mapannounce "guild_vs3","PvP["+.NumPlayers+"v"+.NumPlayers+"] Event:"+strcharinfo(0)+" has killed "+rid2name(killedrid)+".",1,0xD6A4E6;
- Getitem 607, 5; //Reward for killing a member of the other team
- for (set .@x, 0; .@x < 4; set .@x, .@x + 1) { // Decrease Team Alive Player Counter
- if ($OdinR[.@x] == killedrid)
- set $OdinCount, $OdinCount - 1;
- else if ($FreyaR[.@x] == killedrid)
- set $FreyaCount, $FreyaCount - 1;
- }
- mapannounce "guild_vs3","PvP["+.NumPlayers+"v"+.NumPlayers+"] Event: Odin:"+$OdinCount+" Freya:"+$FreyaCount,1,0xD6A4E6;
- CheckSessionProgress();
- }
- end;
- function CheckSessionProgress {
- if (getarraysize($OdinCount) <= 0){ // Check if Team Odin is all dead
- mapannounce "guild_vs3","PvP[4v4] Event: The Odin Team has dominated this round!",1,0xD6A4E6;
- //Reward all of Team Freya for kill of Team Odin
- for (set .@x, 0; .@x < getarraysize($FreyaR); set .@x, .@x + 1){
- attachrid($FreyaR[.@x]);
- getitem 608, 50; //reward for winning the round
- sleep2 3000;
- warpchar "prontera",156,191,getcharid(0);
- detachrid;
- }
- set .started,0;
- callsub OnEventReset;
- } else if (getarraysize($FreyaCount) <= 0){ // Check if Team Freya is all dead
- mapannounce "guild_vs3","PvP["+.NumPlayers+"v"+.NumPlayers+"] Event: The Freya Team has dominated this round!",1,0xD6A4E6;
- //Reward all of Team Freya for kill of Team Odin
- for (set .@x, 0; .@x < getarraysize($OdinR); set .@x, .@x + 1){
- attachrid($OdinR[.@x]);
- getitem 608, 50; //reward for winning the round
- sleep2 3000;
- warpchar "prontera",156,191,getcharid(0);
- detachrid;
- }
- set .started,0;
- callsub OnEventReset;
- }
- return;
- }
- OnPCLogoutEvent:
- if(.started == 1){
- for (set .@x, 0; .@x < .NumPlayers; set .@x, .@x + 1){
- if ($Odin[.@x] == getcharid(0)){
- set $Odin[.@x], 0;
- set $OdinR[.@x], 0;
- set $OdinCount, $OdinCount - 1;
- } else if ($Freya[.@x] == getcharid(0)){
- set $Freya[.@x], 0;
- set $FreyaR[.@x], 0;
- set $FreyaCount, $FreyaCount - 1;
- }
- }
- mapannounce "guild_vs3","PvP["+.NumPlayers+"v"+.NumPlayers+"] Event: "+strcharinfo(0)+" has logged out during the round! His team just had a casualty!",1,0xD6A4E6;
- mapannounce "guild_vs3","PvP["+.NumPlayers+"v"+.NumPlayers+"] Event: Odin:"+$OdinCount+" Freya:"+$FreyaCount,1,0xD6A4E6;
- CheckSessionProgress();
- }
- end;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement