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!

Change song npc example

Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77
Hi, I would like to release a npc that I created to change the songs in game:




Please ignore the songs on the last lines, I was playing around, lol.

For the changeMusic method, you should use the changeMusic packet, it's available in most sources.

The initAr part was generated by exporting all the songs xml into one big XML and then converted ino the format above.. Took like 5 mins using notepad++ with built-in replace functions.

Cheers.
 
Last edited:
Joined
Apr 3, 2010
Messages
1,766
Reaction score
621
If you'd want to use this, sure, nice. Just a few things I noticed.
- Statusses are usually used to keep things chronological. In this script It's 0, then -1, then forced to 1. I'm not sure I understand.
- Why is another NPC suddenly used to deliver the last message?
- Why do you initialize the array thrice during the usage of this npc? (Every time action is called, you initialize it, while you can initialize it during the start method and use it later on)
 
Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77
If you'd want to use this, sure, nice. Just a few things I noticed.
- Statusses are usually used to keep things chronological. In this script It's 0, then -1, then forced to 1. I'm not sure I understand.
- Why is another NPC suddenly used to deliver the last message?
- Why do you initialize the array thrice during the usage of this npc? (Every time action is called, you initialize it, while you can initialize it during the start method and use it later on)
I will post a more updated version which is refactored.
 
Experienced Elementalist
Joined
Mar 12, 2015
Messages
238
Reaction score
43
1. Why not start in start (seems pretty obvious to me)
2. Like luxray said, why tell status is 0, then instantly change it to -1
3. Why not make the array a global variable?
4. Why not increase status when mode === 1 instead of force setting it
5. This is javascript, not java, use === and == accordingly to keep from shoothing youreslf in the foot.
6. Why save currentKey in a variable, its only used once, one line later.
7. Luxray mentioned that you initialize the array 3 times, but you also loop through all those items and place them in a variable which you only use once.
8. What the hell is cm.sendNextNPC(message, 3, 9209001); im not sure i wanna know...
9. What is the use of status 3 in your npc?

Well the NPC works... I guess? I didn't test it, but from the looks of it you can still improve a LOT.

I liked how the array is structured (besides the fact that its made multiple times)
 
Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77
1. Why not start in start (seems pretty obvious to me)
2. Like luxray said, why tell status is 0, then instantly change it to -1
3. Why not make the array a global variable?
4. Why not increase status when mode === 1 instead of force setting it
5. This is javascript, not java, use === and == accordingly to keep from shoothing youreslf in the foot.
6. Why save currentKey in a variable, its only used once, one line later.
7. Luxray mentioned that you initialize the array 3 times, but you also loop through all those items and place them in a variable which you only use once.
8. What the hell is cm.sendNextNPC(message, 3, 9209001); im not sure i wanna know...
9. What is the use of status 3 in your npc?

Well the NPC works... I guess? I didn't test it, but from the looks of it you can still improve a LOT.

I liked how the array is structured (besides the fact that its made multiple times)

OdinMS always did scripting wrong, you know? Anyways, I did some refactoring on it.
About the status, I prefer to have control over it for simple npcs like this.
The fact 5, the actually rule should always be: use always ===.
status = 3 is not used, will only dispose the npc.

I still prefer ES6 anyways.
 
Initiate Mage
Joined
Dec 22, 2015
Messages
9
Reaction score
0
That's.. an awfully ugly code. I hope you formatted it properly on your end.

For readability:
 
Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77
Your npc will never actually change the song, nor is it logical to go from status -1 to status 1.
Are you aware that the status is not special and that we have this statement on the beginning, which will send the menu option to the client?
if (status === -1) { cm.sendSimple(text); status = 1; return;}

As you can see the script is returned, but it's not disposed, so it will do the evaluation on you the next npc talk.

Anyways, I'm implementing the same away GMS does, I will post the implementation of this script in the new way, as soon as I implement the basic npc scripting api.

If you don't ever touched the leaked files from BMS, here is how the npc chat looks like there, which is the correct way:
x = self.askYesNo("Test");
if(x == 1)
foo()
else
foobar()

Lol.
 
Joined
Apr 3, 2010
Messages
1,766
Reaction score
621
Are you aware that the status is not special and that we have this statement on the beginning, which will send the menu option to the client?
if (status === -1) { cm.sendSimple(text); status = 1; return;}

As you can see the script is returned, but it's not disposed, so it will do the evaluation on you the next npc talk.

Anyways, I'm implementing the same away GMS does, I will post the implementation of this script in the new way, as soon as I implement the basic npc scripting api.

If you don't ever touched the leaked files from BMS, here is how the npc chat looks like there, which is the correct way:
x = self.askYesNo("Test");
if(x == 1)
foo()
else
foobar()

Lol.

I meant the continuity of the script. Going from -1 to 1 isn't logical and might confuse users who are new to NPC Scripting.
Also, I didn't mean that the NPC would never start, but that the NPC is disposed before ever reaching status 3.
 
Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77
I liked how the array is structured (besides the fact that its made multiple times)

It's not actually an array, but an javascript object with many array properties.



I meant the continuity of the script. Going from -1 to 1 isn't logical and might confuse users who are new to NPC Scripting.
Also, I didn't mean that the NPC would never start, but that the NPC is disposed before ever reaching status 3.
Yep, that script is missing an return statement. Didn't notice that, but it will play the song anyways, since the changeMusic method is inside the if branch that checks if status = 3.


Thats why OdinMS scripting is error prone and a much cleaner version that allow pausable is required x).
 
Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77
Just for sake of curiosity, here's my new version of this script that runs using the new scripting API that i'm writting:

 
Back
Top