Nebulite Slot Adder(?) NPC

Results 1 to 14 of 14
  1. #1
    Apprentice Spyboy9932 is offline
    MemberRank
    Jul 2013 Join Date
    24Posts

    Nebulite Slot Adder(?) NPC

    Code:
    /*****
     * 
     *  Description : A NPC that adds a nebulite socket to an item for a fixed amount.
     * 
     *****/
    
    
    
    
    importPackage(java.lang);
    importPackage(Packages.client.inventory);
    importPackage(Packages.constants);
    
    
    
    
    var status = -1;
    var mesoCost = 500000; //adjustable
    var outtext = "";
    var eq;
    var slot = Array();
    
    
    
    
    function start(){
        action(1,0,0);
    }
    
    
    
    
    function action(mode, type, selection){
         (mode == 1 ? status++ : cm.dispose());
      if(status == 0){
            cm.sendSimple("Hello. I'll add nebulite slots onto one of your items for a fee of " + mesoCost + " mesos.");
        } else if (status == 1){
                inventory = new Array(cm.EquipList(cm.getPlayer().getClient()));
                inv = cm.getInventory(1);
                    var bbb = false;
                    outtext = "Which item would you like to add a nebulite slot to?\r\n\r\n#b";
                    for (var i = 0; i <= inv.getSlotLimit(); i++) {
                        slot.push(i);
                        var it = inv.getItem(i);
                        if (it == null || it.getSocket1() >= 0 && it.getSocket2() >= 0 && it.getSocket3() >= 0) {
                            continue;
                        }
                        itemid = it.getItemId();
                        bbb = true;
                        outtext += "#L" + i + "##v" + itemid + "##t" + itemid + "##l\r\n";
                    }
                    if (!bbb) {
                        cm.sendOk("It seems like you don't have any equips in your inventory.");
                        cm.dispose();
                    }
            cm.sendSimple(outtext);
        } else if (status == 2){
            eq = cm.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(selection);
            outtext = "Okay, I've added a nebulite slot to your item";
              if (cm.getPlayer().getMeso() < mesoCost) {
                    cm.sendOk("I'm sorry but you don't have #e" + mesoCost + " mesos.");
                    cm.dispose();
                }
              else if (eq.getSocket1() != 0) {
                     eq.setSocket1(0);
                 }
              else if (eq.getSocket1() >= 0 && eq.getSocket2() != 0) {
                     eq.setSocket2(0);
                 }
              else if (eq.getSocket2() >= 0) {
                     eq.setSocket3(0);
                         }
                         else {
                             cm.sendOk("Something wrong happened. You shouldn't be here, please report this to a staff member.");
                             cm.dispose();
                         }
                   cm.getPlayer().forceReAddItem(eq, MapleInventoryType.EQUIP);      
                   cm.gainMeso(-mesoCost);      
                   cm.sendOk(outtext);
                   cm.dispose();
        }
    }
    Nothing really too major, I'd just thought it'd be useful for those who want to make servers with 3-slots of nebulite. It's really easy to make such NPC, but still. If you can't be troubled to make such NPC, you won't have to be.

    Yes, I used part of some code from Skorch's Cubing NPC.

    This should work for all versions, so go wild.


    Helpful Quotes :
    ( Learn a few things here and there while reading them )

    Spoiler:
    Quote Originally Posted by chunkarama View Post
    Well, I shorten mine to the max because idk. For starters, I use ternary for status incrementing.

    Code:
    if(mode == 1){
            status++;
        } else {
            cm.dispose();
            return;
        }
    Code:
    (mode == 1 ? status++ : cm.dispose());
    You include status 0 as a sendSimple with an output. Considering you're not iterating here, you can directly send the output within sendSimple.

    You include the function start which loads action of mode 1 which loads status 0. Rather than doing this, you can immediately load status 0 within start because when clicking next or any other selection the npc's mode will automatically increment.

    Lastly, yeah you could shorten the nebulite slots part haha ;p

    Oh, and I thought I'd also include that cm.sendOk won't end your line here:
    Code:
     }
                         else {
                             cm.sendOk("Something wrong happened. You shouldn't be here, please report this to a staff member.");
                         }
    Make sure to include a cm.dispose() so that it won't continue to throw any NPE or AIOB errors if something wrong does happen. (because it doesn't stop, it continues and takes mesos/etc)
    Quote Originally Posted by chunkarama View Post
    Nah, you'd do this:

    Code:
    function start(){
          cm.sendSimple("Hello. I'll add nebulite slots onto one of your items for a fee of " + mesoCost + " mesos.");
    }
    
    
    function action(mode, type, selection){
        (mode == 1 ? status++ : cm.dispose());
        
         if (status == 0){
                inventory = new Array(cm.EquipList(cm.getPlayer().getClient()));
    However, might I point out, in Lithium (v111+ sources), they had changed the NPCScriptManager so that you can use just directly action without any start. In my v83 before it was changed, I couldn't juse use start or just use action, I had to use both. If you do use both, you can do it the way above. Otherwise, I'd personally just use action.

    Oh, and Ternary's. A Ternary operation (a ? b : c); is a one line if-else statement boolean. The difference of JavaScript Ternary and Java Ternary is that within JavaScript you may use void, while in Java it will return "Not a statement" and you will have to result to a one line if-statement.

    Here's an example that'll make sense for JavaScript:
    useVoid when true = Say the player has to be level 70 to see "Bye" in a void sendNext and if they aren't level 70 it will say"Hi" in a sendOk void
    useVoid when false = Will change the text around, this is what you'd use it for in Java with Strings

    Code:
    var characterLevelRequired = 70; // level req
    var characterLevel = 34; // current char level
    var useVoid = false; // By default we'll see a void ternary
    
    function start() {
        if (useVoid)
            (characterLevel >= characterLevelRequired ? cm.sendNext("Bye") : cm.sendOk("Hi));
        else
            cm.sendOk(characterLevel >= characterLevelRequired ? "Bye" : "Hi");
        cm.dispose();
    }



    Credits :
    @chunkarama for teaching me what a ternary is and helped make the script shorter.
    Last edited by Spyboy9932; 04-03-15 at 09:58 PM.


  2. #2
    Moderator Eric is offline
    ModeratorRank
    Jan 2010 Join Date
    DEV CityLocation
    3,188Posts

    Re: Nebulite Slot Adder(?) NPC

    Other than the fact the code could be shortened up, nice npc I guess. I would like to point out however that you don't need to place "return" at the end of status two, as after disposing the npc they can't continue any further anyways.

  3. #3
    Apprentice Spyboy9932 is offline
    MemberRank
    Jul 2013 Join Date
    24Posts

    Re: Nebulite Slot Adder(?) NPC

    Quote Originally Posted by chunkarama View Post
    Other than the fact the code could be shortened up
    Where exactly? Actually, I think I could shorten the part where it's checking for the Nebulite Slots, but I'll leave that to the person using the script to shorten.

    Quote Originally Posted by chunkarama View Post
    I would like to point out however that you don't need to place "return" at the end of status two, as after disposing the npc they can't continue any further anyways.
    Sorry, it's a habit of mine. Thank you, though.

  4. #4
    Moderator Eric is offline
    ModeratorRank
    Jan 2010 Join Date
    DEV CityLocation
    3,188Posts

    Re: Nebulite Slot Adder(?) NPC

    Quote Originally Posted by Spyboy9932 View Post
    Where exactly? Actually, I think I could shorten the part where it's checking for the Nebulite Slots, but I'll leave that to the person using the script to shorten.



    Sorry, it's a habit of mine. Thank you, though.
    Well, I shorten mine to the max because idk. For starters, I use ternary for status incrementing.

    Code:
    if(mode == 1){
            status++;
        } else {
            cm.dispose();
            return;
        }
    Code:
    (mode == 1 ? status++ : cm.dispose());
    You include status 0 as a sendSimple with an output. Considering you're not iterating here, you can directly send the output within sendSimple.

    You include the function start which loads action of mode 1 which loads status 0. Rather than doing this, you can immediately load status 0 within start because when clicking next or any other selection the npc's mode will automatically increment.

    Lastly, yeah you could shorten the nebulite slots part haha ;p

    Oh, and I thought I'd also include that cm.sendOk won't end your line here:
    Code:
     }
                         else {
                             cm.sendOk("Something wrong happened. You shouldn't be here, please report this to a staff member.");
                         }
    Make sure to include a cm.dispose() so that it won't continue to throw any NPE or AIOB errors if something wrong does happen. (because it doesn't stop, it continues and takes mesos/etc)

    Other than that, everything looks nice. I like how you choose to use variables for your things and properly use importPackage, but I didn't see where use of Packages.constants was (maybe I didn't look hard enough lool).

  5. #5
    Apprentice Spyboy9932 is offline
    MemberRank
    Jul 2013 Join Date
    24Posts

    Re: Nebulite Slot Adder(?) NPC

    Quote Originally Posted by chunkarama View Post
    Well, I shorten mine to the max because idk. For starters, I use ternary for status incrementing.
    Code:
    (mode == 1 ? status++ : cm.dispose());
    I never really understood the how to use ":" or "?".

    Quote Originally Posted by chunkarama View Post
    You include status 0 as a sendSimple with an output. Considering you're not iterating here, you can directly send the output within sendSimple.
    Eh, the variable was there so I decided to use it. I guess it'd be better to just send everything as a string.

    Quote Originally Posted by chunkarama View Post
    You include the function start which loads action of mode 1 which loads status 0. Rather than doing this, you can immediately load status 0 within start because when clicking next or any other selection the npc's mode will automatically increment.
    So, I remove the whole function start?

    Quote Originally Posted by chunkarama View Post
    Oh, and I thought I'd also include that cm.sendOk won't end your line here:
    Code:
     }
                         else {
                             cm.sendOk("Something wrong happened. You shouldn't be here, please report this to a staff member.");
                         }
    Make sure to include a cm.dispose() so that it won't continue to throw any NPE or AIOB errors if something wrong does happen. (because it doesn't stop, it continues and takes mesos/etc)
    Such silly mistakes.

  6. #6
    Moderator Eric is offline
    ModeratorRank
    Jan 2010 Join Date
    DEV CityLocation
    3,188Posts

    Re: Nebulite Slot Adder(?) NPC

    Quote Originally Posted by Spyboy9932 View Post
    So, I remove the whole function start?
    Nah, you'd do this:

    Code:
    function start(){
          cm.sendSimple("Hello. I'll add nebulite slots onto one of your items for a fee of " + mesoCost + " mesos.");
    }
    
    
    function action(mode, type, selection){
        (mode == 1 ? status++ : cm.dispose());
        
         if (status == 0){
                inventory = new Array(cm.EquipList(cm.getPlayer().getClient()));
    However, might I point out, in Lithium (v111+ sources), they had changed the NPCScriptManager so that you can use just directly action without any start. In my v83 before it was changed, I couldn't juse use start or just use action, I had to use both. If you do use both, you can do it the way above. Otherwise, I'd personally just use action.

    Oh, and Ternary's. A Ternary operation (a ? b : c); is a one line if-else statement boolean. The difference of JavaScript Ternary and Java Ternary is that within JavaScript you may use void, while in Java it will return "Not a statement" and you will have to result to a one line if-statement.

    Here's an example that'll make sense for JavaScript:
    useVoid when true = Say the player has to be level 70 to see "Bye" in a void sendNext and if they aren't level 70 it will say"Hi" in a sendOk void
    useVoid when false = Will change the text around, this is what you'd use it for in Java with Strings

    Code:
    var characterLevelRequired = 70; // level req
    var characterLevel = 34; // current char level
    var useVoid = false; // By default we'll see a void ternary
    
    function start() {
        if (useVoid)
            (characterLevel >= characterLevelRequired ? cm.sendNext("Bye") : cm.sendOk("Hi));
        else
            cm.sendOk(characterLevel >= characterLevelRequired ? "Bye" : "Hi");
        cm.dispose();
    }
    Last edited by Eric; 24-02-15 at 09:23 AM.

  7. #7
    Apprentice Spyboy9932 is offline
    MemberRank
    Jul 2013 Join Date
    24Posts

    Re: Nebulite Slot Adder(?) NPC

    Quote Originally Posted by chunkarama View Post
    Oh, and Ternary's. A Ternary operation (a ? b : c); is a one line if-else statement boolean. The difference of JavaScript Ternary and Java Ternary is that within JavaScript you may use void, while in Java it will return "Not a statement" and you will have to result to a one line if-statement.

    Here's an example that'll make sense for JavaScript:
    useVoid when true = Say the player has to be level 70 to see "Bye" in a void sendNext and if they aren't level 70 it will say"Hi" in a sendOk void
    useVoid when false = Will change the text around, this is what you'd use it for in Java with Strings

    Code:
    var characterLevelRequired = 70; // level req
    var characterLevel = 34; // current char level
    var useVoid = false; // By default we'll see a void ternary
    
    function start() {
        if (useVoid)
            (characterLevel >= characterLevelRequired ? cm.sendNext("Bye") : cm.sendOk("Hi));
        else
            cm.sendOk(characterLevel >= characterLevelRequired ? "Bye" : "Hi");
        cm.dispose();
    }
    God bless for this explanation. Never knew/understood what a ternary is. Thank you.



    EDIT :
    Updated OP with "Helpful Quotes".
    Updated Script with help from @chunkarama
    Last edited by Spyboy9932; 25-02-15 at 03:04 AM.

  8. #8
    Member Eltri is offline
    MemberRank
    Dec 2014 Join Date
    S'pore- t('.'t)Location
    64Posts

    Re: Nebulite Slot Adder(?) NPC

    Error using default script on a v117 source - "invalid return" at line 49.

    After removing the return , another invalid return on line 75.
    After removing both returns , there's an extra "}" at the last line which I then removes.
    After removing the "}" the NPC totally doesn't open when clicked , no bat errors too.

    Any help ? :)

  9. #9
    Apprentice Spyboy9932 is offline
    MemberRank
    Jul 2013 Join Date
    24Posts

    Re: Nebulite Slot Adder(?) NPC

    Quote Originally Posted by Eltri View Post
    Error using default script on a v117 source - "invalid return" at line 49.

    After removing the return , another invalid return on line 75.
    After removing both returns , there's an extra "}" at the last line which I then removes.
    After removing the "}" the NPC totally doesn't open when clicked , no bat errors too.

    Any help ? :)
    Thank you for the report! The script has since been fixed and should be working. If not, do post another comment.

  10. #10
    Member Eltri is offline
    MemberRank
    Dec 2014 Join Date
    S'pore- t('.'t)Location
    64Posts

    Re: Nebulite Slot Adder(?) NPC

    Thanks for fixing the script , it's working now.

    Another problem/question , I've added 3 empty sockets into the item & I'm only able to place 1 Nebulite into the first slot. After the first slot it'll have a message saying that the item already has a nebulite inserted.

    I know the NPC is only supposed to add slots only but for the ways of adding neb stats into the 2nd / 3rd slot is it made to be like this or are we supposed to re-script an NPC that gives 2nd / 3rd slot neb stats?

  11. #11
    Apprentice Spyboy9932 is offline
    MemberRank
    Jul 2013 Join Date
    24Posts

    Re: Nebulite Slot Adder(?) NPC

    Quote Originally Posted by Eltri View Post
    Thanks for fixing the script , it's working now.

    Another problem/question , I've added 3 empty sockets into the item & I'm only able to place 1 Nebulite into the first slot. After the first slot it'll have a message saying that the item already has a nebulite inserted.

    I know the NPC is only supposed to add slots only but for the ways of adding neb stats into the 2nd / 3rd slot is it made to be like this or are we supposed to re-script an NPC that gives 2nd / 3rd slot neb stats?
    Thanks for another report.

    Hmph, I never actually 'tried' placing a nebulite into the 2nd/3rd slots via the original method. I don't think it's possible to do it through that method, but that's just me. You'll most likely have to script up a NPC that forcefully places the nebulite in it's slot.

  12. #12
    Account Upgraded | Title Enabled! Veda is offline
    MemberRank
    Mar 2011 Join Date
    808Posts

    Re: Nebulite Slot Adder(?) NPC

    Quote Originally Posted by chunkarama View Post
    Well, I shorten mine to the max because idk. For starters, I use ternary for status incrementing.
    .
    Ternary is a really bad programming practice in regards to maintenance. If someone later on needs to debug the logic or use breakpoints on the statements, they would have to either eyeball it or recreate an if-else structure to debug.

  13. #13
    Member Eltri is offline
    MemberRank
    Dec 2014 Join Date
    S'pore- t('.'t)Location
    64Posts

    Re: Nebulite Slot Adder(?) NPC

    Anyone has a NPC method that could give nebulite slot 1 , 2 & 3 stats ?

    I tried
    PHP Code:
    private static ArrayList<Integernebulite1 = new ArrayList<>();public int socketslolol() {    if (nebulite1.isEmpty()) {        for (int i MapleItemInformationProvider.getInstance().getAllSocketInfo1().keySet()) {            if (!=30640502) {                nebulite1.add(i);            }        }    } else {        return nebulite1.get(Randomizer.nextInt(nebulite1.size()));    }        return 0;} 
    I got this from somewhere in rageZone but when I use
    PHP Code:
    statsSel.setSocket1(cm.socketslolol()); 
    the item only has [D] as the stats , not a real stats.
    Last edited by Eltri; 08-03-15 at 12:33 PM.

  14. #14
    Moderator Eric is offline
    ModeratorRank
    Jan 2010 Join Date
    DEV CityLocation
    3,188Posts

    Re: Nebulite Slot Adder(?) NPC

    Quote Originally Posted by Veda View Post
    Ternary is a really bad programming practice in regards to maintenance. If someone later on needs to debug the logic or use breakpoints on the statements, they would have to either eyeball it or recreate an if-else structure to debug.
    Well, that is kinda true, however in this case when just making status increment in a npc it shouldn't be much of a problem lol



Advertisement