viewing paste rAthena - bg_emp with rejoin | Athena

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
// 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 * seconds
        setarray .rewarditem, 673, 5; // reward to the winning team
        setarray .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 enable
 
        end;
 
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 ) sleep 6000;
        mapannounce "bat_a01", "Rules are simple. The first one to break the opponent's emperium will get a score.", 0;
        if ( !.skip ) sleep 3000;
        mapannounce "bat_a01", "Score "+ .winningscore +" rounds to win ! ... GET READY", 0;
        if ( !.skip ) sleep 2000;
        while (1) {
                callsub L_showdigitall, 0, 0;
                for ( .@i = 5; .@i > 0; --.@i ) {
                        mapannounce "bat_a01", "["+ .@i +"]", 0;
                        if ( !.skip ) sleep 1000;
                }
                callsub L_showdigitall, 0, 1;
                .time = gettimetick(2);
                if ( .score[ .red ] == .winningscore -1 && .score[ .blue ] == .winningscore -1 )
                        mapannounce "bat_a01", "Final Round start!", 0;
                else
                        mapannounce "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 ) sleep 4000;
                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 ) sleep 1000;
                .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];
        } else
                mapannounce "bat_a01", "Time Out. Aborting the match.", 0;
        sleep 5000;
        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];
                showdigit getarg(0), getarg(1);
        }
        for ( .@i = 0; .@i < bg_get_data( .blue, 1 ); ++.@i ) {
                attachrid $@arenamembers[.@i];
                showdigit getarg(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) ) {
                message strcharinfo(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 ) {
                delwaitingroom getarg(1);
                donpcevent getarg(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 ];
        awake strnpcinfo(0);
        end;
OnRedDead: callsub L_dead;
OnBlueDead: callsub L_dead;
L_dead:
        sleep2 1250;
        percentheal 100,100;
        end;
OnRedQuit: callsub L_quit, .red, "Red", .blue, .rednpcname$;
OnBlueQuit: callsub L_quit, .blue, "Blue", .red, .bluenpcname$;
L_quit:
        percentheal 100, 100;
        showdigit gettimetick(2) - .time, 0;
        if ( .delay_rejoin )
                .delay_rejoin_cid[ getcharid(0) ] = gettimetick(2);
        delwaitingroom getarg(3);
        if ( bg_get_data( getarg(0), 0 ) ) {
                donpcevent getarg(3) +"::OnRejoin";
                end;
        }
        donpcevent getarg(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;
        awake strnpcinfo(0);
        end;
}
 
poring_w01,98,105,5     script  Red side#bg_emp 1_F_MARIA,{
        end;
OnInit:
        sleep 1;
        set getvariableofnpc( .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:
        sleep 1;
        set getvariableofnpc( .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] ) ) {
                        attachrid getcharid( 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 work
                        dispbottom "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    2
bat_a01 mapflag nosave  SavePoint
bat_a01 mapflag nowarp
bat_a01 mapflag nowarpto
bat_a01 mapflag noteleport
bat_a01 mapflag nomemo
bat_a01 mapflag nopenalty
bat_a01 mapflag nobranch
bat_a01 mapflag noicewall
//bat_a01       mapflag hidemobhpbar
Viewed 316 times, submitted by AnnieRuru.