Jump to content
  • 0

NPC with sub category


Question

Posted

I've requested a NPC to have a sub category for one category.

Meaning

Sword

-10 sub category

Dagger

-10 sub category

and so on..

Thanks to Z3R0 he have made me that NPC but there is some minor error.

prontera,155,181,5 script Sample 757,{
// I Was just talking with Brian about this last night actually...

// Create the Category Array
setarray .@main_menu$[0],"Sword","Spear","Dagger";
// Item ID's (The Number 0 is the Index of the Category "Sword")
setarray .@equip_0[0],13439,13435,13436,4,5,6,7,8,9;
// Item ID's (The Number 1 is the Index of the Category "Bow")
setarray .@equip_1[0],1443,1439,3,4,5,6,7,8,9;
// Item ID's (The Number 2 is the Index of the Category "Dagger")
setarray .@equip_2[0],1,2,3,4,5,6,7,8,9;
// Create Item Hunt Group Arrays (By Category)
// For adding Zeny, use Item ID 0, and in Amount, use Amount of Zeny
setarray .@items_0[0],501,502,503;
setarray .@items_amount_0[0],1000,2,3;
setarray .@items_1[0],501,502,503;
setarray .@items_amount_1[0],1,2,3;
setarray .@items_2[0],501,502,503;
setarray .@items_amount_2[0],1,2,3;

// Display Categories to Player and Store Answer as Index (-1 Stores as Array Index)
set .@category, select(.@main_menu$) - 1;
// Now Build the Menu Based on This Selection
for (set .@a, 0; .@a < getarraysize(getd(".@equip_" + .@category)); set .@a, .@a + 1) {
set .@item_name$, getitemname(getd(".@equip_" + .@category + "[" + .@a + "]"));
set .@sub_menu$, .@sub_menu$ + (.@sub_menu$ == "" ? .@item_name$ : ":" + .@item_name$);
}
// Now Offer the New Menu to the Player as Index (-1 Stores as Array Index)
set .@item_choice, select(.@sub_menu$) - 1;
// Determine If Player Has Required Items
for (set .@a, 0; .@a < getarraysize(getd(".@items_" + .@category)); set .@a, .@a + 1) {
set .@item_id, getd(".@items_" + .@category + "[" + .@a + "]");
set .@item_requires, getd(".@items_amount_" + .@category + "[" + .@a + "]");
if (.@item_id) {
set .@player_has, countitem(.@item_id);
set .@item_name$, getitemname(.@item_id);
if (.@player_has < .@item_requires) {
set .@errors$[getarraysize(.@errors$)], "You Still Need " + (.@item_requires - .@player_has) + " " + .@item_name$ + ((.@item_requires - .@player_has) > 1 ? "'s." : ".");
}
} else {
// Is Zeny
if (Zeny < .@item_requires) {
set .@errors$[getarraysize(.@errors$)], "You Still Need " + (.@item_requires - Zeny) + " z.";
}
}
}
// Determine Errors to Display
if (getarraysize(.@errors$)) {
for (set .@a, 0; .@a < getarraysize(.@errors$); set .@a, .@a + 1) {
mes .@errors$[.@a];
}
close;
}
// Now For Debugging Purposes
mes "Item ID Chosen: " + getd(".@equip_" + .@category + "[" + .@item_choice + "]");
mes "Item Name: " + getitemname(getd(".@equip_" + .@category + "[" + .@item_choice + "]"));
// Take Items Away
for (set .@a, 0; .@a < getarraysize(getd(".@items_" + .@category)); set .@a, .@a + 1) {
delitem getd(".@items_" + .@category + "[" + .@a + "]"), getd(".@items_amount_" + .@category + "[" + .@a + "]");
}
// Give Item
getitem getd(".@equip_" + .@category + "[" + .@item_choice + "]"), 1;
close;
}

this is the script. the error is when I click at that NPC. Only have one category which is sword. I didn't see bow or dagger. Can someone help me?

4 answers to this question

Recommended Posts

Posted

Reading...

lol I forgot to build the menu.... for the first one...


prontera,155,181,5 script Sample 757,{
// I Was just talking with Brian about this last night actually...

// Create the Category Array
setarray .@main_menu$[0],"Sword","Spear","Dagger";
// Item ID's (The Number 0 is the Index of the Category "Sword")
setarray .@equip_0[0],13439,13435,13436,4,5,6,7,8,9;
// Item ID's (The Number 1 is the Index of the Category "Bow")
setarray .@equip_1[0],1443,1439,3,4,5,6,7,8,9;
// Item ID's (The Number 2 is the Index of the Category "Dagger")
setarray .@equip_2[0],1,2,3,4,5,6,7,8,9;
// Create Item Hunt Group Arrays (By Category)
// For adding Zeny, use Item ID 0, and in Amount, use Amount of Zeny
setarray .@items_0[0],501,502,503;
setarray .@items_amount_0[0],1000,2,3;
setarray .@items_1[0],501,502,503;
setarray .@items_amount_1[0],1,2,3;
setarray .@items_2[0],501,502,503;
setarray .@items_amount_2[0],1,2,3;

// Build Primary Section (Oops Forgot This)
for (set .@a, 0; .@a < getarraysize(.@main_menu$); set .@a, .@a + 1) {
 set .@primary_menu$, .@primary_menu$ + (.@primary_menu$ == "" ? "" : ":") + .@main_menu$[.@a];
}

// Display Categories to Player and Store Answer as Index (-1 Stores as Array Index)
set .@category, select(.@primary_menu$) - 1;

// Now Build the Menu Based on This Selection
for (set .@a, 0; .@a < getarraysize(getd(".@equip_" + .@category)); set .@a, .@a + 1) {
 set .@sub_menu$, .@sub_menu$ + (.@sub_menu$ == "" ? "" : ":") + getitemname(getd(".@equip_" + .@category + "[" + .@a + "]"));
}
// Now Offer the New Menu to the Player as Index (-1 Stores as Array Index)
set .@item_choice, select(.@sub_menu$) - 1;
// Determine If Player Has Required Items
for (set .@a, 0; .@a < getarraysize(getd(".@items_" + .@category)); set .@a, .@a + 1) {
set .@item_id, getd(".@items_" + .@category + "[" + .@a + "]");
set .@item_requires, getd(".@items_amount_" + .@category + "[" + .@a + "]");
if (.@item_id) {
set .@player_has, countitem(.@item_id);
set .@item_name$, getitemname(.@item_id);
if (.@player_has < .@item_requires) {
set .@errors$[getarraysize(.@errors$)], "You Still Need " + (.@item_requires - .@player_has) + " " + .@item_name$ + ((.@item_requires - .@player_has) > 1 ? "'s." : ".");
}
} else {
// Is Zeny
if (Zeny < .@item_requires) {
set .@errors$[getarraysize(.@errors$)], "You Still Need " + (.@item_requires - Zeny) + " z.";
}
}
}
// Determine Errors to Display
if (getarraysize(.@errors$)) {
for (set .@a, 0; .@a < getarraysize(.@errors$); set .@a, .@a + 1) {
mes .@errors$[.@a];
}
close;
}
// Now For Debugging Purposes
mes "Item ID Chosen: " + getd(".@equip_" + .@category + "[" + .@item_choice + "]");
mes "Item Name: " + getitemname(getd(".@equip_" + .@category + "[" + .@item_choice + "]"));
// Take Items Away
for (set .@a, 0; .@a < getarraysize(getd(".@items_" + .@category)); set .@a, .@a + 1) {
delitem getd(".@items_" + .@category + "[" + .@a + "]"), getd(".@items_amount_" + .@category + "[" + .@a + "]");
}
// Give Item
getitem getd(".@equip_" + .@category + "[" + .@item_choice + "]"), 1;
close;
}

Also, be sure to remove any ID's that are invalid from your array...

for example:

setarray .@equip_0[0],13439,13435,13436,4,5,6,7,8,9;

the Item ID's 4,5,6,7,8,9 are not valid item ID's, so remove them so you are left with...

setarray .@equip_0[0],13439,13435,13436;

Posted (edited)

and one more thing zero. you said the 0 at the first is zeny right? but when I talk to the NPC with all the requirement. Got error. at putty it said debug something. then my RO got hang. had to force close it.

Its not a big deal though. I just change it to item instead of zeny. (as you can see I change it to 501 : Redpotion )Just want to tell you one more problem :P

Edited by pojiejapan
Posted

Taking a look at it

My apologies... Forgot getarraysize() does not like 0 parameters... modified...

use Item ID == 1 for Zeny and Amount = Zeny Amount :P in place of Item ID it will now work

// By Z3R0
prontera,155,181,5 script Sample 757,{

// Create the Category Array
setarray .@main_menu$[0],"Sword","Spear","Dagger";

// Item ID's (The Number 0 is the Index of the Category "Sword")
setarray .@equip_0[0],13439,13435,13436,4,5,6,7,8,9;

// Item ID's (The Number 1 is the Index of the Category "Bow")
setarray .@equip_1[0],1443,1439,3,4,5,6,7,8,9;

// Item ID's (The Number 2 is the Index of the Category "Dagger")
setarray .@equip_2[0],1,2,3,4,5,6,7,8,9;

// Create Item Hunt Group Arrays (By Category)
// For adding Zeny, use Item ID 1, and in Amount, use Amount of Zeny
setarray .@items_0[0],501,502,503;
setarray .@items_amount_0[0],1000,2,3;
setarray .@items_1[0],501,502,503;
setarray .@items_amount_1[0],1,2,3;
setarray .@items_2[0],501,502,503;
setarray .@items_amount_2[0],1,2,3;

// Build Primary Section (Oops Forgot This)
for (set .@a, 0; .@a < getarraysize(.@main_menu$); set .@a, .@a + 1) {
set .@primary_menu$, .@primary_menu$ + (.@primary_menu$ == "" ? "" : ":") + .@main_menu$[.@a];
}

// Display Categories to Player and Store Answer as Index (-1 Stores as Array Index)
set .@category, select(.@primary_menu$) - 1;

// Now Build the Menu Based on This Selection
for (set .@a, 0; .@a < getarraysize(getd(".@equip_" + .@category)); set .@a, .@a + 1) {
set .@sub_menu$, .@sub_menu$ + (.@sub_menu$ == "" ? "" : ":") + getitemname(getd(".@equip_" + .@category + "[" + .@a + "]"));
}

// Now Offer the New Menu to the Player as Index (-1 Stores as Array Index)
set .@item_choice, select(.@sub_menu$) - 1;

// Determine If Player Has Required Items
for (set .@a, 0; .@a < getarraysize(getd(".@items_" + .@category)); set .@a, .@a + 1) {
set .@item_id, getd(".@items_" + .@category + "[" + .@a + "]");
set .@item_requires, getd(".@items_amount_" + .@category + "[" + .@a + "]");
if (.@item_id != 1) {
set .@player_has, countitem(.@item_id);
set .@item_name$, getitemname(.@item_id);
if (.@player_has < .@item_requires) {
set .@errors$[getarraysize(.@errors$)], "You Still Need " + (.@item_requires - .@player_has) + " " + .@item_name$ + ((.@item_requires - .@player_has) > 1 ? "'s." : ".");
}
} else {
// Is Zeny
if (Zeny < .@item_requires) {
set .@errors$[getarraysize(.@errors$)], "You Still Need " + (.@item_requires - Zeny) + " z.";
}
}
}

// Determine Errors to Display
if (getarraysize(.@errors$)) {
for (set .@a, 0; .@a < getarraysize(.@errors$); set .@a, .@a + 1) {
mes .@errors$[.@a];
}
close;
}

// Now For Debugging Purposes
mes "Item ID Chosen: " + getd(".@equip_" + .@category + "[" + .@item_choice + "]");
mes "Item Name: " + getitemname(getd(".@equip_" + .@category + "[" + .@item_choice + "]"));

// Take Items Away
for (set .@a, 0; .@a < getarraysize(getd(".@items_" + .@category)); set .@a, .@a + 1) {
delitem getd(".@items_" + .@category + "[" + .@a + "]"), getd(".@items_amount_" + .@category + "[" + .@a + "]");
}

// Give Item
getitem getd(".@equip_" + .@category + "[" + .@item_choice + "]"), 1;
close;
}

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...