Jump to content

  •  

deviruzy

Member Since 11 Feb 2014
Offline Last Active Jan 05 2017 06:01 PM
-----

Posts I've Made

In Topic: I'm trying to make a custom trade npc but it's not counting other ite...

10 December 2016 - 02:10 AM

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.


In Topic: I'm trying to make a custom trade npc but it's not counting other ite...

09 December 2016 - 11:45 AM

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.


In Topic: I'm trying to make a custom trade npc but it's not counting other ite...

09 December 2016 - 04:58 AM

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

 


In Topic: I'm trying to make a custom trade npc but it's not counting other ite...

09 December 2016 - 03:56 AM

    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.


In Topic: I'm trying to make a custom trade npc but it's not counting other ite...

08 December 2016 - 10:18 AM

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.