Jump to content
  • 0

on checking array items infinite loop


utofaery

Question


  • Group:  Members
  • Topic Count:  23
  • Topics Per Day:  0.01
  • Content Count:  228
  • Reputation:   19
  • Joined:  10/27/12
  • Last Seen:  

I am trying to insert this condition check of preventing selling things in the array into the script in below

but everytime I tried it goes into infinite loop

Spoiler

   setarray(.@noSell0x[0], 1065, 6124, 40101, 40102, 40103, 40105 );

 

Spoiler

function    script    F_ETCSELLRefined    {
    setarray .Overcharge[0], 0, 7,9,11,13,15,17,19,21,23,24;
    disable_items;
    getinventorylist;
    for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
        if ( getiteminfo( @inventorylist_id[.@i], ITEMINFO_TYPE ) == IT_ETC ) {
            .@id[.@c] = @inventorylist_id[.@i];
            .@amount[.@c] = @inventorylist_amount[.@i];
            .@zeny_total += getiteminfo( .@id[.@c], ITEMINFO_SELLPRICE ) * .@amount[.@c] *(100 + .Overcharge[ getskilllv(MC_OVERCHARGE)] )/100;
            ++.@c;
        }
    }
    if ( !.@c ) {
        mes "you don't have any items to sell";
        close;
    }
    mes "Are you sure selling :";
    for ( .@i = 0; .@i < .@c; ++.@i )
        mes .@amount[.@i] +"x "+ getitemname(.@id[.@i]);
    mes "for "+ F_InsertComma(.@zeny_total) +" Zeny ?";
    next;
    if ( select( "Yes", "No" ) == 2 ) close;
    if ( Zeny + .@zeny_total > MAX_ZENY ) {
        mes "You can't carry that much Zeny.";
        close;
    }
    for ( .@i = 0; .@i < .@c; ++.@i )
        delitem .@id[.@i], .@amount[.@i];
    mes "All item sold for "+ F_InsertComma(.@zeny_total) +" Zeny";
    Zeny += .@zeny_total;
    return;
}


The Broken Script:: (Loop till infiniti)

Spoiler

function    script    F_ETCSELLRefined    {
    setarray(.@noSell0x[0], 1065, 6124, 40101, 40102, 40103, 40105 );
    setarray .Overcharge[0], 0, 7,9,11,13,15,17,19,21,23,24;
    disable_items;
    getinventorylist;
    for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
        if ( getiteminfo( @inventorylist_id[.@i], ITEMINFO_TYPE ) == IT_ETC ) {
            .@FCheck = 0;
            for( .@c = 0; .@c < getarraysize(.@noSell0x); ++.@c ) {
                    if ( @inventorylist_id[.@i] == .@noSell0x[.@c] ) {
                            .@FCheck = 1;
                    }
            }
            if ( .@FCheck == 0 ) {
                .@id[.@c] = @inventorylist_id[.@i];
                .@amount[.@c] = @inventorylist_amount[.@i];
                .@zeny_total += getiteminfo( .@id[.@c], ITEMINFO_SELLPRICE ) * .@amount[.@c] *(100 + .Overcharge[ getskilllv(MC_OVERCHARGE)] )/100;
            }
            ++.@c;
        }
    }
    if ( !.@c ) {
        mes "you don't have any items to sell";
        close;
    }
    mes "Are you sure selling :";
    for ( .@i = 0; .@i < .@c; ++.@i )
        mes .@amount[.@i] +"x "+ getitemname(.@id[.@i]);
    mes "for "+ F_InsertComma(.@zeny_total) +" Zeny ?";
    next;
    if ( select( "Yes", "No" ) == 2 ) close;
    if ( Zeny + .@zeny_total > MAX_ZENY ) {
        mes "You can't carry that much Zeny.";
        close;
    }
    for ( .@i = 0; .@i < .@c; ++.@i )
        delitem .@id[.@i], .@amount[.@i];
    mes "All item sold for "+ F_InsertComma(.@zeny_total) +" Zeny";
    Zeny += .@zeny_total;
    return;
}

Edit:

Does it has something to do with how much Etc item I has inside my inventory?

like when I don't have more than 40 Count of different types of Etc Item it doesn't go to loop

but when I exceed to count 80 of different type of Etc item the loop happens.

Edited by utofaery
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

1. why you ask question on rathena board when the script was solved on hercules board ?
http://herc.ws/board/topic/16523-hhow-to-make-it-report-actual-sold-item-count/
I can't even merge topic because you ask in different forum

2. why you use a function instead of npc ? issit because you want this to be use from an item ?

and since you ask in rathena forum, I use rathena specific script commands, that throw error on hercules

prontera,155,185,4	script	Mass Junk Seller	1_M_MERCHANT,{
	disable_items;
	getinventorylist;
	for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
		if ( getiteminfo( @inventorylist_id[.@i], 2 ) == IT_ETC && inarray( .item_deny, @inventorylist_id[.@i] ) == -1 ) {
			.@id[.@c] = @inventorylist_id[.@i];
			.@amount[.@c] = @inventorylist_amount[.@i];
			.@zeny_total += getiteminfo( .@id[.@c], 1 ) * .@amount[.@c] *(100 + .Overcharge[ getskilllv("MC_OVERCHARGE")] )/100;
			++.@c;
		}
	}
	if ( !.@c ) {
		mes "you don't have any items to sell";
		close;
	}
	mes "Are you sure selling :";
	for ( .@i = 0; .@i < .@c; ++.@i )
		mes .@amount[.@i] +"x "+ getitemname(.@id[.@i]);
	mes "for "+ F_InsertComma(.@zeny_total) +" Zeny ?";
	next;
	if ( select( "Yes", "No" ) == 2 ) close;
	if ( Zeny + .@zeny_total > MAX_ZENY ) {
		mes "You can't carry that much Zeny.";
		close;
	}
	for ( .@i = 0; .@i < .@c; ++.@i )
		delitem .@id[.@i], .@amount[.@i];
	mes "All item sold for "+ F_InsertComma(.@zeny_total) +" Zeny";
	Zeny += .@zeny_total;
	close;
OnInit:
	setarray .Overcharge[0], 0, 7,9,11,13,15,17,19,21,23,24;
	setarray .item_deny, 907,908,909, 7539;
	end;
}

 

EDIT: and the reason probably why your script give infinite loop error is because
I used .@c to store the total amount of possible items, and you reuse .@c in a loop

Edited by AnnieRuru
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  23
  • Topics Per Day:  0.01
  • Content Count:  228
  • Reputation:   19
  • Joined:  10/27/12
  • Last Seen:  

On 2/7/2019 at 4:03 PM, AnnieRuru said:

2. why you use a function instead of npc ? issit because you want this to be use from an item ?

EDIT: and the reason probably why your script give infinite loop error is because
I used .@c to store the total amount of possible items, and you reuse .@c in a loop

4.

since you ask in rathena forum, I use rathena specific script commands, that throw error on hercules

2

truthfully yes meant to be created as custom vip item so one can use it with autoloot 100 in instance where monster's are filled with lots of drop.  so easier maintaining inventory...

 

3  so what do I make to fix that loop hole???

 

4.  it's like unpopulated place there...

well I will correct and stop this error in the future of posting there and here...

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

2. I hope you can edit this yourself, this isn't an overly complicated script ...

3. just don't use .@c counter ... use some other variable like .@j or .@k ...

4. if you ask in this forum, I'll write in rathena language, otherwise ask in that forum, I'll use hercules language ...
https://annieruru.blogspot.com/2019/01/basic-script-command-comparision.html

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