Prechádzať zdrojové kódy

Fixed vip_status command (#2184)

Fixed different return types for the same function call
Also introduced constants for better function usage.

Fixes #2183
Thanks to @anacondaqq
Lemongrass3110 8 rokov pred
rodič
commit
d0ca637ddd

+ 4 - 4
doc/script_commands.txt

@@ -2465,9 +2465,9 @@ Examples:
 Returns various information about a player's VIP status.
 
 Valid types:
- 1 - VIP status. (1 if VIP, 0 if non-VIP)
- 2 - VIP expire date. (timestamp string if VIP, 0 if non-VIP)
- 3 - VIP time remaining. (timestamp string if VIP, 0 if non-VIP)
+ VIP_STATUS_ACTIVE - VIP status: true if the player is a VIP or false if not
+ VIP_STATUS_EXPIRE - VIP expire timestamp if the player is VIP or 0 if not
+ VIP_STATUS_REMAINING - VIP time remaining in seconds
 
 NOTE: This command is only available if the VIP System is enabled.
 
@@ -5178,7 +5178,7 @@ Values for <mode> are:
 	STOR_MODE_PUT  : Player can put items in the storage.
 
 Example:
-	if (vip_status(1)) {
+	if (vip_status(VIP_STATUS_ACTIVE)) {
 		mes "I will open your Premium storage.";
 		mes "Thank you for using our service.";
 		close2;

+ 1 - 1
npc/battleground/bg_common.txt

@@ -609,7 +609,7 @@ function	script	F_BG_Badge	{
 	close2;
 
 	// If the VIP system is enabled, VIP players receive an extra 2 badges.
-	if (VIP_SCRIPT && vip_status(1))
+	if (VIP_SCRIPT && vip_status(VIP_STATUS_ACTIVE))
 		set .@amount, .@amount+2;
 
 	set .@medal_gap, 500 - countitem(.@badge);

+ 1 - 1
npc/kafras/cool_event_corp.txt

@@ -74,7 +74,7 @@ function	script	F_CoolEventCorp	{
 		mes "Please choose";
 		mes "your destination.";
 		next;
-		if (VIP_SCRIPT && !vip_status(1))
+		if (VIP_SCRIPT && !vip_status(VIP_STATUS_ACTIVE))
 			set .@cost,4400;
 		else
 			set .@cost,2200;

+ 1 - 1
npc/kafras/functions_kafras.txt

@@ -658,7 +658,7 @@ function	script	F_KafSet	{
 	}
 
 	// VIP pricing varies across the regional servers; this is most practical.
-	if (VIP_SCRIPT && !vip_status(1)) {
+	if (VIP_SCRIPT && !vip_status(VIP_STATUS_ACTIVE)) {
 		for (set .@i, 0; .@i < getarraysize(@wrpD$); set .@i, .@i + 1)
 			setd "@wrpP["+.@i+"]",getd("@wrpP["+.@i+"]") * 2;
 	}

+ 1 - 1
npc/merchants/advanced_refiner.txt

@@ -105,7 +105,7 @@ S_RefineValidate:
 	set .@price, getarg(2);
 
 	// If the VIP system is enabled, the prices for non-VIP players are considerably higher.
-	if (VIP_SCRIPT && !vip_status(1)) {
+	if (VIP_SCRIPT && !vip_status(VIP_STATUS_ACTIVE)) {
 		switch(.@weapon_lvl){
 			case 0: set .@price, .@price * 10; break;
 			case 1: set .@price, .@price * 40; break;

+ 1 - 1
npc/merchants/refine.txt

@@ -643,7 +643,7 @@ function	script	refinemain	{
 	}
 
 	// If the VIP system is enabled, the prices for non-VIP players are considerably higher.
-	if (VIP_SCRIPT && !vip_status(1)) {
+	if (VIP_SCRIPT && !vip_status(VIP_STATUS_ACTIVE)) {
 		switch(getequipweaponlv(.@part)) {
 			case 0: set .@price, .@price * 10; break;
 			case 1: set .@price, .@price * 40; break;

+ 1 - 1
npc/other/marriage.txt

@@ -32,7 +32,7 @@ prt_church,97,100,4	script	Wedding Staff#w	71,{
 		// If the VIP system is enabled:
 		// - Non-VIP players must use a Marriage Covenant to get married.
 		// - VIP players may either pay the Zeny fee or use a Marriage Covenant.
-		if (VIP_SCRIPT && !vip_status(1)) {
+		if (VIP_SCRIPT && !vip_status(VIP_STATUS_ACTIVE)) {
 			mes "[Marry Happy]";
 			mes "Sorry but you can't get married right now.";
 			mes "The wedding is only available for subscribed players.";

+ 1 - 1
npc/re/cities/brasilis.txt

@@ -28,7 +28,7 @@ alberta,246,82,3	script	Crewman#bra2	100,{
 	mes "[Crewman]";
 	mes "We recently found a new ocean route to get there easily.";
 	if (VIP_SCRIPT) {
-		set .@cost, vip_status(1)?1000:10000;
+		set .@cost, vip_status(VIP_STATUS_ACTIVE)?1000:10000;
 		mes "It's just 10,000 zeny for a round trip, and 1,000 for VIP! So do you want to go?"; //custom translation (VIP)
 	} else {
 		set .@cost,10000;

+ 1 - 1
npc/re/cities/dewata.txt

@@ -24,7 +24,7 @@ alberta,212,202,4	script	Dewata Sailor#alberta	536,{
 	mes "Do you want to visit ^8B4513Dewata Island^000000?";
 	mes "With its dazzling waves and charming vistas it's a great place to relax.";
 	if (VIP_SCRIPT) {
-		set .@cost, vip_status(1)?1000:10000;
+		set .@cost, vip_status(VIP_STATUS_ACTIVE)?1000:10000;
 		mes "The transit fee is 10,000 Zeny and 1,000 for VIP.";
 	} else {
 		set .@cost,10000;

+ 1 - 1
npc/re/instances/BakonawaLake.txt

@@ -479,7 +479,7 @@ OnMobSpawn:
 		erasequest 12279;
 		mes "[Taho]";
 		mes "This was found from Bakonawa's corpse. It would be better if you take this.";
-		if (!VIP_SCRIPT || vip_status(1))
+		if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 			getitem 6499,7; //Ancient_Grudge
 		else
 			getitem 6499,5; //Ancient_Grudge

+ 1 - 1
npc/re/instances/BangungotHospital.txt

@@ -164,7 +164,7 @@ ma_dun01,147,10,5	script	Nurse#ma_dun01	4_F_NURSE,{
 			}
 			callsub S_Complete, true;
 			getexp 500000,0;
-			if (VIP_SCRIPT == 0 || vip_status(1))
+			if (VIP_SCRIPT == 0 || vip_status(VIP_STATUS_ACTIVE))
 				getitem 6499,7;// Ancient_Grudge
 			else
 				getitem 6499,5;

+ 1 - 1
npc/re/other/CashShop_Functions.txt

@@ -10,7 +10,7 @@
 // VIP Functions
 //============================================================
 function	script	VIP_Third_Class	{
-	if (!vip_status(1)) {
+	if (!vip_status(VIP_STATUS_ACTIVE)) {
 		mes "[Voice from nowhere]";
 		mes "Access to Premium content is only available to those who possess a certain amount of Reset Stones.";
 		next;

+ 3 - 3
npc/re/quests/eden/eden_iro.txt

@@ -98,7 +98,7 @@ moc_para01,14,32,5	script	Aperture#acolytewarp	90,{
 }
 
 function	script	VIP_iRO_Acolyte	{
-	if (!vip_status(1)) {
+	if (!vip_status(VIP_STATUS_ACTIVE)) {
 		mes getarg(0);
 		mes "But, my full powers are only available to those who have are VIPs.";
 		mes "I can still offer you a warp to "+getarg(1)+" though.";
@@ -136,7 +136,7 @@ function	script	VIP_iRO_Acolyte	{
 moc_para01,26,15,3	script	Primo d'Buffer	790,{
 	mes "[Primo d'Buffer]";
 	mes "Hello adventurer, you look like you are itching to get out there and save the world!";
-	if (!vip_status(1)) {
+	if (!vip_status(VIP_STATUS_ACTIVE)) {
 		mes "I can also tell that you haven't been blessed with '^6666ffVIP Status^000000'.";
 		next;
 		mes "[Primo d'Buffer]";
@@ -179,7 +179,7 @@ moc_para01,53,30,3	script	Clearchus	470,{
 	mes "[Clearchus]";
 	mes "Our organization is 10,000 strong! Now let me see if you are registered for this service.";
 	next;
-	if (!vip_status(1)) {
+	if (!vip_status(VIP_STATUS_ACTIVE)) {
 		mes "[Clearchus]";
 		mes "Unfortunately it appears that you are not VIP, please get VIP so that you can use this service. You can get a temporary VIP access by talking to Gramps at the Eden Group Headquarters.";
 		next;

+ 4 - 4
npc/re/quests/quests_brasilis.txt

@@ -52,7 +52,7 @@ brasilis,297,307,5	script	Angelo#br	1_M_04,{
 		mes "Oh, thank you. You found all of 3 puppies.";
 		mes "Thanks a lot.";
 		mes "I hope this is useful to you. hoho.";
-		if (VIP_SCRIPT && vip_status(1))
+		if (VIP_SCRIPT && vip_status(VIP_STATUS_ACTIVE))
 			getexp 75000,0;
 		else
 			getexp 50000,0;
@@ -410,7 +410,7 @@ brasilis,187,162,5	script	Candy Maker	4_M_BRZ_MAN1,{
 		brazil_gua = 11;
 		completequest 2200;
 		getitem 12414,1; //Guarana_Candy
-		if (VIP_SCRIPT && vip_status(1))
+		if (VIP_SCRIPT && vip_status(VIP_STATUS_ACTIVE))
 			getexp 105000,15000;
 		else
 			getexp 70000,10000;
@@ -1029,7 +1029,7 @@ brasilis,203,286,3	script	Botanist Karmen#bra	4_F_HUWOMAN,{
 		mes "The water lily must truly be a lucky flower. hahaha";
 		brazil_regia = 10;
 		completequest 2207;
-		if (VIP_SCRIPT && vip_status(1))
+		if (VIP_SCRIPT && vip_status(VIP_STATUS_ACTIVE))
 			getexp 75000,15000;
 		else
 			getexp 50000,10000;
@@ -2582,7 +2582,7 @@ bra_in01,206,188,1	script	Open Manhole#todunbra	CLEAR_NPC,{
 		brazil_ghost = 8;
 		//completequest 2208;
 		completequest 60355;
-		if (VIP_SCRIPT && vip_status(1))
+		if (VIP_SCRIPT && vip_status(VIP_STATUS_ACTIVE))
 			getexp 135000,0;
 		else
 			getexp 90000,0;

+ 19 - 19
npc/re/quests/quests_malaya.txt

@@ -154,7 +154,7 @@ malaya,266,76,3	script	Rodel the Guard#malaya	570,4,4,{
 				next;
 				mes "[Rodel the Guard]";
 				mes "I think there will be more Jejeling hunts in the future. Please join us again next time.";
-				if (!VIP_SCRIPT || vip_status(1))
+				if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 					getitem 6497, 2; // Lesser_Agimat
 				else
 					getitem 6497, 1; // Lesser_Agimat
@@ -707,7 +707,7 @@ malaya,169,350,5	script	Imelda#malaya	475,{
 		erasequest 7374;
 		erasequest 7379;
 		setquest 7375;
-		if (!VIP_SCRIPT || vip_status(1))
+		if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 			getitem 6497, 2; // Lesser_Agimat
 		else
 			getitem 6497, 1; // Lesser_Agimat
@@ -745,7 +745,7 @@ malaya,169,350,5	script	Imelda#malaya	475,{
 				delitem 6502, 6; // Silver_Cross
 				erasequest 7380;
 				setquest 7381;
-				if (!VIP_SCRIPT || vip_status(1))
+				if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 					getitem 6497, 2; // Lesser_Agimat
 				else
 					getitem 6497, 1; // Lesser_Agimat
@@ -813,7 +813,7 @@ malaya,169,350,5	script	Imelda#malaya	475,{
 				setquest 7375;
 				erasequest 7374;
 				erasequest 7379;
-				if (!VIP_SCRIPT || vip_status(1))
+				if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 					getitem 6497, 2; // Lesser_Agimat
 				else
 					getitem 6497, 1; // Lesser_Agimat
@@ -1115,7 +1115,7 @@ malaya,181,353,5	script	Old Man Nardo#malaya	574,{
 					delitem 6503, 5; // Soul_Protection
 					setquest 7378;
 					erasequest 7377;
-					if (!VIP_SCRIPT || vip_status(1))
+					if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 						getitem 6497, 2; // Lesser_Agimat
 					else
 						getitem 6497, 1; // Lesser_Agimat
@@ -1729,7 +1729,7 @@ malaya,295,171,3	script	Collection Dealer Woeon	582,{
 					delitem 6498, countitem(6498); //Jejellopy
 					setquest 7392;
 					erasequest 7391;
-					if (!VIP_SCRIPT || vip_status(1))
+					if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 						getitem 6497, 2; // Lesser_Agimat
 					else
 						getitem 6497, 1; // Lesser_Agimat
@@ -1963,7 +1963,7 @@ malaya,119,217,3	script	Blacksmith Pandoi	538,{
 				delitem 6508, 10; //Silver_Bracelet
 				setquest 7394;
 				erasequest 7393;
-				if (!VIP_SCRIPT || vip_status(1))
+				if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 					getitem 6497, 2; // Lesser_Agimat
 				else
 					getitem 6497, 1; // Lesser_Agimat
@@ -2375,7 +2375,7 @@ malaya,326,68,2	script	Pedro the Sailor	100,{
 			set malaya_diwata, 6;
 			erasequest 7399;
 			setquest 7401;
-			if (!VIP_SCRIPT || vip_status(1))
+			if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 				getitem 6497, 2; // Lesser_Agimat
 			else
 				getitem 6497, 1; // Lesser_Agimat
@@ -2438,7 +2438,7 @@ malaya,326,68,2	script	Pedro the Sailor	100,{
 				mes "I think you kind of like doing it.";
 				setquest 7401;
 				erasequest 7403;
-				if (!VIP_SCRIPT || vip_status(1))
+				if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 					getitem 6497, 2; // Lesser_Agimat
 				else
 					getitem 6497, 1; // Lesser_Agimat
@@ -2929,7 +2929,7 @@ ma_fild01,239,253,3	script	Dhong the Guard	570,{
 				delitem 6505, 10; // Purified_Bone
 				setquest 7408;
 				erasequest 7407;
-				if (!VIP_SCRIPT || vip_status(1))
+				if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 					getitem 6497, 2; // Lesser_Agimat
 				else
 					getitem 6497, 1; // Lesser_Agimat
@@ -3025,7 +3025,7 @@ ma_fild01,200,190,3	script	Maries#malaya	579,{
 			mes "Thank you for delivering those precious shirts to my children.";
 			setquest 7390;
 			erasequest 7389;
-			if (!VIP_SCRIPT || vip_status(1))
+			if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 				getitem 6497, 2; // Lesser_Agimat
 			else
 				getitem 6497, 1; // Lesser_Agimat
@@ -3264,7 +3264,7 @@ ma_fild02,241,39,5	script	Good Capre Budidai	572,{
 					mes "This is a blessing for friends. Hey hey hey~";
 					setquest 7410;
 					erasequest 7409;
-					if (!VIP_SCRIPT || vip_status(1))
+					if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 						getitem 6497, 2; // Lesser_Agimat
 					else
 						getitem 6497, 1; // Lesser_Agimat
@@ -4264,7 +4264,7 @@ ma_in01,47,101,3	script	Totoy#buwaya	577,7,7,{
 		mes "[Dog]";
 		mes "Woof woof woof!!!!";
 		set malaya_buwaya,14;
-		if (!VIP_SCRIPT || vip_status(1))
+		if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 			getitem 6497,10; //Lesser_Agimat
 		else
 			getitem 6497,5; //Lesser_Agimat
@@ -4700,7 +4700,7 @@ malaya,290,340,3	script	Guard Leader#buwaya	571,{
 			mes "[Guard Leader]";
 			mes "Good work.";
 			erasequest 2281;
-			if (!VIP_SCRIPT || vip_status(1))
+			if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 				getitem 6497,10; //Lesser_Agimat
 			else
 				getitem 6497,5; //Lesser_Agimat
@@ -5225,7 +5225,7 @@ malaya,285,332,4	script	Old Legend Teller#bako1	574,{
 			mes "Please get rid of this monster for us.";
 			erasequest 1179;
 			set malaya_bakona1,7;
-			if (!VIP_SCRIPT || vip_status(1))
+			if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 				getitem 6499,5; //Ancient_Grudge
 			else
 				getitem 6499,3; //Ancient_Grudge
@@ -5745,7 +5745,7 @@ malaya,283,265,4	script	Village Chief#bako2	580,{
 		erasequest 1184;
 		setquest 1185;
 		set malaya_bakona2,6;
-		if (!VIP_SCRIPT || vip_status(1))
+		if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 			getitem 12700,7; //Insideout_Shirt
 		else
 			getitem 12700,5; //Insideout_Shirt
@@ -5851,7 +5851,7 @@ malaya,283,265,4	script	Village Chief#bako2	580,{
 		erasequest 1193;
 		set malaya_bakona2,15;
 		getexp 1000000,600000;
-		if (!VIP_SCRIPT || vip_status(1))
+		if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 			getitem 6497,7; //Lesser_Agimat
 		else
 			getitem 6497,5; //Lesser_Agimat
@@ -6135,7 +6135,7 @@ malaya,289,364,4	script	Young Fortune Teller	583,{
 			erasequest 1186;
 			setquest 1187;
 			set malaya_bakona2,8;
-			if (!VIP_SCRIPT || vip_status(1))
+			if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE))
 				getitem 12699,7; //Tikbalang_Belt
 			else
 				getitem 12699,5; //Tikbalang_Belt
@@ -6753,7 +6753,7 @@ L_Warp:
 	}
 
 L_Reward:
-	if (!VIP_SCRIPT || vip_status(1)) {
+	if (!VIP_SCRIPT || vip_status(VIP_STATUS_ACTIVE)) {
 		getitem 6499,5; //Ancient_Grudge
 		getitem 6497,10; //Lesser_Agimat
 	} else {

+ 2 - 2
src/map/pc.h

@@ -867,9 +867,9 @@ struct {
 #define pc_iscloaking(sd)     ( !((sd)->sc.option&OPTION_CHASEWALK) && ((sd)->sc.option&OPTION_CLOAK) )
 #define pc_ischasewalk(sd)    ( (sd)->sc.option&OPTION_CHASEWALK )
 #ifdef VIP_ENABLE
-	#define pc_isvip(sd)      ( sd->vip.enabled ? 1 : 0 )
+	#define pc_isvip(sd)      ( sd->vip.enabled ? true : false )
 #else
-	#define pc_isvip(sd)      ( 0 )
+	#define pc_isvip(sd)      ( false )
 #endif
 #ifdef NEW_CARTS
 	#define pc_iscarton(sd)       ( (sd)->sc.data[SC_PUSH_CART] )

+ 12 - 16
src/map/script.c

@@ -21221,42 +21221,38 @@ BUILDIN_FUNC(is_clientver) {
 
 /** Returns various information about a player's VIP status. Need to enable VIP system
  * vip_status <type>,{"<character name>"};
- * @param type: Info type, 1: VIP status, 2: Expired date, 3: Remaining time
+ * @param type: Info type, see enum vip_status_type
  * @param name: Character name (Optional)
  */
 BUILDIN_FUNC(vip_status) {
 #ifdef VIP_ENABLE
 	TBL_PC *sd;
-	char vip_str[26];
-	time_t now = time(NULL);
-	int type = script_getnum(st, 2);
+	int type;
 
 	if( !script_nick2sd(3,sd) )
 		return SCRIPT_CMD_FAILURE;
 
+	type = script_getnum(st, 2);
+
 	switch(type) {
-		case 1: // Get VIP status.
+		case VIP_STATUS_ACTIVE: // Get VIP status.
 			script_pushint(st, pc_isvip(sd));
 			break;
-		case 2: // Get VIP expire date.
+		case VIP_STATUS_EXPIRE: // Get VIP expire date.
 			if (pc_isvip(sd)) {
-				time_t viptime = sd->vip.time;
-				strftime(vip_str, 24, "%Y-%m-%d %H:%M", localtime(&viptime));
-				vip_str[25] = '\0';
-				script_pushstrcopy(st, vip_str);
+				script_pushint(st, sd->vip.time);
 			} else
 				script_pushint(st, 0);
 			break;
-		case 3: // Get remaining time.
+		case VIP_STATUS_REMAINING: // Get remaining time.
 			if (pc_isvip(sd)) {
-				time_t viptime_remain = sd->vip.time - now;
-				int year=0,month=0,day=0,hour=0,min=0,sec=0;
-				split_time((int)viptime_remain,&year,&month,&day,&hour,&min,&sec);
-				safesnprintf(vip_str,sizeof(vip_str),"%d-%d-%d %d:%d",year,month,day,hour,min);
-				script_pushstrcopy(st, vip_str);
+				script_pushint(st, sd->vip.time - time(NULL));
 			} else
 				script_pushint(st, 0);
 			break;
+		default:
+			ShowError( "buildin_vip_status: Unsupported type %d.\n", type );
+			return SCRIPT_CMD_FAILURE;
 	}
 #else
 	script_pushint(st, 0);

+ 6 - 0
src/map/script.h

@@ -693,6 +693,12 @@ enum instance_info_type {
 	IIT_MAP
 };
 
+enum vip_status_type {
+	VIP_STATUS_ACTIVE = 1,
+	VIP_STATUS_EXPIRE,
+	VIP_STATUS_REMAINING
+};
+
 /**
  * used to generate quick script_array entries
  **/

+ 5 - 0
src/map/script_constants.h

@@ -3305,6 +3305,11 @@
 	export_constant(IIT_MAPCOUNT);
 	export_constant(IIT_MAP);
 
+	/* VIP status */
+	export_constant(VIP_STATUS_ACTIVE);
+	export_constant(VIP_STATUS_EXPIRE);
+	export_constant(VIP_STATUS_REMAINING);
+
 	/* item groups */
 	export_constant(IG_BLUEBOX);
 	export_constant(IG_VIOLETBOX);