Jump to content
  • 0
6ttctt9

NPC script Question: setarray with too many value, the npc script wont run ?

Question

Posted (edited)

Why setarray with too many value, the npc script wont run ?
This is NPC script, who will buy card from player with different price depend what is that card, like MVP card price 1 billion zeny and other is 100k or millions zeny.
with setarray just 1 or 2,3 value, the script run fine. but with many value each setarray, it wont run.
Example:
setarray .card100k,4032;//,4013,4023,4009,4004,4002,4026,4019,4006,4050,4008,4011,4001,4021,4022,4028,4016,4051; = it run
setarray .card100k,4032,4013,4023,4009,4004,4002,4026,4019,4006,4050,4008,4011,4001,4021,4022,4028,4016,4051; = it wont run.

prontera,181,204,4	script	Card Buyer	  658,{

mes "[Card Buyer]";
mes "You have any card to sell ? <3";
next;
		
getinventorylist;
for (; [email protected] < @inventorylist_count; [email protected]++) {
	if(getiteminfo(@inventorylist_id[[email protected]],2) == 6){
		[email protected][[email protected]] = @inventorylist_id[[email protected]];
		.el = 0;
		for ( [email protected] = 0; [email protected] < getarraysize(.card100k); [email protected]++ ) {
		   if(@inventorylist_id[[email protected]] == .card100k[[email protected]]) {
		    [email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^00FF00100K Zeny^000000:";
		   .el = 1;
		   }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card500k); [email protected]++ ) {
		   if(@inventorylist_id[[email protected]] == .card500k[[email protected]]) {
		    [email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^00FF00500K Zeny^000000:";
		    .el = 1;
		  }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card5m); [email protected]++ ) {
		   if(@inventorylist_id[[email protected]] == .card5m[[email protected]]) {
		    [email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^0000FF5M Zeny^000000:";
		    .el = 1;
		  }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card10m); [email protected]++ ) {
		   if(@inventorylist_id[[email protected]] == .card10m[[email protected]]) {
		    [email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^0000FF10M Zeny^000000:";
		    .el = 1;
		  }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card50m); [email protected]++ ) {
		   if(@inventorylist_id[[email protected]] == .card50m[[email protected]]) {
		    [email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^0000FF50M Zeny^000000:";
		    .el = 1;
		  }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card100m); [email protected]++ ) {
		   if(@inventorylist_id[[email protected]] == .card100m[[email protected]]) {
		    [email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^FF0000100M Zeny^000000:";
		   .el = 1;
		   }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card500m); [email protected]++ ) {
		   if(@inventorylist_id[[email protected]] == .card500m[[email protected]]) {
		    [email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^FF0000500M Zeny^000000:";
		    .el = 1;
		  }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card1b); [email protected]++ ) {
		   if(@inventorylist_id[[email protected]] == .card1b[[email protected]]) {
		    [email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^FF00001B Zeny^000000:";
		    .el = 1;
		  }
		}
		if(.el == 0) {
		[email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^00FF001M Zeny^000000:";
		}
		[email protected]++;
	}
}

[email protected] = select([email protected]$) - 1;

delitem [email protected][[email protected]],1;
		.el = 0;
		for ( [email protected] = 0; [email protected] < getarraysize(.card100k); [email protected]++ ) {
		   if([email protected][[email protected]] == .card100k[[email protected]]) {
		    set Zeny, Zeny + 100000;
		   .el = 1;
		   }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card500k); [email protected]++ ) {
		   if([email protected][[email protected]] == .card500k[[email protected]]) {
		    set Zeny, Zeny + 500000;
		    .el = 1;
		  }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card5m); [email protected]++ ) {
		   if([email protected][[email protected]] == .card5m[[email protected]]) {
		    set Zeny, Zeny + 5000000;
		    .el = 1;
		  }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card10m); [email protected]++ ) {
		   if([email protected][[email protected]] == .card10m[[email protected]]) {
		    set Zeny, Zeny + 10000000;
		    .el = 1;
		  }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card50m); [email protected]++ ) {
		   if([email protected][[email protected]] == .card50m[[email protected]]) {
		    set Zeny, Zeny + 50000000;
		    .el = 1;
		  }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card100m); [email protected]++ ) {
		   if([email protected][[email protected]] == .card100m[[email protected]]) {
		    set Zeny, Zeny + 100000000;
		   .el = 1;
		   }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card500m); [email protected]++ ) {
		   if([email protected][[email protected]] == .card500m[[email protected]]) {
		    set Zeny, Zeny + 500000000;
		    .el = 1;
		  }
		}
		for ( [email protected] = 0; [email protected] < getarraysize(.card1b); [email protected]++ ) {
		   if([email protected][[email protected]] == .card1b[[email protected]]) {
		    set Zeny, Zeny + 1000000000;
		    .el = 1;
		  }
		}
		if(.el == 0) {
		set Zeny, Zeny + 1000000;
		}
end;

OnInit:
	//Ambernite,Andre Egg,Baby Desert Wolf,Chonchon,Drops,Fabre,Female Thief Bug,Hornet,Lunatic,Male Thief Bug,Picky,Picky Egg,Poring,Rocker,Spore,Tarou,Thief Bug,Yoyo
	setarray .card100k,4032;//,4013,4023,4009,4004,4002,4026,4019,4006,4050,4008,4011,4001,4021,4022,4028,4016,4051;
    //Andre,Condor,Elder Willow,Kukre,Pupa,Roda Frog,Thief Bug Egg,Willow,Wormtail
	setarray .card500k,4043;//,4015,4052,4027,4003,4014,4012,4010,4034;
    //Anubis,Beholder,Bigfoot,Bloody Butterfly,Bloody Knight,Cecil Damon,Creamy,Deviruchi,Dimik,Dragon Fly,Drosera,Eclipse,Egnigem Cenia,Eremes Guile,Enchanted Peach Tree,Executioner,Frilldora,Giant Whisper,Giearth,Goblin Leader,Gryphon,Horn,Horong,Howard Alt-Eisen,Joker,Kathryne Keyron,Khalitzburg,Kobold Leader,Loli Ruri,Marc,Marduk,Margaretha Sorin,Marine Sphere,Mastering,Medusa,Mutant Dragonoid,Mysteltainn,Nightmare,Obeaune,Ogretooth,Orc Warrior,Penomena,Phen,Pirate Skeleton,Poison Spore,Poporing,Rafflesia,Raydric,Seeker,Seyren Windsor,Sky Petite,Smokie,Soldier Andre,Stapo,Teddy Bear,Thara Frog,Toad,Ungoliant,Vagabond Wolf,Vitata,Vocal,Whisper,Zealotus
	setarray .card5m,4138,4356;//,4074,4327,4320,4368,4040,4122,4370,4179,4421,4266,4346,4360,4217,4250,4088,4303,4087,4155,4163,4045,4103,4362,4139,4366,4136,4291,4191,4105,4112,4364,4084,4197,4124,4203,4207,4127,4093,4254,4066,4314,4077,4073,4048,4033,4083,4133,4414,4358,4120,4044,4059,4424,4340,4058,4306,4336,4183,4053,4211,4102,4277;
    //Argiope,Banshee,Bathory,Bow Guardian,Despero of Thanatos,Dokebi,Dolor of Thanatos,Evil Druid,Hydrolancer,Imp,Kasa,Maero of Thanatos,Odium of Thanatos,Pasana,Salamander,Sandman,Siroma,Sword Guardian,Swordfish,Zerom
	setarray .card10m,4114;//,4438,4119,4428,4397,4098,4398,4141,4384,4433,4431,4395,4396,4099,4429,4101,4416,4427,4089,4064;
    //Abysmal Knight,Alice,Elder,Maya Purple
	setarray .card50m,4140;//,4253,4251,4198;
    //Angeling,Arc Angeling,Dark Illusion,Deviling,Ghostring
	setarray .card100m,4054;//,4241,4169,4174,4047;
    //Amon Ra,Atroce,Baphomet,Dark Lord,Detardeurus,Doppelganger,Dracula,Drake,Eddga,Evil Snake Lord,Fallen Bishop Hibram,General Egnigem Cenia,Gloom Under Night,Golden Thief Bug,Hatii,Kiel-D-01,Lady Tanee,Lord of The Dead,Maya,Mistress,Moonlight Flower,Orc Hero,Orc Lord,Osiris,Pharaoh,Phreeoni,RSX-0806,Samurai Spector,Stormy Knight,Tao Gunka,Turtle General,Vesper,White Lady
	setarray .card500m,4236,4425;//,4147,4168,4386,4142,4134,4137,4123,4330,4441,4352,4408,4128,4324,4403,4376,4276,4146,4132,4131,4143,4135,4144,4148,4121,4342,4263,4318,4302,4305,4374,4372;
    //Assassin Cross,Berzebub,Entweihen Crothen,High Priest,High Wizard,Ifrit,Ktullanux,Lord Knight,MasterSmith,Memory of Thanatos,Randgris,Sniper
	setarray .card1b,4359;//,4145,4451,4363,4365,4430,4419,4357,4361,4399,4407,4367;
	//All else : 1m
	end;
}

 

Edited by 6ttctt9
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

too many loop, simplify your script

prontera,181,204,4	script	Card Buyer	658,{
	mes "[Card Buyer]";
	mes "You have any card to sell ? <3";
	next;
	getinventorylist;
	for ([email protected] = 0; [email protected] < @inventorylist_count; [email protected]++)
	{
		[email protected]_id = @inventorylist_id[[email protected]];
		[email protected]_qt = @inventorylist_amount[[email protected]];

		if (getiteminfo([email protected]_id, 2) != 6)
			continue; // skip not card

		// find if this card can be sold to this npc
		[email protected] = inarray(.card_list, [email protected]_id);

		// not in list card that can be sold, skip!
		if ([email protected] == -1)
			continue;

		[email protected]$[[email protected]]     = getitemname([email protected]_id) + callfunc("F_InsertComma", .card_price[[email protected]_id]);
		[email protected]_ids[[email protected]] = [email protected]_id;
		[email protected]_qts[[email protected]] = [email protected]_qt;
		[email protected]++;
	}
	[email protected] = select(implode([email protected]$, ":")) -1;
	mes "[Card Buyer]";
	[email protected]_id = [email protected]_ids[[email protected]];
	[email protected]_qt = [email protected]_qts[[email protected]];
	mes "You want to sell "+ getitemname([email protected]_id) +"?";
	mes "I will pay you "+ callfunc("F_InsertComma", .card_price[[email protected]_id]) +"z/ea";
	[email protected] = .card_price[[email protected]_id] * [email protected]_qt;
	mes "Total Price: "+ callfunc("F_InsertComma", [email protected])+"z.";
	select("Yes");
	delitem [email protected]_id, [email protected]_qt;
	Zeny += [email protected];
	mes "[Card Buyer]";
	mes "Thank you for your patronage!";
	close;
	
OnInit:
	function AddCard;
	/*
		@param price in zeny
		@param "card id:card id:card id:...."
		
		Sample:
			AddCard(10000, "4001:4002:4003");
	*/
	freeloop(true);

	AddCard(100000, "4032:4013:4023:4009:4004:4002:4026:4019:4006:4050:4008:4011:4001:4021:4022:4028:4016:4051");
	AddCard(500000, "4043:4015:4052:4027:4003:4014:4012:4010:4034");

	freeloop(false);
	end;

function	AddCard	{
	[email protected] = getarg(0, 0);
	if ([email protected] < 1)
	{
		debugmes sprintf("[%s] AddCard: buying price is %d, minimum price is 1", strnpcinfo(0), [email protected]);
		return;
	}
	[email protected]_list$ = getarg(1, "");
	if ([email protected]$ == "")
	{
		debugmes sprintf("[%s] AddCard: card list is empty for price %d", strnpcinfo(0), [email protected]);
		return;
	}
	explode([email protected]$, [email protected]_list$, ":");
	for ([email protected] = 0; [email protected] < getarraysize([email protected]$); [email protected]++)
	{
		[email protected] = atoi([email protected]$);
		if (getitemname([email protected]) == "null")
		{
			debugmes sprintf("[%s] AddCard: card id %d is not exist price %d", strnpcinfo(0), [email protected], [email protected]);
			continue;
		}
		[email protected] = inarray(.card_list, [email protected]);
		if ([email protected] > -1)
		{
			debugmes sprintf("[%s] AddCard: card id %d duplicate entry, first set price %d", strnpcinfo(0), [email protected], .card_price[[email protected]]);
			continue;
		}
		.card_list[getarraysize(.card_list)] = [email protected];
		.card_price[[email protected]] = [email protected];
	}
	return;
}
	
}

writing it with out testing it work or not, you can use this as sample tho.. if you want

  • Like 1
Link to comment
Share on other sites

  • 0
Posted (edited)
On 5/24/2021 at 11:00 PM, Litro Endemic said:

too many loop, simplify your script

i dont know how to simple it, there is about 9 type price, each type price have many cards id in it.
So it need 9 loop for check card id, it is in list of each type or not.

How to check:

if ([email protected] == <mutil value>)
example :
if ([email protected] == 4040,4041,4042,4043,...) ?

 

On 5/24/2021 at 11:38 PM, Litro Endemic said:
prontera,181,204,4	script	Card Buyer	658,{
	mes "[Card Buyer]";
	mes "You have any card to sell ? <3";
	next;
	getinventorylist;
	for ([email protected] = 0; [email protected] < @inventorylist_count; [email protected]++)
	{
		[email protected]_id = @inventorylist_id[[email protected]];
		[email protected]_qt = @inventorylist_amount[[email protected]];

		if (getiteminfo([email protected]_id, 2) != 6)
			continue; // skip not card

		// find if this card can be sold to this npc
		[email protected] = inarray(.card_list, [email protected]_id);

		// not in list card that can be sold, skip!
		if ([email protected] == -1)
			continue;

		[email protected]$[[email protected]]     = getitemname([email protected]_id) + callfunc("F_InsertComma", .card_price[[email protected]_id]);
		[email protected]_ids[[email protected]] = [email protected]_id;
		[email protected]_qts[[email protected]] = [email protected]_qt;
		[email protected]++;
	}
	[email protected] = select(implode([email protected]$, ":")) -1;
	mes "[Card Buyer]";
	[email protected]_id = [email protected]_ids[[email protected]];
	[email protected]_qt = [email protected]_qts[[email protected]];
	mes "You want to sell "+ getitemname([email protected]_id) +"?";
	mes "I will pay you "+ callfunc("F_InsertComma", .card_price[[email protected]_id]) +"z/ea";
	[email protected] = .card_price[[email protected]_id] * [email protected]_qt;
	mes "Total Price: "+ callfunc("F_InsertComma", [email protected])+"z.";
	select("Yes");
	delitem [email protected]_id, [email protected]_qt;
	Zeny += [email protected];
	mes "[Card Buyer]";
	mes "Thank you for your patronage!";
	close;
	
OnInit:
	function AddCard;
	/*
		@param price in zeny
		@param "card id:card id:card id:...."
		
		Sample:
			AddCard(10000, "4001:4002:4003");
	*/
	freeloop(true);

	AddCard(100000, "4032:4013:4023:4009:4004:4002:4026:4019:4006:4050:4008:4011:4001:4021:4022:4028:4016:4051");
	AddCard(500000, "4043:4015:4052:4027:4003:4014:4012:4010:4034");

	freeloop(false);
	end;

function	AddCard	{
	[email protected] = getarg(0, 0);
	if ([email protected] < 1)
	{
		debugmes sprintf("[%s] AddCard: buying price is %d, minimum price is 1", strnpcinfo(0), [email protected]);
		return;
	}
	[email protected]_list$ = getarg(1, "");
	if ([email protected]$ == "")
	{
		debugmes sprintf("[%s] AddCard: card list is empty for price %d", strnpcinfo(0), [email protected]);
		return;
	}
	explode([email protected]$, [email protected]_list$, ":");
	for ([email protected] = 0; [email protected] < getarraysize([email protected]$); [email protected]++)
	{
		[email protected] = atoi([email protected]$);
		if (getitemname([email protected]) == "null")
		{
			debugmes sprintf("[%s] AddCard: card id %d is not exist price %d", strnpcinfo(0), [email protected], [email protected]);
			continue;
		}
		[email protected] = inarray(.card_list, [email protected]);
		if ([email protected] > -1)
		{
			debugmes sprintf("[%s] AddCard: card id %d duplicate entry, first set price %d", strnpcinfo(0), [email protected], .card_price[[email protected]]);
			continue;
		}
		.card_list[getarraysize(.card_list)] = [email protected];
		.card_price[[email protected]] = [email protected];
	}
	return;
}
	
}

writing it with out testing it work or not, you can use this as sample tho.. if you want

Thank you for sample!
I test it and it gives me only 1 NULL in list window. and sample is too complex for me to understand.
So I just replace all loop in my script by: if (inarray(.card100k, [email protected]_id) >= 0) {} then it run good.
Only one problem now is i dont know how to scipt auto close "list of selects" and reopen it again (for load the list after i sell one of them) and not need to talk npc again from begin for sell each card.
 


prontera,181,204,4	script	Card Buyer	  666,{

mes "[Card Buyer]";
mes "You have any card to sell ? <3";
next;

getinventorylist;
for (; [email protected] < @inventorylist_count; [email protected]++) {
	if(getiteminfo(@inventorylist_id[[email protected]],2) == 6){
        [email protected]_id = @inventorylist_id[[email protected]];
		[email protected]_qt = @inventorylist_amount[[email protected]];
		[email protected][[email protected]] = [email protected]_id;
		.el = 0;
		   if(inarray(.card100k, [email protected]_id) >= 0) {
		    [email protected]$ = [email protected]$ + getitemname([email protected]_id) + " ^00FF00100K Zeny^000000 (" + [email protected]_qt + "):";
		   .el = 1;
		   }
		   if(inarray(.card500k, [email protected]_id) >= 0) {
		    [email protected]$ = [email protected]$ + getitemname([email protected]_id) + " ^00FF00500K Zeny^000000 (" + [email protected]_qt + "):";
		   .el = 1;
		   }
		   if(inarray(.card5m, [email protected]_id) >= 0) {
		    [email protected]$ = [email protected]$ + getitemname([email protected]_id) + " ^0000FF5M Zeny^000000 (" + [email protected]_qt + "):";
		   .el = 1;
		   }
		   if(inarray(.card10m, [email protected]_id) >= 0) {
		    [email protected]$ = [email protected]$ + getitemname([email protected]_id) + " ^0000FF10M Zeny^000000 (" + [email protected]_qt + "):";
		   .el = 1;
		   }
		   if(inarray(.card50m, [email protected]_id) >= 0) {
		    [email protected]$ = [email protected]$ + getitemname([email protected]_id) + " ^0000FF50M Zeny^000000 (" + [email protected]_qt + "):";
		   .el = 1;
		   }
		   if(inarray(.card100m, [email protected]_id) >= 0) {
		    [email protected]$ = [email protected]$ + getitemname([email protected]_id) + " ^FF0000100M Zeny^000000 (" + [email protected]_qt + "):";
		   .el = 1;
		   }
		   if(inarray(.card500m, [email protected]_id) >= 0) {
		    [email protected]$ = [email protected]$ + getitemname([email protected]_id) + " ^FF0000500M Zeny^000000 (" + [email protected]_qt + "):";
		   .el = 1;
		   }
		   if(inarray(.card1b, [email protected]_id) >= 0) {
		    [email protected]$ = [email protected]$ + getitemname([email protected]_id) + " ^FF00001B Zeny^000000 (" + [email protected]_qt + "):";
		   .el = 1;
		   }
		if(.el == 0) {
		[email protected]$ = [email protected]$ + getitemname([email protected]_id) + " ^00FF001M Zeny^000000 (" + [email protected]_qt + "):";
		}
		[email protected]++;
	}
}

[email protected] = select([email protected]$) - 1;

[email protected] = [email protected][[email protected]];

delitem [email protected],1;
		.el = 0;
		   if(inarray(.card100k, [email protected]) >= 0) {
		    set Zeny, Zeny + 100000;
		   .el = 1;
		   }
		   if(inarray(.card500k, [email protected]) >= 0) {
		    set Zeny, Zeny + 500000;
		   .el = 1;
		   }
		   if(inarray(.card5m, [email protected]) >= 0) {
		    set Zeny, Zeny + 5000000;
		   .el = 1;
		   }
		   if(inarray(.card10m, [email protected]) >= 0) {
		    set Zeny, Zeny + 10000000;
		   .el = 1;
		   }
		   if(inarray(.card50m, [email protected]) >= 0) {
		    set Zeny, Zeny + 50000000;
		   .el = 1;
		   }
		   if(inarray(.card100m, [email protected]) >= 0) {
		    set Zeny, Zeny + 100000000;
		   .el = 1;
		   }
		   if(inarray(.card500m, [email protected]) >= 0) {
		    set Zeny, Zeny + 500000000;
		   .el = 1;
		   }
		   if(inarray(.card1b, [email protected]) >= 0) {
		    set Zeny, Zeny + 1000000000;
		   .el = 1;
		   }
		if(.el == 0) {
		set Zeny, Zeny + 1000000;
		}
		
end;

OnInit:
	//Ambernite,Andre Egg,Baby Desert Wolf,Chonchon,Drops,Fabre,Female Thief Bug,Hornet,Lunatic,Male Thief Bug,Picky,Picky Egg,Poring,Rocker,Spore,Tarou,Thief Bug,Yoyo
	setarray .card100k,4032,4013,4023,4009,4004,4002,4026,4019,4006,4050,4008,4011,4001,4021,4022,4028,4016,4051;
    //Andre,Condor,Elder Willow,Kukre,Pupa,Roda Frog,Thief Bug Egg,Willow,Wormtail
	setarray .card500k,4043,4015,4052,4027,4003,4014,4012,4010,4034;
    //Anubis,Beholder,Bigfoot,Bloody Butterfly,Bloody Knight,Cecil Damon,Creamy,Deviruchi,Dimik,Dragon Fly,Drosera,Eclipse,Egnigem Cenia,Eremes Guile,Enchanted Peach Tree,Executioner,Frilldora,Giant Whisper,Giearth,Goblin Leader,Gryphon,Horn,Horong,Howard Alt-Eisen,Joker,Kathryne Keyron,Khalitzburg,Kobold Leader,Loli Ruri,Marc,Marduk,Margaretha Sorin,Marine Sphere,Mastering,Medusa,Mutant Dragonoid,Mysteltainn,Nightmare,Obeaune,Ogretooth,Orc Warrior,Penomena,Phen,Pirate Skeleton,Poison Spore,Poporing,Rafflesia,Raydric,Seeker,Seyren Windsor,Sky Petite,Smokie,Soldier Andre,Stapo,Teddy Bear,Thara Frog,Toad,Ungoliant,Vagabond Wolf,Vitata,Vocal,Whisper,Zealotus
	setarray .card5m,4138,4356,4074,4327,4320,4368,4040,4122,4370,4179,4421,4266,4346,4360,4217,4250,4088,4303,4087,4155,4163,4045,4103,4362,4139,4366,4136,4291,4191,4105,4112,4364,4084,4197,4124,4203,4207,4127,4093,4254,4066,4314,4077,4073,4048,4033,4083,4133,4414,4358,4120,4044,4059,4424,4340,4058,4306,4336,4183,4053,4211,4102,4277;
    //Argiope,Banshee,Bathory,Bow Guardian,Despero of Thanatos,Dokebi,Dolor of Thanatos,Evil Druid,Hydrolancer,Imp,Kasa,Maero of Thanatos,Odium of Thanatos,Pasana,Salamander,Sandman,Siroma,Sword Guardian,Swordfish,Zerom
	setarray .card10m,4114,4438,4119,4428,4397,4098,4398,4141,4384,4433,4431,4395,4396,4099,4429,4101,4416,4427,4089,4064;
    //Abysmal Knight,Alice,Elder,Maya Purple
	setarray .card50m,4140,4253,4251,4198;
    //Angeling,Arc Angeling,Dark Illusion,Deviling,Ghostring
	setarray .card100m,4054,4241,4169,4174,4047;
    //Amon Ra,Atroce,Baphomet,Dark Lord,Detardeurus,Doppelganger,Dracula,Drake,Eddga,Evil Snake Lord,Fallen Bishop Hibram,General Egnigem Cenia,Gloom Under Night,Golden Thief Bug,Hatii,Kiel-D-01,Lady Tanee,Lord of The Dead,Maya,Mistress,Moonlight Flower,Orc Hero,Orc Lord,Osiris,Pharaoh,Phreeoni,RSX-0806,Samurai Spector,Stormy Knight,Tao Gunka,Turtle General,Vesper,White Lady
	setarray .card500m,4236,4425,4147,4168,4386,4142,4134,4137,4123,4330,4441,4352,4408,4128,4324,4403,4376,4276,4146,4132,4131,4143,4135,4144,4148,4121,4342,4263,4318,4302,4305,4374,4372;
    //Assassin Cross,Berzebub,Entweihen Crothen,High Priest,High Wizard,Ifrit,Ktullanux,Lord Knight,MasterSmith,Memory of Thanatos,Randgris,Sniper
	setarray .card1b,4359,4145,4451,4363,4365,4430,4419,4357,4361,4399,4407,4367;
	//All else : 1m
	end;
}

 

Edited by 6ttctt9
Link to comment
Share on other sites

  • 0
5 hours ago, 6ttctt9 said:

I test it and it gives me only 1 NULL in list window.

after re-reading the script I see err in my writing..

	[email protected]_list$ = getarg(1, "");
	if ([email protected]$ == "")
	{
		debugmes sprintf("[%s] AddCard: card list is empty for price %d", strnpcinfo(0), [email protected]);
		return;
	}
	explode([email protected]$, [email protected]_list$, ":");
	for ([email protected] = 0; [email protected] < getarraysize([email protected]$); [email protected]++)
	{
		[email protected] = atoi([email protected]$);

should be

	[email protected]_list$ = getarg(1, "");
	if ([email protected]_list$ == "")
	{
		debugmes sprintf("[%s] AddCard: card list is empty for price %d", strnpcinfo(0), [email protected]);
		return;
	}
	explode([email protected]$, [email protected]_list$, ":");
	for ([email protected] = 0; [email protected] < getarraysize([email protected]$); [email protected]++)
	{
		[email protected] = atoi([email protected]$[[email protected]]);

here fixed script.

prontera,181,204,4	script	Card Buyer#rAthena	658,{
	mes "[Card Buyer]";
	mes "You have any card to sell ? <3";
	next;
	getinventorylist;
	for ([email protected] = 0; [email protected] < @inventorylist_count; [email protected]++)
	{
		[email protected]_id = @inventorylist_id[[email protected]];
		[email protected]_qt = @inventorylist_amount[[email protected]];

		if (getiteminfo([email protected]_id, 2) != 6)
			continue; // skip not card

		// find if this card can be sold to this npc
		[email protected] = inarray(.card_list, [email protected]_id);

		// not in list card that can be sold, skip!
		if ([email protected] == -1)
			continue;

		[email protected]$[[email protected]]     = getitemname([email protected]_id) +" "+ callfunc("F_InsertComma", .card_price[[email protected]_id]);
		[email protected]_ids[[email protected]] = [email protected]_id;
		[email protected]_qts[[email protected]] = [email protected]_qt;
		[email protected]++;
	}
	if ([email protected])
	{
		mes "[Card Buyer]";
		mes "You don't have any card huh?";
		close;
	}
	[email protected] = select(implode([email protected]$, ":")) -1;
	mes "[Card Buyer]";
	[email protected]_id = [email protected]_ids[[email protected]];
	[email protected]_qt = [email protected]_qts[[email protected]];
	mes "You have "+ callfunc("F_InsertComma", [email protected]_qt) +"x "+ getitemname([email protected]_id);
	mes "You want to sell "+ getitemname([email protected]_id) +"? I will pay you "+ callfunc("F_InsertComma", .card_price[[email protected]_id]) +"z/ea";
	[email protected] = .card_price[[email protected]_id] * [email protected]_qt;
	mes "For total: "+ callfunc("F_InsertComma", [email protected])+"z.";
	select("Yes");
	delitem [email protected]_id, [email protected]_qt;
	Zeny += [email protected];
	clear;
	mes "[Card Buyer]";
	mes "Thank you for your patronage!";
	close;
	
OnInit:
	function AddCard;
	/*
		@param price in zeny
		@param "card id:card id:card id:...."
		
		Sample:
			AddCard(10000, "4001:4002:4003");
	*/
	freeloop(true);

	AddCard(100000, "4032:4013:4023:4009:4004:4002:4026:4019:4006:4050:4008:4011:4001:4021:4022:4028:4016:4051");
	AddCard(500000, "4043:4015:4052:4027:4003:4014:4012:4010:4034");

	freeloop(false);
	end;

function	AddCard	{
	[email protected] = getarg(0, 0);
	if ([email protected] < 1)
	{
		debugmes sprintf("[%s] AddCard: buying price is %d, minimum price is 1", strnpcinfo(0), [email protected]);
		return;
	}
	[email protected]_list$ = getarg(1, "");
	if ([email protected]_list$ == "")
	{
		debugmes sprintf("[%s] AddCard: card list is empty for price %d", strnpcinfo(0), [email protected]);
		return;
	}
	explode([email protected]$, [email protected]_list$, ":");
	for ([email protected] = 0; [email protected] < getarraysize([email protected]$); [email protected]++)
	{
		[email protected] = atoi([email protected]$[[email protected]]);
		if (getitemname([email protected]) == "null")
		{
			debugmes sprintf("[%s] AddCard: card id %d is not exist price %d", strnpcinfo(0), [email protected], [email protected]);
			continue;
		}
		[email protected] = inarray(.card_list, [email protected]);
		if ([email protected] > -1)
		{
			debugmes sprintf("[%s] AddCard: card id %d duplicate entry, first set price %d", strnpcinfo(0), [email protected], .card_price[[email protected]]);
			continue;
		}
		.card_list[getarraysize(.card_list)] = [email protected];
		.card_price[[email protected]] = [email protected];
	}
	return;
}
	
}

 

5 hours ago, 6ttctt9 said:

sample is too complex for me to understand.

just ask... if anyone has time and understand it, maybe there is someone will answer.

  • Love 1
Link to comment
Share on other sites

  • 0

there are multiple way to do it ....

 

method 1. by exploit the setd/getd to store the price of each card into a variable, so less looping required.

prontera,155,181,5	script	Card Buyer	757,{
	
	mes "["+strnpcinfo(1)+"]";
	mes "You have any card to sell ? <3";
	next;
	getinventorylist;
	for ([email protected] = 0; [email protected] < @inventorylist_count; [email protected]++) {
		[email protected] = getd(".card_"[email protected]_id[[email protected]]);
		if ([email protected])
			[email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^FF0000"+F_InsertComma([email protected])+" Zeny^000000";
		[email protected]$ = [email protected]$ + ":";
	}
	[email protected] = select([email protected]$) - 1;
	clear;
	[email protected] = getd(".card_"[email protected]_id[[email protected]]);
	mes "["+strnpcinfo(1)+"]";
	mes "Sell "+getitemname(@inventorylist_id[[email protected]])+" for ^FF0000"+F_InsertComma([email protected])+" Zeny^000000?";
	if (select("Confirm", "Cancel") == 1) {
		delitem @inventorylist_id[[email protected]], 1;
		Zeny += [email protected];
		clear;
		mes "["+strnpcinfo(1)+"]";
		mes "You have sold "+getitemname(@inventorylist_id[[email protected]])+" for ^FF0000"+F_InsertComma([email protected])+" Zeny^000000.";
	}
	close;
	
	function	AddCard	{
		[email protected] = getarg(0, 0);
		[email protected] = getargcount();
		
		for ([email protected] = 1; [email protected] <= [email protected]; [email protected]++)
			setd(".card_"+getarg([email protected], 0), [email protected]);
		return;
	}
	
	OnInit:
		// AddCard( <zeny>, <card_id>...);
		AddCard( 10000, 4001, 4002, 4003, 4004);
		AddCard(100000, 4011, 4012, 4013, 4014);
		AddCard(500000, 4021, 4022, 4023, 4024, 4025);
		AddCard(999999, 4031, 4032, 4033, 4034, 4035, 4036);
		end;
}

 

method 2. by adjust the buy field in item_db, and set it to the value you want, then have the NPC to check for "Buy" value (why buy and not sell? because we wouldn't want player to exploit overcharge skill and direct sell to NPC)

Example: set the Poring Card's Buy value to 999,999 Zeny

  - Id: 4001
    AegisName: Poring_Card
    Buy: 999999

and have the NPC check and retrieve the Buy field value and use as selling price.

prontera,155,181,5	script	Card Buyer	757,{
	
	mes "["+strnpcinfo(1)+"]";
	mes "You have any card to sell ? <3";
	next;
	getinventorylist;
	for ([email protected] = 0; [email protected] < @inventorylist_count; [email protected]++) {
		[email protected] = getiteminfo(@inventorylist_id[[email protected]], ITEMINFO_BUY);
		if ([email protected] && getiteminfo(@inventorylist_id[[email protected]], ITEMINFO_TYPE) == IT_CARD)
			[email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^FF0000"+F_InsertComma([email protected])+" Zeny^000000";
		[email protected]$ = [email protected]$ + ":";
	}
	[email protected] = select([email protected]$) - 1;
	clear;
	[email protected] = getiteminfo(@inventorylist_id[[email protected]], ITEMINFO_BUY);
	mes "["+strnpcinfo(1)+"]";
	mes "Sell "+getitemname(@inventorylist_id[[email protected]])+" for ^FF0000"+F_InsertComma([email protected])+" Zeny^000000?";
	if (select("Confirm", "Cancel") == 1) {
		delitem @inventorylist_id[[email protected]], 1;
		Zeny += [email protected];
		clear;
		mes "["+strnpcinfo(1)+"]";
		mes "You have sold "+getitemname(@inventorylist_id[[email protected]])+" for ^FF0000"+F_InsertComma([email protected])+" Zeny^000000.";
	}
	close;
}

 

  • Love 1
  • MVP 1
Link to comment
Share on other sites

  • 0
3 hours ago, Emistry said:

method 1. by exploit the setd/getd to store the price of each card into a variable, so less looping required.

prefer method 1, another note with an array and card id as index and price will get same output.

duh when I said "simplify", my script is too extra haha.. 

Link to comment
Share on other sites

  • 0
Posted (edited)
7 hours ago, Litro Endemic said:

an array and card id as index and price will get same output

true, but its not really an ideal solution.

why? although the emulator is kinda updated but the emulator still assume array value 0 still exists.

.array[4001] = 999999;
debugmes ".array size = " + getarraysize(.array); // output: .array size = 4002

this meant, your current array total size is 4002, which wasted the memory the allocated for the total of 4001 data from index 0 to 4000, and you dont even need it.

dont forgot that card_id could be above 5 digits or even 6 digits ID nowadays, which will end up wasting even more than we expected..

 

Edited by Emistry
Link to comment
Share on other sites

  • 0
Posted (edited)
1 hour ago, Emistry said:

true, but its not really an ideal solution.

why? although the emulator is kinda updated but the emulator still assume array value 0 still exists.

.array[4001] = 999999;
debugmes ".array size = " + getarraysize(.array); // output: .array size = 4002

this meant, your current array total size is 4002, which wasted the memory the allocated for the total of 4001 data from index 0 to 4000, and you dont even need it.

dont forgot that card_id could be above 5 digits or even 6 digits ID nowadays, which will end up wasting even more than we expected..

 

Heya,

I just wanted to add there that this is actually incorrect (unless there was a major update on rAthena I'm not aware of). The script engine does not allocate memory for the 0 to 4000 values in your example. Technically speaking, arrays are emulated and not actually arrays in the source. When you use ".array[4001]", the engine does the following:

  • ".array" is a string that gets indexed. The string is given a unique number, say 9048. From then on, everytime the string ".array" is used, it will be refered to as 9048. This is called the id.
  • 4001 is the index.
  • uid (id and index): Both of the values above combined as one (32bit for the id, 32bit for the index, making up 64bit for the uid).

The uid with its value is then stored in a big collection for the whole NPC script. This big collection also contains the values of other non-array variables such as ".temp = 20;". They are all stored in the same place. If you had written the variable as ".array_4001", it would have created a new unique value for the string such as 9049 and the index would have been 0. As you need to index the string everytime you create a new variable, using setd with a big amount of variables is usually not a good practice. Using .array[4001] is handled better source wise.

Quick note, but this is also why [email protected] = 5 is identical to [email protected][0] = 5 and both would return the same value. They have the same uid.

What rAthena also does when you use an index greater than 0 is that it starts keeping track of the array keys (members). So say you used .array[4001], it will keep track that 4001 is a member of the array for the .array variable.

As for getarraysize(), it should be used very carefully and never in the condition of the for loop. getarraysize() does the following:

  • Checks if the .array value exists in the big collection. If not, adds 0 as a member of the array. (This is more of a hack, as it's impossible to know otherwise if [0] is part of the array or not.)
  • Go through all the members of the array and find the highest key, then does + 1.

So in your case, using getarraysize(.array) would indeed return 4002 as 4001 is the only member of the array. Using arrays instead of getd/setd would be much faster (and cleaner) in your script sample as a result:

prontera,155,181,5	script	Card Buyer	757,{
	mes "["+strnpcinfo(1)+"]";
	mes "You have any card to sell ? <3";
	next;
	getinventorylist;
	for ([email protected] = 0; [email protected] < @inventorylist_count; [email protected]++) {
		[email protected] = .card[@inventorylist_id[[email protected]]];
		if ([email protected])
			[email protected]$ = [email protected]$ + getitemname(@inventorylist_id[[email protected]]) + " ^FF0000"+F_InsertComma([email protected])+" Zeny^000000";
		[email protected]$ = [email protected]$ + ":";
	}
	[email protected] = select([email protected]$) - 1;
	clear;
	[email protected] = .card[@inventorylist_id[[email protected]]];
	mes "["+strnpcinfo(1)+"]";
	mes "Sell "+getitemname(@inventorylist_id[[email protected]])+" for ^FF0000"+F_InsertComma([email protected])+" Zeny^000000?";
	if (select("Confirm", "Cancel") == 1) {
		delitem @inventorylist_id[[email protected]], 1;
		Zeny += [email protected];
		clear;
		mes "["+strnpcinfo(1)+"]";
		mes "You have sold "+getitemname(@inventorylist_id[[email protected]])+" for ^FF0000"+F_InsertComma([email protected])+" Zeny^000000.";
	}
	close;
function	AddCard	{
	[email protected] = getarg(0, 0);
	[email protected] = getargcount();
	
	for ([email protected] = 1; [email protected] <= [email protected]; [email protected]++)
		.card[getarg([email protected], 0)] = [email protected];
	return;
}

OnInit:
	// AddCard( <zeny>, <card_id>...);
	AddCard( 10000, 4001, 4002, 4003, 4004);
	AddCard(100000, 4011, 4012, 4013, 4014);
	AddCard(500000, 4021, 4022, 4023, 4024, 4025);
	AddCard(999999, 4031, 4032, 4033, 4034, 4035, 4036);
	end;
}

Edit: This of course doesn't hold true if you would start iterating through the whole array with for ([email protected] = 0; [email protected] < getarraysize(.array); [email protected]++). This would give horrendous performance. We use the array there as a dictionary rather than a list.

Edited by Tokei
  • Upvote 3
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...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.