Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[NPC scripting] Using a case inside of a case..

Initiate Mage
Joined
Dec 13, 2009
Messages
75
Reaction score
2
Hello everyone!

I am currently learning to script NPC's, and i am facing a problem.

The problem is,

i am making an starting npc, and the player is able to choose the job they would like to become.

Now when doing this, i am using sendSimple, and after that i use a case to give the selections an action.

But the thing is, when they select "Explorer" , they still need to select what kind of explorer they want to be.

Now, this would be a case inside of a case..

Could someone explain me how to do this?

here is the code:

Code:
function start() {
    cm.sendSimple("Hello, Welcome to TroepieMS! My task here at TroepieMS is to help you start your journey. Please start by using the job you would like to be.\r\n\ 
#L1#Explorer (Warrior/Magician/Bowman/Thief/Pirate/Dual Blade/Cannoneer)\r\n\
#L2#Cygnus Knights (Dawn Warrior/Blaze Wizard/Wind Archer/Night Walker/Thunder Breaker/Mihile)\r\n\
#L3#Resistance (Battle Mage/Wild Hunter/Mechanic/Demon Slayer)\r\n\
#L4#Heroes (Aran/Evan/Mercedes/Phantom)\r\n\ "); // Choose your job
}

function action(mode, type, selection) {
    switch (selection) {
   case 1:
   		cm.sendSimple("Good choice! What kind of explorer would you like to become?\r\n\
#L1#Warrior\r\n\
#L2#Magician\r\n\
#L3#Bowman\r\n\
#L4#Thief\r\n\
#L5#Pirate\r\n\
#L6#Dual Blade\r\n\
#L7#Cannoneer\r\n\ "); //Choose your job (more specific)
   		switch (selection) {
   			case 100:
   				cm.sendNext("Allright!"); 
   		}
        break;
   case 2:
    	cm.sendSimple("Good Choice! What kind of Cygnus knight would you like to become?\r\n\
#L1#Dawn Warrior\r\n\
#L2#Blaze Wizard\r\n\
#L3#Wind Archer\r\n\
#L4#Night Walker\r\n\
#L5#Thunder Breaker\r\n\
#L6#Mihile\r\n\ "); //Choose your job (more specific)
        break;
   case 3:
    	cm.sendSimple("Good Choice! What kind of Resistance would you like to become?\r\n\
#L1#Batt Hunter\r\n\
#L3#Mechanic\r\n\
#L4#Demonle Mage\r\n\
#L2#Wild Slayer\r\n\ "); //Choose your job (more specific)
		break;
	case 4:
	    cm.sendSimple("Good Choice! What kind of Hero would you like to become?\r\n\
#L1#Aran\r\n\
#L2#Evan\r\n\
#L3#Mercedes\r\n\
#L4#Phantom\r\n\ "); //Choose your job (more specific)
	    break;
	}
if (mode == 0){
    cm.dispose();
    }



	
}

Thanks in advance guys!
 
Junior Spellweaver
Joined
Oct 12, 2012
Messages
137
Reaction score
6
Simply putting in the name of the job doesn't mean they can become it >.>. All you did was put names into the script, you need to actually add in the IDS. Also, your "case inside a case" is wrong, your not even making them options, its just gonna be a text, not a button. I would advise you to look up java tutorials, theres a good 1 by Shawn. Plus, learn how to use arrays also, big helper. I'm not trying to sad harsh or anything just telling you straight up.

Edit: If your to lazy to script 1, there's alot of job advancer scripts in the release section.
 
Upvote 0
Initiate Mage
Joined
Dec 13, 2009
Messages
75
Reaction score
2
Simply putting in the name of the job doesn't mean they can become it >.>. All you did was put names into the script, you need to actually add in the IDS. Also, your "case inside a case" is wrong, your not even making them options, its just gonna be a text, not a button. I would advise you to look up java tutorials, theres a good 1 by Shawn. Plus, learn how to use arrays also, big helper. I'm not trying to sad harsh or anything just telling you straight up.

Edit: If your to lazy to script 1, there's alot of job advancer scripts in the release section.

I know i havent put in the ID's yet... i just want to know how i can code the part where u choose 1 of the selections, and then u get another selection...
 
Upvote 0
Initiate Mage
Joined
Dec 13, 2009
Messages
75
Reaction score
2
This still doesn't solve my problem.

i know how to make an npc with a selection, but the youtube video doesn't explain me how to make a selection in a selection....

Code:
function start() {
    cm.sendSimple("Hello, Welcome to TroepieMS! My task here at TroepieMS is to help you start your journey. Please start by using the job you would like to be.\r\n\ 
#L1#Explorer (Warrior/Magician/Bowman/Thief/Pirate/Dual Blade/Cannoneer)\r\n\
#L2#Cygnus Knights (Dawn Warrior/Blaze Wizard/Wind Archer/Night Walker/Thunder Breaker/Mihile)\r\n\
#L3#Resistance (Battle Mage/Wild Hunter/Mechanic/Demon Slayer)\r\n\
#L4#Heroes (Aran/Evan/Mercedes/Phantom)\r\n\ "); // Choose your job
}

function action(mode, type, selection) {
    switch (selection) {
   case 1:
   		cm.sendSimple("Good choice! What kind of explorer would you like to become?\r\n\
#L1#Warrior\r\n\
#L2#Magician\r\n\
#L3#Bowman\r\n\
#L4#Thief\r\n\
#L5#Pirate\r\n\
#L6#Dual Blade\r\n\
#L7#Cannoneer\r\n\ "); //Choose your job (more specific)
   		switch (selection) {
   			case 100:
   				cm.sendNext("Allright!"); 
   		}
        break;

If you look at the part after Selection 7, which is cannoneer, i try making another switch, to be able to get another selection screen.

this doesn't seem to work.

if anyone could care explaining this, please do.

thanks.
 
Upvote 0
Experienced Elementalist
Joined
Mar 21, 2011
Messages
237
Reaction score
118
Why do it like that? Why not keep it simple:

PHP:
public start() {
     cm.sendSimple("job1, job2, job3, job4, etc ");
}

public action(m,t,s) {
if (m>0) {
if (s == 1) {
cm.sendSimple(" job1.sub, etc ")
} else if ( s== 2) {
cm.sendSimple(" job2.sub.etc ");
}
}

And then, for the second set of selections, make the selections the JobID. I.E. cm.sendSimple(" #L"+idofpirate+"# etc ");

Better yet, make an array, loop through and get ids and names of jobs for each selection according to what you chose.

That is, unless I am not understanding you. :(
 
Upvote 0
Junior Spellweaver
Joined
Oct 12, 2012
Messages
137
Reaction score
6
Why do it like that? Why not keep it simple:

PHP:
public start() {
     cm.sendSimple("job1, job2, job3, job4, etc ");
}

public action(m,t,s) {
if (m>0) {
if (s == 1) {
cm.sendSimple(" job1.sub, etc ")
} else if ( s== 2) {
cm.sendSimple(" job2.sub.etc ");
}
}

And then, for the second set of selections, make the selections the JobID. I.E. cm.sendSimple(" #L"+idofpirate+"# etc ");

Better yet, make an array, loop through and get ids and names of jobs for each selection according to what you chose.

That is, unless I am not understanding you. :(

Lol, i already explained to him about arrays. I also explained how that his script is not correctly written and that the his sections are written incorrectly "hinted youtube". You just putted them as a text but gave it no options. Maybe it just me explaining it wrong, i apologize.

Anyways check this script out Aristocat, could help you out

Code:
*
 * Job Advancer
 * Creator: Aristocat
 */


var job = [
[[100, "Warrior"], [200, "Magician"], [300, "Bowman"], [400, "Thief"], [500, "Pirate"]],
[[1100, "Dawn Warrior"], [1200, "Blaze Wizard"], [1300, "Wind Archer"], [1400, "Night Walker"], [1500, "Thunder Breaker"]],
[[3200, "Battle Mage"], [3300, "Wild Hunter"], [3500, "Mechanic"]],
[[110, "Fighter"], [120, "Page"], [130, "Spearman"]],
[[210, "Wizard (F/P)"], [220, "Wizard (I/L)"], [230, "Cleric"]],
[[310, "Hunter"], [320, "Crossbow Man"]],
[[410, "Assassin"], [420, "Bandit"]],
[[510, "Brawler"], [520, "Gunslinger"]]];
var status = 0;
var select;

function start() {
    status = -1;
    action(1, 0, 0);
} 

function action(mode, type, selection) {
    if (mode == 1)
        status++;
    else if (mode == -1)
        status--;
    else {
        cm.dispose();
        return;
    }
    if (status == 0) {
        if (cm.getPlayer().getLevel() >= 10 && (cm.getPlayer().getJob() % 1000 == 0 || cm.getPlayer().getJob() == 501 || cm.getPlayer().getJob() == 507 || cm.getPlayer().getJob() == 3001 || cm.getPlayer().getJob() >= 2001 && cm.getPlayer().getJob() <= 2003) || cm.getPlayer().getLevel() >= 30 && (cm.getPlayer().getJob() % 1000 > 0 && cm.getPlayer().getJob() % 100 == 0 || cm.getPlayer().getJob() == 508) || cm.getPlayer().getLevel() >= 70 && cm.getPlayer().getJob() % 10 == 0 && cm.getPlayer().getJob() % 100 != 0 || cm.getPlayer().getLevel() >= 120 && cm.getPlayer().getJob() % 10 == 1 || cm.getPlayer().getLevel() >= 55 && cm.getPlayer().getJob() == 431)
            cm.sendYesNo("Would you like to job advance?");
        else {
            cm.sendOk("You may not advance at the current state.");
            cm.dispose();
        }
    } else if (status == 1) {
        if (cm.getPlayer().getSubcategory() == 1 && cm.getPlayer().getJob() == 0) { //Dual Blade
            cm.getPlayer().changeJob(400);
            cm.dispose();
            return;
        }
        if (cm.getPlayer().getSubcategory() == 1 && cm.getPlayer().getJob() == 400) { //Dual Blade
            cm.getPlayer().changeJob(430);
            cm.dispose();
            return;
        }
        if (cm.getPlayer().getSubcategory() == 2 && cm.getPlayer().getJob() == 0) { //Cannoneer
            cm.getPlayer().changeJob(501);
            cm.dispose();
            return;
        }
        switch (cm.getPlayer().getJob()) {
            //Jobs with selections
            case 0: // Beginner
                jobSelection(0);
                break;
            case 1000: // Noblesse
                jobSelection(1);
                break;
            //Note: Heroes doesn't get job selection, the same goes about Nova.
            case 3000: // Citizen
                jobSelection(2);
                break;
            case 100: // Warrior
                jobSelection(3);
                break;
            case 200: // Magician
                jobSelection(4);
                break;
            case 300: // Bowman
                jobSelection(5);
                break;
            case 400: // Thief
                jobSelection(6);
                break;
            case 500: // Pirate
                jobSelection(7);
                break;
            //Special Jobs
            case 501: // Pirate(Cannoneer)
                cm.getPlayer().changeJob(530);
                cm.dispose();
                break;
            case 507: // Jett
                cm.getPlayer().changeJob(508);
                cm.dispose();
                break;
            case 508: // Pirate(Jett)
                cm.getPlayer().changeJob(570);
                cm.dispose();
                break;
            case 2000: // Legend(Aran)
                cm.getPlayer().changeJob(2100);
                cm.dispose();
                break;
            case 2001: // Farmer(Evan)
                cm.getPlayer().changeJob(2200);
                cm.dispose();
                break;
            case 2002: // Mercedes
                cm.getPlayer().changeJob(2300);
                cm.dispose();
                break;
            case 2003: // Phantom Jr.
                cm.getPlayer().changeJob(2400);
                cm.dispose();
                break;
            case 3001: // Demon Slayer
                cm.getPlayer().changeJob(3100);
                cm.dispose();
                break;
            //Nova should be added here. KMS already got it, wait for GMS to get it.
            //My guess is that Nova are 4xxx because Mihile is 5xxx.
            //Guesses: Luminous - 2004, 24xx Kaiser - 4000, 41xx Angelic Burster - 4001, 45xx
            case 5000: // Nameless Warden (Mihile)
                cm.getPlayer().changeJob(5100);
                cm.dispose();
                break;
            // Dual Blader
            case 430: // Blade Reqruit
            case 431: // Blade Acolyte
            case 432: // Blade Specialist
            case 433: // Blade Lord
                cm.getPlayer().changeJob(cm.getPlayer().getJob() + 1);
                cm.dispose();
                break;
            //1st Job
            case 1100: // Dawn Warrior
            case 1200: // Blaze Wizard
            case 1300: // Wind Archer
            case 1400: // Night Walker
            case 1500: // Thunder Breaker
            case 2100: // Aran
            case 2300: // Mercedes
            case 2400: // Phantom
            case 3100: // Demon Slayer
            case 3200: // Battle Mage
            case 3300: // Wild Hunter
            case 3500: // Mechanic
            case 5100: // Mihile
                cm.getPlayer().changeJob(cm.getPlayer().getJob() + 10);
                cm.dispose();
                break;
            //2nd Job
            case 110: // Fighter
            case 120: // Page
            case 130: // Spearman
            case 210: // Wizard(F/P)
            case 220: // Wizard(I/L)
            case 230: // Cleric
            case 310: // Hunter
            case 320: // Crossbow man
            case 410: // Assassin
            case 420: // Bandit
            case 510: // Brawler
            case 520: // Gunslinger
            case 530: // Cannoneer
            case 570: // Jett
            case 1110: // Dawn Warrior
            case 1210: // Blaze Wizard
            case 1310: // Wind Archer
            case 1410: // Night Walker
            case 1510: // Thunder Breaker
            case 2110: // Aran
            case 2310: // Mercedes
            case 2410: // Phantom
            case 3110: // Demon Slayer
            case 3210: // Battle Mage
            case 3310: // Wild Hunter
            case 3510: // Mechanic
            case 5110: // Mihile
            //3rd Job
            case 111: // Crusader
            case 121: // White Knight
            case 131: // Dragon Knight
            case 211: // Mage(F/P)
            case 221: // Mage(I/L)
            case 231: // Priest
            case 311: // Ranger
            case 321: // Sniper
            case 411: // Hermit
            case 421: // Chief Bandit
            case 511: // Marauder
            case 521: // Outlaw
            case 531: // Cannon Trooper
            case 571: // Jett
            case 1111: // Dawn Warrior
            case 1211: // Blaze Wizard
            case 1311: // Wind Archer
            case 1411: // Night Walker
            case 1511: // Thunder Breaker
            case 2111: // Aran
            case 2311: // Mercedes
            case 2411: // Phantom
            case 3111: // Demon Slayer
            case 3211: // Battle Mage
            case 3311: // Wild Hunter
            case 3511: // Mechanic
            case 5111: // Mihile
                cm.getPlayer().changeJob(cm.getPlayer().getJob() + 1);
                cm.dispose();
                break;
            default:
                cm.sendOk("An error occured, or a new job found.\r\nPlease report to the Admins.\r\nYour job id: " + cm.getPlayer().getJob() + "");
                cm.dispose();
        }
    } else if (status == 2) {
        select = selection;
        cm.sendYesNo("Are you sure you want to Job Advance?");
    } else if (status == 3) {
        cm.getPlayer().changeJob(select);
        cm.dispose();
    }
}

function jobSelection(index) {
    var choose = "Please, select your job:"
    for (var i = 0; i < job[index].length; i++)
        choose += "\r\n#L" + job[index][i][0] + "#" + job[index][i][1] + "#l";
    cm.sendSimple(choose);
}
 
Upvote 0
Back
Top