viewing paste topic/4624- instanced_battleground | 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
function    script  shuffle__   {
    .@static = getarg(0);
    .@range = getarg(1) +1 - .@static;
    .@count = getarg(3, 0);
    if ( .@range <= 0 )
        return 0;
    if ( !.@count || .@count > .@range )
        .@count = .@range;
    while ( .@i < .@count ) {
        .@r = .@save = rand( .@i, .@range -1 ) ;
        if ( !.@tmp1[.@i] ) {
            .@r = .@tmp1[.@r] ? .@tmp2[.@r] : .@r;
            .@tmp2[.@i] = .@r;
            .@tmp2[.@save] = .@i;
            .@tmp1[.@save] = 1;
            set getelementofarray( getarg(2), .@i ), .@r + .@static;
            if ( .@save < .@count )
                set getelementofarray( getarg(2), .@save ), .@i + .@static;
        }
        .@i++;
    }
    return .@count;
}
 
prontera,152,178,5  script  bg_pvp  100,{
    end;
OnInit:
    .eventlasting = 3; // duration in minutes
    setarray .rewardwin, 501,10, 502,5, 503,3; // reward to winning team
    setarray .rewardlose, 501,5, 502,3, 503,1; // reward to losing team
    setarray .rewarddraw, 501,3, 502,1; // reward to both teams when draw
 
    .rewardwinsize = getarraysize( .rewardwin );
    .rewardlosesize = getarraysize( .rewardlose );
    .rewarddrawsize = getarraysize( .rewarddraw );
 
    waitingroom "Battleground", 3, strnpcinfo(0)+"::OnStart", 2;
    end;
OnStart:
    if ( ( .@ins = instance_create( "Battleground", 0, IOT_NONE ) ) < 0 ) {
        announce "failed", bc_all;
        end;
    }
    if ( instance_attachmap( "guild_vs3", .@ins, 1, .@ins +"BG" ) == "" ) {
        announce "failed", bc_all;
        end;
    }
    instance_set_timeout .eventlasting * 60 +6, 0, .@ins;
    instance_init .@ins;
    instance_attach .@ins;
    'mapname$ = .@ins +"BG";
    'red = createbgid( "guild_vs3", 48,50, instance_npcname( "battleground_ins" )+"::OnRedQuit", instance_npcname( "battleground_ins" )+"::OnRedDead" );
    'blue = createbgid( "guild_vs3", 52,50, instance_npcname( "battleground_ins" )+"::OnBlueQuit", instance_npcname( "battleground_ins" )+"::OnBlueDead" );
    'teamname$['red] = "Red";
    'teamname$['blue] = "Blue";
    .@tmp = waitingroom2bg( "prontera",152,178, "","" );
    bg_destroy .@tmp;
    callfunc "shuffle__", 0, $@arenamembersnum -1, .@r;
    .@modulus = rand(2);
    for ( .@i = 0; .@i < $@arenamembersnum; .@i++ )
        setbgid ( .@i % 2 == .@modulus )? 'red : 'blue, $@arenamembers[ .@r[.@i] ];
    'score['red] = bg_get_data( 'red, 0 );
    'score['blue] = bg_get_data( 'blue, 0 );
    bg_updatescore 'mapname$, 'score['red], 'score['blue];
    bg_warp 'red, 'mapname$, 48,50;
    bg_warp 'blue, 'mapname$, 52,50;
    end;
}
 
guild_vs3,0,0,0 script  battleground_ins    -1,{
OnInstanceInit:
    sleep getvariableofnpc( .eventlasting, "bg_pvp" ) * 60000;
    if ( 'score['red] > 'score['blue] ) {
        mapannounce 'mapname$, "- Red Team is victorious! -", bc_map;
        callsub L_reward, 'red, getvariableofnpc( .rewardwin, "bg_pvp" ),  getvariableofnpc( .rewardwinsize, "bg_pvp" );
        callsub L_reward, 'blue, getvariableofnpc( .rewardlose, "bg_pvp" ),  getvariableofnpc( .rewardlosesize, "bg_pvp" );
    }
    else if ( 'score['red] < 'score['blue] ) {
        mapannounce 'mapname$, "- Blue Team is victorious! -", bc_map;
        callsub L_reward, 'blue, getvariableofnpc( .rewardwin, "bg_pvp" ),  getvariableofnpc( .rewardwinsize, "bg_pvp" );
        callsub L_reward, 'red, getvariableofnpc( .rewardlose, "bg_pvp" ),  getvariableofnpc( .rewardlosesize, "bg_pvp" );
    }
    else { // same score
        mapannounce 'mapname$, "- The match has ended in a draw! -", bc_map;
        callsub L_reward, 'red, getvariableofnpc( .rewarddraw, "bg_pvp" ),  getvariableofnpc( .rewarddrawsize, "bg_pvp" );
        callsub L_reward, 'blue, getvariableofnpc( .rewarddraw, "bg_pvp" ),  getvariableofnpc( .rewarddrawsize, "bg_pvp" );
    }
    sleep 5000;
//  bg_match_over "KVM (Level 80 and up)";
    mapwarp .@ins +"BG", "prontera",152,178;
    bg_destroy 'red;
    bg_destroy 'blue;
    instance_destroy;
    end;
L_reward:
    getbgusers getarg(0);
    for ( .@i = 0; .@i < $@arenamembersnum; .@i++ )
        for ( .@j = 0; .@j < getarg(2); .@j += 2 )
            getitem getelementofarray( getarg(1), .@j ), getelementofarray( getarg(1), .@j +1 ), $@arenamembers[.@i];
    return;
OnRedDead:  callsub L_Dead, 'red;
OnBlueDead: callsub L_Dead, 'blue;
L_Dead:
    warp "Save", 0,0;
    'score[ getarg(0) ]--;
    bg_updatescore 'mapname$, 'score['red], 'score['blue];
    if ( !'score[ getarg(0) ] )
        awake instance_npcname( strnpcinfo(0) );
    bg_leave;
    sleep2 1250;
    percentheal 100,100;
    end;
OnRedQuit:  callsub L_Quit, 'red;
OnBlueQuit: callsub L_Quit, 'blue;
L_Quit:
    'score[ getarg(0) ]--;
    bg_updatescore 'mapname$, 'score['red], 'score['blue];
    if ( !'score[ getarg(0) ] )
        awake instance_npcname( strnpcinfo(0) );
    percentheal 100, 100;
    end;
}
 
guild_vs3   mapflag battleground    2
guild_vs3   mapflag nosave  SavePoint
guild_vs3   mapflag nowarp
guild_vs3   mapflag nowarpto
guild_vs3   mapflag noreturn
guild_vs3   mapflag nomemo
guild_vs3   mapflag noteleport
guild_vs3   mapflag nopenalty
guild_vs3   mapflag nobranch
guild_vs3   mapflag noicewall
guild_vs3   mapflag src4instance
Viewed 1470 times, submitted by AnnieRuru.