// https://rathena.org/board/topic/115076-annieruru-bg_emp05/- script bg_emp#control -1,{OnInit: .minplayer2start=1; // minimum player to start. If 2vs2, set to 2 .winningscore=2; // final score to win .eventlasting=20*60; // abort the system if there's no progress, 20 mins * secondssetarray .rewarditem, 673, 5; // reward to the winning teamsetarray .consolationitem, 673, 3; // reward to the losing team// ** New ** Now players can join an ongoing battleground ~// If .minplayer2start is 3 and .maxplayer2join is 10, just 3vs3 players enough to start a battleground, but can maximum hold up to 10vs10 players// Note: maximum number is 30, which is define in src\map\battleground.hpp MAX_BG_MEMBERS. Require recompile to increase this limit .maxplayer2join=2;// If a player disconnect/quit from this round, how many seconds it takes to rejoin this round ?// NOTE: This shouldn't block players from entering a new battleground ID, only block them from entering an existing one .delay_rejoin=5*60; // 5 mins * seconds// Prevent team imbalance -> always encourage a balance team ~// When set to 1, when Blue=5:Red=4 battleground members, Blue team cannot register new players, only Red team still can accept new registration.// When set to 3, when Blue=7:Red=4 battleground members, Blue team cannot register new players, only Red team still can accept new registration.// DO NOT set this as 0 !! .imbalance_team_prevent=3;// If a player already has a character in Blue side, he cannot multi-client to join Red side.// Note: players still can quit the existing battleground and get another character to join opposing side ! But yeah they lose their consolation prize for the character he quit .nosameip_opposingteam=0; // set to 1 to enableend;OnStart:if(getwaitingroomstate(0, .rednpcname$ ) < .minplayer2start || getwaitingroomstate(0, .bluenpcname$ ) < .minplayer2start)end; .red=waitingroom2bg("bat_a01", 171,346, strnpcinfo(0)+"::OnRedQuit", strnpcinfo(0)+"::OnRedDead", .rednpcname$ ); .blue=waitingroom2bg("bat_a01", 162,50, strnpcinfo(0)+"::OnBlueQuit", strnpcinfo(0)+"::OnBlueDead", .bluenpcname$ );delwaitingroom .rednpcname$;delwaitingroom .bluenpcname$;if( .minplayer2start < .maxplayer2join){announce"Battleground Emperium has now open ~ accepting new warriors ~", bc_all;donpcevent .rednpcname$ +"::OnRejoin";donpcevent .bluenpcname$ +"::OnRejoin";}else{donpcevent .rednpcname$ +"::OnFull";donpcevent .bluenpcname$ +"::OnFull";}setwall"bat_a01", 154,51, 6, 4, 0, "bg_emp_town_blue";setwall"bat_a01", 164,347, 6, 4, 0, "bg_emp_town_red";bg_warp .red, "bat_a01", 171,346;bg_warp .blue, "bat_a01", 162,50;bg_updatescore"bat_a01", 0, 0;if(!.skip)sleep6000;mapannounce"bat_a01", "Rules are simple. The first one to break the opponent's emperium will get a score.", 0;if(!.skip)sleep3000;mapannounce"bat_a01", "Score "+ .winningscore+" rounds to win ! ... GET READY", 0;if(!.skip)sleep2000;while(1){callsub L_showdigitall, 0, 0;for( .@i =5; .@i > 0; --.@i ){mapannounce"bat_a01", "["+ .@i +"]", 0;if(!.skip)sleep1000;}callsub L_showdigitall, 0, 1; .time=gettimetick(2);if( .score[ .red]== .winningscore-1&& .score[ .blue]== .winningscore-1)mapannounce"bat_a01", "Final Round start!", 0;elsemapannounce"bat_a01", "Round "+++.round+" start!", 0;bg_monster .red,"bat_a01",171,346, "--ja--",1915, strnpcinfo(3)+"::OnRedDown";bg_monster .blue,"bat_a01",162,50, "--ja--",1914, strnpcinfo(3)+"::OnBlueDown";delwall"bg_emp_town_red";delwall"bg_emp_town_blue";if(!.skip)sleep .eventlasting*1000;bg_updatescore"bat_a01", .score[ .red], .score[ .blue];killmonster"bat_a01", strnpcinfo(3)+"::OnRedDown";killmonster"bat_a01", strnpcinfo(3)+"::OnBlueDown";if(getstrlen( .empkiller$ ))mapannounce"bat_a01", .empkiller$ +" has Destroy "+(( .winside== .red)? "Blue":"Red")+"'s side Emperium. "+(( .winside== .red)? "Red":"Blue")+" team score a point !", 0;callsub L_showdigitall, gettimetick(2)- .time, 0;if( .score[ .red]== .winningscore || .score[ .blue]== .winningscore || !.winside)break;if(!.skip)sleep4000;bg_warp .red, "bat_a01", 171,346;bg_warp .blue, "bat_a01", 162,50;setwall"bat_a01", 154,51, 6, 4, 0, "bg_emp_town_blue";setwall"bat_a01", 164,347, 6, 4, 0, "bg_emp_town_red";if(!.skip)sleep1000; .winside=0; .empkiller$ ="";}if( .winside){mapannounce"bat_a01", " "+(( .winside== .red)? "Red":"Blue")+" side wins !", 0;for( .@i =0; .@i < bg_get_data( .winside, 1); ++.@i )getitem .rewarditem[0], .rewarditem[1], $@arenamembers[.@i];for( .@i =0; .@i < bg_get_data(( .winside== .red)? .blue: .red , 1); ++.@i )getitem .consolationitem[0], .consolationitem[1], $@arenamembers[.@i];}elsemapannounce"bat_a01", "Time Out. Aborting the match.", 0;sleep5000;bg_warp .red, "poring_w01", 100,100;bg_warp .blue, "poring_w01", 100,100;bg_destroy .red;bg_destroy .blue;delwall"bg_emp_town_red";delwall"bg_emp_town_blue"; .round= .winside= .skip= .score[ .red]= .score[ .blue]= .time=0;delwaitingroom .rednpcname$;delwaitingroom .bluenpcname$;donpcevent .rednpcname$ +"::OnStart";donpcevent .bluenpcname$ +"::OnStart";if( .delay_rejoin)deletearray .delay_rejoin_cid;end;L_showdigitall:for( .@i =0; .@i < bg_get_data( .red, 1); ++.@i ){attachrid $@arenamembers[.@i];showdigitgetarg(0), getarg(1);}for( .@i =0; .@i < bg_get_data( .blue, 1); ++.@i ){attachrid $@arenamembers[.@i];showdigitgetarg(0), getarg(1);}detachrid;return;OnRedRejoin:callsub L_Rejoin, .red, .rednpcname$, .blue;OnBlueRejoin:callsub L_Rejoin, .blue, .bluenpcname$, .red;L_Rejoin: getwaitingroomusers getarg(1); kickwaitingroomall getarg(1);attachrid .@waitingroom_users;if( .delay_rejoin&& .delay_rejoin_cid[getcharid(0)]&& .delay_rejoin_cid[getcharid(0)]+ .delay_rejoin > gettimetick(2)){messagestrcharinfo(0), "You must wait "+( .delay_rejoin_cid[getcharid(0)]+ .delay_rejoin-gettimetick(2))+" seconds before rejoining this battleground.";end;}if( .nosameip_opposingteam){ .@ip$ = getcharip();bg_get_data(getarg(2), 1);for( .@i =0; .@i < $@arenamemberscount; ++.@i ){if( .@ip$ == getcharip( $@arenamembers[.@i])){dispbottom"Same IP detected ! You cannot join this battleground on both sides using the same IP address.";end;}}} bg_join getarg(0);showdigit .time-gettimetick(2), 1;if(bg_get_data(getarg(0), 0) >= .maxplayer2join || bg_get_data(getarg(0), 0)-bg_get_data(getarg(2), 0) >= .imbalance_team_prevent){delwaitingroomgetarg(1);donpceventgetarg(1)+"::OnFull";}end;OnRedDown:callsub L_EmpDown, .blue, .red, .bluenpcname$, .rednpcname$;OnBlueDown:callsub L_EmpDown, .red, .blue, .rednpcname$, .bluenpcname$;L_EmpDown: .empkiller$ =strcharinfo(0); .winside=getarg(0);++.score[ .winside];awakestrnpcinfo(0);end;OnRedDead:callsub L_dead;OnBlueDead:callsub L_dead;L_dead:sleep21250;percentheal100,100;end;OnRedQuit:callsub L_quit, .red, "Red", .blue, .rednpcname$;OnBlueQuit:callsub L_quit, .blue, "Blue", .red, .bluenpcname$;L_quit:percentheal100, 100;showdigitgettimetick(2)- .time, 0;if( .delay_rejoin) .delay_rejoin_cid[getcharid(0)]=gettimetick(2);delwaitingroomgetarg(3);if(bg_get_data(getarg(0), 0)){donpceventgetarg(3)+"::OnRejoin";end;}donpceventgetarg(3)+"::OnFull";mapannounce"bat_a01", "All "+getarg(1)+" team members has Quit !", 0, 0xff3333; // purposely use different color .score[getarg(2)]= .winningscore; .winside=getarg(2); .skip=1;awakestrnpcinfo(0);end;}poring_w01,98,105,5 script Red side#bg_emp 1_F_MARIA,{end;OnInit:sleep1;setgetvariableofnpc( .rednpcname$, "bg_emp#control"), strnpcinfo(0);OnStart:waitingroom"Red side", getvariableofnpc( .minplayer2start, "bg_emp#control")+1, strnpcinfo(0)+"::OnJoin", 1;end;OnJoin:if(getvariableofnpc( .nosameip_opposingteam, "bg_emp#control"))callfunc"bg_emp_register", strnpcinfo(0), getvariableofnpc( .bluenpcname$, "bg_emp#control");;announce"The Red side has ["+getwaitingroomstate(0)+"/"+getvariableofnpc( .minplayer2start, "bg_emp#control")+"] User", bc_all;donpcevent"bg_emp#control::OnStart";end;OnRejoin:waitingroom"Red side", 2, "bg_emp#control::OnRedRejoin", 1;end;OnFull:waitingroom"Red side", 0;end;}poring_w01,103,105,5 script Blue side#bg_emp 1_F_MARIA,{end;OnInit:sleep1;setgetvariableofnpc( .bluenpcname$, "bg_emp#control"), strnpcinfo(0);OnStart:waitingroom"Blue side", getvariableofnpc( .minplayer2start, "bg_emp#control")+1, strnpcinfo(0)+"::OnJoin", 1;end;OnJoin:if(getvariableofnpc( .nosameip_opposingteam, "bg_emp#control"))callfunc"bg_emp_register", strnpcinfo(0), getvariableofnpc( .rednpcname$, "bg_emp#control");announce"The Blue side has ["+getwaitingroomstate(0)+"/"+getvariableofnpc( .minplayer2start, "bg_emp#control")+"] User", bc_all;donpcevent"bg_emp#control::OnStart";end;OnRejoin:waitingroom"Blue side", 2, "bg_emp#control::OnBlueRejoin", 1;end;OnFull:waitingroom"Blue side", 0;end;}function script bg_emp_register { getwaitingroomusers getarg(0); .@name$ =rid2name( .@waitingroom_users[ .@waitingroom_usercount -1]); .@ip$ = getcharip( .@waitingroom_users[ .@waitingroom_usercount -1]); getwaitingroomusers getarg(1);for( .@i =0; .@i < .@waitingroom_usercount; ++.@i ){if( .@ip$ == getcharip( .@waitingroom_users[.@i])){attachridgetcharid(3, .@name$ );// message strcharinfo(0), "Same IP detected ! You cannot register this battleground on both sides using the same IP address."; // I wonder why this line doesn't workdispbottom"Same IP detected ! You cannot register this battleground on both sides using same IP address."; waitingroomkick getarg(0), .@name$;end;}}return;}bat_a01 mapflag battleground 2bat_a01 mapflag nosave SavePointbat_a01 mapflag nowarpbat_a01 mapflag nowarptobat_a01 mapflag noteleportbat_a01 mapflag nomemobat_a01 mapflag nopenaltybat_a01 mapflag nobranchbat_a01 mapflag noicewall//bat_a01 mapflag hidemobhpbar