Lil Troll Posted August 14, 2013 Posted August 14, 2013 (edited) How can i make it properly work, for example i will set an arrays: setarray $ITEMS[0],15000,15001,15002,15003; Then for example i want to count that items in inventory if(countitem($Items,$Items[getarraysize($Items)])<1) { Then i want to make an statement of ifequipped if(isequipped($Items,$Items[getarraysize($Items)])==0) { Is that correct or? I Should set first? like this? set $Items,getarraysize($Items); if(countitem($Items)<1) { close } if(isequipped($Items)==0) { close } if(isequipped($Items)) { enter } I cant find any solution, sorry im really new to scripting, trying to learn things by observing, and learning tru trials/errors. Edited August 14, 2013 by Lil Troll Quote
Emistry Posted August 14, 2013 Posted August 14, 2013 like this ? setarray .@items[0],15000,15001,15002,15003; .@item_size = getarraysize( .@items ); for( .@i = 0; .@i < .@item_size; .@i++ ){ if( !countitem( .@items[.@i] ) ){ dispbottom "You dont have "+getitemname( .@items[.@i] ); end; }else if( !isequipped( .@items[.@i] ) ){ dispbottom "You didnt equip with "+getitemname( .@items[.@i] ); end; } } Quote
Lil Troll Posted August 14, 2013 Author Posted August 14, 2013 (edited) WOW! A very quick response from sir Emistry gonna try using that, thanks now my scripting is going to level up again. Anyways whats this means? for( .@i = 0; .@i < .@item_size; .@i++ ){ Edited August 14, 2013 by Lil Troll Quote
KoolKat29 Posted August 14, 2013 Posted August 14, 2013 ^ it's a "for loop" http://rathena.org/wiki/Loops Quote
Patskie Posted August 14, 2013 Posted August 14, 2013 You can also iterate an array through a while loop : setarray .@items[0],15000,15001,15002,15003; .@item_size = getarraysize( .@items ); while ( .@i < .@item_size ) { if ( !countitem( .@items[.@i] ) ){ dispbottom "You dont have "+getitemname( .@items[.@i] ); end; } else if ( !isequipped( .@items[.@i] ) ){ dispbottom "You didnt equip with "+getitemname( .@items[.@i] ); end; } .@i++; } Quote
Lil Troll Posted August 14, 2013 Author Posted August 14, 2013 (edited) Wow thanks for the reply guys! Im really learning alot. Anyways I do have another question, Is there a way of combining this arrays into one, setarray $CastSpeed[0],0,100,200; setarray $EquipItem[0],15000,15001,15002; For example, if Equip $EquipItem it will give me $CastSpeed, based on their arrangements? .@combo = getarraysize( $EquipSpeed ); .@combo = getarraysize( $EquipItem ); for( .@i = 0; .@i < .@combo; .@i++ ) {while ( .@i < .@item_size ) { if ( !isequipped( .@combo[.@i] ) ) { dispbottom "Your Cast Speed Increase( .$EquipSpeed[.@i] ); } end; } Like the the script above? Sorry i dont know how to start properly and do that. Just like my reference creating a menu like this: set .@pro, getd(".pro"+.@menu+"["+@menu+"]"); set .@crf, getd(".crf"+.@menu+"["+@menu+"]"); set .@men, getd(".men"+.@menu+"["+@menu+"]"); set .@chn, getd(".chn"+.@menu+"["+@menu+"]"); OnInit: setarray .men0, 15000, 15001, 15001; setarray .crf0, 100 , 100 , 100 ; setarray .pro0, 15002, 15002, 15002; setarray .chn0, 100 , 100 , 100 ; Edited August 14, 2013 by Lil Troll Quote
Patskie Posted August 14, 2013 Posted August 14, 2013 Combine in one array : setarray .@items[0],15000,0,15001,100,15002,200; // <equip item>,<cast speed> .@item_size = getarraysize( .@items ); while ( .@i < .@item_size ) { mes .@items[.@i]+ " " +.@items[.@i+1]; .@i += 2; } Quote
Lil Troll Posted August 14, 2013 Author Posted August 14, 2013 (edited) OMG! Thank you sir patskie!! You made my life easier! Anyways can you explain this? Please.. setarray .@items[0],15000,0,15001,100,15002,200; // <equip item>,<cast speed> .@item_size = getarraysize( .@items ); while ( .@i < .@item_size ) { mes .@items[.@i]+ " " +.@items[.@i+1]; .@i += 2; } so the mes is? 1500 0 1501 100 1502 200 i dont get it actually gonna try figuring this by my self and can i ask last question?How can i set also this? 0 = OFF 1 = ON Like this below? setarray .@f[0],0,OFF,1,ON; .@f = getarraysize( .@status ); if ( SwitchOn ) set SwitchBoxOn, 0 ; else set SwitchBoxOn, 1 ; { while ( .@i < .@status ) { dispbottom "Switch Box: "+.@status[.@i+1]+"; .@i + =2; { Edited August 14, 2013 by Lil Troll Quote
Patskie Posted August 14, 2013 Posted August 14, 2013 Example : I have an array like this : setarray .items[0],7227,5,7179,5; // <itemd id>,<amount> set .size, getarraysize(.items); Iterate it ( either for loop or while loop will do ) : while ( .@i < .size ) { // Right now the index is 0 because we didn't increment the .@i variable getitem .items[.@i], .items[.@i+1]; // right now the .@i is 0 so meaning .items[0] is 7227 which is TCG and the next argument is [.@i + 1] so 0 + 1 = 1, meaning .items[1] which 5 and 5 is the amount set .@i, .@i + 2; // since you want to combine 2 pieces of data in one array which in our case is <item id>, <amount> then you should not use .@i++ or set .@i, .@i + 1 because this will iterate like .items[0], .items[1] and so on which is not the proper in our example. It should be .@i += 2 or set .@i, .@i + 2. Why? because the .@i + 1 is always the amount so the loop will disregard it and proceed to the next index } Sorry for noob explanation ha ha ha Quote
Lil Troll Posted August 15, 2013 Author Posted August 15, 2013 (edited) Wow thanks sir patskie im really learning a lot, now i did produce this, but im having a lil problem, i dont know how to read the separate variables of the arraysize, here is the script.. ITEMS =15000,15001,15002,15003,15004 EXP = 1 , 2 , 3 , 4 , 5 setarray $EquipsArray[0],15000,1,15001,2,15002,3,15003,4,15004,5; set .@equip_exp,getarraysize($EquipsArray); while ( .@i < .@equip_exp ); if(!isequipped(.@eqiup_exp[.@i])) { set EquipNowExp,EquipNowExp+ 1 + .@equip_exp[.@i+1]; } else set EquipNowExp, EquipNowExp + 1; if ( EquipNowExp >= $EquipExpMax ) { set EquipLevel, EquipLevel + 1 ; set EquipNowExp, 0 ; dispbottom "Equip exp : " + EquipLevel + "" ; specialeffect2 410 ; } return ; } Or this one? Im very confused, i almost reach the answer... setarray $EquipsArray[0],2764,5317,2550,2443,2758; setarray $EquipExp[0], 1, 1, 1 ,1 ,1 ; .@equip_size = getarraysize( $EquipsArray ); .@equip_exp = getarraysize( $EquipExp ); set .@combo,getd(".@equip_size"+".@equip_exp"); for( .@i = 0; .@i < .@combo; .@i++ ) { if( !isequipped( .@combo[.@i] ) ){ set EquipNowExp,EquipNowExp + 1 + .@combo[.@i++]; } } Also this wont work: setarray $EquipsArray[0],15000,1,15001,2,15002,3,15003,4,15004,5; .@array_size = getarraysize( $EquipsArray ); while ( .@i < .@array_size ) { if( !isequipped(.@array_size[.@i])) { set EquipExp,EquipExp + 1 + .@array_size[.@i+1]; } } Edited August 15, 2013 by Lil Troll Quote
Question
Lil Troll
How can i make it properly work, for example i will set an arrays:
Then for example i want to count that items in inventory
Then i want to make an statement of ifequipped
Is that correct or?
I Should set first? like this?
I cant find any solution, sorry im really new to scripting, trying to learn things by observing, and learning tru trials/errors.
Edited by Lil Troll9 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.