My attempt at Arrays.

Results 1 to 7 of 7
  1. #1
    Proficient Member ItsKevin is offline
    MemberRank
    Aug 2009 Join Date
    Austin, TexasLocation
    171Posts

    My attempt at Arrays.

    Ehh First Release? I was just playing with arrays :)
    Well anyways this NPC sell pets o-O

    Code:
    /* 
        Author: ItsKevin
        Pet Manager      
    */
    
    var pets = Array(5000000, 5000001, 5000002, 5000003, 5000004, 5000005, 5000006, 5000007, 5000008, 5000011, 5000012, 5000014, 5000020, 5000022, 5000025, 5000029, 5000036, 5000039, 5000044, 5000048);
    var names = Array("Brown Kitty","Brown Puppy","Pink Bunny","Mini Kargo","Black Kitty","White Bunny"," Husky"," Black Pig"," Panda"," Monkey"," White Tiger"," Rudolph"," Mini Yeti"," Turkey"," Golden Pig"," Dragon"," Jr. Reaper"," Porcupine"," Orange Tiger"," Robo");
    
    function start() {
        var sendstr = "Would you like to adopt a pet? \r\n\r\n#rPets (1 Charm Each)#k \r\n#b";
        for (var i = 0;i < pets.length;i++) {
            sendstr += "#L"+i+"# "+names[i]+" "+"#v"+pets[i]+"# ";
            sendstr += "#b\r\n";
        }
        cm.sendSimple (sendstr);
    }
    
    function action(mode, type, selection) {
        if (mode == -1)
            cm.dispose();
        else {
            if (cm.haveItem(4032031)) {
                  cm.gainItem(4032031, -1);
                  cm.gainItem(pets[selection]);
                  cm.sendOk("Here is your "+names[selection]+". Have a nice day!");
                  cm.dispose();
            } else {
                cm.sendOk("These Pets are nothing to joke about...");
                cm.dispose();
            }
            cm.dispose();
        }
    }
    Extra Info:
    This is my first time using Arrays so its not that good o-O
    Any Feedback would be nice on how I can improve myself, Thanks!
    Last edited by ItsKevin; 19-12-09 at 02:42 AM.


  2. #2
    Infraction Banned =-=Thomas=-= is offline
    MemberRank
    Sep 2009 Join Date
    282Posts

    Re: My attempt at Arrays.

    Nice job Man keep it up Ur Friend From msn ~thomas

  3. #3
    Alpha Member Anujan is offline
    MemberRank
    May 2008 Join Date
    Ontario, CanadaLocation
    1,633Posts

    Re: My attempt at Arrays.

    There's an NPC function that shows the items name from the itemid forget what it was. But it'd mean you wouldn't need the name array (:

  4. #4
    Member C_plus_plus is offline
    MemberRank
    Nov 2009 Join Date
    79Posts

    Re: My attempt at Arrays.

    Quote Originally Posted by Anujan View Post
    There's an NPC function that shows the items name from the itemid forget what it was. But it'd mean you wouldn't need the name array (:
    PHP Code:
    #tItem Id# 
    This makes it show it ID =]

  5. #5
    Proficient Member ItsKevin is offline
    MemberRank
    Aug 2009 Join Date
    Austin, TexasLocation
    171Posts

    Re: My attempt at Arrays.

    I'm trying to see if i can shorten the script more o-O

  6. #6
    Account Upgraded | Title Enabled! X-Tasis is offline
    MemberRank
    Feb 2009 Join Date
    1,192Posts

    Re: My attempt at Arrays.

    PHP Code:
    pets = [50000005000001500000250000035000004500000550000065000007500000850000115000012500001450000205000022500002550000295000036500003950000445000048];

    function 
    start() {
        var 
    sendstr "Would you like to adopt a pet? \r\n\r\n#rPets (1 Charm Each)\r\n#b";
        for (var 
    0;pets.lengthi++)
            
    sendstr += "#L" "##t" pets[i] + "##k. #i" pets[i] + "##b";
        
    cm.sendSimple (sendstr);
    }

    function 
    action(modetypeselection) {
        if (
    mode == 1){
            if (
    cm.haveItem(4032031)) {
                
    cm.gainItem(4032031, -1);
                
    cm.gainItem(pets[selection], 1);
                
    cm.sendOk("Here is your #b#t" pets[selection] + "##k. Have a nice day!");
            } else
                
    cm.sendOk("These Pets are nothing to joke about...");
        }
        
    cm.dispose();


  7. #7
    Valued Member Red Tape is offline
    MemberRank
    Oct 2009 Join Date
    141Posts

    Re: My attempt at Arrays.

    this is good for a first time :)



Advertisement