Jump to content

  •  

xapaon123

Member Since 03 Sep 2015
Offline Last Active Apr 29 2017 05:55 PM
-----

Topics I've Started

Rewrite this script to work with new InstanceDB

16 January 2016 - 08:05 PM

Hello i want if possible someone who can help rewrite this instance to work with latest rev 

//	~~~~~ show time left in days, hours, minutes and seconds ~~~~~
function	script	timeleft__	{
	if ( ( .@left = getarg(0) ) <= 0 ) return getarg(0);
	.@day = .@left / 86400;
	.@hour = .@left % 86400 / 3600;
	.@min = .@left % 3600 / 60;
	.@SEC = .@left % 60;
	if ( .@day )
		return .@day +" day "+ .@hour +" hour";
	else if ( .@hour )
		return .@hour +" hour "+ .@min +" min";
	else if ( .@min )
		return .@min +" min "+ .@SEC +" sec";
	else
		return .@SEC +" sec";
}


prontera,152,178,3	script	szfjkii	406,{

	mes "- each difficulty have 10 levels",
		"- each difficulty have given time to finish the instance",
		"- for Normal: 30 minutes",
		"- for Hard: 45 minutes",
		"- for Nightmare: 60 minutes",
		"- for Hardcore: 90 minutes";
	next;
	// can re-enter if already generated
	if( instance_id(1) && getcharid(1) ) {
		if ( select( "Enter", "Cancel" ) -1 ) {
			mes "See ya.";
			close;
		}
		if ( has_instance( .map_inst$ ) == "" ) { 
			mes "Your group is already registered at an other instance.";
			close;
		}
		getpartymember getcharid(1), 1;
		if ( $@partymembercount > .max_players ) {
			mes "Maximum of "+ .max_players +" members in the party";
			close;
		}
		// check job if a player is invited
		if( .same_job ) {
			.@self = getcharid(3);
			for( .@i = 0; .@i < $@partymembercount; .@i++ ) {
				if( isloggedin( $@partymemberaid[ .@i ], $@partymembercid[ .@i ] ) ) {
					attachrid( $@partymemberaid[ .@i ] );
					.@job_name$ = .@job_name$ + jobname(Class) +"|";
				}
			}
			attachrid( .@self );
			if( countstr( .@job_name$, jobname(Class) ) > 1 ) {
				mes "sorry there is 2 same job in the party, you can't enter.";
				close;
			}
		}
		// check delay if a player is invited
		for( .@i = 0; .@i < getarraysize( getd( ".char_id"+ getcharid(1) ) ); .@i++ )
			if( getd( ".char_id"+ getcharid(1) +"["+ .@i +"]" ) == getcharid(0) ) {
				.@pass = 1;
				break;
			}
		if( !.@pass ) {
			if( gettimetick(2) < Delay_instance ) {
				mes "sorry you must wait "+ callfunc( "timeleft__", Delay_instance - gettimetick(2) ) +" before enter";
				close;
			}
			.@size = getarraysize( getd( ".char_id"+ getcharid(1) ) );
			setd( ".char_id"+ getcharid(1) +"[ "+ .@size +" ]", getcharid(0) );
			Delay_instance = gettimetick(2) + 3600 * 3;
		}
		instance_announce instance_id(1), strcharinfo(0)+" of the party "+ getpartyname( getcharid(1) ) +" is entering in the instance.",bc_map;
		warp has_instance( .map_inst$ ),50,50;
		end; 
	}
	if ( select ( "Normal", "Hard", "Hardcore", "Nightmare", "Leave" ) == 5 ) {// using @menu for instancing
		mes "See ya.";
		close;
	}
	else if( !getcharid(1) ) {
		mes "You need to be in party ( Maximum of "+ .max_players +" members ).";
		close;
	}
	// check delay of players in the party
	getpartymember getcharid(1), 1;
	getpartymember getcharid(1), 2;
	.@self = getcharid(3);
	for( .@i = 0; .@i < $@partymembercount; .@i++ ) {
		if( isloggedin( $@partymemberaid[ .@i ], $@partymembercid[ .@i ] ) ) {
			attachrid( $@partymemberaid[ .@i ] );
			if( gettimetick(2) < Delay_instance ) {
				.@name$ = strcharinfo(0);
				.@time = Delay_instance - gettimetick(2);
				attachrid( .@self );
				mes "sorry "+ .@name$ +" must wait "+ callfunc( "timeleft__", .@time ) +" before enter";
				close;
			}
			else if( compare( .@job_name$, jobname(Class) ) && .same_job ) {
				.@name$ = strcharinfo(0);
				.@job$ = jobname(Class);
				attachrid( .@self );
				mes "sorry, "+ .@name$ +" is "+ .@job$ +" and there is already a "+ .@job$ +" in the party";
				close;
			}
			.@job_name$ = .@job_name$ + jobname(Class) +"|";
		}
	}
	attachrid( .@self );
	if ( $@partymembercount > .max_players ) {
		mes "Maximum of "+ .max_players +" members in the party";
		close;
	}
	else if( getpartyleader( getcharid(1),2 ) != getcharid(0) ) {
		mes "I only talk to your leader.";
		close;
	}
	mes "If the instance is successfully generated all your party will be warp inside. Get ready";
	next;

	.@inst_id = instance_create( .name_inst$,getcharid(1) ); 
	if( .@inst_id < 0 ){
		mes "Failed. Contact a GM.";
		close;
	}
	instance_attachmap( .map_inst$,.@inst_id );
	instance_set_timeout .timelimit[ @menu ], .timeidle, .@inst_id;
	instance_init .@inst_id;
	instance_attach .@inst_id;
	'diff$ = .diff$[ @menu ];
	'party_id = getcharid(1);
	'time_inst = gettimetick(2) + .timelimit[ @menu ];
	'inst_id = .@inst_id;
	'max_players = .max_players;
	donpcevent instance_npcname( "Inst_cust" ) +"::Oninstancing";
	sleep2 50;
	getpartymember getcharid(1), 1;
	getpartymember getcharid(1), 2;
	.@self = getcharid(3);
	if( .same_job ) {
		.@job_name$ = "";
		for( .@i = 0; .@i < $@partymembercount; .@i++ ) {
			if( isloggedin( $@partymemberaid[ .@i ], $@partymembercid[ .@i ] ) ) {
				attachrid( $@partymemberaid[ .@i ] );
				.@job_name$ = .@job_name$ + jobname(Class) +"|";
			}
		}
	}
	// dispbottom .@job_name$;
	for( .@i = 0; .@i < $@partymembercount; .@i++ ) {
		if( isloggedin( $@partymemberaid[ .@i ], $@partymembercid[ .@i ] ) ) {
			attachrid( $@partymemberaid[ .@i ] );
			if( gettimetick(2) >= Delay_instance && countstr( .@job_name$, jobname(Class) ) <= 1 ) {
				Delay_instance = gettimetick(2) + 3600 * 3;
				.@size = getarraysize( getd( ".char_id"+ getcharid(1) ) );
				setd( ".char_id"+ getcharid(1) +"[ "+ .@size +" ]", getcharid(0) );
				warp has_instance( .map_inst$ ),50,50;
			}
		}
	}
	// warpparty has_instance( .map_inst$ ),50,50, getcharid(1);
	close;
OnDelete:
	deletearray getd( ".char_id"+ getvariableofnpc( .party_id, "Inst_cust") );
	end;
OnInit:
	.same_job = 1;				// DON'T allow 2 same job to enter in the instance
	.map_inst$ = "1@guild";		// instance map's name
	.name_inst$ = "Custom instance";	// instance name display
	.timeidle = 300;			// time (sec) to re-enter in the instance when all players outside
	.max_players = 4;			// max players in the party

// time limit (sec) of the instance per level - Normal, Hard, Hardcore, Nightmare
	setarray .timelimit[ 1 ], 1800, 2700, 3600, 4500;

// Difficulty's names - Don't touch
	setarray .diff$[ 1 ], "Normal", "Hard", "Hardcore", "Nightmare";
	end;
}

1@guild,0,0,0	script	Inst_cust	-1,{
function Countpartyonline;
function Reward;

OnInit:
	.npc_enter$ = "szfjkii"; // name of the NPC to enter in the instance
// Number ( monsters / round / difficulty ) initialized
	setarray .mob_init_Normal[ 1 ], 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
	setarray .mob_init_Hard[ 1 ], 2, 3, 4, 5, 6, 7, 8, 9, 10, 12;
	setarray .mob_init_Hardcore[ 1 ], 3, 4, 5, 6, 7, 8, 9, 10, 11, 13;
	setarray .mob_init_Nightmare[ 1 ], 5, 6, 7, 8, 9, 10, 12, 14, 16, 20;

// Hero ( points / round / difficulty ) - using #hero_points variable
	setarray .hero_points_Normal[ 1 ], 100,110,120,130,140,150,160,170,180,200;
	setarray .hero_points_Hard[ 1 ], 120,140,160,180,200,220,240,260,280,300;
	setarray .hero_points_Hardcore[ 1 ], 150,180,210,240,270,300,330,360,390,420;
	setarray .hero_points_Nightmare[ 1 ], 200,250,300,350,400,450,500,550,600,700;

// Time (min) / round / difficulty
	setarray .time_Normal[ 1 ], 1,2,3,4,5,6,7,8,9,10;
	setarray .time_Hard[ 1 ], 2,4,6,8,10,12,14,16,18,20;
	setarray .time_Hardcore[ 1 ], 3,6,9,12,15,18,21,24,27,30;
	setarray .time_Nightmare[ 1 ], 4,8,12,16,20,24,28,32,36,40;

// Mob ID / round
// Level : Normal
	setarray .mob_ID_Normal_round1[ 0 ], 1002,1005,1004;// poring, hornet, familiar
	setarray .mob_ID_Normal_round2[ 0 ], 1002,1005;
	setarray .mob_ID_Normal_round3[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Normal_round4[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Normal_round5[ 0 ], 1002,1005,1004,1005;
	setarray .mob_ID_Normal_round6[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Normal_round7[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Normal_round8[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Normal_round9[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Normal_round10[ 0 ], 1002,1005,1004;
// Level : Hard
	setarray .mob_ID_Hard_round1[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hard_round2[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hard_round3[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hard_round4[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hard_round5[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hard_round6[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hard_round7[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hard_round8[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hard_round9[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hard_round10[ 0 ], 1002,1005,1004;
// Level : Hardcore
	setarray .mob_ID_Hardcore_round1[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hardcore_round2[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hardcore_round3[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hardcore_round4[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hardcore_round5[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hardcore_round6[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hardcore_round7[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hardcore_round8[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hardcore_round9[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Hardcore_round10[ 0 ], 1002,1005,1004;
// Level : Nightmare
	setarray .mob_ID_Nightmare_round1[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Nightmare_round2[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Nightmare_round3[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Nightmare_round4[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Nightmare_round5[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Nightmare_round6[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Nightmare_round7[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Nightmare_round8[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Nightmare_round9[ 0 ], 1002,1005,1004;
	setarray .mob_ID_Nightmare_round10[ 0 ], 1002,1005,1004;
	.round_max = 10; // round max
	end;

// Instance start
// --------------
Oninstancing:
	sleep 10000;
// New round
// ---------
LStart:
	'round++;
	instance_announce 'inst_id, 'round + ( 'round % 10 == 1 ? "st" : ( 'round % 10 == 2 ? "nd" : ( 'round % 10 == 3 ? "rd" : "th" ) ) ) +" round in :", bc_map;
	for( .@i = 5; .@i > 0; .@i-- ) {
		instance_announce 'inst_id, .@i +"" ,bc_map;
		sleep 1000;
	}
	donpcevent instance_npcname( "Inst_cust" ) +"::OnTimevent";// initialize time limit for the round
	goto OnRound;

// Monster is dead : check player on map + reward if 0 mob
// -------------------------------------------------------
OnMobDead:
	if( instance_check_party( 'party_id,'max_players +1 ) ) {// check if there are more than 4 players in the party instance
		instance_announce 'inst_id, "To much players. End of instance.", bc_map;
		'round = .round_max + 1;
		goto L_pr;
	}
	'count = mobcount( strnpcinfo(4), instance_npcname( "Inst_cust", 'inst_id ) +"::OnMobDead" );
	instance_announce instance_id(0), 'count +" monsters left" ,bc_map;
	if( !'count ) {
		instance_announce 'inst_id, "All monsters on the "+ 'round + ( 'round % 10 == 1 ? "st" : ( 'round % 10 == 2 ? "nd" : ( 'round % 10 == 3 ? "rd" : "th" ) ) ) +" level have been defeated.", bc_map;
		Reward();// hero points / round / difficulty
		if( 'round == .round_max ) {
			'round = .round_max + 1;
			goto L_end;
		}
		goto LStart;
	}
	end;

// Random (spawn / round / difficulty)
// -----------------------------------
OnRound:
	.@spawn = 'count = Countpartyonline() + getd( ".mob_init_"+ 'diff$ +"[ "+ 'round +" ]" );// spawn count = ( monster initialized / round / difficulty ) + number players online in party
	instance_announce 'inst_id, "you have "+ getd( ".time_"+ 'diff$ +"[ "+ 'round +" ]" ) +" min to finish this round in "+ 'diff$ +" mode. "+ .@spawn +" mobs are spawned",bc_map;
	while( .@spawn ) {// spawned ( monster / round / difficulty ) randomly 
		.@Rand = rand( 1,.@spawn );// number mobs
		.@spawn = .@spawn - .@Rand;
		.@i = rand( getarraysize( getd( ".mob_ID_"+ 'diff$ +"_round"+ 'round ) ) );// ID mob
		monster "1@guild",0,0,"--ja--", getd( ".mob_ID_"+ 'diff$ +"_round"+ 'round +"[ "+ .@i +" ]" ), .@Rand, instance_npcname( strnpcinfo(0),'inst_id )+"::OnMobDead";
	}
	end;

// End of instance
// ---------------
L_end:
	instance_announce 'inst_id, "Congratulation you have finished the instance in "+ callfunc( "timeleft__", 'time_inst - gettimetick(2) ), bc_map;
OnTimevent:// time limit / round / difficulty
	awake instance_npcname( "Inst_cust" );
	if( 'round <= .round_max ) {
		sleep 1;
		'tmp = 'round;
		sleep 1000 * 60 * getd( ".time_"+ 'diff$ +"[ "+ 'round +" ]" );
		if( 'round != 'tmp ) end;
		instance_announce 'inst_id, "you take to much time.", bc_map;
	}
L_pr:
	instance_warpall "prontera", 152,178, 'inst_id;
	.party_id = 'party_id;
	donpcevent .npc_enter$ +"::OnDelete";
	sleep 500;
	instance_destroy 'inst_id;
	end;


// Functions
// ---------
function Countpartyonline {
	getpartymember 'party_id, 1;
	getpartymember 'party_id, 2;
	for( .@i = 0; .@i < $@partymembercount; .@i++ ) {
		if( isloggedin( $@partymemberaid[ .@i ], $@partymembercid[ .@i ] ) && getarg( 0,1 ) ) .@j++;
		// else if( isloggedin( $@partymemberaid[ .@i ], $@partymembercid[ .@i ] ) && !getarg( 0,1 ) ) {
			// attachrid( $@partymemberaid[ .@i ] );
			// Delay_instance = gettimetick(2) + 3600 * 3;
		// }
	}
	return .@j;
}

function Reward {
	getpartymember 'party_id, 1;
	getpartymember 'party_id, 2;
	.@tmp$ = strcharinfo(3);
	for( .@i = 0; .@i < $@partymembercount; .@i++ )
		if( isloggedin( $@partymemberaid[ .@i ], $@partymembercid[ .@i ] ) ) {
			attachrid( $@partymemberaid[ .@i ] );
			if( strcharinfo(3) == .@tmp$ ) {
				#hero_points = #hero_points + getd( ".hero_points_"+ 'diff$ +"[ "+ 'round +" ]" );
				dispbottom "Gained : "+ getd( ".hero_points_"+ 'diff$ +"[ "+ 'round +" ]" ) +" Hero Points. Total : "+ #hero_points;
			}
		}
	return;
}

// function Delayparty {
	// Countpartyonline( 0 );
	// return;
// }

}

1@guild	mapflag	nowarp
1@guild	mapflag	partylock
1@guild	mapflag	nowarpto
1@guild	mapflag	noteleport
1@guild	mapflag	nosave	SavePoint
1@guild	mapflag	nomemo
1@guild	mapflag	nobranch
1@guild	mapflag	monster_noteleport