Jump to content
  • 0

Card Counter NPC


suimin

Question


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  10
  • Reputation:   2
  • Joined:  01/18/16
  • Last Seen:  

Hi, I'm new to scripting, but I'm trying to learn more.

 

I'm currently trying to make an NPC that counts how many cards are in the inventory of the player, then counts the quantity of each card, and finally adds up all the numbers to make the result, the entire amount of cards in the player's inventory.

 

I worked really hard to learn this, and it seemed to work for a bit... But when a friend got on my server and tested it with me, it stopped working. I don't know what went wrong.

 

prontera,163,189,3 script Test NPC 90,{


getinventorylist;
while(.@i < @inventorylist_count && getiteminfo(@inventorylist_id[.@i],2) != 6) 
.@i++;
copyarray .@a[0],@inventorylist_amount[.@i],@inventorylist_count;
while(.@a < @inventorylist_count)
.@a++;
set .@b,.@a[1]+.@a[2]+.@a[3]+.@a[4]+.@a[5]+.@a[6]+.@a[7]+.@a[8]+.@a[9]+.@a[10]+.@a[11]+.@a[12]+.@a[13]+.@a[14]+.@a[15]+.@a[16]+.@a[17]+.@a[18]+.@a[19]+.@a[20]+.@a[21]+.@a[22]+.@a[23]+.@a[24]+.@a[25]+.@a[26]+.@a[27]+.@a[28]+.@a[29]+.@a[30];
if(.@i < @inventorylist_count) {
mes "You have cards.";
mes ""+.@b+"";
close;
}
mes "You don't have cards.";
close;
}

Sorry about the lack of tabs in the script, I'm not sure how to add those in a post. ^^;

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

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

something like this ?

prontera,155,175,5	script	Sample#cardcount	4_F_KAFRA9,{
	getinventorylist;
	while ( .@i < @inventorylist_count ) {
		if ( getiteminfo( @inventorylist_id[.@i] ) == IT_CARD ) {
			.@total_card_count += @inventorylist_amount[.@i];
		}
		.@i++;
	}
	mes "You have "+.@total_card_count+" Card(s)";
	close;
}
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  10
  • Reputation:   2
  • Joined:  01/18/16
  • Last Seen:  

 

something like this ?

prontera,155,175,5	script	Sample#cardcount	4_F_KAFRA9,{
	getinventorylist;
	while ( .@i < @inventorylist_count ) {
		if ( getiteminfo( @inventorylist_id[.@i] ) == IT_CARD ) {
			.@total_card_count += @inventorylist_amount[.@i];
		}
		.@i++;
	}
	mes "You have "+.@total_card_count+" Card(s)";
	close;
}

 

Wow! Your code is so much more condensed than mine! It looks much better, and it also works! Thank you!

 

Looking at your code, I can learn a lot about what I can do for next time I try to do a script like this, too. It's very helpful!

Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

something like this ?

prontera,155,175,5	script	Sample#cardcount	4_F_KAFRA9,{
	getinventorylist;
	while ( .@i < @inventorylist_count ) {
		if ( getiteminfo( @inventorylist_id[.@i] ) == IT_CARD ) {
			.@total_card_count += @inventorylist_amount[.@i];
		}
		.@i++;
	}
	mes "You have "+.@total_card_count+" Card(s)";
	close;
}

Which is more efficient while() or for()

Link to comment
Share on other sites

  • 0

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

@Stolao

while-loop is more efficient than for-loop.

 

but this only limit to athena-language... in C language or other, both are similar or you could barely seen the different.

 

https://rathena.org/board/topic/72907-channel-system/?p=156998

https://rathena.org/board/topic/72907-channel-system/?p=157119

Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

@Stolao

while-loop is more efficient than for-loop.

but this only limit to athena-language... in C language or other, both are similar or you could barely seen the different.

https://rathena.org/board/topic/72907-channel-system/?p=156998

https://rathena.org/board/topic/72907-channel-system/?p=157119

Ty learned something new today :)

Though I do think for() look cleaner imo, I'll try and use while more.

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