Browse Source

Hunting Missions script update.
- Added check for deleted characters. (credits: @AnnieRuru)
- Modernized script syntax and improved readability.

Signed-off-by: Euphy <euphy.raliel@rathena.org>

Euphy 10 years ago
parent
commit
3c24f458ce
1 changed files with 116 additions and 83 deletions
  1. 116 83
      npc/custom/quests/hunting_missions.txt

+ 116 - 83
npc/custom/quests/hunting_missions.txt

@@ -3,7 +3,7 @@
 //===== By: ==================================================
 //= Euphy
 //===== Current Version: =====================================
-//= 1.3b
+//= 1.4
 //===== Compatible With: ===================================== 
 //= rAthena Project
 //===== Description: =========================================
@@ -19,12 +19,14 @@
 //= 1.3 Re-added a blacklist adapted for the SQL query.
 //= 1.3a Added mission reset options.
 //= 1.3b Function updates.
+//= 1.4 Check for deleted characters, thanks to AnnieRuru.
+//=     Syntax updates and style cleaning.
 //============================================================
 
 prontera,152,187,6	script	Hunting Missions	951,{
 function Chk;
 	mes "[Hunting Missions]";
-	mes "Hello, "+strcharinfo(0)+"!";
+	mes "Hello, " + strcharinfo(0) + "!";
 	if (!#Mission_Delay) {
 		next;
 		mes "[Hunting Missions]";
@@ -34,34 +36,50 @@ function Chk;
 		next;
 		callsub Mission_Info;
 		emotion e_go;
-		set #Mission_Delay,1;
+		#Mission_Delay = 1;
 		close;
 	}
-	mes rand(2)?"Working hard, as always...":"Not slacking, I hope...";
+	mes rand(2) ? "Working hard, as always..." : "Not slacking, I hope...";
 	mes "Is there anything I can help";
 	mes "you with?";
 	mes " ";
-	mes "^777777~ You've completed "+callfunc("F_InsertPlural",Mission_Total,"mission",0,"^0055FF%d^777777 %s")+". ~^000000";
+	mes "^777777~ You've completed " + callfunc("F_InsertPlural",Mission_Total,"mission",0,"^0055FF%d^777777 %s") + ". ~^000000";
 	next;
-	switch(select(((!Mission0)?" ~ New Mission::":": ~ Mission Status: ~ Abandon Mission")+": ~ Information: ~ Mission Shop: ~ View Top Hunters: ~ ^777777Cancel^000000")) {
+	switch(select(
+		((!Mission0) ? " ~ New Mission::" : ": ~ Mission Status: ~ Abandon Mission") +
+		": ~ Information: ~ Mission Shop: ~ View Top Hunters: ~ ^777777Cancel^000000"
+	)) {
 	case 1:
 		mes "[Hunting Missions]";
 		if (#Mission_Count) {
 			mes "You've started a mission";
 			mes "on another character.";
+			if (!@hm_char_del_check) {  // check for deleted character
+				query_sql("SELECT 1 FROM `global_reg_value` WHERE `str` = 'Mission0' AND `char_id` IN(SELECT `char_id` FROM `char` WHERE `account_id` = " + getcharid(3) + ")", .@i);
+				if (!.@i) {
+					next;
+					mes "[Hunting Missions]";
+					mes "I can't seem to find any records";
+					mes "for that character, though...";
+					mes "One moment, please.";
+					emotion e_hmm;
+					#Mission_Count = 0;
+				}
+				@hm_char_del_check = 1;
+			}
 			close;
 		}
 		if (#Mission_Delay > gettimetick(2) && .Delay) {
-			mes "I'm afraid you'll have to wait "+callfunc("Time2Str",#Mission_Delay)+" before taking another mission.";
+			mes "I'm afraid you'll have to wait " + callfunc("Time2Str",#Mission_Delay) + " before taking another mission.";
 			close;
 		}
 		mes "You must hunt:";
-		query_sql("SELECT ID FROM `" + .mob_db$ + "` WHERE left(Sprite, 4) != 'meta' AND left(Sprite, 2) != 'E_' AND ~Mode & 32 AND EXP > 0 AND MVP1id = 0 AND DropCardid > 4000 AND DropCardid < 5000 AND ID < 2000 AND instr('"+.Blacklist$+"',ID) = 0 ORDER BY rand() LIMIT "+.Quests, .@mob);
-		for (set .@i,0; .@i<.Quests; set .@i,.@i+1) {
-			setd "Mission"+.@i, .@mob[.@i];
-			setd "Mission"+.@i +"_",0;
+		query_sql("SELECT ID FROM `" + .mob_db$ + "` WHERE left(Sprite, 4) != 'meta' AND left(Sprite, 2) != 'E_' AND ~Mode & 32 AND EXP > 0 AND MVP1id = 0 AND DropCardid > 4000 AND DropCardid < 5000 AND ID < 2000 AND instr('"+.Blacklist$+"',ID) = 0 ORDER BY rand() LIMIT " + .Quests, .@mob);
+		for (.@i = 0; .@i < .Quests; .@i++) {
+			setd "Mission" + .@i, .@mob[.@i];
+			setd "Mission" + .@i +"_", 0;
 		}
-		set #Mission_Count, rand(.Count[0],.Count[1]);
+		#Mission_Count = rand(.Count[0], .Count[1]);
 		callsub Mission_Status;
 		next;
 		mes "[Hunting Missions]";
@@ -81,7 +99,7 @@ function Chk;
 		if (.Reset < 0 && .Delay)
 			mes "Your delay time will not be reset.";
 		else if (.Reset > 0)
-			mes "It will cost "+callfunc("F_InsertComma",.Reset)+" Zeny.";
+			mes "It will cost " + callfunc("F_InsertComma",.Reset) + " Zeny.";
 		next;
 		switch(select(" ~ Abandon...: ~ ^777777Cancel^000000")) {
 		case 1:
@@ -93,19 +111,20 @@ function Chk;
 					emotion e_sry;
 					close;
 				}
-				set Zeny, Zeny-.Reset;
+				Zeny -= .Reset;
 				emotion e_cash;
 			}
 			mes "[Hunting Missions]";
 			mes "Alright, I've dropped";
 			mes "your current mission.";
 			specialeffect2 EF_STORMKICK4;
-			for(set .@i,0; .@i<.Quests; set .@i,.@i+1) {
-				setd "Mission"+.@i,0;
-				setd "Mission"+.@i+"_",0;
+			for (.@i = 0; .@i < .Quests; .@i++) {
+				setd "Mission"+.@i, 0;
+				setd "Mission"+.@i+"_", 0;
 			}
-			set #Mission_Count,0;
-			if (.Reset < 0 && .Delay) set #Mission_Delay, gettimetick(2)+(.Delay*3600);
+			#Mission_Count = 0;
+			if (.Reset < 0 && .Delay)
+				#Mission_Delay = gettimetick(2) + (.Delay * 3600);
 			close;
 		case 2:
 			mes "[Hunting Missions]";
@@ -119,7 +138,7 @@ function Chk;
 		close;
 	case 5:
 		mes "[Hunting Missions]";
-		mes "You have ^0055FF"+#Mission_Points+"^000000 Mission Points.";
+		mes "You have ^0055FF" + #Mission_Points + "^000000 Mission Points.";
 		mes "Use them well!";
 		callshop "mission_shop",1;
 		npcshopattach "mission_shop";
@@ -127,9 +146,9 @@ function Chk;
 	case 6:
 		mes "[Hunting Missions]";
 		mes "The top hunters are:";
-		query_sql("SELECT char_id AS id, (SELECT `name` FROM `char` WHERE char_id = id),`value` FROM `global_reg_value` WHERE str = 'Mission_Total' ORDER BY CAST(`value` AS SIGNED) DESC LIMIT 5",.@id,.@name$,.@val);
-		for(set .@i,0; .@i<5; set .@i,.@i+1)
-			mes "  [Rank "+(.@i+1)+"]  "+((.@name$[.@i] == "")?"^777777none":"^0055FF"+.@name$[.@i]+"^000000 : ^FF0000"+.@val[.@i]+" pt.")+"^000000";
+		query_sql("SELECT char_id AS id, (SELECT `name` FROM `char` WHERE char_id = id),`value` FROM `global_reg_value` WHERE str = 'Mission_Total' ORDER BY CAST(`value` AS SIGNED) DESC LIMIT 5", .@id, .@name$, .@val);
+		for (.@i = 0; .@i < 5; .@i++)
+			mes "  [Rank " + (.@i+1) + "]  " + ((.@name$[.@i] == "") ? "^777777none" : "^0055FF" + .@name$[.@i]+"^000000 : ^FF0000" + .@val[.@i] + " pt.") + "^000000";
 		close;
 	case 7:
 		mes "[Hunting Missions]";
@@ -137,32 +156,36 @@ function Chk;
 		emotion e_hmm;
 		close;
 	}
+	end;
 
 Mission_Status:
-	set @f,0;
+	@f = 0;
 	deletearray .@j[0], getarraysize(.@j);
-	for(set .@i,0; .@i<.Quests; set .@i,.@i+1) {
-		set .@j[.@i], getd("Mission"+.@i);
-		set .@j[.Quests], .@j[.Quests]+strmobinfo(3,.@j[.@i]);
-		set .@j[.Quests+1], .@j[.Quests+1]+(strmobinfo(6,.@j[.@i])/(getbattleflag("base_exp_rate")/100)*.Modifier[0]);
-		set .@j[.Quests+2], .@j[.Quests+2]+(strmobinfo(7,.@j[.@i])/(getbattleflag("job_exp_rate")/100)*.Modifier[1]);
-		mes " > "+Chk(getd("Mission"+.@i+"_"),#Mission_Count)+strmobinfo(1,.@j[.@i])+" ("+getd("Mission"+.@i+"_")+"/"+#Mission_Count+")^000000";
+	for (.@i = 0; .@i < .Quests; .@i++) {
+		.@j[.@i] = getd("Mission" + .@i);
+		.@j[.Quests] = .@j[.Quests] + strmobinfo(3,.@j[.@i]);
+		.@j[.Quests+1] = .@j[.Quests+1] + (strmobinfo(6,.@j[.@i]) / (getbattleflag("base_exp_rate") / 100) * .Modifier[0]);
+		.@j[.Quests+2] = .@j[.Quests+2] + (strmobinfo(7,.@j[.@i]) / (getbattleflag("job_exp_rate") / 100) * .Modifier[1]);
+		mes " > "+Chk(getd("Mission"+.@i+"_"),#Mission_Count) + strmobinfo(1,.@j[.@i]) + " (" + getd("Mission"+.@i+"_") + "/" + #Mission_Count + ")^000000";
 	}
 
 	// Reward formulas:
-	set .@Mission_Points, 3+(.@j[.Quests]/.Quests/6);
-	set .@Base_Exp, #Mission_Count*.@j[.Quests+1]/5;
-	set .@Job_Exp, #Mission_Count*.@j[.Quests+2]/5;
-	set .@Zeny, #Mission_Count*.Quests*.@j[.@i]*.Modifier[2];
+	.@Mission_Points = 3 + (.@j[.Quests] / .Quests / 6);
+	.@Base_Exp = #Mission_Count * .@j[.Quests+1] / 5;
+	.@Job_Exp = #Mission_Count * .@j[.Quests+2] / 5;
+	.@Zeny = #Mission_Count * .Quests * .@j[.@i] * .Modifier[2];
 
 	next;
 	mes "[Hunting Missions]";
 	mes "Mission rewards:";
-	mes " > Mission Points: ^0055FF"+.@Mission_Points+"^000000";
-	mes " > Base Experience: ^0055FF"+callfunc("F_InsertComma",.@Base_Exp)+"^000000";
-	mes " > Job Experience: ^0055FF"+callfunc("F_InsertComma",.@Job_Exp)+"^000000";
-	mes " > Zeny: ^0055FF"+callfunc("F_InsertComma",.@Zeny)+"^000000";
-	if (@f) { set @f,0; return; }
+	mes " > Mission Points: ^0055FF" + .@Mission_Points + "^000000";
+	mes " > Base Experience: ^0055FF" + callfunc("F_InsertComma",.@Base_Exp) + "^000000";
+	mes " > Job Experience: ^0055FF" + callfunc("F_InsertComma",.@Job_Exp) + "^000000";
+	mes " > Zeny: ^0055FF" + callfunc("F_InsertComma",.@Zeny) + "^000000";
+	if (@f) {
+		@f = 0;
+		return;
+	}
 	next;
 	mes "[Hunting Missions]";
 	mes "Oh, you're done!";
@@ -171,19 +194,22 @@ Mission_Status:
 	emotion e_no1;
 	specialeffect2 EF_ANGEL;
 	specialeffect2 EF_TRUESIGHT;
-	set #Mission_Points, #Mission_Points+.@Mission_Points;
-	set BaseExp, BaseExp+.@Base_Exp;
-	set JobExp, JobExp+.@Job_Exp;
-	set Zeny, Zeny+.@Zeny;
-	for(set .@i,0; .@i<.Quests; set .@i,.@i+1) {
-		setd "Mission"+.@i,0;
-		setd "Mission"+.@i+"_",0;
+	#Mission_Points += .@Mission_Points;
+	BaseExp += .@Base_Exp;
+	JobExp += .@Job_Exp;
+	Zeny += .@Zeny;
+	for (.@i = 0; .@i < .Quests; .@i++) {
+		setd "Mission" + .@i, 0;
+		setd "Mission" + .@i+"_", 0;
 	}
-	set #Mission_Count,0;
-	if (.Delay) set #Mission_Delay, gettimetick(2)+(.Delay*3600);
-	set Mission_Total, Mission_Total+1;
-	if (Mission_Total == 1) query_sql("INSERT INTO `global_reg_value` (`char_id`,`str`,`value`,`type`,`account_id`) VALUES ("+getcharid(0)+",'Mission_Total','1',3,0)");
-	else query_sql("UPDATE `global_reg_value` SET `value` = "+Mission_Total+" WHERE char_id = "+getcharid(0)+" AND `str` = 'Mission_Total'");
+	#Mission_Count = 0;
+	if (.Delay)
+		#Mission_Delay = gettimetick(2) + (.Delay * 3600);
+	Mission_Total++;
+	if (Mission_Total == 1)
+		query_sql("INSERT INTO `global_reg_value` (`char_id`,`str`,`value`,`type`,`account_id`) VALUES (" + getcharid(0) + ",'Mission_Total','1',3,0)");
+	else
+		query_sql("UPDATE `global_reg_value` SET `value` = " + Mission_Total + " WHERE char_id = " + getcharid(0) + " AND `str` = 'Mission_Total'");
 	close;
 
 Mission_Info:
@@ -196,41 +222,46 @@ Mission_Info:
 	mes "[Hunting Missions]";
 	mes "Missions points are shared";
 	mes "amongst all your characters.";
-	if (.Delay) mes "Delay time is, too.";
+	if (.Delay)
+		mes "Delay time is, too.";
 	mes "You can't take missions on";
 	mes "multiple characters at once.";
 	next;
 	mes "[Hunting Missions]";
 	mes "You can start a quest";
-	if (.Delay) mes "every "+((.Delay == 1)?"hour.":.Delay+" hours.");
-	else mes "whenever you want.";
+	mes (.Delay ? "every " + ((.Delay == 1) ? "hour." : .Delay + " hours.") : "whenever you want.");
 	mes "That's everything~";
 	return;
 
 function Chk {
-	if (getarg(0) < getarg(1)) { set @f,1; return "^FF0000"; }
-	else return "^00FF00"; }
+	if (getarg(0) < getarg(1)) {
+		@f = 1;
+		return "^FF0000";
+	} else
+		return "^00FF00";
+}
 
 OnBuyItem:
-	set @cost,0;
-	for(set .@i,0; .@i<getarraysize(@bought_nameid); set .@i,.@i+1)
-		for(set .@j,0; .@j<getarraysize(.Shop); set .@j,.@j+2)
+	@cost = 0;
+	for (.@i = 0; .@i < getarraysize(@bought_nameid); .@i++)
+		for (.@j = 0; .@j < getarraysize(.Shop); .@j += 2)
 			if (@bought_nameid[.@i] == .Shop[.@j]) {
-				set @cost, @cost+(.Shop[.@j+1]*@bought_quantity[.@i]);
+				set @cost, @cost + (.Shop[.@j+1] * @bought_quantity[.@i]);
 				break;
 			}
 	mes "[Hunting Missions]";
-	if (@cost > #Mission_Points) mes "You don't have enough Mission Points.";
+	if (@cost > #Mission_Points)
+		mes "You don't have enough Mission Points.";
 	else {
-		for(set .@i,0; .@i<getarraysize(@bought_nameid); set .@i,.@i+1) {
+		for (.@i = 0; .@i < getarraysize(@bought_nameid); .@i++) {
 			getitem @bought_nameid[.@i], @bought_quantity[.@i];
-			dispbottom "Purchased "+@bought_quantity[.@i]+"x "+getitemname(@bought_nameid[.@i])+".";
+			dispbottom "Purchased " + @bought_quantity[.@i] + "x " + getitemname(@bought_nameid[.@i]) + ".";
 		}
-		set #Mission_Points, #Mission_Points-@cost;
+		#Mission_Points -= @cost;
 		mes "Deal completed.";
 		emotion e_cash;
 	}
-	set @cost,0;
+	@cost = 0;
 	deletearray @bought_nameid[0], getarraysize(@bought_nameid);
 	deletearray @bought_quantity[0], getarraysize(@bought_quantity);
 	close;
@@ -238,29 +269,31 @@ OnBuyItem:
 OnNPCKillEvent:
 	if (!getcharid(1) || !.Party) {
 		if (!#Mission_Count || !Mission0) end;
-		for (set .@i, 0; .@i<.Quests; set .@i,.@i+1) {
-			if (strmobinfo(1,killedrid) == strmobinfo(1,getd("Mission"+.@i))) {
-				if (getd("Mission"+.@i+"_") < #Mission_Count) {
-					dispbottom "[Hunting Mission] Killed "+(set(getd("Mission"+.@i+"_"),getd("Mission"+.@i+"_")+1))+" of "+#Mission_Count+" "+strmobinfo(1,killedrid)+".";
+		for (.@i = 0; .@i < .Quests; .@i++) {
+			if (strmobinfo(1,killedrid) == strmobinfo(1,getd("Mission" + .@i))) {
+				if (getd("Mission" + .@i + "_") < #Mission_Count) {
+					dispbottom "[Hunting Mission] Killed " + (set(getd("Mission" + .@i + "_"),getd("Mission" + .@i + "_") + 1)) +
+					           " of " + #Mission_Count + " " + strmobinfo(1,killedrid) + ".";
 					end;
 				}
 			}
 		}
 	} else if (.Party) {
-		set .@mob, killedrid;
+		.@mob = killedrid;
 		getmapxy(.@map1$,.@x1,.@y1,0);
 		getpartymember getcharid(1),1;
 		getpartymember getcharid(1),2;
-		for(set .@i,0; .@i<$@partymembercount; set .@i,.@i+1) {
+		for (.@i = 0; .@i < $@partymembercount; .@i++) {
 			if (isloggedin($@partymemberaid[.@i], $@partymembercid[.@i])) {
 				attachrid $@partymemberaid[.@i];
 				if (#Mission_Count && Mission0 && HP > 0) {
 					getmapxy(.@map2$,.@x2,.@y2,0);
 					if ((.@map1$ == .@map2$ || .Party == 1) && (distance(.@x1,.@y1,.@x2,.@y2) <= 30 || .Party < 3)) {
-						for(set .@j,0; .@j<.Quests; set .@j,.@j+1) {
+						for (.@j = 0; .@j < .Quests; .@j++) {
 							if (strmobinfo(1,.@mob) == strmobinfo(1,getd("Mission"+.@j))) {
 								if (getd("Mission"+.@j+"_") < #Mission_Count) {
-									dispbottom "[Hunting Mission] Killed "+(set(getd("Mission"+.@j+"_"),getd("Mission"+.@j+"_")+1))+" of "+#Mission_Count+" "+strmobinfo(1,.@mob)+".";
+									dispbottom "[Hunting Mission] Killed " + (set(getd("Mission" + .@j + "_"),getd("Mission" + .@j + "_") + 1)) +
+									           " of " + #Mission_Count + " " + strmobinfo(1,.@mob) + ".";
 									break;
 								}
 							}
@@ -273,19 +306,19 @@ OnNPCKillEvent:
 	end;
 
 OnInit:
-	set .Delay,12;		// Quest delay, in hours (0 to disable).
-	set .Quests,4;		// Number of subquests per mission (increases rewards).
-	set .Party,3;		// Party options: 0 (exclude party kills), 1 (include party kills), 2 (same map only), 3 (screen area only)
-	set .Reset,-1;		// Reset options: -1 (abandoning mission sets delay time), 0 (no delay time), [Zeny] (cost to abandon mission, no delay time)
-	setarray .Count[0],	// Min and max monsters per subquest (increases rewards).
+	.Delay = 12;            // Quest delay, in hours (0 to disable).
+	.Quests = 4;            // Number of subquests per mission (increases rewards).
+	.Party = 3;             // Party options: 0 (exclude party kills), 1 (include party kills), 2 (same map only), 3 (screen area only)
+	.Reset = -1;            // Reset options: -1 (abandoning mission sets delay time), 0 (no delay time), [Zeny] (cost to abandon mission, no delay time)
+	setarray .Count[0],     // Min and max monsters per subquest (increases rewards).
 		40,70;
-	setarray .Modifier[0],	// Multipliers for Base Exp, Job Exp, and Zeny rewards.
+	setarray .Modifier[0],  // Multipliers for Base Exp, Job Exp, and Zeny rewards.
 		getbattleflag("base_exp_rate")/100,getbattleflag("job_exp_rate")/100,60;
-	set .mob_db$,		// Table name of SQL mob database
+	.mob_db$ =              // Table name of SQL mob database
 		(checkre(0))?"mob_db_re":"mob_db";
-	setarray .Shop[0],	// Reward items: <ID>,<point cost> (about 10~20 points per hunt).
+	setarray .Shop[0],      // Reward items: <ID>,<point cost> (about 10~20 points per hunt).
 		512,1,513,1,514,1,538,5,539,5,558,10,561,10;
-	set .Blacklist$,	// Blacklisted mob IDs.
+	.Blacklist$ =           // Blacklisted mob IDs.
 		"1062,1088,1183,1186,1200,1212,1220,1221,1234,1235,"+
 		"1244,1245,1250,1268,1290,1293,1294,1296,1298,1299,"+
 		"1300,1301,1303,1304,1305,1306,1308,1309,1311,1313,"+
@@ -293,7 +326,7 @@ OnInit:
 		"1975,1976,1977,1978,1979";
 
 	npcshopdelitem "mission_shop",512;
-	for(set .@i,0; .@i<getarraysize(.Shop); set .@i,.@i+2)
+	for (.@i = 0; .@i < getarraysize(.Shop); .@i += 2)
 		npcshopadditem "mission_shop", .Shop[.@i], .Shop[.@i+1];
 	end;
 }