Hey everyone. I wrote this shop script to merge all my weapon shops into one NPC and have that NPC make a dynamic menu that changes the color and order of the menu options based on your class.
However, due to my knowledge of arrays and NPC menu structure... the script became large for something so simple. So I wanted to post it here and see if anyone knew a way of simplifying this:
/* Dynamic Weapon Shop NPC
// Scripted by Vach
// ====================================
This script checks the players class and then opens a list of shops
with the higher shops on the list being applicable to their class.
Players can still access the other shops, to buy weapons for friends
or just look around.
// ======= LOG ========================
11/03/2012 - Script Creation
12/03/2012 - Fixed some errors and made the interface cleaner
*/
prt_in.gat,172,140,3 script Weapons Shop 951,{
// Reference material
//set .@ShopTag[1],"Daggers";
//set .@ShopTag[2],"Swords";
//set .@ShopTag[3],"Spears";
//set .@ShopTag[4],"Axes";
//set .@ShopTag[5],"Maces";
//set .@ShopTag[6],"Wands";
//set .@ShopTag[7],"Bows";
//set .@ShopTag[8],"Knuckles";
//set .@ShopTag[9],"Instruments";
//set .@ShopTag[10],"Whips";
//set .@ShopTag[11],"Books";
//set .@ShopTag[12],"Guns";
//set .@ShopTag[13],"Huuma and Kunai";
//set .@ShopTag[14],"Katars";
//setarray .@ShopTag$[1],"Daggers","Swords","Spears","Axes","Maces","Wands","Bows","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
//setarray .@Shops$[1],"( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
//set .@MaxShops,14; // Total Array size (shops)
// ^0000FF - Blue
// ^FF0000 - Red
switch (BaseClass) {
case Job_Novice: setarray .@ShopTag$[1],"Daggers","Swords","Spears","Axes","Maces","Wands","Bows","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Daggers^000000 )","( ^FF0000Swords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Swordman: setarray .@ShopTag$[1],"Swords","Spears","Daggers","Axes","Maces","Wands","Bows","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Swords^000000 )","( ^FF0000Spears^000000 )","( ^0000FFDaggers^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Mage: setarray .@ShopTag$[1],"Wands","Daggers","Swords","Spears","Axes","Maces","Bows","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Wands^000000 )","( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Archer: setarray .@ShopTag$[1],"Bows","Daggers","Swords","Spears","Axes","Maces","Wands","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Bows^000000 )","( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Acolyte: setarray .@ShopTag$[1],"Maces","Wands","Daggers","Swords","Spears","Axes","Bows","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Maces^000000 )","( ^FF0000Wands^000000 )","( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Merchant: setarray .@ShopTag$[1],"Axes","Daggers","Maces","Swords","Spears","Wands","Bows","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Axes^000000 )","( ^FF0000Daggers^000000 )","( ^FF0000Maces^000000 )","( ^FF0000Swords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFWands^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Thief: setarray .@ShopTag$[1],"Daggers","Bows","Swords","Spears","Axes","Maces","Wands","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Daggers^000000 )","( ^FF0000Bows^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
default: // Set default to avoid errors
setarray .@ShopTag$[1],"Daggers","Swords","Spears","Axes","Maces","Wands","Bows","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break; }
// Override original shops if any of these are "True"
switch (BaseJob) {
case Job_Priest: setarray .@ShopTag$[1],"Maces","Wands","Books","Knuckles","Daggers","Swords","Spears","Axes","Bows","Instruments","Whips","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Maces^000000 )","( ^FF0000Wands^000000 )","( ^FF0000Books^000000 )","( ^FF0000Knuckles^000000 )","( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFBows^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Assassin: setarray .@ShopTag$[1],"Daggers","Katars","Swords","Spears","Axes","Maces","Wands","Bows","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai";
setarray .@Shops$[1],"( ^FF0000Daggers^000000 )","( ^FF0000Katars^000000 )","( ^FF0000Swords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )";
break;
case Job_Monk: setarray .@ShopTag$[1],"Maces","Knuckles","Daggers","Swords","Spears","Axes","Wands","Bows","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Maces^000000 )","( ^FF0000Knuckles^000000 )","( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFWands^000000 )","( ^0000FFBows^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Sage: setarray .@ShopTag$[1],"Books","Wands","Daggers","Swords","Spears","Axes","Maces","Bows","Knuckles","Instruments","Whips","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Wands^000000 )","( ^FF0000Books^000000 )","( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Rogue: setarray .@ShopTag$[1],"Daggers","Swords","Bows","Spears","Axes","Maces","Wands","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Daggers^000000 )","( ^FF0000Swords^000000 )","( ^FF0000Bows^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Bard: setarray .@ShopTag$[1],"Bows","Instruments","Daggers","Swords","Spears","Axes","Maces","Wands","Knuckles","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Bows^000000 )","( ^FF0000Instruments^000000 )","( ^FF0000Daggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Dancer: setarray .@ShopTag$[1],"Bows","Whips","Daggers","Swords","Spears","Axes","Maces","Wands","Knuckles","Instruments","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Bows^000000 )","( ^FF0000Whips^000000 )","( ^FF0000Daggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Gunslinger: setarray .@ShopTag$[1],"Guns","Daggers","Swords","Spears","Axes","Maces","Wands","Bows","Knuckles","Instruments","Whips","Books","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^FF0000Guns^000000 )","( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Ninja: setarray .@ShopTag$[1],"Huuma and Kunai","Daggers","Swords","Spears","Axes","Maces","Wands","Bows","Knuckles","Instruments","Whips","Books","Guns","Katars";
setarray .@Shops$[1],"( ^FF0000Huuma and Kunai^000000 )","( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFKatars^000000 )";
break;
case Job_Taekwon: // Taekwon is defaulted just in case.
setarray .@ShopTag$[1],"Daggers","Swords","Spears","Axes","Maces","Wands","Bows","Knuckles","Instruments","Whips","Books","Guns","Huuma and Kunai","Katars";
setarray .@Shops$[1],"( ^0000FFDaggers^000000 )","( ^0000FFSwords^000000 )","( ^0000FFSpears^000000 )","( ^0000FFAxes^000000 )","( ^0000FFMaces^000000 )","( ^0000FFWands^000000 )","( ^0000FFBows^000000 )","( ^0000FFKnuckles^000000 )","( ^0000FFInstruments^000000 )","( ^0000FFWhips^000000 )","( ^0000FFBooks^000000 )","( ^0000FFGuns^000000 )","( ^0000FFHuuma and Kunai^000000 )","( ^0000FFKatars^000000 )";
break;
default: // Do nothing
break; }
mes "[ ^0000FFWeapon Shop^000000 ]";
mes "Please choose your desired shop.";
set .@menu,select(.@Shops$[1],.@Shops$[2],.@Shops$[3],.@Shops$[4],.@Shops$[5],.@Shops$[6],.@Shops$[7],.@Shops$[8],.@Shops$[9],.@Shops$[10],.@Shops$[11],.@Shops$[12],.@Shops$[13],.@Shops$[14]);
callshop .@ShopTag$[.@menu],1;
close;
}
- shop Daggers -1,1203:-1,1201:-1,1202:-1,1206:-1,1204:-1,1205:-1,1209:-1,1207:-1,1208:-1,1212:-1,1210:-1,1211:-1,1215:-1,1213:-1,1214:-1,1218:-1,1216:-1,1217:-1,1221:-1,1219:-1,1220:-1,1222:-1,1226:-1,1245:-1,1246:-1,1247:-1,1248:-1,1249:-1,13000:-1,13003:-1,13004:-1
- shop Swords -1,1103:-1,1101:-1,1102:-1,1106:-1,1104:-1,1105:-1,1109:-1,1107:-1,1108:-1,1112:-1,1110:-1,1111:-1,1113:-1,1114:-1,1121:-1,1119:-1,1120:-1,1122:-1,1125:-1,1123:-1,1128:-1,1126:-1,1127:-1,1129:-1,1149:-1,1146:-1,1147:-1,1118:-1,1116:-1,1117:-1,1153:-1,1151:-1,1152:-1,1156:-1,1154:-1,1155:-1,1159:-1,1157:-1,1158:-1,1160:-1,1162:-1,1163:-1,31172:-1,1172:-1
- shop Spears -1,1403:-1,1401:-1,1402:-1,1406:-1,1404:-1,1405:-1,1409:-1,1407:-1,1408:-1,1411:-1,1453:-1,1451:-1,1452:-1,1456:-1,1454:-1,1455:-1,1459:-1,1457:-1,1458:-1,1462:-1,1460:-1,1461:-1,1465:-1,1463:-1,1464:-1
- shop Axes -1,1303:-1,1301:-1,1302:-1,1353:-1,1351:-1,1352:-1,1356:-1,1354:-1,1355:-1,1359:-1,1357:-1,1358:-1,1362:-1,1360:-1,1361:-1
- shop Maces -1,1503:-1,1501:-1,1502:-1,1506:-1,1504:-1,1505:-1,1509:-1,1507:-1,1508:-1,1512:-1,1510:-1,1511:-1,1519:-1,1520:-1,1521:-1,1513:-1,1514:-1,1515:-1,1516:-1,1517:-1,1518:-1,1522:-1,1532:-1
- shop Wands -1,1603:-1,1601:-1,1602:-1,1606:-1,1604:-1,1605:-1,1609:-1,1607:-1,1608:-1,1612:-1,1610:-1,1611:-1,1617:-1,1618:-1,1619:-1,1620:-1
- shop Bows -1,1703:-1,1701:-1,1702:-1,1706:-1,1704:-1,1705:-1,1709:-1,1707:-1,1708:-1,1712:-1,1710:-1,1711:-1,1713:-1,1715:-1,1714:-1,1716:-1,1726:-1,1721:-1
- shop Knuckles -1,1801:-1,1802:-1,1803:-1,1804:-1,1805:-1,1806:-1,1807:-1,1808:-1,1809:-1,1810:-1,1811:-1,1812:-1
- shop Instruments -1,1901:-1,1902:-1,1903:-1,1904:-1,1905:-1,1906:-1,1907:-1,1908:-1,1909:-1,1910:-1,1921:-1,1911:-1,1912:-1,1913:-1
- shop Whips -1,1950:-1,1951:-1,1952:-1,1953:-1,1954:-1,1955:-1,1956:-1,1957:-1,1958:-1,1959:-1,1960:-1,1961:-1,1963:-1
- shop Books -1,1550:-1,1551:-1,1552:-1,1553:-1,1568:-1,1554:-1,1569:-1,1570:-1,1556:-1,1571:-1,1557:-1,1578:-1
- shop Guns -1,13102:-1,13103:-1,13150:-1,13151:-1,13152:-1,13163:-1,13164:-1,13165:-1,13166:-1,13154:-1,13155:-1,13168:-1,13169:-1
- shop Huuma and Kunai -1,13010:-1,13011:-1,13007:-1,13008:-1,13012:-1,13013:-1,13006:-1,13300:-1,13301:-1,13302:-1,13303:-1,13311:-1,13313:-1,13314:-1,13315:-1,13312:-1
- shop Katars -1,1250:-1,1251:-1,1252:-1,1253:-1,1254:-1,1255:-1
One alternative would be make the label name be the shop name that is called... but then I lose the colors and the formatting unless I make some uniquely clever string scrubber to filter out the color and everything.
Essentially, just not having to call an enormous switch in the beginning would be good. =P
Edited by AnnieRuru use [codebox] if the script > 10 lines
Question
Vach
Hey everyone. I wrote this shop script to merge all my weapon shops into one NPC and have that NPC make a dynamic menu that changes the color and order of the menu options based on your class.
However, due to my knowledge of arrays and NPC menu structure... the script became large for something so simple. So I wanted to post it here and see if anyone knew a way of simplifying this:
One alternative would be make the label name be the shop name that is called... but then I lose the colors and the formatting unless I make some uniquely clever string scrubber to filter out the color and everything.
Essentially, just not having to call an enormous switch in the beginning would be good. =P
Edited by AnnieRuruuse [codebox] if the script > 10 lines
Link to comment
Share on other sites
21 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.