I'm trying to make a custom trade npc but it's not counting other items but first one

deviruzy

New member
Messages
67
Points
0
 Good days.

 I'm trying to make a custom trade npc that is like old card trader, which I have failed to find in both Hercules and rathena. An npc that gives you one 'item 19305' for every 100 items that is in range of item 18660 to 19222. For example if I bring 30 of 'item 18760' and 80 of 'item 18900' it will give me one '19305' and leave 10 of either 18760 or 18900. I hope this makes sense. Here's what I got so far.

        for (set .@i,18660; .@i < 19223; set .@i,.@i+1) {
        if (countitem(.@i) < 100) goto Enog;
        set .@j,(countitem(.@i)/100);
        delitem .@i,100*.@j;
        getitem 19305,1*.@j;
        close;
 

    Enog:
        mes "  "; 
        close;
 
    }

 Thanks to Aeromesi now I know this is deeply wrong. This script only changes 18660 only. If I bring 18661 it goes straight to the label Enog.
Please teach me how to make this npc right. I would really appreciate it if you help me.
 Thank you.
 
Last edited by a moderator:
Are you sure item ID from 18660 to 19223 exist ?
count item with non-exist item will return 0 and 0 always < 100
 

 
Are you sure item ID from 18660 to 19223 exist ?

count item with non-exist item will return 0 and 0 always < 100
 They exist. Yes. They are my custom items. I have tested this script by spawning those items in my inventory. What happened is no other than 'item 18660' it won't turn into 'item 19305'.

 
Last edited by a moderator:
Are you just trying to obtain all the custom items in your inventory? Your script makes me clueless what you're really trying to achieve.. >.< whatever logics going on I have hard time grasping... from what I can tell is

For item ID 18660 is less than 19223 "perform operation." Which is adding .@i until become 19223. will always be greater than 100 because it starts at 18660. I just suggest maybe better explanation or better grasp on script_commands.txt in our public github repo.. unless I'm only one confused someone please help our fellow Hercules user.

 
Are you just trying to obtain all the custom items in your inventory? Your script makes me clueless what you're really trying to achieve.. >.< whatever logics going on I have hard time grasping... from what I can tell is

For item ID 18660 is less than 19223 "perform operation." Which is adding .@i until become 19223. will always be greater than 100 because it starts at 18660. I just suggest maybe better explanation or better grasp on script_commands.txt in our public github repo.. unless I'm only one confused someone please help our fellow Hercules user.
 It appears I am insanely confused here. Hahahaha. I've edited the original post to clarify what I'm trying to do. I'm trying to make a npc that is like the old version of card trader. For example if you bring 100 items that is in range of 18660 to 19222 it will give me one 19305 in return. I hope I'm making sense.

 
for (.@i = 18660; .@i < 19223; ++.@i) {

if (countitem(.@i) < 100)

continue;

.@j = (countitem(.@i)/100);

delitem .@i, 100 * .@j;

getitem 19305, .@j;

break;

}

if (.@i == 19223) {

mes " ";

close;

}

mes "Successfully changed";

close;

 
for (.@i = 18660; .@i < 19223; ++.@i) {
if (countitem(.@i) < 100)
continue;
.@j = (countitem(.@i)/100);
delitem .@i, 100 * .@j;
getitem 19305, .@j;
break;
}
if (.@i == 19223) {
mes " ";
close;
}
mes "Successfully changed";
close;
 Thank you
default_laugh.png
 ! Thank you! Wow it's gorgoues 
default_laugh.png
 ! But when I tested this npc I noticed that it only takes the items in 100s. For example when I have '100 of 18960', '50 of 18770, and 50 of 18880' it will take 18960s and give me one 19305. I was hoping this NPC can also take those two 50s and leave me two 19305 in this situation.

 I've also found out that it only takes one kind at a time. For instance when I have '200 of 18760' and '100 of 18770' instead of changing them to 3 19305s it just gave me two 19305. I had to ask the npc again for the leftovers. I know I'm asking too much here but It would be more than perfect if this can be done. I really hope it could for it's so close. Please.

 Thank you.

 
Last edited by a moderator:
.@q = 0; .@qd = 0;
for (.@i = 18660; .@i < 19223; ++.@i) {
.@q += countitem(.@i);
}
if (.@q < 100) {
mes " ";
close;
}
.@q /= 100;
.@get = .@q;
for (.@i = 18660; .@i < 19223 && .@q != 0; ++.@i) {
.@qd_bef = .@qd;
.@qd += countitem(.@i);
if (.@qd >= 100) {
delitem .@i, ((.@qd-.@qd_bef)/100)*100;
.@q -= .@qd/100;
.@qd -= (.@qd/100)*100;
}
if (.@q != 0) {
delitem .@i, countitem(.@i);
}
}
getitem 19305, .@get;
mes "Successfully changed";
close;Haven't tested, (it could have been done in more simpler way, but not having enough time to optimize it more)Edit: for previous script, if you remove "break;" it would consider more than 1 item in quantity of 100's

 
Last edited by a moderator:
.@q = 0; .@qd = 0;
for (.@i = 18660; .@i < 19223; ++.@i) {
.@q += countitem(.@i);
}
if (.@q < 100) {
mes " ";
close;
}
.@q /= 100;
.@get = .@q;
for (.@i = 18660; .@i < 19223 && .@q != 0; ++.@i) {
.@qd_bef = .@qd;
.@qd += countitem(.@i);
if (.@qd >= 100) {
delitem .@i, ((.@qd-.@qd_bef)/100)*100;
.@q -= .@qd/100;
.@qd -= (.@qd/100)*100;
}
if (.@q != 0) {
delitem .@i, countitem(.@i);
}
}
getitem 19305, .@get;
mes "Successfully changed";
close;Haven't tested, (it could have been done in more simpler way, but not having enough time to optimize it more)Edit: for previous script, if you remove "break;" it would consider more than 1 item in quantity of 100's
 Wow
default_laugh.png
 . Thank you Dastgir .
default_biggrin.png
  I've tested this and turns out it has a problem, I'm afraid. It does not delete the scattered items. For example if I have '20 of 18670', '90 of 18680', and '90 of 18690' it gives me two 19305s which is good but it does not take away those 200 items. I can just get 2 19305s over and over.

 Previous script without "break;" seems to be working in more refined way like you said, which was amazing
default_laugh.png
. Great skills you got there. It appears everything is solved except the ability to take scattered 100s such as '30 of 18880' and '70 of 18890'. Which makes me keep hoping you know? It's just one step away and I just can't stop wishing for this to work. However, I can and should be happy with this. I've been thinking and I could just make this NPC say something like, "For every 100 items you bring, I'll give you one 19305 in return." You can consider this like a kick in her personality. Yes, the npc is a female. Hahaha
default_laugh.png
 . You have made this trading NPC to completion. Thank you so much.

 Sincerely.

Solved and Completed script is below:

 
    for (.@i = 18660; .@i < 19223; ++.@i) {
        if (countitem(.@i) < 100)
        continue;
 
        .@j = (countitem(.@i)/100);
        delitem .@i,100*.@j;
        getitem 19305,1*.@j;
        }
 
    if (.@i == 19223) {
    mes "You need at least 100 of certain kind."; 
    close;
    }
 
    mes "Successfully changed.";
    close;
 

 
Last edited by a moderator:
You could try this maybe

Code:
    .@q = 0; .@qd = 0;
    for (.@i = 18660; .@i < 19223; ++.@i) {
        .@q += countitem(.@i);
    }
    if (.@q < 100) {
        mes " ";
        close;
    }
    .@q = .@q/100;
    .@get = .@q;
    for (.@i = 18660; .@i < 19223; ++.@i) {
        if (.@q <= 0) {
            getitem 19305, .@get;
            break;
        }
        .@qd += countitem(.@i);
        if (.@qd >= 100) {
            .@q -= .@qd/100;
            .@qd -= (.@qd/100)*100;
            delitem .@i, countitem(.@i)-.@qd;
        }
       if (.@q != 0) {
            delitem .@i, countitem(.@i);
        }
    }
    mes "Successfully changed";
   
    close;
 
You could try this maybe

.@q = 0; .@qd = 0;
for (.@i = 18660; .@i < 19223; ++.@i) {
.@q += countitem(.@i);
}
if (.@q < 100) {
mes " ";
close;
}
.@q = .@q/100;
.@get = .@q;
for (.@i = 18660; .@i < 19223; ++.@i) {
if (.@q <= 0) {
getitem 19305, .@get;
break;
}
.@qd += countitem(.@i);
if (.@qd >= 100) {
.@q -= .@qd/100;
.@qd -= (.@qd/100)*100;
delitem .@i, countitem(.@i)-.@qd;
}
if (.@q != 0) {
delitem .@i, countitem(.@i);
}
}
mes "Successfully changed";

close;
 Wow, You're a hound. Once you bite you never let go Dastgir. Amazing
default_ohmy.png
 . Well, I just tested it and once the combination gets complicated it goes into infinite loop. What I had was '30 of 18740', '60 of 18840', '50 of 18940', and '70 of 19040' and map-server gave me an error message saying "infinite loop!" Dast, Can I call you that way? Haha
default_laugh.png
. I am grateful. I am psyched with the first script you built, without "break;". Thank you so much for your passionate help.

 
You could try this maybe

.@q = 0; .@qd = 0;
for (.@i = 18660; .@i < 19223; ++.@i) {
.@q += countitem(.@i);
}
if (.@q < 100) {
mes " ";
close;
}
.@q = .@q/100;
.@get = .@q;
for (.@i = 18660; .@i < 19223; ++.@i) {
if (.@q <= 0) {
getitem 19305, .@get;
break;
}
.@qd += countitem(.@i);
if (.@qd >= 100) {
.@q -= .@qd/100;
.@qd -= (.@qd/100)*100;
delitem .@i, countitem(.@i)-.@qd;
}
if (.@q != 0) {
delitem .@i, countitem(.@i);
}
}
mes "Successfully changed";

close;
  Wow, You're a hound. Once you bite you never let go Dastgir. Amazing
default_ohmy.png
 . Well, I just tested it and once the combination gets complicated it goes into infinite loop. What I had was '30 of 18740', '60 of 18840', '50 of 18940', and '70 of 19040' and map-server gave me an error message saying "infinite loop!" Dast, Can I call you that way? Haha
default_laugh.png
. I am grateful. I am psyched with the first script you built, without "break;". Thank you so much for your passionate help.
Great
default_tongue.png
Btw, just in case anyone wants the 2nd type , the infinite error is caused due to many loop >100, which can be prevented by using freeloop command as shown here;

Code:
    .@q = 0; .@qd = 0;
    freeloop(1);
    for (.@i = 18660; .@i < 19223; ++.@i) {
        .@q += countitem(.@i);
    }
    freeloop(0);
    if (.@q < 100) {
        mes " ";
        close;
    }
    .@q = .@q/100;
    .@get = .@q;
    freeloop(1);
    for (.@i = 18660; .@i < 19223; ++.@i) {
        if (.@q <= 0) {
            getitem 19305, .@get;
            break;
        }
        .@qd += countitem(.@i);
        if (.@qd >= 100) {
            .@q -= .@qd/100;
            .@qd -= (.@qd/100)*100;
            delitem .@i, countitem(.@i)-.@qd;
        }
       if (.@q != 0) {
            delitem .@i, countitem(.@i);
        }
    }
    freeloop(0);
    mes "Successfully changed";
   
    close;
 
Great
default_tongue.png
Btw, just in case anyone wants the 2nd type , the infinite error is caused due to many loop >100, which can be prevented by using freeloop command as shown here;

.@q = 0; .@qd = 0;
freeloop(1);
for (.@i = 18660; .@i < 19223; ++.@i) {
.@q += countitem(.@i);
}
freeloop(0);
if (.@q < 100) {
mes " ";
close;
}
.@q = .@q/100;
.@get = .@q;
freeloop(1);
for (.@i = 18660; .@i < 19223; ++.@i) {
if (.@q <= 0) {
getitem 19305, .@get;
break;
}
.@qd += countitem(.@i);
if (.@qd >= 100) {
.@q -= .@qd/100;
.@qd -= (.@qd/100)*100;
delitem .@i, countitem(.@i)-.@qd;
}
if (.@q != 0) {
delitem .@i, countitem(.@i);
}
}
freeloop(0);
mes "Successfully changed";

close;

 OH MY
default_ohmy.png
 ! Oh my, oh my, oh my! Dast, This NPC is gold! It works flawlessly! The NPC is perfected! Wow! I'm just.. I'm just.. I wanna jump around. Hahahahahaha 
default_laugh.png
 . Thank you so much! Wow, hahahahaha. Amazing.

 
Back
Top