// https://rathena.org/board/topic/115861-woe-random-castle/ // remember to disable these links //== npc\guild\agit_controller.txt //== npc\guild2\agit_start_se.txt //== npc\re\guild3\agit_start_te.txt 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; } - script castle_randomize -1,{ OnInit: for ( .@i = 0; .@i < 8; ++.@i ) .castle$[.@i] = "06guild_0"+( .@i +1 ); end; OnClock2100: agitstart; end; OnClock2200: agitend; end; OnAgitStart: if ( gettime(DT_HOUR) != 21 ) end; // luckily 8/2 has no remainder if ( !getarraysize( $castle_random$ ) ) { callfunc "F_ShuffleNumbers", 0, 7, .@r; for ( .@i = 0; .@i < 8; ++.@i ) $castle_random$[.@i] = .castle$[ .@r[.@i] ]; } sleep 100; announce "The Castles open today are "+ getcastlename( $castle_random$[0] ) +" and "+ getcastlename( $castle_random$[1] ) +" !!", bc_woe; for ( .@i = 0; .@i < 8; ++.@i ) { if ( .castle$[.@i] != $castle_random$[0] && .castle$[.@i] != $castle_random$[1] ) { removemapflag .castle$[.@i], mf_gvg_castle; killmonster .castle$[.@i], "custom_castle#"+ charat( .castle$[.@i], 9 ) +"::OnEmpBreak"; } } deletearray $castle_random$, 2; // for ( .@i = 0; .@i < 8; ++.@i ) // announce getcastlename( .castle$[.@i] ), bc_all, ( ( getmapflag( .castle$[.@i], mf_gvg_castle ) )? 0x00FF00 : 0xFF0000 ) ; end; OnAgitEnd: for ( .@i = 0; .@i < 8; ++.@i ) if ( !getmapflag( .castle$[.@i], mf_gvg_castle ) ) setmapflag .castle$[.@i], mf_gvg_castle; end; } /* db\castle_db.txt 51,06guild_01,Custom Castle 1,custom_castle#1 52,06guild_02,Custom Castle 2,custom_castle#2 53,06guild_03,Custom Castle 3,custom_castle#3 54,06guild_04,Custom Castle 4,custom_castle#4 55,06guild_05,Custom Castle 5,custom_castle#5 56,06guild_06,Custom Castle 6,custom_castle#6 57,06guild_07,Custom Castle 7,custom_castle#7 58,06guild_08,Custom Castle 8,custom_castle#8 */ 06guild_01,53,53,3 script custom_castle#1 GUILD_FLAG,{ .@gid = getcastledata( strnpcinfo(4), 1 ); dispbottom "========================="; dispbottom "castle map : "+ getcastlename( strnpcinfo(4) ); dispbottom "owner of the castle : "+( ( .@gid )? "["+ getguildname(.@gid) +"]" : "" ); dispbottom "agit check : "+( ( agitcheck() )?"on":"off" ); dispbottom "gvg_castle mapflag : "+( ( getmapflag( strcharinfo(3), mf_gvg_castle )?"on":"off" ) ); dispbottom "========================="; end; OnInit: if ( agitcheck() ) donpcevent strnpcinfo(0)+"::OnAgitStart"; setmapflag strnpcinfo(4), mf_gvg_castle; flagemblem getcastledata( strnpcinfo(4), 1 ); end; OnAgitStart: monster strnpcinfo(4),49,49,"EMPERIUM",1288,1,strnpcinfo(0)+"::OnEmpBreak"; setunitdata $@mobid, UMOB_HP, 5; end; OnAgitEnd: killmonster strnpcinfo(4), strnpcinfo(0)+"::OnEmpBreak"; end; OnEmpBreak: announce "The Emperium has fallen", bc_woe; setcastledata strnpcinfo(4), 1, getcharid(2); donpcevent strnpcinfo(0)+"::OnRecvCastle123"; sleep 6750; if ( agitcheck() ) goto OnAgitStart; end; OnAgitInit: requestguildinfo getcastledata( strnpcinfo(4), 1 ); OnRecvCastle123: flagemblem getcastledata( strnpcinfo(4), 1 ); end; OnGuildBreak: setcastledata strnpcinfo(4), 1, 0; donpcevent strnpcinfo(0)+"::OnRecvCastle123"; end; } 06guild_02,53,53,3 duplicate(custom_castle#1) custom_castle#2 GUILD_FLAG 06guild_03,53,53,3 duplicate(custom_castle#1) custom_castle#3 GUILD_FLAG 06guild_04,53,53,3 duplicate(custom_castle#1) custom_castle#4 GUILD_FLAG 06guild_05,53,53,3 duplicate(custom_castle#1) custom_castle#5 GUILD_FLAG 06guild_06,53,53,3 duplicate(custom_castle#1) custom_castle#6 GUILD_FLAG 06guild_07,53,53,3 duplicate(custom_castle#1) custom_castle#7 GUILD_FLAG 06guild_08,53,53,3 duplicate(custom_castle#1) custom_castle#8 GUILD_FLAG