Jump to content
  • 0

countitem in mes


ToiletMaster

Question


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

Hi there, i've searched the forum actually. i've stumbled it before but i can't find back the thread.

 

Currently i wanna place like example i need 20 apples.

 

If lets say i only have 5 apples, it'll state that you need 15 more apples.

 

Thanks!

Edited by ToiletMaster
Link to comment
Share on other sites

16 answers to this question

Recommended Posts


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

	if ( countitem(501) < 5  && countitem(502) < 5 ) {
		mes "I still require "+ ( 20-countitem(512) ) +" more apples!";
		close;
	}

The brackets !

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  175
  • Reputation:   14
  • Joined:  11/21/11
  • Last Seen:  

if (countitem(512) < 20)

{

     mes "You need "+20-countitem(512)+" apples";

}

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

Hey feefty thanks for the help, however i'm getting debug messages from this and the chat goes blank.

 

I've actually tried this code before but it dint work >_>

 

the error code

[Error]: script:op_2: invalid data for operator C_SUB
[Debug]: Data: string value="I still require 20"
[Debug]: Data: number value=0
[Debug]: Source (NPC): Xyratra at lunette (43,98)

 

part of my script

if (countitem(501) < 5) && (countitem(502) < 5) {
                mes "I still require "+20-countitem(512)+" more apples!";
                close; }
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

if ( countitem(501) < 5  && countitem(502) < 5 ) {

 

should be

if ( countitem(501) < 5 || countitem(502) < 5 ) {

 

 

 

btw...you are checking on RED POTION while the NPC request for Apples ?

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

	if ( countitem(501) < 5  && countitem(502) < 5 ) {
		mes "I still require "+ ( 20-countitem(512) ) +" more apples!";
		close;
	}

The brackets !

 

Oh gosh! Thank you so much! That's what i was missing the entire time! The bloody brackets! Thanks for your help capuche!

if ( countitem(501) < 5  && countitem(502) < 5 ) {

 

should be

if ( countitem(501) < 5 || countitem(502) < 5 ) {

Thanks for noticing it emistry! I've changed it as well! Thanks again !

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

Dawn I didn't notice comparisons problems

I go to sleep %#*$ ><

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

just one thing to add on though emistry,

 

because if have more than one if in that script

 

so i need to use

 

&&

instead of

 

||

 

Thanks again !

Edited by ToiletMaster
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

because you are checking on more than 1 items...you should use || instead of && otherwise the condition will be bypassed when any 1 of the items has fulfilled the requirements.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

errr, well i tested just now and it din't trigger the other ones, here's how i made it look like. hopefully it'll clear some confusion so far lol.

 

 

if ( countitem(909) < 20 && countitem(935) < 20 ) {
mes "[^80B584Xyratra^000000]";
mes "I still require "+( 20-countitem(909) )+" more Jellopies from porings,";
mes "and "+( 20-countitem(935) )+" more Shells from chonchons.";
close; }
                            
if (countitem(909) >= 20 && countitem(935) <= 19) {
mes "[^80B584Xyratra^000000]";
mes "I see you have enough jellopies. But i still require "+( 20-countitem(935) )+" more Shells from chonchons.";
close; }
                            
if ( countitem(935) >= 20 &&  countitem (909) <= 19) {
mes "[^80B584Xyratra^000000]";
mes "I see you have enough shells, however I still require "+( 20-countitem(909) )+" more Jellopies from porings.";
close; }
                        

if i used || it would trigger the first command even though i had one of the items and it'll state -80 if let's say i had 100 jellopies.

so i wanted to make sure no negative values came out so that's why i did it like this.

 

 

edit:

 

I believe || would trigger when i fufilled one of the conditions?

where && would trigger when both conditions are fufilled?

Edited by ToiletMaster
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  58
  • Reputation:   0
  • Joined:  09/23/12
  • Last Seen:  

Try using else if & else

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

one thing that i am confuse with your idea......why are you checking for 2 items but inside the condition only mentioned 1 item ?

Example :

if (countitem(909) >= 20 && countitem(935) <= 19) {
mes "[^80B584Xyratra^000000]";
mes "I see you have enough jellopies. But i still require "+( 20-countitem(935) )+" more Shells from chonchons.";
close; }

 

 

just do it like this...make it simple...easy for you...

//item 1
if( countitem( 512 ) < 10 ){
	mes "I need "+( 10 - countitem( 512 ) )+" x "+getitemname( 512 )+".";
}

// item 2
if( countitem( 607 ) < 15 ){
	mes "I need "+( 15 - countitem( 607 ) )+" x "+getitemname(  607 )+".";
}
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

Ok lemme explain fully how my quest works.

Edit: Additional Info
Forgotten to mention, however i would prefer the NPC to state both items throughout the entire conversation. That's why i made the script to work like this.



First off all, the quest requires the person to collect 20 Jellopies and 20 Shells.

why are you checking for 2 items but inside the condition only mentioned 1 item ?



Now for this part, if you've read the message, it's stated,

I see you have enough shells, But i still require "+( 20-countitem(935) )+" more Shells from chonchons.


"I See you have enough shells " would reconfirm that he has gotten the shells and does not require anymore shells.

and also this is the part where

 

 

if (countitem(909) >= 20 && countitem(935) <= 19) {

 

 

comes in. once i have 20 items it'll just reconfirm i have enough.

 

 



This is to ensure that no negative values come about and confirm that the player has gotten enough shells.

Because i've tested having 100 Jellopies and then the quest giver would say I require -80 More jellopies and 20 more shells. Therefore, i've set the script to work in that sense where if the person has gotten 1 of the requirements, it would not state how much more of the completed item that he require anymore, and would state only the ones he's still missing.

If they have both 20 jellopies and 20 shells, then the quest would continue progressing.

(No hard feelings anywhere, i'm here to learn as well however i currently fail to see my mistake.)


Thank you for your feedback,

Cheers,

TM

Edited by ToiletMaster
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

this part...

if (countitem(909) >= 20 && countitem(935) <= 19) {

 

user can bypass this when they got ....20 or more item with ID 909....even though they have less than 19 item id 935...

what i mean here.....if either one of the item has fulfill part of the condition....the another part of the same condition will be ignored...

which resulting your condition checking failed if you are checking for both.....that's why you have to use || and not using the &&

 


 


//item 1
if( countitem( 512 ) < 10 ){
	mes "I need "+( 10 - countitem( 512 ) )+" x "+getitemname( 512 )+".";
}

// item 2
if( countitem( 607 ) < 15 ){
	mes "I need "+( 15 - countitem( 607 ) )+" x "+getitemname(  607 )+".";
}

 

 

the mesage will only display when the item didnt have sufficient amount.....

it will still work for as many item you add here...

 

 

 

otherwise...just do like this..


if( countitem( 909 ) < 20 ) mes "I still require "+( ( countitem(909) < 20 )? ( 20 - countitem(909) ):"0"  )+" more Jellopy.";

 

 

 

 

 

did i miss anything ?  well, my intention is just to let you know that in your case....using && in your above condition checking are incorrect....

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

user can bypass this when they got ....20 or more item with ID 909....even though they have less than 19 item id 935...

what i mean here.....if either one of the item has fulfill part of

the condition....the another part of the same condition will be

ignored...

which resulting your condition checking failed if you are checking for both.....that's why you have to use || and not using the &&

 

Err it dint bypass though, everything seems to working fine for it. Here's some picture to show you.

 

 

For those who do not know what items are they.
Item 909 : Jellopy
Item 935 : Shell

Used the same code as before.

 

if ( countitem(909) < 20 && countitem(935) < 20 ) {
mes "[^80B584Xyratra^000000]";
mes "I still require "+( 20-countitem(909) )+" more Jellopies from porings,";
mes "and "+( 20-countitem(935) )+" more Shells from chonchons.";
close; }
                            
if (countitem(909) >= 20 && countitem(935) <= 19) {
mes "[^80B584Xyratra^000000]";
mes "I see you have enough jellopies. But i still require "+( 20-countitem(935) )+" more Shells from chonchons.";
close; }
                            
if ( countitem(935) >= 20 &&  countitem (909) <= 19) {
mes "[^80B584Xyratra^000000]";
mes "I see you have enough shells, however I still require "+( 20-countitem(909) )+" more Jellopies from porings.";
close; }

Picture one, this is without any of the required items. 

P_noitem_zps827a286c.png

 

Picture two shows having less of than both of the required quantity.

P_2item_zpsa8bef1c3.png

 

Picture Three shows having 20 Jellopies.

P_Jellopy_zps302516eb.png

 

Picture Four shows having 20 Shells

P_Noshell_zps0ae7b198.png

 

Picture 5 shows fulfilling both the required quantity

P_Enoughitem_zpsaf4f6c22.png

 

From doc/script_commands.txt

Comparisons can be stacked in the same condition:

 && - Is True if and only if BOTH sides are true.
      ('1==1 && 2==2' is true. '2==1 && 1==1' is false.)
 || - Is True if either side of this expression is True.

 1==1 && 2==2 is True.
 1==1 && 2==1 is False.
 1==1 || 2==1 is True.

 

Did i miss any methods of bypassing? Hope to know thanks!

 

Cheers,

 

TM

Edited by ToiletMaster
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

/... now i noticed...you are using 3 condition checking for this.....LOL....i thought you are using only 1 part to check for 2 items...but you are using 3 condition checking to check for 2 items..or checking for 2 items...but display only 1 items.....

which you did here..

if ( countitem(909) < 20 && countitem(935) < 20 ) {
mes "[^80B584Xyratra^000000]";
mes "I still require "+( 20-countitem(909) )+" more Jellopies from porings,";
mes "and "+( 20-countitem(935) )+" more Shells from chonchons.";
close; }
                            
if (countitem(909) >= 20 && countitem(935) <= 19) {
mes "[^80B584Xyratra^000000]";
mes "I see you have enough jellopies. But i still require "+( 20-countitem(935) )+" more Shells from chonchons.";
close; }
                            
if ( countitem(935) >= 20 &&  countitem (909) <= 19) {
mes "[^80B584Xyratra^000000]";
mes "I see you have enough shells, however I still require "+( 20-countitem(909) )+" more Jellopies from porings.";
close; }

 

 


 

i would rather do it like this..

mes "[^80B584Xyratra^000000]";
if ( countitem(909) < 20 )
	mes "I still require "+( 20 - countitem(909) )+" more Jellopies from porings";
if ( countitem(935) < 20 )
	mes "I still require "+( 20-countitem(935) )+" more Shells from chonchons.";
           

 

or

mes "[^80B584Xyratra^000000]";
.@item_1 = countitem(909);
.@item_2 = countitem(935);
if( .@item_1 < 20 || countitem(935) < 10 ){
	mes "[ "+( ( .@item_1 < 20 )? ( 20 - .@item_1 ):.@item_1 )+" / 20 ] "+getitemname( 909 );
	mes "[ "+( ( .@item_2 < 20 )? ( 20 - .@item_2 ):.@item_2 )+" / 10 ] "+getitemname( 909 );
}

there are alot way to do it...

 

well.. a separated condition checking would be better for your case...

 

 

anything i missed ?

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

/...

now i noticed...you are using 3 condition checking for

this.....LOL....i thought you are using only 1 part to check for 2

items...but you are using 3 condition checking to check for 2 items..or

checking for 2 items...but display only 1 items.....

which you did here.

 

lol that's why i was wondering, where did i go wrong this time xD. Well at least the confusion is cleared!

 

 

 

mes "[^80B584Xyratra^000000]";
if ( countitem(909) < 20 )
    mes "I still require "+( 20 - countitem(909) )+" more Jellopies from porings";
if ( countitem(935) < 20 )
    mes "I still require "+( 20-countitem(935) )+" more Shells from chonchons.";

 

This is a pretty nice code here hahaha. it can really reduce the amount of lines i need to write /heh

 

Thanks again Emistry!

 

All problems solved!

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