//@unloadnpc nodual
//@loadnpc npc/valhalla/nodual.txt

-	script	nodual	-1,{
end;
OnPCLoadMapEvent:
	set .@charmap$, strcharinfo(PC_MAP);
	if(!compare(.tmp$,.@charmap$)) end;
  
	set .@len, query_sql("SELECT DISTINCT `account_id` FROM `char` WHERE `account_id` IN (SELECT `account_id` FROM `login` WHERE `last_unique_id` = (SELECT `last_unique_id` FROM `login` WHERE `account_id`="+getcharid(3)+")) AND `online` <> 0;",.@a);
	.@c = 0;
	for( .@d = 0 ;.@d < .@len; .@d++) {
		if(!getmapxy(.@map$,.@x,.@y,0,rid2name(.@a[.@d])))
			query_sql "SELECT COUNT(account_id) FROM autotrade_merchants WHERE `account_id`="+.@a[.@d],.@trade;
			if( compare(.tmp$,.@map$) ) ++.@c;
     		}
		if(.@c > .limitacc ) {
			if (agitcheck() || agitcheck2() ) {
				message strcharinfo(0), "WARNING: Dual accounts login on GVG Maps is not permitted. Close the other window and try again.";
				warp "SavePoint",0,0;
			}
			if (getvariableofnpc(.shower,"Miu")) {
				 message strcharinfo(0), "WARNING: Dual accounts on SHOWER EVENT is not permitted. Close the other window and try again.";
				warp "SavePoint",0,0;
			}	
    	}
	end;
    
OnInit:
     	set .limitacc,1;
    	setarray .maps$,"alde_gld",
	"office",
	"gef_fild13",
	"pay_gld",
	"prt_gld",
	"aldeg_cas01",
	"aldeg_cas02",
	"aldeg_cas03",
	"aldeg_cas04",
	"aldeg_cas05",
	"gefg_cas01",
	"gefg_cas02",
	"gefg_cas03",
	"gefg_cas04",
	"gefg_cas05",
	"payg_cas01",
	"payg_cas02",
	"payg_cas03",
	"payg_cas04",
	"payg_cas05",
	"prtg_cas01",
	"prtg_cas02",
	"prtg_cas03",
	"prtg_cas04",
	"prtg_cas05",
	"schg_cas01",
	"schg_cas02",
	"schg_cas03",
	"schg_cas04",
	"schg_cas05",
	"sch_gld",
	"arug_cas01",
	"arug_cas02",
	"arug_cas03",
	"arug_cas04",
	"arug_cas05",
	"aru_gld",
	"guild_vs1",
	"pvp_y_8-2";

        .lens = getarraysize(.maps$) ;
	for( .a = 0; .a < .lens; .a++) {
		setmapflag .maps$[.a], mf_loadevent;
            	set .tmp$ ,.tmp$+.maps$[.a]+",";
        }
	end;
}