123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //===== rAthena Script =======================================
- //= Sample: inarray
- //===== By: ==================================================
- //= rAthena Dev Team
- //===== Last Updated: ========================================
- //= 20180424
- //===== Description: =========================================
- //= Demonstrates the 'inarray' and 'countinarray' commands.
- //============================================================
- prontera,160,190,3 script inarray sample 847,{
- switch(select("inarray:countinarray")){
- case 1: //inarray command test
- mes "[inarray Test]";
- setarray .@array1[0],100,200,300,400,500,600,700;
- setarray .@array2$[0],"One Hundred","Two Hundred","Three Hundred","Four Hundred","Five Hundred","Six Hundred","Seven Hundred";
-
- mes .@array2$[inarray(.@array1,100)]; //return One Hundred
- mes .@array2$[inarray(.@array1,300)]; //return Three Hundred
-
- //mes .@array2$[inarray(.@array1,800)]; //this will return with an error
- //800 is not an element of the array .@array1
-
- mes "" + inarray(.@array1,800); //this return -1
- //800 is not an element of the array .@array1
-
- close;
- case 2: //countinarray command test
- switch(select("Basic:Advanced")){
- case 1:
- mes "[countinarray Basic Test]";
- setarray .@array$[0],"rathena","ragnarok","poring","script";
- mes "the array elements: ";
- for(.@i=0;.@i<getarraysize(.@array$);.@i++)
- mes .@array$[.@i];
-
- input .@element$;
- clear;
-
- //also in this example we are using normal variable instead of an array
- //arrays are variables but with more than one index
- //so you can use array or variable
-
- //using countinarray command
- mes "[countinarray Basic Test]";
- if(countinarray(.@array$[0], .@element$) == 1)
- mes "we found " + .@element$ + " inside the array";
- else
- mes .@element$ + " is not an element of the array";
- /*
- without using countinarray command
- ------------------------------------------
- for(.@i=0;.@i<getarraysize(.@array$);.@i++){
- if(.@array$[.@i] == .@element$){
- .@count ++;
- }
- }
- if(.@count == 1)
- mes "we found " + .@element$ + " inside the array";
- else
- mes .@element$ + " is not an element of the array";
- ------------------------------------------
- */
- close;
-
- case 2:
- mes "[countinarray Advanced Test]";
- setarray .@array[0],50,40,80,90,70,500,60,400,700,1,2,2,2,2;
- mes "open the script and read to know what's going on";
- mes " ";
-
- //50 and 70 are elements of the array
- //we make new array that have the values 50 and 70
- //you will see this all over the sample
- setarray .@array2[0],50,70;
- //2 cases true, so the command returns 2
- mes "searching for 50 and 70";
- mes "return " + countinarray(.@array[0], .@array2[0]);
- mes " ";
-
- //50 is an element of the array
- //100 is not an element of the array
- setarray .@array3[0],50,100;
- //1 case true, so the command returns 1
- mes "searching for 50 and 100";
- mes "return " + countinarray(.@array[0], .@array3[0]);
- mes " ";
-
- //586 and 100 are not elements of the array
- setarray .@array4[0],586,100;
- //0 case true, so the command returns 0
- mes "searching for 586 and 100";
- mes "return " + countinarray(.@array[0], .@array4[0]);
- mes " ";
-
- //1 and 1 are elements of the array
- setarray .@array5[0],1,1;
- //2 cases true, so the command returns 2
- mes "searching for 1 and 1";
- mes "return " + countinarray(.@array[0], .@array5[0]);
- mes " ";
-
- //2 is an element of the array, but it's in four indexes
- //the command will return the number valid cases
- //so here the command returns 4
- //this can be used to know the count of an element inside an array
- .@variable = 2;
-
- mes "searching for 2";
- mes "return " + countinarray(.@array[0], .@variable);
-
- close;
- }
- }
- }
|