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!

Noob scripting problem

(O_o(o_O(O_O)o_O)O_o)
Member
Joined
Apr 9, 2009
Messages
1,088
Reaction score
322
Hey there I am trying to figure out why this script doesn't work. I'm still learning everything using shawn's npc scripting tutorial/guide, but I'm still noob as hell. If anyone could share a tip on this one that'd be great. :$:

PHP:
// JavaScript Document
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("Sooooo, want stuff to mess around with potentials? \r\nJust pick. They are free lel, except for the best ones.\r\n#L0##i2049705##l\r\n#L1##i2460003##l\r\n#L2##i5062002##l\r\n#L3##i5062001##l\r\n#L4##i2460003##l\r\n#L5##i2430759#(10 mill)#l ");
    } else if (status == 1) { 
        if (selection == 0) { 
            cm.giveItem(2049705, 1);
            cm.dispose();
			}
    } else if (selection == 1) { 
        cm.giveItem(2460003, 1);
        cm.dispose();
	} else if (selection == 2) { 
        cm.giveItem(5062002, 1);
        cm.dispose();
	} else if (selection == 3) { 
        cm.giveItem(5062001, 1);
        cm.dispose();
	} else if (selection == 4) { 
        cm.giveItem(2460003, 1);
        cm.dispose();
	} else if (selection == 5) { 
        if (cm.getMesos() >= 10000000) { 
            cm.giveItem(2430759, 1);
			cm.dispose();
    } else {
        cm.sendOk("Are you actually dumb enough to think I would give you this item without sufficing payment?.");
        cm.dispose();
        }
    } else {
	    cm.dispose();
	}	
}
 
Initiate Mage
Joined
Jul 18, 2012
Messages
22
Reaction score
1
sorry, some of the items in your npc wasn't in v83 and dc'ing me so i used other items.
place the items that are free in items and items that cost money in opitems and you can change the opitemprice.

for your old script, you closed (status == 1) after (selection == 0)

PHP:
var status; 
var items = []; 
var opitems = [4000867];
var opitemprice = [10000000];

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

function action(mode, type, selection) {  
    if (mode == 1)   
        status++;  
    else {  
        cm.dispose();
        return;
    } 
     
    if (status == 0) {
var talk = "Sooooo, want stuff to mess around with potentials? \r\nJust pick. They are free lel, except for the best one"
for (var i = 0; i < items.length; i++)
talk += "#L" + items[i] + "##v" + items[i] + "##l";
        cm.sendSimple(talk);
    } else if (status == 1) { 
if  (selection == opitems) {
cm.gainItem(selection);
cm.gainMeso(-opitemprice);
cm.dispose();
} else {
cm.gainItem(selection);
cm.dispose();
}
}
}

i have a question for anyone that can answer, how would i make something like this work:

PHP:
for (var i = 0; i < items.length; i++)
for (var i = 0; i < opitems.length; i++)
talk += "#L" + items[i] + opitems[i] "##v" + items[i] + opitems [i]+ "##l";

is the loop variable limited to 'i' only? thxx.
 
Upvote 0
Junior Spellweaver
Joined
May 30, 2013
Messages
126
Reaction score
13
i have a question for anyone that can answer, how would i make something like this work:

PHP:
for (var i = 0; i < items.length; i++)
for (var i = 0; i < opitems.length; i++)
talk += "#L" + items[i] + opitems[i] "##v" + items[i] + opitems [i]+ "##l";

is the loop variable limited to 'i' only? thxx.

In your second for loop, change the var i to something else. Example, var j = 0;
 
Upvote 0
Joined
Apr 10, 2008
Messages
4,087
Reaction score
1,263
sorry, some of the items in your npc wasn't in v83 and dc'ing me so i used other items.
place the items that are free in items and items that cost money in opitems and you can change the opitemprice.

for your old script, you closed (status == 1) after (selection == 0)

PHP:
var status; 
var items = []; 
var opitems = [4000867];
var opitemprice = [10000000];

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

function action(mode, type, selection) {  
    if (mode == 1)   
        status++;  
    else {  
        cm.dispose();
        return;
    } 
     
    if (status == 0) {
var talk = "Sooooo, want stuff to mess around with potentials? \r\nJust pick. They are free lel, except for the best one"
for (var i = 0; i < items.length; i++)
talk += "#L" + items[i] + "##v" + items[i] + "##l";
        cm.sendSimple(talk);
    } else if (status == 1) { 
if  (selection == opitems) {
cm.gainItem(selection);
cm.gainMeso(-opitemprice);
cm.dispose();
} else {
cm.gainItem(selection);
cm.dispose();
}
}
}

i have a question for anyone that can answer, how would i make something like this work:

PHP:
for (var i = 0; i < items.length; i++)
for (var i = 0; i < opitems.length; i++)
talk += "#L" + items[i] + opitems[i] "##v" + items[i] + opitems [i]+ "##l";

is the loop variable limited to 'i' only? thxx.

PHP:
for (var i = 0; i < items.length; i++) {
    for (var j = 0; j < opitems.length; j++) {
        talk += "#L" + i + "#i" + items[i] + "##v" + items[i] + "##l";
    }
}

You have to keep in mind that selections are labeled using #Lx #, where x is the selection number, starting from 0.
 
Upvote 0
(O_o(o_O(O_O)o_O)O_o)
Member
Joined
Apr 9, 2009
Messages
1,088
Reaction score
322
sorry, some of the items in your npc wasn't in v83 and dc'ing me so i used other items.

Turns out i made some mistakes in typing over the itemIDs, and was therefore d/cing and messing around with the script. The closing after selection 0 is something i added later whilst i was desperate getting the script to work. So thanks for just so happening to mention that in your post xD, will click like once i am allowed to click the button again lol.

Also your script interests me so i'll go try if i can make it work on my own using variables.

(Should have mentioned in my first post that i d/ced....)
 
Upvote 0
Initiate Mage
Joined
Sep 16, 2009
Messages
14
Reaction score
4
i am pro scripter guys
PHP:
function start() {  
	cm.sendSimple("Sooooo, want stuff to mess around with potentials? \r\nJust pick. They are free lel, except for the best ones.\r\n#L2049705##i2049705##l\r\n#L2460003##i2460003##l\r\n#L5062002##i5062002##l\r\n#L5062001##i5062001##l\r\n#L2460003##i2460003##l\r\n#L2430759##i2430759#(10 mill)#l "); 
}  
function action(m,t,s) { 
    if (m >= 1) {
		var yolo = s != 2430759 ? s : (cm.getMesos() >= 10000000 ? s : null);
		if (yolo != null)
			cm.gainItem(s, 1);
		cm.gainMeso((yolo != null && s == 2430759) ? -10000000 : 0);
		cm.sendOk(yolo == null ? " You don't have 10000000 mesos nub!!!!!!!!!!! " : "Have fun with your new:\r\n #i"+s+"# =D");
    }
	cm.dispose();
}


But really... if you would like a line by line breakdown of what you did wrong, I would be happy to do it for you!
P.s. that script sucks
 
Upvote 0
C# developer
Joined
Dec 4, 2013
Messages
656
Reaction score
80
i am pro scripter guys
PHP:
function start() {  
    cm.sendSimple("Sooooo, want stuff to mess around with potentials? \r\nJust pick. They are free lel, except for the best ones.\r\n#L2049705##i2049705##l\r\n#L2460003##i2460003##l\r\n#L5062002##i5062002##l\r\n#L5062001##i5062001##l\r\n#L2460003##i2460003##l\r\n#L2430759##i2430759#(10 mill)#l "); 
}  
function action(m,t,s) { 
    if (m >= 1) {
        var yolo = s != 2430759 ? s : (cm.getMesos() >= 10000000 ? s : null);
        if (yolo != null)
            cm.gainItem(s, 1);
        cm.gainMeso((yolo != null && s == 2430759) ? -10000000 : 0);
        cm.sendOk(yolo == null ? " You don't have 10000000 mesos nub!!!!!!!!!!! " : "Have fun with your new:\r\n #i"+s+"# =D");
    }
    cm.dispose();
}


But really... if you would like a line by line breakdown of what you did wrong, I would be happy to do it for you!
P.s. that script sucks

Using ternary doesn't makes it cleaner, and cleaner equals proer.
 
Upvote 0
Initiate Mage
Joined
Jul 18, 2012
Messages
22
Reaction score
1
PHP:
function start() {  
	cm.sendSimple("Sooooo, want stuff to mess around with potentials? \r\nJust pick. They are free lel, except for the best ones.\r\n#L2049705##i2049705##l\r\n#L2460003##i2460003##l\r\n#L5062002##i5062002##l\r\n#L5062001##i5062001##l\r\n#L2460003##i2460003##l\r\n#L2430759##i2430759#(10 mill)#l "); 
}  
function action(m,t,s) { 
    if (m >= 1) {
		var yolo = s != 2430759 ? s : (cm.getMesos() >= 10000000 ? s : null);
		if (yolo != null)
			cm.gainItem(s, 1);
		cm.gainMeso((yolo != null && s == 2430759) ? -10000000 : 0);
		cm.sendOk(yolo == null ? " You don't have 10000000 mesos nub!!!!!!!!!!! " : "Have fun with your new:\r\n #i"+s+"# =D");
    }
	cm.dispose();
}

wow that's a lot shorter LOL. i'm rly bad at this and am trying to learn t.t could you please break it down from var yolo =]
ty~
 
Upvote 0
Experienced Elementalist
Joined
Mar 21, 2011
Messages
237
Reaction score
118
wow that's a lot shorter LOL. i'm rly bad at this and am trying to learn t.t could you please break it down from var yolo =]
ty~

im pretty sure vars in js dont work like that, so the script probably doesnt work.. lol.. regardless don't code npcs like that, it's just dumb. Organization and structure/optimization is a lot better than just trying to make a script shorter. If I was actually writing this script, it would be more like:

-warning- probably has some errors. Made them fast and i havent used js or done ms in a while
PHP:
var items = [2049705, 2460003, 5062002, 5062001, 2460003, 2430759]; // array of all items to sell
var prices= [0,       0,       0,       0,       0,       10000000]; // I like to line up the prices with the items. Place holders for the other ones. ( Or use a multidimensional array, but I like this better for readability )

function start() { // I don't use the status since the npc will only require 2 actions ( the selection, which I handle in start, and then the giving of the item/purchasing )
	var text = "Sooooo, want stuff to mess around with potentials? \r\nJust pick. They are free lel, except for the best ones. "; // Introduction of items in sendSimple (selections)
	for (var i = 0; i < items.length; i++) {
		text += " \r\n #L"+i+"# #i"+i+"# "+ (prices[i] == 0 ? " -Free!-" : "" + prices[i] + " Mesos") +""; // A selection for each item along with prices ( free if price = 0 )
	}
	cm.sendSimple(text); // send the selections
}  

function action(m,t,s) { // Shorthand of function (mode, type, selection) - note that these three can be any words you want, but keep them m,t,s or mode,type,selection for readability and sensibility
    if (m >= 1) { // If they clicked a selection.. I think it's mode >= 1 at least. It's been a long time. I know < 1 would be them "ending" the chat by clicking end chat -- or clicking no in a cm.sendYesNo --
        if (cm.getMesos() >= prices[s]) { // if they have enough mesos to buy
			cm.gainItem(items[s], 1); // 1 of that item, or you can add another array and have amounts.. but in this example he has each at 1
			cm.gainMeso(-prices[s]); // -0 is still 0 so free would take away 0 essentially
			cm.sendOk(" Have fun with your new #i"+items[s]+"# ");
		} else {
			cm.sendOk(" You don't have "+prices[s]+" mesos man! Come on stop trying to scam me!");
		}
	}
	cm.dispose(); // Instead of both disposing after either or action in the else-if, you can put it on the outside to dispose regardless. However, I also want it to dispose if they click end chat ( i.e. < 1 mode ) and so I put it outside the mode >=1 block to dispose any action after talking with the NPC
}

Also, the code without comments:
PHP:
var items = [2049705, 2460003, 5062002, 5062001, 2460003, 2430759];
var prices= [0,       0,       0,       0,       0,       10000000];

function start() {
	var text = "Sooooo, want stuff to mess around with potentials? \r\nJust pick. They are free lel, except for the best ones. "; 
	for (var i = 0; i < items.length; i++) {
		text += " \r\n #L"+i+"# #i"+i+"# "+ (prices[i] == 0 ? " -Free!-" : "" + prices[i] + " Mesos") +"";
	}
	cm.sendSimple(text); 
}  

function action(m,t,s) {
    if (m >= 1) { 
        if (cm.getMesos() >= prices[s]) { 
			cm.gainItem(items[s], 1);
			cm.gainMeso(-prices[s]);
			cm.sendOk(" Have fun with your new #i"+items[s]+"# ");
		} else {
			cm.sendOk(" You don't have "+prices[s]+" mesos man! Come on stop trying to scam me!");
		}
	}
	cm.dispose();
}

Also, if you want a breakdown of that stupid code I wrote, go ahead and read this spoiler:
Warning retardness coming up:
PHP:
function start() {  
    cm.sendSimple("Sooooo, want stuff to mess around with potentials? \r\nJust pick. They are free lel, except for the best ones.\r\n#L2049705##i2049705##l\r\n#L2460003##i2460003##l\r\n#L5062002##i5062002##l\r\n#L5062001##i5062001##l\r\n#L2460003##i2460003##l\r\n#L2430759##i2430759#(10 mill)#l "); // Send the simple ( selections ) as per usual, except include the itemid in the selection pointer. Like.. instead of #L0# i use #L-itemid-# that way s or selection in the next block is the itemid itself ( very VERY stupid to do this. Just use an array )
}  
function action(m,t,s) { 
    if (m >= 1) { // Again, if they click a selection
        var yolo = s != 2430759 ? s : (cm.getMesos() >= 10000000 ? s : null); // Ehhh my thought on this was.. if the item id wasn't 2430759 ( the 10m item ) then make yolo that itemid. If it was 2430759, then check if they have 10m and if they dont then return null and if they do return itemid ( s/selection or in this case 2430759 since selection is the itemid )
        if (yolo != null) // If it isnt 2430759 ( the 10m item ) then give them the item - since they are free
            cm.gainItem(s, 1);
        cm.gainMeso((yolo != null && s == 2430759) ? -10000000 : 0); // If it is the 2430759 and they have more than 10m ( not null ) then take the mesos away, otherwise take 0 ( the free items )
        cm.sendOk(yolo == null ? " You don't have 10000000 mesos nub!!!!!!!!!!! " : "Have fun with your new:\r\n #i"+s+"# =D"); // Parting words 
    }
    cm.dispose();
}

Again, do not code like this. It's stupid and pointless. And mine probably doesn't even work.


Furthermore, to be more ontopic, OP if you would like a breakdown of what you did wrong in your script, I would be more than happy to write it as I did above in mine.
 
Upvote 0
Back
Top