RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Mersenne Prime Item Gain

0 Members and 1 Guest are viewing this topic.

*
Scripter
Rep:
Level 40
Crownless King
Mersenne Prime Item Gain
Version: 1
Author: Soulpour777
Date: February 18, 2015

Description


For those who are wondering what Mersenne Prime is, here is a brief explanation:
for p an odd prime, the Mersenne number 2p − 1 is prime if and  only if 2p − 1 divides S(p − 1) where S(n + 1) = (S(n))2 − 2, and S(1) = 4.
This script allows you to execute and check the Mersenne Primes and adds item, weapon and armor variation item gain. This script calculate all  Mersenne primes up to the implementation's maximum precision,  or the 47th Mersenne prime. (Which ever comes first) and adds that item on your inventory.

Features

  • Mersenne Based Items
  • Mersenne Based Weapons
  • Mersenne Based Armors

Instructions

Script Calls:

Code: [Select]
prime_change_number(prime_number_value)
where prime_number_value is the value you want to change the UPB_Prime dividing number. For example, the default UPB_Prime = (Long_Bits_Width - 1).to_i / 2 - 0 has no changes of how many item is given. If you do: UPB_Prime = (Long_Bits_Width - 1).to_i / 2 - 5, this will give only 1 item. Since the default gives you 6 items. 6 - 5, simple, gives you 1.

Script Example:
Code: [Select]
prime_change_number(4)
gives you 2 items in either item, weapon or armor.

Code: [Select]
mersenne_gain_item
^ This calls the script's main function, creates the Mersenne Prime and adds item according to this algorithm.

Script


Code: [Select]
#==============================================================================
# ** Mersenne Prime Item Gain
# Author: Soulpour777
# Script Version 1.0
# February 18, 2015
#------------------------------------------------------------------------------
# Description:
# For those who are wondering what Mersenne Prime is, here is a brief
# explanation:
# for p an odd prime, the Mersenne number 2p − 1 is prime if and
# only if 2p − 1 divides S(p − 1) where S(n + 1) = (S(n))2 − 2, and S(1) = 4.
# This script allows you to execute and check the Mersenne Primes and adds
# item, weapon and armor variation item gain. This script calculate all
# Mersenne primes up to the implementation's maximum precision,
# or the 47th Mersenne prime. (Which ever comes first) and adds that item on
# your inventory.
#------------------------------------------------------------------------------
# Script Calls:
# prime_change_number(prime_number_value)
# where prime_number_value is the value you want to change the UPB_Prime
# dividing number. For example, the default
# UPB_Prime = (Long_Bits_Width - 1).to_i / 2 - 0 has no changes of how many
# item is given. If you do: UPB_Prime = (Long_Bits_Width - 1).to_i / 2 - 5,
# this will give only 1 item. Since the default gives you 6 items. 6 - 5,
# simple, gives you 1.
# Script Example: prime_change_number(4) - gives you 2 items in either item,
# weapon or armor.
# mersenne_gain_item
# ^ This calls the script's main function, creates the Mersenne Prime and
# adds item according to this algorithm.
#------------------------------------------------------------------------------
# Author's Note: Someone of you would surely ask, why on earth are you,
# Soulpour777 make this kind of script? The answer is because I am tired
# using the old style of randomizing items to gain. This script allows me
# to make more changes than the usual randomizing of things. I also want
# to apply some kind of math into my games, so here's one I could think of.
# You can use this script if you want...but if no one does, I would.
#------------------------------------------------------------------------------
# Terms of Use:
# For Non Commercial use only. For Commercial Use, please contact m
#==============================================================================
module Soul
  module MersennePrime
    # Would you like to use an SE when you gain this mystery item?
    Use_SE = false
    # What sound effect do you want to play? Must be in Audio/SE
    Item_SE = "Chime1"
    # Default Count...don't change this.
    Count = 0
    Precision = 5   # maximum requested number of decimal places of 2 ** MP-1 #
    Long_Bits_Width = Precision / Math.log(2) * Math.log(10)
    UPB_Prime = (Long_Bits_Width - 1).to_i / 2 - 0  # no unsigned #
    UPB_Count = 45      # find 45 mprimes if int was given enough bits #
    #--------------------------------------------------------------------------
    # * Mersenne Prime : use method to check if it is a normal prime
    #-------------------------------------------------------------------------- 
    def self.is_prime ( p )
      return true  if p == 2
      return false if p <= 1 || p.even?
      (3 .. Math.sqrt(p)).step(2) do |i|
        return false  if p % i == 0
      end
      true
    end
    #--------------------------------------------------------------------------
    # * Mersenne Prime Check : use method to check if it is a mersenne prime
    #-------------------------------------------------------------------------- 
    def self.is_mersenne_prime ( p )
      return true  if p == 2
      m_p = ( 1 << p ) - 1
      s = 4
      (p-2).times { s = (s ** 2 - 2) % m_p }
      s == 0
    end   
   
  end
 
end

#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
  alias :soul_mersenne_prime_initialize                     :initialize
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------   
  attr_accessor                                             :mersenne_counter
  attr_accessor                                             :prime_change
  attr_accessor                                             :kind_randomizer
  attr_accessor                                             :old_decrease_value
  #--------------------------------------------------------------------------
  # * Start Processing
  #-------------------------------------------------------------------------- 
  def initialize(depth = 0)
    soul_mersenne_prime_initialize(depth = 0) # Call original method
    @prime_change = Soul::MersennePrime::UPB_Prime # Changes to default
    @kind_randomizer = 1 # default, this goes as item
    @old_decrease_value = 0
  end
  #--------------------------------------------------------------------------
  # * Prime Change Number :new method
  #-------------------------------------------------------------------------- 
  def prime_change_number(prime_number_value)
    @old_decrease_value = prime_number_value
    @prime_change = (Soul::MersennePrime::Long_Bits_Width - 1).to_i / 2 - @old_decrease_value
  end
  #--------------------------------------------------------------------------
  # * Mersenne Gain Item
  #-------------------------------------------------------------------------- 
  def mersenne_gain_item
    @mersenne_counter = Soul::MersennePrime::Count
    @kind_randomizer = rand(3) + 1
    puts @kind_randomizer
    for p in 2..@prime_change
      if Soul::MersennePrime.is_prime(p) && Soul::MersennePrime.is_mersenne_prime(p)
          case @kind_randomizer
            when 1 # item
              $game_party.gain_item($data_items[p],1,true)
            when 2 # Weapon
              $game_party.gain_item($data_weapons[p],1,true)
            when 3
              $game_party.gain_item($data_armors[p],1,true)   
          end
        @mersenne_counter += 1
      end
      break if @mersenne_counter >= Soul::MersennePrime::UPB_Count
      RPG::SE.new(Soul::MersennePrime::Item_SE,100,100).play if Soul::MersennePrime::Use_SE
    end   
  end
end


Credit


  • Soulpour777

Thanks

  • Marin Mersenne, creator of the said formula

Support


For support, comment on this post or contact me here on RMRK.

Known Compatibility Issues

None.

Author's Notes


Someone of you would surely ask, why on earth are you, Soulpour777 make this kind of script? The answer is because I am tired using the old style of randomizing items to gain. This script allows me to make more changes than the usual randomizing of things. I also want to apply some kind of math into my games, so here's one I could think of. You can use this script if you want...but if no one does, I would.

Terms of Use


This script is free only for Non Commercial use. For Commercial Uses, please contact me.


If you like my work, please do support me on Patreon.
https://www.patreon.com/Soulpour777?ty=h

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Best RPG Maker User - Creativity2014 Kindest Member2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
So it's an alternative to random item gains? :)

Thanks for sharing all these scripts! You're a gem, soulpour! :ladyj:
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]