- Joined
- Jun 16, 2010
- Messages
- 23
- Reaction score
- 1
I'm relatively new to NPC scripting. What I'm trying to do here is make an NPC that will check if you have a certain number of Miracle Cubes. If you have the required number, the NPC will take away that number of Miracle Cubes and give you a certain number of mesos based on the amount of Cubes you gave. But right now each selection says "You do not have 1 #i5062000#." except for the first selection which will say ""You just traded 1 #i5062000# for 2,000,000 mesos!" regardless of whether or not you actually have cubes. It doesn't give any mesos either.
Here's the code:
Never mind, I tweaked the brackets a little and now it works. The code above is a working script now, if anyone wants to use it.
Here's the code:
PHP:
var status;
function start() {
status = -1;
action (1, 0, 0);
}
function action (mode, type, selection) {
if (mode == 1) {
status++;
}else{
status--;
}
if (status == 0) {
cm.sendSimple("Yo! You can trade #i5062000# with me in exchage for mesos!\r\n#L0#Trade 1 #i5062000# for 2,000,000 mesos.\r\n#L1#Trade 5 #i5062000# for 10,000,000 mesos.\r\n#L2#Trade 10 #i5062000# for 20,000,000 mesos.\r\n#L3#Trade 50 #i5062000# for 100,000,000 mesos.");
}
else if (status == 1) {
if (selection == 0) {
if (cm.haveItem(5062000, 1)){
cm.gainItem(5062000, -1);
cm.gainMeso(2000000);
cm.sendOk("You just traded 1 #i5062000# for 2,000,000 mesos!");}
else{
cm.sendOk("You do not have 1 #i5062000#.");}
cm.dispose();
}
if (selection == 1) {
if (cm.haveItem(5062000, 5)){
cm.gainItem(5062000, -5);
cm.gainMeso(10000000);
cm.sendOk("You just traded 5 #i5062000# for 10,000,000 mesos!");}
else{
cm.sendOk("You do not have 5 #i5062000#.");}
cm.dispose();
}
if (selection == 2) {
if (cm.haveItem(5062000, 10)){
cm.gainItem(5062000, -10);
cm.gainMeso(20000000);
cm.sendOk("You just traded 10 #i5062000# for 20,000,000 mesos!");}
else{
cm.sendOk("You do not have 10 #i5062000#.");}
cm.dispose();
}
if (selection == 3) {
if (cm.haveItem(5062000, 50)){
cm.gainItem(5062000, -50);
cm.gainMeso(100000000);
cm.sendOk("You just traded 50 #i5062000# for 100,000,000 mesos!");}
else{
cm.sendOk("You do not have 50 #i5062000#.");}
cm.dispose();
}
}else{
cm.dispose();
}
}
Never mind, I tweaked the brackets a little and now it works. The code above is a working script now, if anyone wants to use it.
Last edited:

