JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 72 of 171 View original ↗
  1. Hello! I'm trying to obtain the Item ID of the last item used by the player, then call that in a conditional branch. Since all 40+ items utilize the same Common Event, it seems silly to create 40 separate ones. I feel like I'm missing something here...can someone help out?

    I saw this thread with a good response from Gamefall Team, but I don't believe it shows how to obtain the ID. Anyway, thanks again!
  2. GoodSelf said:
    Hello! I'm trying to obtain the Item ID of the last item used by the player, then call that in a conditional branch. Since all 40+ items utilize the same Common Event, it seems silly to create 40 separate ones. I feel like I'm missing something here...can someone help out?

    I saw this thread with a good response from Gamefall Team, but I don't believe it shows how to obtain the ID. Anyway, thanks again!

    I looked around a bit, and originally thought $gameParty.lastItem().itemId() would work, but that's the last item you selected, for cursor memory purposes, not the last item actually used, so if two different actors used different items, they'd both read as being the second one selected.

    A better alternative seems to be storing the item ID in a variable from within the item execution itself- this is much easier if you're using something like Yanfly's Skill Core, which gives you access to lunatic mode tags that can run whatever javascript you want at specific points, but you could also stick it in a damage formula. The code for that would be:
    JavaScript:
    $gameVariables.setValue(VariableNumberGoesHere, item.id);
    If you're using a damage formula already, just stick that code at the beginning, before the actual damage formula.

    [EDIT] Fixed "set" to "setValue" in the code.
  3. @Doktor_Q So, I typed this in, and tried to get it to work, but it's just not happening. Would you be able to PM me? I would very much appreciate the help!

    Edit:
    @Doktor_Q Yeah, that fixed it! This is awesome, thanks so much!
  4. I am trying to make Steal & Snatch (YEP) http://www.yanfly.moe/wiki/Steal_&_Snatch_(YEP).
    I want to create a customize stealing in which an actor gets the amount of Money from stealing is equal to the user. Level x user.Speed

    <After Steal Effect>
    gameParty.gainGold() += user.level * user.agi;
    </After Steal Effect>
    Is this correct? Thank you for helping me.
  5. @GoodSelf Re-checked the code, I typed "set" when it should have been "setValue". Edited my previous post, try that instead.

    @Kupotepo No, you have the syntax a bit wrong. A correct version would be $gameParty.gainGold(user.level * user.agi);

    Further explanation if you're curious:
    Anything with () after it is a function, that is, you're telling the code to perform an action, and the values inside the () are the parameters- in this case, $gameParty.gainGold is a function that adds money, and the parameter is how much money to add. Some functions, as part of doing their thing, will fetch information for you- such as a list of all living enemies, the tile position of a character on the map, etc. That's when you can do someValue = someFunction(), but you can't do someFunction() = someValue because someFunction() is a function, not a variable, and is not a place to store values. Sometimes, you might see a function like someObject.setSomeProperty(someValue)- in that case, the function's job is to store the parameter (someValue) in a different position, but it also can do other work at the same time, like making sure sprites get refreshed, keeping track of the previous value, etc.
  6. @Doktor_Q So, this works great, but I've seem to come across something else. The variable doesn't update when the scope is set to None. I don't want to have to select the character to use the item. I even downloaded the yanfly plugin and used the <Before Eval> tags and such, but it's still not working with a scope of None. Any ideas on this?
  7. GoodSelf said:
    @Doktor_Q So, this works great, but I've seem to come across something else. The variable doesn't update when the scope is set to None. I don't want to have to select the character to use the item. I even downloaded the yanfly plugin and used the <Before Eval> tags and such, but it's still not working with a scope of None. Any ideas on this?

    If the scope is None, then it won't run a damage formula, or any of the damage calculation related tags. However, <Custom Execution> in yanfly's skill core runs immediately after paying the skill's cost, so it should work even if you don't have a target.
  8. Doktor_Q said:
    $gameParty.gainGold(user.level * user.agi);
    Sorry. my memory is foggy. Is that for the note tag or script call?
    I would like note tag in skill one.

    How to customize the success rate like for example like success rate equal to 50 + User.Magic Attack?
    user.hit = 50 + user.mat; Thank you for helping me.
  9. Doktor_Q said:
    If the scope is None, then it won't run a damage formula, or any of the damage calculation related tags. However, <Custom Execution> in yanfly's skill core runs immediately after paying the skill's cost, so it should work even if you don't have a target.

    Sadly, that didnt work for me, but it's okay! Thanks again for your help with the issue, I'm sure I'll make do.
  10. Edit: please delete.
  11. Is there any way to move these battlers closer to the bottom of the screen? I have yanfly core reposition battlers turned on. I didn't find that any settings in the other plugins changed it. I'm using larger resolution as well. Capture.PNG
    It's not a big deal but it would look better with the larger enemies.
  12. michaelmartin341 said:
    Is there any way to move these battlers closer to the bottom of the screen? I have yanfly core reposition battlers turned on. I didn't find that any settings in the other plugins changed it. I'm using larger resolution as well. View attachment 151799
    It's not a big deal but it would look better with the larger enemies.

    Edit2:

    Ok, I keep finding better methods doing this.
    Hopefully this will be my last edit.

    Download my plugin and put it somewhere after Yanfly plugins.
    Now you have 2 options:

    Option 1:
    Go to "Enemies" setting and type into the Notes: <homeY:YOURVALUE> and/or <homeX:YOURVALUE> to set a fixed enemy position.

    Option 2:
    Go to plugin settings of this plugin and change the values of homeX and/or homeY in order to increase or decrease enemy position value.

    So basically, if you want to move ALL your enemies down by lets say 200 pixel, you change the homeY value in the plugin settings to 200. You can of course, also set negative numbers for moving in opposite directions.

    Hope this helps.
  13. @Lanzy Thank you so much it worked perfectly! I love it :biggrin:
  14. I have a need to place a list in a javascript variable as an array and then pick a random element of that array. I can do that with this event

    1595377070176.png

    The displayed variable looks like this

    1595377159257.png

    and I get the expected outcome

    1595376883853.png

    ..... but, when I input that same text from a textfile, written the exact same way,

    1595377386089.png

    and replacing only the first line of code with

    1595377552104.png

    The output is different.

    1595377670237.png

    and that output isn't treated as an array.

    1595377771889.png

    I would be truly grateful if someone could tell me what steps I am missing. Thank you.

    I forgot to mention that I am using Ozubon's plugin found here, though the problem is certainly my inept javascript and not in the plugin. The plugin works great.
  15. Lady_JJ said:
    I have a need to place a list in a javascript variable as an array and then pick a random element of that array. I can do that with this event

    View attachment 152121

    The displayed variable looks like this

    View attachment 152122

    and I get the expected outcome

    View attachment 152119

    ..... but, when I input that same text from a textfile, written the exact same way,

    View attachment 152123

    and replacing only the first line of code with

    View attachment 152124

    The output is different.

    View attachment 152127

    and that output isn't treated as an array.

    View attachment 152128

    I would be truly grateful if someone could tell me what steps I am missing. Thank you.

    I forgot to mention that I am using Ozubon's plugin found here, though the problem is certainly my inept javascript and not in the plugin. The plugin works great.

    Have you tried saving your file as a ". json" and see if it recognizes that as an array?

    Edit:
    I looked at the code. It doesn't recognize your array, because the plugin reads the file's content as a string. So basically what you are getting when reading the file is "["cat", "dog", "mouse"]" instead of ["cat", "dog", "mouse"]. That's why ingame it appears as a regular array, because you don't see the quotation marks.

    Your best solution is making your own .json file and telling the game where to access it.
    You will need 2 things (it's really not hard, just bare with me):

    First:
    Your own costum plugin for your game that tells the game what files to look for.
    JavaScript:
    //=============================================================================
    // Costum Files
    //=============================================================================
    
    var $dataList = null; // Create an object that will represent your costum file in MV
    
    // Tell the game what your file is called (src: yourFile.json) and assign the object
    // you created above to that file.
    DataManager._databaseFiles.push({name: '$dataList', src: 'List.json'});

    We will call this plugin "fileManager.js" (also attached for download).

    Second:
    You now can create your costum file. We will call it List.json in this case.
    Simply insert your array ["dog", "cat", "bird", "mouse", "horse", "rabbit", "cow"] into a file, like you have done before and save the file as a .json. You can also for future purposes use arrays within your array so you don't need a new file for every list. You can also save objects in them of course.

    The file List.json must be stored in the "data" folder, NOT JS or PLUGINS.

    Edit2:
    Maybe I should tell you how to access the file in MV lol.
    Same as before basically, go to control variables and insert: $dataList

    Hope this helps!
  16. This is so perfect! Thank you very much. Works like a charm and now I can move on to adding details to the game.
  17. Lady_JJ said:
    This is so perfect! Thank you very much. Works like a charm and now I can move on to adding details to the game.

    I'm happy I could help :)
  18. Sorry if this an easy question!
    How do you check the actor 1's sprite index via script call?
  19. CosmicMagician said:
    Sorry if this an easy question!
    How do you check the actor 1's sprite index via script call?

    Are you talking about the character sprite of the first actor?
    That would be in the array "SceneManager._scene._spriteset._characterSprites"
    However, the array changes depending on how many other character sprites are on the map.
    I'm not sure, but I think the first actor sprite is the last sprite in the array, the second actor in the second last one, etc.

    So in the script you would go:

    JavaScript:
    var charSprites = SceneManager._scene._spriteset._characterSprites;
    var actor1 = charSprites[charSprites.length - 1];
    var actor2 = charSprites[charSprites.length - 2];

    Edit:
    That only works when you are in the map scene.
  20. I'm using Yanfly's EquipCore plug-in to allow my party members to each equip up to 4 accessories at the same time, using the class notetag <Equip Slot: 1, 2, 3, 4, 5, 5, 5, 5> where "5" represents accessories. This works perfectly so far. My question is: Is it possible to prevent a party member from wearing duplicate/identical accessories? I want to force each of those 4 equipped accessories to all be different, to prevent a single party member from wearing 2 or 3 or 4 of the same accessory. (I'm fine with each party member wearing accessories A, B, C, and D; I just don't want any party member wearing accessories B, B, B, and B.) Thank you!