Jump to content
  • 0

How to modify this script


ooGubAoo

Question


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.03
  • Content Count:  55
  • Reputation:   1
  • Joined:  06/08/23
  • Last Seen:  

I need price from 5000z to 100*lv player

 

-	script	buff_cmd	-1,{
OnInit:
	bindatcmd "buff", strnpcinfo(0)+"::OnCommand";
	end;

OnCommand:
	.@price = 5000; // ราคาต่อการกดบัฟ
	if ( getmapflag(strcharinfo(3),MF_PVP) || getmapflag(strcharinfo(3),MF_BATTLEGROUND) ||  getmapflag(strcharinfo(3),MF_GVG) ) {
		mes "ใช้ไม่ได้ในแผนที่ PVP/BG/WOE";
		close;
	}
	if ( Zeny < .@price ) {
		mes "ต้องใช้เงิน "+F_InsertComma(.@price)+"z. ในการกดใช้บัฟ";
		close;
	}
	if ( select("บัฟเลย 5,000z ก็ไหว!","ไม่เอาดีกว่า!")==2 ) {
		mes "แค่ 5,000z ก็ยัง ^FF0000งก^000000 เนอะ";
		mes "ตีมอนแปปเดียวก็ได้แล้ว";
		mes "ฆ่ามอนยังไงก็ได้เงินไปด้วยอยู่แล้ว";
		close;
	}
	Zeny -= .@price;

	// บัฟที่ได้
	specialeffect2 42;sc_start SC_BLESSING,3600000,10;
	specialeffect2 37;sc_start SC_INCREASEAGI,3600000,10;
	specialeffect2 112;sc_start SC_KYRIE,3600000,10;
	specialeffect2 76;sc_start SC_MAGNIFICAT,3600000,10;
}

	mes "จัดไป!";
	mes "ขอให้มีความสุขกับการเก็บเลเวล!";
	mes "ด้วยความปรารถนาดีจาก TooHard-RO!";
	close;
}

but when i change
OnCommand:
    .@price = 5000; // ราคาต่อการกดบัฟ
    if ( getmapflag(strcharinfo(3),MF_PVP) || getmapflag(strcharinfo(3),MF_BATTLEGROUND) ||  getmapflag(strcharinfo(3),MF_GVG) ) {
        mes "ใช้ไม่ได้ในแผนที่ PVP/BG/WOE";
        close;
    }
to ------------------------------------------------------------------------

OnCommand:
    .@base_price = 5000; // ราคาพื้นฐานสำหรับการให้บัฟ
    .@price = .@base_price * strcharinfo(3);
    if ( getmapflag(strcharinfo(3),MF_PVP) || getmapflag(strcharinfo(3),MF_BATTLEGROUND) ||  getmapflag(strcharinfo(3),MF_GVG) ) {
        mes "ใช้ไม่ได้ในแผนที่ PVP/BG/WOE";
        close;
    }

it not work

please help me

Thank you.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  245
  • Reputation:   93
  • Joined:  06/30/18
  • Last Seen:  

You use strcharinfo(3) which first of all returns a string, so your calculation fails and second it returns the name of the map the character is in, which sure isn't what you want.
 

.@price = .@base_price * strcharinfo(3);
*strcharinfo(<type>{,<char_id>})

This function will return either the name, party name or guild name for the
invoking character. Whatever it returns is determined by type.

To get the level of a character, you can simply use the BaseLevel variable, which is pre-defined by rAthena. This should do what you want:
 

.@price = .@base_price * BaseLevel;

Also, since you always need the same base price, you could move the variable to OnInit and use a NPC variable.
This saves your script from having to assign the variable on every call. Probably this isn't really crucial performancewise, but it also helps to organize your script better, because you can use NPC variables globally in your NPC, you can use them anywhere you want and know they are defined.

Lastly, you are writing the zeny price hard in your string. I assume because you want it to be comma separated. You can achieve this dynamically with the global F_InsertComma function.

Here is an example of the script you provided, with what I mean:
 

-	script	BUFF_CMD	FAKE_NPC,{
	OnInit:
	  	.basePrice = 5000; // ราคาพื้นฐานสำหรับการให้บัฟ
		bindatcmd "buff", strnpcinfo(0) + "::OnCommand";
		end;

	OnCommand:
		.@price = BaseLevel * .basePrice;

		if ( getmapflag(strcharinfo(3), MF_PVP) || getmapflag(strcharinfo(3), MF_BATTLEGROUND) ||  getmapflag(strcharinfo(3), MF_GVG) ) {
			mes "ใช้ไม่ได้ในแผนที่ PVP/BG/WOE";
			close;
		}

		if ( Zeny < .@price ) {
			mes "ต้องใช้เงิน " + F_InsertComma(.@price) + "z. ในการกดใช้บัฟ";
			close;
		}
		
		if ( select("บัฟเลย " + F_InsertComma(.@price) + "z ก็ไหว!","ไม่เอาดีกว่า!") == 2 ) {
			mes "แค่ " + F_InsertComma(.@price) + "z ก็ยัง ^FF0000งก^000000 เนอะ";
			mes "ตีมอนแปปเดียวก็ได้แล้ว";
			mes "ฆ่ามอนยังไงก็ได้เงินไปด้วยอยู่แล้ว";
			close;
		}
		Zeny -= .@price;

		// บัฟที่ได้
		specialeffect2(42);
		sc_start(SC_BLESSING, 3600000, 10);
		
		specialeffect2(37);
		sc_start(SC_INCREASEAGI, 3600000, 10);
		
		specialeffect2(112);
		sc_start(SC_KYRIE, 3600000, 10);

		specialeffect2(76);
		sc_start(SC_MAGNIFICAT, 3600000, 10);

		mes "จัดไป!";
		mes "ขอให้มีความสุขกับการเก็บเลเวล!";
		mes "ด้วยความปรารถนาดีจาก TooHard-RO!";
		close;
}

 

  • MVP 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.03
  • Content Count:  55
  • Reputation:   1
  • Joined:  06/08/23
  • Last Seen:  

27 minutes ago, Winterfox said:

You use strcharinfo(3) which first of all returns a string, so your calculation fails and second it returns the name of the map the character is in, which sure isn't what you want.
 

.@price = .@base_price * strcharinfo(3);
*strcharinfo(<type>{,<char_id>})

This function will return either the name, party name or guild name for the
invoking character. Whatever it returns is determined by type.

To get the level of a character, you can simply use the BaseLevel variable, which is pre-defined by rAthena. This should do what you want:
 

.@price = .@base_price * BaseLevel;

Also, since you always need the same base price, you could move the variable to OnInit and use a NPC variable.
This saves your script from having to assign the variable on every call. Probably this isn't really crucial performancewise, but it also helps to organize your script better, because you can use NPC variables globally in your NPC, you can use them anywhere you want and know they are defined.

Lastly, you are writing the zeny price hard in your string. I assume because you want it to be comma separated. You can achieve this dynamically with the global F_InsertComma function.

Here is an example of the script you provided, with what I mean:
 

-	script	BUFF_CMD	FAKE_NPC,{
	OnInit:
	  	.basePrice = 5000; // ราคาพื้นฐานสำหรับการให้บัฟ
		bindatcmd "buff", strnpcinfo(0) + "::OnCommand";
		end;

	OnCommand:
		.@price = BaseLevel * .basePrice;

		if ( getmapflag(strcharinfo(3), MF_PVP) || getmapflag(strcharinfo(3), MF_BATTLEGROUND) ||  getmapflag(strcharinfo(3), MF_GVG) ) {
			mes "ใช้ไม่ได้ในแผนที่ PVP/BG/WOE";
			close;
		}

		if ( Zeny < .@price ) {
			mes "ต้องใช้เงิน " + F_InsertComma(.@price) + "z. ในการกดใช้บัฟ";
			close;
		}
		
		if ( select("บัฟเลย " + F_InsertComma(.@price) + "z ก็ไหว!","ไม่เอาดีกว่า!") == 2 ) {
			mes "แค่ " + F_InsertComma(.@price) + "z ก็ยัง ^FF0000งก^000000 เนอะ";
			mes "ตีมอนแปปเดียวก็ได้แล้ว";
			mes "ฆ่ามอนยังไงก็ได้เงินไปด้วยอยู่แล้ว";
			close;
		}
		Zeny -= .@price;

		// บัฟที่ได้
		specialeffect2(42);
		sc_start(SC_BLESSING, 3600000, 10);
		
		specialeffect2(37);
		sc_start(SC_INCREASEAGI, 3600000, 10);
		
		specialeffect2(112);
		sc_start(SC_KYRIE, 3600000, 10);

		specialeffect2(76);
		sc_start(SC_MAGNIFICAT, 3600000, 10);

		mes "จัดไป!";
		mes "ขอให้มีความสุขกับการเก็บเลเวล!";
		mes "ด้วยความปรารถนาดีจาก TooHard-RO!";
		close;
}

 

Thank you again....

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...