Jump to content
  • 0
deviruzy

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

Question

 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.
Edited by deviruzy

Share this post


Link to post
Share on other sites

12 answers to this question

Recommended Posts

  • 0

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

Edited by deviruzy

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites
  • 0


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;

Share this post


Link to post
Share on other sites
  • 0

 

    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 :lol: ! Thank you! Wow it's gorgoues  :lol: ! 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.

Edited by deviruzy

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites
  • 0

 

.@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 :lol: . Thank you Dastgir . :D  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 :lol: . 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 :lol: . 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;
 

 

Edited by deviruzy

Share this post


Link to post
Share on other sites
  • 0

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;

Share this post


Link to post
Share on other sites
  • 0

 

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 :o . 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 :lol:. I am grateful. I am psyched with the first script you built, without "break;". Thank you so much for your passionate help.

Share this post


Link to post
Share on other sites
  • 0

 

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 :o . 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 :lol:. I am grateful. I am psyched with the first script you built, without "break;". Thank you so much for your passionate help.

Great :P

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;

Share this post


Link to post
Share on other sites
  • 0

 

Great :P

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 :o ! 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  :lol: . Thank you so much! Wow, hahahahaha. Amazing.

Share this post


Link to post
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.   Restore formatting

  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.

Loading...

×
×
  • Create New...

Important Information

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