what's the equivalent of those Ruby line in JS?

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
Hi I'm converting a script I commissionned from @Shaz and I liked a lots and I add permission in the past to convert it to MV but I still struggle to convert it.


What's the equivalent for those lines in JS?


$data_weapons.compact.each { |w| w.build_equipment_restrictions }

@restrict_users = /<user (.*)>/i.match(line)[1].scan(/\d+/).collect { |i| i.to_i}

@restrict_users.empty? || @restrict_users.include?(actor_id)

equips.compact.inject(super) {|r, item| r += item.user_params(@actor_id, param_id) }


do you know how I could "transfert" those methods to MV? 


thanks for your further answer :)  
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,100
Reaction score
13,705
First Language
English
Primarily Uses
RMMV
Ugh!  Regular expressions and injecting.  My two favourite subjects (not!)


I don't know what the conversions are.  Hopefully there'll be a JS pro who can tell you.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
Ugh!  Regular expressions and injecting.  My two favourite subjects (not!)


I don't know what the conversions are.  Hopefully there'll be a JS pro who can tell you.
yeah I'm searching some work around for make the User Restriction plugin conversion you made for me in Vx Ace....and I can say this not easy XD
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,100
Reaction score
13,705
First Language
English
Primarily Uses
RMMV
I can't really remember that script, but I'll have items restricted by users so I imagine I'll have to do something similar, when I get around to it.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
I can't really remember that script, but I'll have items restricted by users so I imagine I'll have to do something similar, when I get around to it.
it's that haha but SO small but so hard to do! because simply the classes areq inexistant in MV and are configurated differently lol.


The regexp part is not that hard to do it's easy to eval it or even to extends it the problem is that how the  difference is big.

Code:
module DataManager
  class << self
    alias shaz_equip_restrict_load_database load_database
  end
 
  def self.load_database
    shaz_equip_restrict_load_database
    build_equipment_restrictions
  end
 
  def self.build_equipment_restrictions
    $data_weapons.compact.each { |w| w.build_equipment_restrictions }
    $data_armors.compact.each { |a| a.build_equipment_restrictions }
  end
end
 
class RPG::EquipItem < RPG::BaseItem
  def build_equipment_restrictions
    @restrict_users = []
    @restrict_minus = 0
 
    note.split(/[\r\n]+/).each do |line|
      case line
      when /<user /i
        @restrict_users = /<user (.*)>/i.match(line)[1].scan(/\d+/).collect { |i| i.to_i}
      when /<minus (\d+)>/i
        @restrict_minus = (100 - $1.to_i)/100.0
      end
    end
  end
 
  def user_params(actor_id, param_id)
    if @restrict_users.empty? || @restrict_users.include?(actor_id)
      value = params[param_id]
    else
      value = (params[param_id] * @restrict_minus).to_i
    end
    value
  end
 
  attr_accessor :restrict_users
  attr_accessor :restrict_minus
end
 
class Game_Actor < Game_Battler
  def param_plus(param_id)
    equips.compact.inject(super) {|r, item| r += item.user_params(@actor_id, param_id) }
  end
end
 

chaucer

Veteran
Veteran
Joined
Aug 6, 2014
Messages
325
Reaction score
549
First Language
English
Primarily Uses
RMMV
Apologies if i misunderstood, but basically you're trying to find a way to copy the effect of this code in javascript? If so I'll try to help, apologies if im off, but I'll try my best.


for the first line of code, this is the best i could think of.


#RUBY
$data_weapons.compact.each { |w| w.build_equipment_restrictions }

#=================================================================
#================================================================

//JAVASCRIPT
$dataWeapons.forEach( function( w ) {
//check if the weapon exists.
if ( w )
//executewhatever code you want here, below is an example.
w.buildEquipRestrictions();
};







for the 3rd line of code.
 


#RUBY
@restrict_users.empty? || @restrict_users.include?(actor_id)

//JAVASCRIPT
restrictUsers.length == 0 || restrictUsers.indexOf( actorId ) >= 0;



if this is what you're looking for i can look into the other lines as well( my ruby is a bit rusty and i cant think of solutions off the top of my head for them ), just let me know, if not sorry xD I probably misunderstood, apologies.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,100
Reaction score
13,705
First Language
English
Primarily Uses
RMMV
That last line would be restrictUsers.length === 0, not > 0, since it's checking if the array is empty.
 

chaucer

Veteran
Veteran
Joined
Aug 6, 2014
Messages
325
Reaction score
549
First Language
English
Primarily Uses
RMMV
Haha, Thanks shaz, glad you caught that, sorry I'm a bit tired atm ^^;
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

A bit of a "sparkle" update to the lower portion of the world map. :LZSexcite:
attack on titan final season is airing tomorrow, I'm excited and scared at the same time!

Forum statistics

Threads
105,882
Messages
1,017,230
Members
137,607
Latest member
Maddo
Top