JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 37 of 171 View original ↗
  1. Phinx said:
    Tried this with several values ranging from 0 to 255, but it seemed to have no actual effect.

    I just tested it and it did have an effect, but the opacity didn't change until I opened the menu, which is of course not what you want... There should be a way to force the program to update, but I haven't found it yet.


    I have, however, found some plugins that seem to do what you want - use a custom texbox during conversations:


    https://galvs-scripts.com/2015/10/25/mv-message-background/


    http://forums.rpgmakerweb.com/index.php?/topic/46926-nasty-replace-window-with-picture/


    and there are probably more. Maybe have a look at them and see if they make things easier for you.
  2. Hi there,


    I have a question...  I wondered if I could use the right mouse button another way... 


    I wanted it to simulate the alt key, because I use Galv's simple crops and tools and wanted the tools (alt)  to be usable with the right mouse button, too. In the keymap in rpg.core there is the alt button defined with 18. 


    A click with the RMB is TouchInput.isCancelled in line 3061... 

    Spoiler
    * Checks whether the right mouse button is just pressed.
     *
     * @static
     * @method isCancelled
     * @return {Boolean} True if the right mouse button is just pressed


    TouchInput.isCancelled = function() {
        return this._cancelled;
    };

    Because I'm a total noob at programming I have absolutely no idea what there should stand... 


    In this thread 





     Astfgl66 wrote this little plugin

    Spoiler
    (function() {
    var _Astfgl_newSMU = Scene_Map.prototype.update
    Scene_Map.prototype.update = function() {
    _Astfgl_newSMU.call(this);
    if (TouchInput.isCancelled()) {
    $gameTemp
    .reserveCommonEvent(4); //change 4 to the id of the common event you want to call
    }
    }
    })();

    so my questions are: what do I have to write underneath the if (TouchInput.isCancelled()) { line to actually have a key (especially the alt key, or another custom keymapper key) pressed when I rightclick the mouse? Is that even possible?


    I tried to program for hours now, trying do get the right syntax and commands and stuff, but without ANY knowledge it's way too hard to figure it out... But kind of interesting :D


    Thanks in advance!


    EDIT: Is there maybe a way to even "keymap" the right mousebutton?
  3. @AcoBaco  I sadly can't help with that, but i would otherwise try with another key mapping plugin ? or at maybe open them to find the syntax


    I'm making a variant of the Thornmail (reflects damage to attacker) that wouldn't reflect ranged damage, or spells..


    I thought about a way using a "ranged" state, and checking against that state, which would work perfectly for a state added when a bow is equipped for exemple, but not with magic...(some of my magic is dealing physical damage). So if anyone has an idea for that..


    Else, could you help with what i shoudl write in place of the XXXXXXXX to prompt nothing ?


    IE : (If my attacker has the ranged state, ignore the thornmail effect)

    Spoiler
    <Custom React Effect>


    If (user.isStateAffected(31))


    { XXXXXXXX


    }


    Else if (value > 0 && this.isPhysical())


    {


    var elementId = 2;


    var dmg = (Math.randomInt(6)+1);


    var damage = Math.ceil(target.elementRate(elementId) * dmg)


    user.gainHp(-1 * damage);


    if (user.isDead())


    {


    user.performCollapse();


    }


    }


    </Custom React Effect>
  4. @AcoBaco I would rather have the right mouse button call the function that is otherwise called when the alt key is pressed. Could you plovide a link to Galv's plugin so that we can see what's happening in his code?


    @Nol You can just use an single if-statement:
     


    if (value > 0 && this.isPhysical() && !user.isStateAffected(31)) {
    // code for thornmail effect
    }


    The exclamation mark is a negation ("... and if the user is not affected by state #31").
  5. I didn't know about the negation, thanks, it works flawlessly, my thanks.


    if any one has a similar idea :  to negate some specific skills, i added "ranged state" for 1 action to any such skills.


    Follow up :  If my formula deals no damage, any way to simply not show anything instead of the "0" ?
  6. Hi all,


    What I'm trying to make is a state which will be possible to apply if mpRate (MP current level in %) is above 5%. This state then will take 5% of MP every turn. Everything work just fine till this moment. Next thing I'm trying to make is that if MP is below 5% then that state should be removed.


    I'm using all Yanfly's plugins, but the most important here are Visual State EffectsBuffs and States CoreAuto Passive States and Passive Aura Effects.


    My skill notetag:

    Spoiler
    // Requires user to have at least 5% MP


    <Custom Requirement>


    value = user.mpRate() > 0.05;


    </Custom Requirement>


    // Display cost


    <Custom Cost Display>


    \fs[20]\c[23]5% KI or more\c[0]\fr


    </Custom Cost Display>

    and my state notetag

    Spoiler
    <Custom Passive Condition>


    // Check if the party is in battle and if the affected Mp rate is above 5%.


    if ($gameParty.inBattle() && user.mpRate() >= 0.05) {


    // Set the condition to true


    condition = true;


    } else {


    // Otherwise, set the condition to false.


    condition = false;


    }


    </Custom Passive Condition>



    Everything till removing state is working just fine so there must be something wrong with state notetags, but I have no idea what that could be.


    Thank you very much in advance for any help.


    Both code fragments I took from Tips & Tricks series: Death and Power Up Mode.


    Regards.
  7. This is my little problem. Working on a simple plugin to add state based on the equipment (sort of equip set), it work perfectly until the last couple of lines. Is a simple for that iterate over an array of states to apply to the actor. But don't work. Apply only few states or nothing at all and the result changes also with same equipment. Printing the array on the console show correct and expected values.  Any idea why I've this problem? 
  8. Show us your code please...
  9. Engr. Adiktuzmiko said:
    Show us your code please...

    Sorry, I wrote the message with my phone. Here is the code:

    Spoiler
    var Imported = Imported || {};
    Imported.MSX_EquipmentSet = true;

    var MSX = MSX || {};
    MSX.EquipmentSet = MSX.EquipmentSet || {};

    /*:
    * @plugindesc v1.0
    * @author Melosx
    *
    * @param Set 1 Weapon
    * @desc The ID of the required weapon for the set.
    * Leave empty if no weapon is required.
    * @default 1
    *
    * @param Set 1 Armors
    * @desc The IDs of the required weapon for the set.
    * Leave empty if no armor is required.
    * @default 1 2 3
    *
    * @param Set 1 Effects
    * @desc The effect and the required number of pieces.
    * Syntax [PIECES REQUIRED, STATE ID TO APPLY] separate by comma
    * @default [[2,4],[4,5]]
    *
    * @param ------------
    * @default ------------
    *
    * @param Set 2 Weapon
    * @desc The ID of the required weapon for the set.
    * Leave empty if no weapon is required.
    * @default 2

    * @param Set 2 Armors
    * @desc The IDs of the required weapon for the set.
    * Leave empty if no armor is required.
    * @default 4 5 6
    *
    * @param Set 2 Effects
    * @desc The effect and the required number of pieces.
    * Syntax [PIECES REQUIRED, STATE ID TO APPLY] separate by comma
    * @default [[2,4],[4,5]]
    *
    * @param ------------
    * @default ------------
    *
    * @param Set 3 Weapon
    * @desc The ID of the required weapon for the set.
    * Leave empty if no weapon is required.
    * @default 2

    * @param Set 3 Armors
    * @desc The IDs of the required weapon for the set.
    * Leave empty if no armor is required.
    * @default 4 5 6
    *
    * @param Set 3 Effects
    * @desc The effect and the required number of pieces.
    * Syntax [PIECES REQUIRED, STATE ID TO APPLY] separate by comma
    * @default [[2,4],[4,5]]
    *
    * @param ------------
    * @default ------------
    *
    * @param Set 4 Weapon
    * @desc The ID of the required weapon for the set.
    * Leave empty if no weapon is required.
    * @default 2

    * @param Set 4 Armors
    * @desc The IDs of the required weapon for the set.
    * Leave empty if no armor is required.
    * @default 4 5 6
    *
    * @param Set 4 Effects
    * @desc The effect and the required number of pieces.
    * Syntax [PIECES REQUIRED, STATE ID TO APPLY] separate by comma
    * @default [[2,4],[4,5]]
    *
    * @param ------------
    * @default ------------
    *
    * @help
    * #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
    * Introduction
    * #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
    *
    * .
    *
    * #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
    * Parameters
    * #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
    *
    *
    *
    * #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
    * Changelog
    * #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
    *
    * v1.0 Initial release.
    */

    //var params = PluginManager.parameters("MSX_EquipmentSet");
    var params = PluginManager.parameters(/([^\/]+)\.js$/.exec(document.currentScript.src)[1]);

    MSX.EquipmentSet.maxEquip = 4;
    var $equipmentSet = [null];
    for(var i = 1; i< MSX.EquipmentSet.maxEquip + 1; ++i){
    $equipmentSet = {
    weapon: String(params["Set " + i + " Weapon"]),
    armors: String(params["Set " + i + " Armors"]),
    effects: eval(String(params["Set " + i + " Effects"]))
    }
    }


    MSX.EquipmentSet.SceneEquip_onItemOk = Scene_Equip.prototype.onItemOk;
    Scene_Equip.prototype.onItemOk = function () {
    MSX.EquipmentSet.SceneEquip_onItemOk.call(this);
    this.checkSet();
    this._statusWindow.refresh();
    };

    MSX.EquipmentSet.SceneEquip_commandOptimize = Scene_Equip.prototype.commandOptimize;
    Scene_Equip.prototype.commandOptimize = function() {
    MSX.EquipmentSet.SceneEquip_commandOptimize.call(this);
    this.checkSet();
    };

    MSX.EquipmentSet.SceneEquip_commandClear = Scene_Equip.prototype.commandClear;
    Scene_Equip.prototype.commandClear = function() {
    MSX.EquipmentSet.SceneEquip_commandClear.call(this);
    this.checkSet();
    };

    MSX.EquipmentSet.SceneEquip_onActorChange = Scene_Equip.prototype.onActorChange;

    Scene_Equip.prototype.onActorChange = function() {
    MSX.EquipmentSet.SceneEquip_onActorChange.call(this);
    this.checkSet();
    };



    Scene_Equip.prototype.checkSet = function () {

    var id = this.actor().actorId();
    var act = $gameActors.actor(id);
    var slots = this.actor().equipSlots();
    var maxSlots = slots.length;
    var equippedWeapon = [];
    var equippedArmors = [];
    var setStates = [];
    var stateToApply = [];
    for(var m = 0; m < maxSlots; m++){
    if(act.equips()[m] != null){
    if(DataManager.isWeapon(act.equips()[m])){
    equippedWeapon.push(act.equips()[m].id);
    }
    if(DataManager.isArmor(act.equips()[m])){
    equippedArmors.push(act.equips()[m].id);
    }
    }
    }
    for(var i = 1; i< $equipmentSet.length; ++i){
    var weaponID = $equipmentSet.weapon.split(" ");
    var armorsID = $equipmentSet.armors.split(" ");
    var effects = $equipmentSet.effects;
    var check = 0;
    var stateCheck = 0;
    for(var j = 0; j < weaponID.length; j++){
    weaponID[j] = parseInt(weaponID[j], 10);
    }
    for(var k = 0; k < armorsID.length; k++){
    armorsID[k] = parseInt(armorsID[k], 10);
    }

    for(var s = 0; s < effects.length; s++){
    setStates.push(effects[1]);
    }

    for(var w = 0; w < equippedWeapon.length; w++){
    if(weaponID.indexOf(equippedWeapon[w]) != -1){
    check = check + 1;
    }
    }
    for(var a = 0; a < equippedArmors.length; a++){
    if(armorsID.indexOf(equippedArmors[a]) != -1){
    check = check + 1;
    }
    }

    console.log(check);

    for(var z = 0; z < effects.length; z++){
    if(check >= effects[z][0]){
    stateCheck = effects[z][1];
    }
    }
    stateToApply.push(stateCheck);


    }
    console.log(setStates);
    console.log(stateToApply);

    for(var h = 0; h < setStates.length; h++){
    act.removeState(setStates[h]);
    }
    if(stateToApply.length > 0){
    for(var b = 0; b < stateToApply.length; b++){
    console.log(stateToApply);
    act.addState(stateToApply);
    }
    }
    };




    The script see if there is a state to apply when change equip/optimize/clear.
  10. Hey there, i'm using Mog's Linear Motion Battle System! 'Till now it's working fine, i just wanted to ask if was possibile to play a sound each time the character walks.
    I'm creating a cave battleground so when you walk you should be able to hear your footstep, but creating condition inside the troop event it's just making the battle freeze!
    How should i do it?
  11. Is there a way to obtain an event's page number? I know how to retrieve the event's ID number, as shown below:

     
    ◆Script:$gameMessage.add('Hi. I am on Page 2. My Id is ' + this._eventId);I just wanted to know if there was something to retrieve the Page ID of an event, like "this._eventPage" but that didn't work and I haven't been able to find such googling. I looked through the js files too, but didn't find anything matching that wording. 
  12. Hi. I want to obtain a random number between 1 and 4, but prevent getting either 1, 2, 3 or 4 sometimes.

    ◆Label:REDO RANDOM
    ◆Control Variables:#0025 Free/Random Variable 1 = Random 1..4
    ◆If:Free/Random Variable 1 = Free/Random Variable 2
      ◆Jump to Label:REDO RANDOM
      ◆
    :End

    The code above would work, but I'd like to know if it is possible to set a string of numbers (that could be disjointed) and have one randomly selected. Example: Set 1, 3, 4 and 6. Randomly select one of those five. Or set 1, 2, 3, 4, 7, 8, 12 and select one of those seven. [Without having to set another variable check like I've done below] I assume that might involve arrays?


    $gameVariables.setValue(7, [, , ]);


    But I don't know how to randomly select a value from an array in MV. I've come across VX Ace code:
    @random = rand(3)


    which is used something like:
    @message[@random]


    Where message was an array. I'm not sure if that is right and if so, what is the MV equivalent. 
    I also saw

    $game_message.add($npc_1_chatter.sample)

    And would like to know what " .sample " does? Does it select a random value from the array ($npc_1_chatter in this case)? If so, is their an MV equivalent?

    EDIT: Found out how to pick a random value for what I want to do, but not sure about the .sample code.
  13. I'm having a lot of trouble with something simple.


    How can I do that when you open the menu, it shows an image over it and when you exit it, the image dissapears.


    I made a mess trying to make it work with no luck.
  14. @SML That is not as simple as you think, and it definitely is too complex for this topic.


    Please make a new topic where you include the code you tried in learning javascript
  15. @Rink27

    $gameVariables.setValue(7, [, , ]);



    var ary = $gameVariables.value(7)


    ary[Math.floor(Math.random()*ary.length)];


    should give you a random value form the array

    And would like to know what " .sample " does? Does it select a random value from the array ($npc_1_chatter in this case)? If so, is their an MV equivalent?



    I think the .sample there is a custom method created by whoever wrote that text that you quoted. 
  16. Thank you! I have another issue for anyone.

      ◆Control Variables:#0088 Last Death  = 12
      ◆Control Variables:#0428 [Word (Comment Death)] = "It's sad that \N[\V[88]] died."
      ◆Text:None, Window, Bottom
      :    :\V[428]

    My problem is that the message window says "It's sad that \N[\V[88]] died." instead of "It's sad that (Person's Name) died."
    I do not want to restrict that window message box to a sentence with \N[\V[]].


    Is there a work around or scripting for what I want?
     
  17. Hmm... \V[ID] is already a text code so I think by default the text display function doesn't check if it has text codes on it's own (which is what you did in your example).


    As of now, the only thing I can suggest to you is to use the  "It's sad that \N[\V[88]] died." directly into your message box rather than saving it first in a variable. If you cannot do that for some reason, I don't have any workarounds right now.
  18. Hello guys, I actually have a thread on this, but not sure if it was worthy...

    I have a feeling I'm missing something silly.

    Here it goes anyway:

    I want to show the full window (with frame) on the battle log instead of a transparent line.

    Think of something like FF6:
    7-ffvi45_011.png

    I've dived into rpg_windows.js -> Window_BattleLog and I can't find where is the frame from the battle log being removed, or why/how is it a frameless window.

    The only thing I was able to modify was to make the log non transparent.

    Any help or guidance would be strongly appreciated!

    Viva the new forums!

    Edit: Figured it out myself!

    To show frame in battle log...

    In DisplayAction fn add
    this.opacity = 255;

    And in clear fn add
    this.opacity = 0;

    CASE SOLVED :)
  19. Editted line 544 in rpg_managers from this.meVolume = this.readVolume(config, 'meVolume');

    to this.meVolume = this.readVolume(config, 'BgmVolume');

    This ties both BGM and ME setting to one value, but once an ME is played and I alter the volume in the config menu, it does not take effect until the next BGM plays. MEs will stop playing altogether. That is the only alteration I've made to that code.

    What am I missing for the volume to work as intended?
  20. Sorry I realized the problem after I posted