Jump to content
  • 0

Q > getinventorylist(); and countitem if exist delitem captured itemids based on Array


Johnson

Question


  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   1
  • Joined:  08/22/18
  • Last Seen:  

Hi,

For Context: I'm creating an exchange script of Common Eggs to item(not egg).

Scenario: if player has 10 of Common Eggs it will be deleted and will receive an item. Excluding the hatched egg of current player.

I have an array list of Pet Eggs and if the player has >= 10 based on .C_PetEggs it will delitem all the captured itemIDs.

Note* : Pet Eggs is only 1 as default as it is non-stackable

I'm having trouble as it deletes the hatched egg and will be deleted as well on database and cannot return to egg or feed etc.

  setarray .C_PetEggs,
  9150, 9151, 9152, 9153, 9154, 9155, 9156, 9157, 9158, 9159, 9198, 9200, 9201, 9203, 9204, 9206, 9210; 

        
	getinventorylist;
	for (set .@i, 0; .@i < @inventorylist_count; set .@i, .@i + 1) {
			
		for (set .@j, 0; .@j < getarraysize(.C_PetEggs); set .@j, .@j + 1) {
			if(@inventorylist_id[.@i] == .C_PetEggs[.@j]){
				if(countitem(.C_PetEggs[.@j]) > 0){
					if(.@ctr == 10)
						end;
					delitem .C_PetEggs[.@j], 1;
					.@ctr++;
				}else end;
			}
		}
	}
 
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  25
  • Topics Per Day:  0.01
  • Content Count:  927
  • Reputation:   169
  • Joined:  04/05/13
  • Last Seen:  

if(countitem(.C_PetEggs[.@j]) > 0){
					if(.@ctr == 10)
						end;
					delitem .C_PetEggs[.@j], 1;
					.@ctr++;
				}else end;

 

Store .@j index and delete it later because you need 10x amount.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  477
  • Reputation:   269
  • Joined:  06/13/17
  • Last Seen:  

    setarray .C_PetEggs,
    9150, 9151, 9152, 9153, 9154, 9155, 9156, 9157, 9158, 9159, 9198, 9200, 9201, 9203, 9204, 9206, 9210;

	getinventorylist();
	for(.@i=0;.@i<@inventorylist_count;.@i++){
		if(inarray(.C_PetEggs,@inventorylist_id[.@i]) < 0) continue; // If the item is not an egg from the array list. continue the loop
		if(!@inventorylist_attribute[.@i]){ // Check if the egg is not hatched, Attribute 1 if it is hatched, 0 if not.
			delitemidx @inventorylist_idx[.@i],1; // Delete the item via the index
			.@delete++;	// Add a counter for deleted eggs
		}
		if(.@deleted >= 10) break; // if the deleted eggs is more than 10. exit the loop
	}

	mes "10 Unhatched eggs are deleted.";

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   1
  • Joined:  08/22/18
  • Last Seen:  

Hi, will test this once I got back from vacation. Thanks guys!

22 hours ago, Haruka Mayumi said:
    setarray .C_PetEggs,
    9150, 9151, 9152, 9153, 9154, 9155, 9156, 9157, 9158, 9159, 9198, 9200, 9201, 9203, 9204, 9206, 9210;

	getinventorylist();
	for(.@i=0;.@i<@inventorylist_count;.@i++){
		if(inarray(.C_PetEggs,@inventorylist_id[.@i]) < 0) continue; // If the item is not an egg from the array list. continue the loop
		if(!@inventorylist_attribute[.@i]){ // Check if the egg is not hatched, Attribute 1 if it is hatched, 0 if not.
			delitemidx @inventorylist_idx[.@i],1; // Delete the item via the index
			.@delete++;	// Add a counter for deleted eggs
		}
		if(.@deleted >= 10) break; // if the deleted eggs is more than 10. exit the loop
	}

	mes "10 Unhatched eggs are deleted.";

 

 

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