//===== eAthena Script =======================================
//= ùJɶ]
//===== By: ==================================================
//= acky (god@acky.com)
//===== Current Version: =====================================
//= 1.2
//===== Compatible With: =====================================
//= Any eAthena Version
//===== Description: =========================================
//= Lets players race around Morroc (pvp_y_1-5)
//===== Additional Comments: =================================
//= If there are more than 3 players, at least 3 people
//= must finish before a new race can be started.
//=
//= If there are less than 3 players, at least 1 person
//= must finish before a new race can be started.
//=
//= Removed permanent global variables
//= 1.2 Removed Duplicates [Silent]
//===== : =================================
//= u@ë2006/02/16
//============================================================

//Warps you into race way
morocc,166,105,6	script	w]B֤k#01	116,{
mes "[w]B֤k]";
mes "AQiJ ^0000FFڬJɶ]^000000?";
next;
menu "O",L_Warp,"",-;
mes "[w]B֤k]";
mes "n,AQn}ɭԽЧiD.";
close;

L_Warp:
warp "pvp_y_1-5",165,256;
close;
}

//Warps you out of raceway
pvp_y_1-5,169,265,5	script	w]B֤k#02	116,{
mes "[w]B֤k]";
mes "wӨڬJɶ]!";
next;
menu "H",-,"}",L_Warp,"",L_Cancel;
mes "[w]B֤k]";
mes "HI_] NPCӶ}lɶ]";
next;
mes "[w]B֤k]";
mes "ɶ]}l,ЫӰfɰw¶ڬJb].";
next;
mes "[w]B֤k]";
mes "AgLҦаOI,n@@!!";
close;

L_Warp:
warp "morocc",165,101;

L_Cancel:
mes "[w]B֤k]";
mes "wA!";
close;
}

//Counts down and starts race
pvp_y_1-5,145,269,5	script	_]	733,{
if ($@race != 0) goto L_Started;
if ($@counting != 0) goto L_Started;
if ($@racecount == 1) goto L_Started;
L_Menu:
mes "[_]]";
mes "ЫObaڪF䪺Z.";
menu "}]",L_Count,"",-;
close;

	L_Count:
		set $@counting,1;
		mes "˭pɷǳƤ.....";
		addtimer 1000, "_]::OnCount1000";
		addtimer 2000, "_]::OnCount2000";
		addtimer 3000, "_]::OnCount3000";
		addtimer 4000, "_]::OnCount4000";
		announce strcharinfo(0) + "}l˭p",1;
		announce "зǳƴN!!",1;
		close;


	OnCount1000:
		announce "[3]",1;
		end;

	OnCount2000:
		announce "[2]",1;
		end;

	OnCount3000:
		announce "[1]",1;
		end;

	OnCount4000:
		emotion 27;
		specialeffect 267;
		announce "[}l!!!]",1;
		set $@race,1;
		set $@position,0;
		set $@counting,0;
		set $@raceid,rand(100000,999999);
		end;


L_Started:
if ((getmapusers("pvp_y_1-5") < 3) && ($@position > 0)) goto L_Menu;
if ($@position > 2) goto L_Menu;
mes "[_]]";
mes "ɶ]i椤";
close;

OnInit:
set $@race,0;
set $@position,0;
set $@racecount,0;
end;
}

//ˬdI 1
pvp_y_1-5,144,262,5	script	Check Point 1	111,0,5,{
end;
OnTouch:
if (@raceid != $@raceid) goto L_Started;
if (@race == 6) goto L_Finished;
if ($@race == 1) goto L_Started;
mes "ɶ]٥}l,Ц^_I.";
close;
L_Started:
set @race,1;
set @raceid,$@raceid;
end;
L_Finished:
mes "Aɶ]{.";
close;
}

//ˬdI 2
pvp_y_1-5,73,247,5	script	Check Point 2	111,6,6,{
end;
OnTouch:
if (@race != 1) goto L_Miss;
set @race,2;
announce "[" + strcharinfo(0) +"] wgFFˬdI [1]",1;
end;
L_Miss:
mes "ALFˬdI,ЭsӹL.";
close;
}

//ˬdI 3
pvp_y_1-5,77,44,5	script	Check Point 3	111,6,6,{
end;
OnTouch:
if (@race != 2) goto L_Miss;
set @race,3;
announce "[" + strcharinfo(0) +"] wgFFˬdI [2]",1;
end;
L_Miss:
mes "ALFˬdI,ЭsӹL.";
close;
}

//ˬdI 4
pvp_y_1-5,249,60,5	script	Check Point 4	111,6,6,{
end;
OnTouch:
if (@race != 3) goto L_Miss;
set @race,4;
announce "[" + strcharinfo(0) +"] wgFFˬdI [3]",1;
end;
L_Miss:
mes "ALFˬdI,ЭsӹL.";
close;
}

//ˬdI 5
pvp_y_1-5,255,256,5	script	Check Point 5	111,6,6,{
end;
OnTouch:
if (@race != 4) goto L_Miss;
set @race,5;
announce "[" + strcharinfo(0) +"] wgFFˬdI [4]",1;
end;
L_Miss:
mes "ALFˬdI,ЭsӹL.";
close;
}

//Iu
pvp_y_1-5,174,244,5	script	Finish Line	111,6,6,{
end;
OnTouch:
if (@raceid != $@raceid) goto L_WrongRace;
if (@race != 5) goto L_Miss;
set @race,6;
set $@position,$@position+1;
announce "[" + strcharinfo(0) +"] ĹLFI!!! [Position: " + $@position + "]",1;
end;
L_Miss:
mes "ALFˬdI,ЭsӹL.";
close;
L_WrongRace:
mes "AS.";
close;
}

//ˬdIX
pvp_y_1-5,144,267,4	script	Check Point 1#01	722,{
end;
}
pvp_y_1-5,144,257,4	script	Check Point 1#02	722,{
end;
}
pvp_y_1-5,70,252,3	script	Check Point 2#01	722,{
end;
}
pvp_y_1-5,77,243,3	script	Check Point 2#02	722,{
end;
}
pvp_y_1-5,81,48,1	script	Check Point 3#01	722,{
end;
}
pvp_y_1-5,72,40,1	script	Check Point 3#02	722,{
end;
}
pvp_y_1-5,244,65,7	script	Check Point 4#01	722,{
end;
}
pvp_y_1-5,252,57,7	script	Check Point 4#02	722,{
end;
}
pvp_y_1-5,259,260,5	script	Check Point 5#01	722,{
end;
}
pvp_y_1-5,251,252,5	script	Check Point 5#02	722,{
end;
}
pvp_y_1-5,174,249,4	script	Finish Line#01	722,{
end;
}
pvp_y_1-5,174,238,4	script	Finish Line#02	722,{
end;
}