Change song npc example

Results 1 to 12 of 12
  1. #1
    Account Upgraded | Title Enabled! br1337 is offline
    True MemberRank
    Apr 2015 Join Date
    206Posts

    Change song npc example


    RaGEZONE Recommends

    RaGEZONE Recommends

    Hi, I would like to release a npc that I created to change the songs in game:

    https://gist.github.com/anonymous/59...ile-npc-js-L88


    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 by br1337; 24-03-17 at 05:38 PM.


  2. #2
    while(true) spam(); kevintjuh93 is offline
    ModeratorRank
    Jun 2008 Join Date
    The NetherlandsLocation
    4,118Posts

    Re: Change song npc example

    Edited your post with formatted code... pls
    Quote Originally Posted by mavin0107 View Post
    can anyone tell me how to make pokemon system in lithium work cuz i try to go to a map have pokemon but there are no pokemon in that map
    Quote Originally Posted by MentaL View Post
    ps... if you dont like butterflys then ur a homo.

  3. #3
    That one pokemon thing Luxray is offline
    Alpha MaleRank
    Apr 2010 Join Date
    2,081Posts

    Re: Change song npc example

    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)


  4. #4
    Account Upgraded | Title Enabled! br1337 is offline
    True MemberRank
    Apr 2015 Join Date
    206Posts

    Re: Change song npc example

    Quote Originally Posted by Luxray View Post
    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.

  5. #5
    Account Upgraded | Title Enabled! Las Systos is offline
    True MemberRank
    Mar 2015 Join Date
    NetherlandsLocation
    207Posts

    Re: Change song npc example

    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)
    What's mine is yours,
    for a price.

  6. #6
    Account Upgraded | Title Enabled! br1337 is offline
    True MemberRank
    Apr 2015 Join Date
    206Posts

    Re: Change song npc example

    Quote Originally Posted by Las Systos View Post
    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.

  7. #7
    Newbie rrtyui is offline
    MemberRank
    Dec 2015 Join Date
    4Posts

    Re: Change song npc example

    That's.. an awfully ugly code. I hope you formatted it properly on your end.

    For readability: https://gist.github.com/anonymous/59...1e39fc324e5562

  8. #8
    That one pokemon thing Luxray is offline
    Alpha MaleRank
    Apr 2010 Join Date
    2,081Posts

    Re: Change song npc example

    Quote Originally Posted by rrtyui View Post
    That's.. an awfully ugly code. I hope you formatted it properly on your end.

    For readability: https://gist.github.com/anonymous/59...1e39fc324e5562
    Your npc will never actually change the song, nor is it logical to go from status -1 to status 1.


  9. #9
    Account Upgraded | Title Enabled! br1337 is offline
    True MemberRank
    Apr 2015 Join Date
    206Posts

    Re: Change song npc example

    Quote Originally Posted by Luxray View Post
    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.

  10. #10
    That one pokemon thing Luxray is offline
    Alpha MaleRank
    Apr 2010 Join Date
    2,081Posts

    Re: Change song npc example

    Quote Originally Posted by br1337 View Post
    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.


  11. #11
    Account Upgraded | Title Enabled! br1337 is offline
    True MemberRank
    Apr 2015 Join Date
    206Posts

    Re: Change song npc example

    Quote Originally Posted by Las Systos View Post
    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.

    - - - Updated - - -

    Quote Originally Posted by Luxray View Post
    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).

  12. #12
    Account Upgraded | Title Enabled! br1337 is offline
    True MemberRank
    Apr 2015 Join Date
    206Posts

    Re: Change song npc example

    Just for sake of curiosity, here's my new version of this script that runs using the new scripting API that i'm writting:

    https://gist.github.com/br1337/ae4c9...1d734e663322ea




Advertisement