// https://rathena.org/board/topic/115504-bg_warp-and-instance_enter-are-equals/
/* db\re\instance_db.txt
34,BG_PVP,86400,86400,bat_c01,100,95
*/
function script F_ShuffleNumbers {
deletearray getarg(2);
.@static = getarg(0);
.@range = getarg(1) +1 - .@static;
.@count = getarg(3, .@range);
if (.@range <= 0 || .@count <= 0)
return 0;
if (.@count > .@range)
.@count = .@range;
for (.@i = 0; .@i < .@range; ++.@i)
.@temparray[.@i] = .@i;
for (.@i = 0; .@i < .@count; ++.@i) {
.@rand = rand(.@range);
set getelementofarray( getarg(2), .@i ), .@temparray[.@rand] + .@static;
.@temparray[.@rand] = .@temparray[--.@range];
}
return .@count;
}
prontera,150,185,5 script BG_SIGNUP 1_F_MARIA,{
.minplayer2start = 1; // 1vs1
mes "Test ... BG_PVP + BG_EMP combine";
mes "kill all opponent team to win";
mes "or kill the shining plant to win";
next;
while ( .aid[.@i] != getcharid(3) && .@i < .size ) ++.@i;
if ( .@i < .size ) {
mes "You already join the queue.";
close;
}
select "join";
mes "you have to stick to this map";
close2;
.aid[ .size++ ] = getcharid(3);
for ( .@i = 0; .@i < .size; ++.@i ) {
if ( !isloggedin( .aid[.@i] ) ) {
deletearray .aid[.@i], 1;
--.@i;
--.size;
}
else {
attachrid .aid[.@i];
if ( strcharinfo(3) != strnpcinfo(4) ) {
deletearray .aid[.@i], 1;
--.@i;
--.size;
}
}
}
detachrid;
if ( .size == .minplayer2start *2 ) {
instance_create( "BG_PVP", IM_NONE );
deletearray .aid;
.size = 0;
}
else
announce .size +" players join", bc_npc | bc_area;
end;
}
bat_c01,0,0,0 script BG_PVP_EMP -1,{
OnInstanceInit:
announce instance_id() +" ID start", bc_all;
monster strnpcinfo(4), 100,95, "--ja--", 1083,1, instance_npcname( strnpcinfo(0) )+"::OnPlantDown";
'red = bg_create( strnpcinfo(4), 90,95, instance_npcname( strnpcinfo(0) )+"::OnRedQuit", instance_npcname( strnpcinfo(0) )+"::OnRedDead" );
'blue = bg_create( strnpcinfo(4), 90,95, instance_npcname( strnpcinfo(0) )+"::OnBlueQuit", instance_npcname( strnpcinfo(0) )+"::OnBlueDead" );
callfunc "F_ShuffleNumbers", 0, getvariableofnpc( .size, "BG_SIGNUP" ) -1, .@r;
for ( .@i = 0; .@i < getvariableofnpc( .size, "BG_SIGNUP" ); ++.@i ) {
attachrid getvariableofnpc( getd( ".aid["+ .@r[.@i] +"]" ), "BG_SIGNUP" );
bg_join ( .@i % 2 )? 'red : 'blue;
}
detachrid;
bg_warp 'red, strnpcinfo(4), 90,95;
bg_warp 'blue, strnpcinfo(4), 110,95;
initnpctimer;
sleep 30000; // time out
if ( !'winside )
announce "Battle end as time out", bc_npc | bc_map | bc_blue;
else if ( 'winside == 'red ) {
announce "- Red side Won the match !", bc_npc | bc_map | bc_blue;
callsub L_reward, 'red;
}
else if ( 'winside == 'blue ) {
announce "- Blue side Won the match !", bc_npc | bc_map | bc_blue;
callsub L_reward, 'blue;
}
bg_destroy 'red;
bg_destroy 'blue;
mapwarp strnpcinfo(4), "prontera",150,185;
sleep 1; // prevent aFree error
instance_destroy;
end;
OnTimer1000:
bg_get_data 'red, 1;
for ( .@i = 0; .@i < $@arenamemberscount; ++.@i ) {
attachrid $@arenamembers[.@i];
++Zeny;
}
bg_get_data 'blue, 1;
for ( .@i = 0; .@i < $@arenamemberscount; ++.@i ) {
attachrid $@arenamembers[.@i];
++Zeny;
}
initnpctimer;
end;
L_reward:
bg_get_data getarg(0), 1;
for ( .@i = 0; .@i < $@arenamemberscount; ++.@i )
getitem 501,1, $@arenamembers[.@i];
return;
OnPlantDown:
announce strcharinfo(0) +" from "+( ( getcharid(4) == 'red )? "Red" : "Blue" )+" team has killed the shining plant !", bc_npc | bc_map | bc_blue;
'winside = getcharid(4);
awake instance_npcname( strnpcinfo(0) );
end;
OnRedQuit: callsub L_Quit, 'red, 'blue, "Red";
OnBlueQuit: callsub L_Quit, 'blue, 'red, "Blue";
L_Quit:
if ( bg_get_data( getarg(0), 0 ) ) end;
announce "All "+ getarg(2) +" team members has Quit!", bc_npc | bc_map | bc_blue;
'winside = getarg(1);
awake instance_npcname( strnpcinfo(0) );
end;
OnRedDead: callsub L_Dead, 'red, 'blue, "Red";
OnBlueDead: callsub L_Dead, 'blue, 'red, "Blue";
L_Dead:
bg_leave;
if ( bg_get_data( getarg(0), 0 ) ) end;
announce "All "+ getarg(2) +" team members has killed!", bc_npc | bc_map | bc_blue;
'winside = getarg(1);
awake instance_npcname( strnpcinfo(0) );
sleep2 1250;
percentheal 100,100;
end;
}
bat_c01 mapflag battleground
bat_c01 mapflag nosave SavePoint
bat_c01 mapflag nowarp
bat_c01 mapflag nowarpto
bat_c01 mapflag noteleport
bat_c01 mapflag nomemo
bat_c01 mapflag nopenalty
bat_c01 mapflag nobranch
bat_c01 mapflag noicewall