Jump to content
  • 0

question about proper way of using arrays


Question

Posted (edited)

Hi guys wanted to learn how to use array since I'm always using variables and it would take me some time to list everything there.

I wanted to use an array for my Quests and I wanted to use 2 set of array 1 for the Items needed and 1 for it's Quantity.

 

as you can see below I wanted them to countitem first then if it's true they will be deleted. else end;

 

example:

setarray .@ItemReq[0], 501, 502, 503, 504;
setarray .@ItemQty[0], 5, 10, 15, 20;

if(countitem(.@ItemReq[0]) >= .@ItemQty[0] || (.@ItemReq[1]) >= .@ItemQty[1] || (.@ItemReq[2]) >= .@ItemQty[2] || (.@ItemReq[3]) >= .@ItemQty[3] ) {
delitem .@ItemReq[0],.@ItemQty[0];
delitem .@ItemReq[1],.@ItemQty[1];
delitem .@ItemReq[2],.@ItemQty[2];
delitem .@ItemReq[3],.@ItemQty[3];
mes "Deleted all items .";
close;
} else { end; }

 

I'm really new to scripting and arrays.
appreciate any help you would mention :)

anyone can help me make it work and much easier?

Edited by THPO

4 answers to this question

Recommended Posts

Posted

something like this.


prontera,155,181,5	script	Sample#array	757,{
// loop + check item
for( .@i = 0; .@i < .item_size; .@i++ )
	if( countitem( .item[.@i] ) < .amount[.@i] ){
		mes "You need "+.amount[.@i]+"x "+getitemname( .item[.@i] );
		close;
	}

// loop again to delete item
for( .@i = 0; .@i < .item_size; .@i++ )
	delitem .item[.@i],.amount[.@i];

// done, get item
getitem 607;
mes "Done.";
close;

OnInit:
	// initialize items
	setarray .item,501,502,503,504,505;
	setarray .amount,1,2,3,4,5;
	.item_size = getarraysize( .item );
	end;
}
  • Upvote 1
Posted

Thanks for your moment Mr. Emistry for taking a look at my thread but can I ask

what does this mean:

for( .@i = 0; .@i < .item_size; .@i++ )

especially the .@i

Posted

I need to read that :),

 

and here if I wanted do display all the items need:

how should i make it should I add someting like .item[.@i+1]

so all items needed will appear: 

You still need :

1x Red Potion

2x Orange Potion

3x Yellow Potion

4x White Potion etc..

mes "You still need "+.amount[.@i]+"x "+getitemname( .item[.@i] );

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...