Jump to content
  • 0

help me my script is bug keep old value input :(


rakmomteesud

Question


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  05/01/18
  • Last Seen:  

my script is bug i'm try to upgrade this script to can select many day of VIP

but it not work i'm try check it before keep old value input and cal program help me fix script pls . ty so much

dewata,196,165,5	script	CashToVIP	123,{
	.@cashperday = 100;
	.@timeperday = 1440;
	
	mes "["+ strnpcinfo(1)+"]";
	if( #CASHPOINTS < .@cashperday ){
		mes "You don't have enough Cash Points to purchase VIP Days";
		close;
	}
	
	switch(vip_status(1)){
		case 0:
			mes "You're not a VIP";
			break;
		case 1:
			mes "You are a VIP";
			break;
	}
	
	mes "You currently have "+ #CASHPOINTS +" Cash Points.";
	mes "Each VIP Day will cost you ^0000ff"+ .@cashperday +"^000000";
	next;
	
	mes "["+ strnpcinfo(1)+"]";
	mes "Would you like to purchase/increase your VIP Days?";
	switch(select(" - Nope: - 1 day: - many days")){
		case 1:
			break;
		case 2:
			#CASHPOINTS -= .@cashperday;
			vip_time 1440;
			set .@Timer, vip_status(2);
			dispbottom "Current Cash Points: "+ #CASHPOINTS;
			dispbottom "Time left : "+ callfunc("Time2Str",.@Timer);
			break;
		case 3:
			set .@inputDay, 0;
			input .@inputDay;
			if(.@inputDay > 0 && (.@cashperday*.@inputDay) < #CASHPOINTS){
				set .@Timer, vip_status(2);
				#CASHPOINTS -= .@cashperday*.@inputDay;
				vip_time .@timeperday*.@inputDay;
				dispbottom "Current Cash Points: "+ #CASHPOINTS;
				dispbottom "Time left : "+ callfunc("Time2Str",.@Timer);
			}else{
				mes "-";
				mes "^FF0000You don't have enough Cash Points to purchase VIP Days^FF0000";
				close;
			}
			break;
	}
	close;

} 

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  81
  • Reputation:   14
  • Joined:  11/17/17
  • Last Seen:  

Hi, I guess the VIP time has not been saved to the database yet so I put sleep2 into your code and it works.

Fixed code:

dewata,196,165,5	script	CashToVIP	123,{
	.@cashperday = 100;
	.@timeperday = 1440;
	
	mes "["+ strnpcinfo(1)+"]";
	if( #CASHPOINTS < .@cashperday ){
		mes "You don't have enough Cash Points to purchase VIP Days";
		close;
	}
	
	switch(vip_status(VIP_STATUS_ACTIVE)){
		case 0:
			mes "You're not a VIP";
			break;
		case 1:
			mes "You are a VIP";
			break;
	}
	
	mes "You currently have "+ #CASHPOINTS +" Cash Points.";
	mes "Each VIP Day will cost you ^0000ff"+ .@cashperday +"^000000";
	next;
	
	mes "["+ strnpcinfo(1)+"]";
	mes "Would you like to purchase/increase your VIP Days?";
	switch(select(" - Nope: - 1 day: - many days")){
		case 1:
			break;
		case 2:
			#CASHPOINTS -= .@cashperday;
			vip_time .@timeperday;
			sleep2 1;
			set .@Timer, vip_status(VIP_STATUS_EXPIRE);
			dispbottom "Current Cash Points: "+ #CASHPOINTS;
			dispbottom "Time left : "+ callfunc("Time2Str",.@Timer);
			break;
		case 3:
			input .@inputDay;
			if(.@inputDay > 0 && (.@cashperday*.@inputDay) < #CASHPOINTS){
				#CASHPOINTS -= .@cashperday*.@inputDay;
				vip_time .@timeperday*.@inputDay;
				sleep2 1;
				set .@Timer, vip_status(VIP_STATUS_EXPIRE);
				dispbottom "Current Cash Points: "+ #CASHPOINTS;
				dispbottom "Time left : "+ callfunc("Time2Str",.@Timer);
			}else{
				mes "-";
				mes "^FF0000You don't have enough Cash Points to purchase VIP Days^FF0000";
				close;
			}
			break;
	}
	close;

} 


Bonus:
 

dewata,196,165,5	script	CashToVIP	123,{
	.@cashperday = 100;
	.@timeperday = 1440;
	.@n$ = "["+strnpcinfo(0)+"]";

	mes .@n$;
	switch(vip_status(VIP_STATUS_ACTIVE)){
	case 0:
		mes "You're not a VIP.";
		break;
	case 1:
		mes "VIP time left: " + Time2Str(vip_status(VIP_STATUS_EXPIRE));
		break;
	}
	
	mes "You currently have "+ #CASHPOINTS +" Cash Points.";
	mes "Each VIP Day will cost you ^0000ff"+ .@cashperday +"^000000";
	next;

	mes .@n$;
	mes "Would you like to purchase/increase your VIP Days?";
	next;

	switch(select(" - Nope: - 1 day: - Many days")){
	case 1:
		break;
	case 2:
		.@inputDay = 1;
	case 3:
		if (!.@inputDay)
			input .@inputDay;

		if (.@inputDay == 0) {
			mes .@n$;
			mes "Invalid day!";
			close;
		}

		.@total = .@cashperday*.@inputDay;

		if (.@total > #CASHPOINTS) {
			mes .@n$;
			mes "^FF0000You don't have enough Cash Points to purchase VIP Days^FF0000";
			close;
		}

		mes .@n$;
		mes .@inputDay + " x " + .@cashperday + " = ^FF0000" + .@total + "^000000 Cash Points.";
		mes "Are you sure?";

		if (select("No:Yes") == 1)
			close;

		#CASHPOINTS -= .@total;
		vip_time .@timeperday*.@inputDay;
		sleep2 1;
		.@Timer = vip_status(VIP_STATUS_EXPIRE);
		dispbottom "Current Cash Points: "+ #CASHPOINTS;
		dispbottom "VIP time left : "+ callfunc("Time2Str",.@Timer);
		break;
	}
	close;
}

Hope you like it ?

  • MVP 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  05/01/18
  • Last Seen:  

it work ! ty so much guy im just try to use it ?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  23
  • Topics Per Day:  0.01
  • Content Count:  228
  • Reputation:   19
  • Joined:  10/27/12
  • Last Seen:  

if (.@inputDay == 0) {

What if I input a negative value ??

your script may fail..??

May be this works better??

if (.@inputDay < 1) {
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  81
  • Reputation:   14
  • Joined:  11/17/17
  • Last Seen:  

1 hour ago, utofaery said:

if (.@inputDay == 0) {

What if I input a negative value ??

your script may fail..??

May be this works better??


if (.@inputDay < 1) {

From script_commands.txt

Quote

*input(<variable>{,<min>{,<max>}})
...

Normally you may not input a negative number with this command.
This is done to prevent exploits in badly written scripts, which would
let people, for example, put negative amounts of Zeny into a bank script and
receive free Zeny as a result.

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  23
  • Topics Per Day:  0.01
  • Content Count:  228
  • Reputation:   19
  • Joined:  10/27/12
  • Last Seen:  

I was wondering about this part.

		if (.@inputDay == 0) {
			mes .@n$;
			mes "Invalid day!";
			close;
		}

at case 3:

if (.@inputDay == 0) { <<< this is the one if .@inputDay is negative wouldn't the script be broken somehow??

say entry of -5 or -10..

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  81
  • Reputation:   14
  • Joined:  11/17/17
  • Last Seen:  

46 minutes ago, utofaery said:

I was wondering about this part.


		if (.@inputDay == 0) {
			mes .@n$;
			mes "Invalid day!";
			close;
		}

at case 3:

if (.@inputDay == 0) { <<< this is the one if .@inputDay is negative wouldn't the script be broken somehow??

say entry of -5 or -10..

 

The player can not send negative number so that line can't be broken. If you type -1,-5,-100 or even "bla bla" on input script command with the variable .@inputDay (not .@inputDay$) it will automatically change to 0. That's why I only use .@inputDay == 0.

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...