Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
NuKa_BuBble

Need short Randomization tutorial

Question

I need a short tutorial about randomization in RGSS. I know only rand(value).

 

Someone can say me:

-how to make a variable is choose randomly between six.

-if the player lvl is between 1 or 9, give an item with a random quantity between 1 to 5

-put a random in a if statement. Like: you have 6 possibilities, you have 1 chance on 100 than the first accomplished. You have 1 chance on 50 than the second accomplished... If the first or the second or the third or... Do that. Else, do this:...

Share this post


Link to post
Share on other sites

22 answers to this question

Recommended Posts

  • 0

$random = rand(8) Will give you a random number between 0 and 8, or in other words nine possible values.

 

..So what are you asking for?

Share this post


Link to post
Share on other sites
  • 0

rand(max) calculates a random number between 0 and max, exclusive. If max is 0 or nil, it returns a floating decimal value between 0 and 1 exclusive.

 

For a number between 1 and 6:

rand(6) + 1 # 1 - 6 inclusive
rand(6) # 0 - 6 exclusive
rand(7) # 0 - 6 inclusive

 

For Character between level 1-9 :

if $game_party.actors[0].level >= 1 && $game_party.actors[0].level <= 9
 #give character ( rand(4) + 1 ) for the number of items
end

 

And for chances, you can do this:


if rand(100) == 0 # 1 in 100 chance
 #code
end

if rand(50) == 0 # 1 in 50 chance
 #code
end

Share this post


Link to post
Share on other sites
  • 0

Can I say you something? I LIKE YOU! The code work fine! :alright: :clap: :jay: :king: :lol: :drool: :sweatdrop:

Share this post


Link to post
Share on other sites
  • 0

No you may not say that.

 

 

 

 

Lol. I'm kidding, of course. Anyways, as you can clearly see, this site is full of totally awesome and epic people like kell, so stick around and enjoy your game making adventure. ^_^

Share this post


Link to post
Share on other sites
  • 0

If I do:

 

#Other
1 + rand(6)    # 1 - 6,

#instead of

#Original
rand(6) + 1    # 1 - 6, inclusive

 

The first 'll give 1 to 6 exclusive? :haha:

Edited by NuKa_BuBble

Share this post


Link to post
Share on other sites
  • 0

rand(6) + 1 is exactly the same as 1 + rand(6)...which will be 1-6 inclusive.

 

rand(6) is 0 - 5 inclusive, + 1 and you get 1-6.

 

if you want 1-6 EXCLUSIVE (which is 1-5 inclusive)

 

rand(5) + 1

 

0-4 inclusive + 1 = 1-5 inclusive

 

1-5 inclusive IS 1-6 exclusive.

Share this post


Link to post
Share on other sites
  • 0

For the biased distribution I suggest doing something like this:

def weighted_random(array)
 sum = array.inject {|sum, n| sum + n} 
 n = rand(sum)
 array.each_with_index do |i, index|
   return index if n < i
   n -= i
 end
end

# Retrieve the index with 1/100 chance of 0 being picked (1+50+30+10+5+4 = 100), 50/100 chance of 1 being picked, ...
index = weighted_random([1, 50, 30, 10, 5, 4])

# If we want the first index to start at 1 instead of 0
#index += 1

 

 

*hugs*

Share this post


Link to post
Share on other sites
  • 0

Sorry Zeriab, I didn't understand your code.

I'm new in ruby and I make a script to practise. I did'nt read anything about random (I didn't found anything really complete about that too). :rolleyes: It's why in the title I wrote "I need a short randomization tutorial".

 

Do you have a trick to make that shorter? It's my problem. My codes are too longs.

 

Module RANDOM
def random_logs

while logs_ID == nil
if rand(100) == 0
logs_ID = A
else if rand(50) == 0
#code
[...]
end # end "if"
end # end while
end # end random_logs method

logs_ID = nil

# Other random define method and end
end # end module

 

Oh, and the method are automaticly executed and refresh or I need to call them or make a refresh method?

Edited by NuKa_BuBble

Share this post


Link to post
Share on other sites
  • 0

Shouldn't this topic be moved to the correct forum?

 

Thanks, totally didn't notice. Moved to Game Making Support.

 

 

@Nuka_Bubble: I am not too sure what exactly you are trying to achieve here. One thing I will say, is that shorter code does not necessarily mean better code. It can, in some cases, but in others sometimes a certain number of lines is the shortest you can write a script.

 

As for your code, what are you trying to achieve EXACTLY? maybe I can help you out a bit.

 

As for calling the method, you would need to call it manually whenever you need the method...but as it stands you would not be able to call that method from that Module. You declared it as a mix-in method, and that module would need to be included by another class/script:

 include RANDOM 

which will cause the class to include any instance methods, such as the one you have there.

 

if you want to call the method directly, it would need to be declared as module method/function,

 
def RANDOM.random_logs
 # Code
end

#or

def self.random_logs
 # Code
end

 

and then, from anywhere in your game you could call the method as:

RANDOM.random_logs

 

As for the rest of it, I am not sure exactly what you want to do, so I dunno if it could be optimized/reduced much... It might be able to, but I would need to know what you are trying to do first.

 

@ Zeriab:

 

*HUGZ* Thank you for this idea, I never would have thought of something like that. I really need to pay more attention to my Ruby docs! I keep forgetting about those other obscure but useful built-in class methods :)

Share this post


Link to post
Share on other sites
  • 0

EXACTLY? :lol:

 

It's my project. I need to polish it and finish 1 or 2 things but, there is it.

 

 

################################################################################
#                            Wood cutting system                               #
#                                                                              #
#    By: NuKa_BuBble                                                           #
#    Version: 1.0                                                              #
#    Started: 29/08/2011                                                       #
#                                                                              #
#    You can find me on these websites:                                        #
#    http://gameface101.playogame.com/                                         #
#    http://www.rmxpunlimited.net                                              #
#                                                                              #
#                                                                              #
################################################################################
#                                                                              #
#                        No Graphics needed                                    #
#                                                                              #
################################################################################
#                                                                              #
#                              Instructions                                    #
#                                                                              #
#                   In an event, add this part of script                       #
#                      if the player learned the job                           #
#                            $job_learn = true                                 #
#                                                                              #
#                          Call the script with                                #
#                             $Woodcutting.new                                 #
#                                                                              #
################################################################################



#------------------------------------------------------------------------------#
#------------------------------- NUKA module ----------------------------------#
#------------------------------------------------------------------------------#

module NUKA
#-------------Self Switch------------------------------------------------------#
  SELF_SWITCH = $game_self_switches
#-------------Woodcutting Stats------------------------------------------------#
 woodcutting_exp = 0
 woodcutting_lvl = 1
 energie_rem = 100

#-------------The tools for woodcutting----------------------------------------#
 WOODCUTTING_WPN_ID
 {
  6, 7
 }
#-------------Other------------------------------------------------------------#
can_gain_wc_exp = true
$job_learn = false

end

#------------------------------------------------------------------------------#
#------Woodcutting randomization module----------------------------------------#
#------------------------------------------------------------------------------#

#module RANDOM

#1. how to make a variable is choose randomly between six.

#2. if the player lvl is between 1 or 9, give an item with a 
#random quantity between 1 to 5

#3. put a random in a if statement. Like: you have 6 possibilities, 
#you have 1 chance on 100 than the first accomplished. 
#You have 1 chance on 50 than the second accomplished... 
#If the first or the second or the third or... Do that. Else, do this:... 


#1.
#rand(6) + 1 # 1 - 6 inclusive
#rand(6) # 0 - 6 exclusive
#rand(7) # 0 - 6 inclusive

#2.
#if woodcutting_lvl >= 1 && woodcutting_lvl <= 9
#give character ( rand(4) + 1 ) for the number of items
#end

#3.
#if rand(100) == 0 # 1 in 100 chance
#code
#end
#if rand(50) == 0 # 1 in 50 chance
#code
#end

#Other method

#end

#------------------------------------------------------------------------------#
#---------------------------- End of the modules ------------------------------#
#------------------------------------------------------------------------------#




#------------------------------------------------------------------------------#
#-------------------------- Class Woodcutting ---------------------------------#
#------------------------------------------------------------------------------#
class Woodcutting

#------------------------------------------------------------------------------#
#                              Initialize                                      #
#------------------------------------------------------------------------------#
def initialize
 @logs_gain = false
 @logs_number
 @logs_ID = $data[item_id]
 @old_wc_lvl = 1
 @wc_xp_gain
 @wc_next_lvl
 @i = 15

# If the logs type = to "A", 
#the amount of gain xp is multiplied by the logs number and divided by 2.
 @logs_type = {10, 5, 4, 3, 2, 1.5}

# cctt means "Can cut tree type"
# DO NOT TOUCH THIS PART OF CODE! 
# Set the tree type that can be cut in the "CASE BLOCK"
@cctt = 1

$tree_type = { 
#(Value = tree_type) => item_ID
#The value is use for the xp multiplication
#Here, you add different type of tree for different logs. 
 1 => 100,
 2 => 101,
 3 => 102,
 4 => 103,
 5 => 104,
 6 => 105,
 7 => 106,
 8 => 107,
 9 => 108,
 10 => 109
 }

end #end of define "initialize"

#------------------------------------------------------------------------------#
#------Define woodcutting stats------------------------------------------------#
#------------------------------------------------------------------------------#
#define the woodcutting lvl
def woodcutting_lvl
 NUKA::woodcutting_lvl = woodcutting_lvl
 woodcutting_lvl = 1
end

#define the woodcutting xp
def woodcutting_exp
 NUKA::woodcutting_exp = woodcutting_xp
 woodcutting_xp = 0
end

#define the woodcutting energie
def energie_rem
 NUKA::energie_rem = energie_rem
 energie_rem = 100
end

def logs_type_value
   if @logs_type = 10
     @logs_type = A
   else if @logs_type = 5
     @logs_type = B
   else if @logs_type = 4
     @logs_type = C
   else if @logs_type = 3
     @logs_type = D
   else if @logs_type = 2
     @logs_type = E
   else if @logs_type = 1.5
     @logs_type = F
 end
end

def tree_type
v = $tree_type[@logs_ID]
n = v != nil ? v : v == nil ? 0 : 0
return n
end
#------------------------------------------------------------------------------#
#-----Define if the player can cut---------------------------------------------#
#------------------------------------------------------------------------------#
def can_cut
#-If the player is equip with a woodcutting weapon, he can cut. Else, he can't.#

 if $data_actors[weapon_id] = NUKA::WOODCUTTING_WPN_ID
   can_cut = true
 else
   can_cut = false
 end
#----If the job is not learned, you can't cut----------------------------------#
   if $job_learn = false
      can_cut = false
   end

#----If you are out of energie, you can't cut----------------------------------#
   if energie_rem = 0
      can_cut = false
    end

   if energie_rem < 0
      can_cut = false
      energie_rem = 0
    end

   if energie_rem > 100
     energie_rem = 100
   end

end #end of define "can_cut"

#------------------------------------------------------------------------------#
#-----Define what appens if the player perform an action-----------------------#
#------------------------------------------------------------------------------#
def cut_tree
 cut_tree = false
 if $cut_tree = true
   NUKA::SELF_SWITCH[key] = "C"
   $game_actors[item_id] = @logs_ID
   cut_tree = false
 end
end


#------------------------------------------------------------------------------#
#----Define the woodcutting lvl------------------------------------------------#
#------------------------------------------------------------------------------#

#----Compute the XP gain-------------------------------------------------------#
def compute_wc_xp
((@logs_number * @logs_type)/2) * $tree_type = @wc_xp_gain
woodcutting_xp += @wc_xp_gain
@wc_xp_gain = 0
end
#----Compute the next lvl------------------------------------------------------#

def wc_next_lvl
 if @old_wc_lvl != woodcutting_lvl
 @i * 1.75
    woodcutting_lvl + @i = @wc_next_lvl.integer
 end
end
#----Compute the user lvl------------------------------------------------------#

def comp_woodcutting_lvl
 if woodcutting_xp >= @wc_next_level
   woodcutting_lvl += 1
   end

 if @old_wc_lvl != woodcutting_lvl
    @old_wc_lvl = woodcutting_lvl
  end

end

def conditions

#---If the woodcutting lvl is under 100, you can gain woodcutting experience---#
   if woodcutting_lvl < 100
     can_gain_wc_exp = true
   end

#-----If the woodcutting lvl is 100, you can't gain woodcutting experience-----#
   if woodcutting_lvl = 100
     can_gain_wc_exp = false
   end

#----If the woodcutting lvl is less or equal 0, set it to 1--------------------#
   if woodcutting_lvl <= 0
     woodcutting_lvl = 1
   end

#----If the woodcutting lvl is more than to 100, set it to 100-----------------#
   if woodcutting_lvl > 100
      woodcutting_lvl = 100
    end
#----If the player cctt variables is equal or greater to 1, -------------------#
#----player can cut tree type 1------------------------------------------------#

if $tree_type = 1
 if @cctt >= 1
   can_cut = true
 end

else if $tree_type = 2
 if @cctt >= 2
   can_cut = true
 end

else if $tree_type = 3
 if @cctt >= 3
   can_cut = true
 end

else if $tree_type = 4
 if @cctt >= 4
   can_cut = true
 end

else if $tree_type = 5
 if @cctt >= 5
   can_cut = true
 end

else if $tree_type = 6
 if @cctt >= 6
   can_cut = true
 end

else if $tree_type = 7
 if @cctt >= 7
   can_cut = true
 end

else if $tree_type = 8
 if @cctt >= 8
   can_cut = true
 end

else if $tree_type = 9
 if @cctt >= 9
   can_cut = true
 end

else if $tree_type = 10
 if @cctt = 10
   can_cut = true
 end


else
 can_cut = false
end

end # end of define conditions method
#------------------------------------------------------------------------------#
#----Define what appens if the player lvl is equal to X------------------------#
#------------------------------------------------------------------------------#


#-----------------------------CASE BLOCK---------------------------------------#
if can_cut = true
 # If the player woodcutting level is 1 to 9...
case $woodcutting_level
 when 1 [1...9]
 @cctt = 1
 cut_tree = true
end

case $woodcutting_level
 when 2 [10...19]
 @cctt = 2
 cut_tree = true    
end

case $woodcutting_level
 when 3 [20...29]
 @cctt = 3
 cut_tree = true    
end

case $woodcutting_level
 when 4 [30...39]
 @cctt = 4
 cut_tree = true   
end

case $woodcutting_level
 when 5 [40...49]
 @cctt = 5
 cut_tree = true   
end 

case $woodcutting_level
 when 6 [50...59]
 @cctt = 6
 cut_tree = true
end

case $woodcutting_level
 when 7 [60...69]
 @cctt = 7
 cut_tree = true
end

case $woodcutting_level
 when 8 [70...79]
 @cctt = 8
 cut_tree = true
end

case $woodcutting_level
 when 9 [80...89]
 @cctt = 9
 cut_tree = true 
end

case $woodcutting_level
 when 10 [90...100]
 @cctt = 10
 cut_tree = true
end

end #end of the if statement

#------------------------------------------------------------------------------#
#-----------------------End of the block and class-----------------------------#
#------------------------------------------------------------------------------#
end #class woodcutting end
$Woodcutting.new

 

 

:alright:

 

YOU CAN'T FINISH IT AND REPOST IT ON OTHER WEBSITE. :nono4:

YOU NEED MY PERMISSION. But you can help me. It's my first script.

 

And, wait when I'll have finish. ;)

 

 

 

I don't know why but, the last line of code bug the script with or without "Woodcutting.new"

Edited by NuKa_BuBble

Share this post


Link to post
Share on other sites
  • 0

Lol, you didn't need to post the entire script, but right away i see what you are TRYING to do exactly so it helps. (Don't worry, I won't take your idea/mess with your script/etc.)

 

Anyways, I'll see if I can help you and give you some pointers.

 

Firstly, I see you use alot of global variables (ex. $variable_name)

I would HIGHLY suggest you avoid using global variables as MUCH as possible. Global variables are accessible from anywhere in the game, and use up sometimes unnecessary memory. as a rule of thumb, if you do not need to access a variable outside an object, make an instance variable (ex. @variable_name)

 

Here is some reading on ruby variables to help you out:

http://www.techotopia.com/index.php/Ruby_Variable_Scope

 

Next, I would like to touch on some logical errors in your code. In all your if statements that check if something is equal to something, you use the assignment operator (=) when you should be using the equality comparison operator (==)

ex.

if energie_rem = 0
 can_cut = false
end

should be

if energie_rem == 0
 can_cut = false
end

Currently, your if statement assigns 0 to energie_rem (which will always return "true" thus, the next line of code WILL ALWAYS execute, making can_cut false)

 

Also, if checking if a variable is equal to true or false, you do not need to use the equality operator

ex.

if variable == true
 # Code
end

can be

if variable
 # Code
end

to check for false you can use the not (!) logical operator

ex.

if !variable
 #code
end

 

Also, you should use double sided if statements over stacked if statements when possible, this will use much less computing power (for the most part)

Also, any method that should return a value should return a value. If there is no return statement, then 'nil' is returned (I might be wrong, but I am pretty sure).

ex. ( I will use your can_cut method as an example, I have changed it to return a value as well as changed it to multi-sided if statement as opposed to stacked if statements and simplified some of the logic)

def can_cut

 if $data_actors[weapon_id] == NUKA::WOODCUTTING_WPN_ID && $job_learn
   can_cut = true
 else
   return false # If the $job_learn is false or they do not have the right weapon, then they cannot cut
 end

#----If you are out of energie, you can't cut----------------------------------#
   if energie_rem == 0
     return false
   elsif energie_rem < 0
     energie_rem = 0
     return false
   elsif energie_rem > 100
     energie_rem = 100
   end

  return can_cut # Return whether the player can cut or not

end #end of define "can_cut"

 

You could actually simplify this even moreso:

 

def can_cut
 # returns the result of the weapon equal to the correct id AND job_learn AND energie_rem greater than 0
 # if ALL of these are TRUE, the result is TRUE, and therefore the player can_cut.
 return ($data_actors[weapon_id] == NUKA::WOODCUTTING_WPN_ID && $job_learn && energie_rem > 0)
end #end of define "can_cut"

 

Also, I would like to mention that

$data_actors[weapon_id] doesn't make any sense. This is using weapon_id (a local variable which has not been initialized, and thus "nil") within the $data_actors global hash variable, which contains all the actor data from the database. $data_actors[nil] is always going to be a nil value.

 

what you are probably looking for is the party leader's current weapon, to get this use: $game_party.actors[0].weapon_id

 

Also, be careful when trying to assign a literal to a variable:

 @logs_type = A

this will look for the constant variable named A, which does not exist, so therefore @logs_type will be nil in this statement. If you want to set it to the letter A use:

@logs_type = "A"

 

The last thing I want to touch on, is your use of the "case" statement.

 

case statments, can be merged:

ex:

case $woodcutting_level
when 1
 #do this
when 2
 # do this
when 3
 # do this
end

 

also, what you have at the end there will not work

 when 1 [1...9] 

i am assuming you are checking for the level from 1-9?

 

use:

case $woodcutting_level
when 1..9 # 1 - 9 inclusive
 # Do this
when 10..19 # 10-19 inclusive
 # Do this
end

etc.

 

Also, be careful when using ranges (number...number or number..number)

... is range EXCLUSIVE ex. (1...5 is 1, 2, 3, 4)

.. is range INCLUSIVE ex. (1..5 is 1, 2, 3, 4, 5)

 

Ruby Ranges:

http://www.techotopia.com/index.php/Ruby_Ranges

 

also, you may find these useful:

Ruby if statements : http://www.howtogeek.com/howto/programming/ruby/ruby-if-else-if-command-syntax/

ruby case statements : http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/

 

Sorry for the novel, but I hope this helps. Learning to script can be a VERY daunting task, especially if you are learning it on your own and have no experience in programming. Good luck, if you need any further clarification/help, let me know.

 

EDIT: I forgot to mention, that last bit you have:

 $Woodcutting.new

is an invalid statement.

$ is the global variable indicator, and .new is ONLY used when initializing a class/object.

$variable = Woodcutting.new makes sense, but what you have now will produce errors.

Share this post


Link to post
Share on other sites
  • 0

:alright: Nice. I'll have 3 days for that. I'll edit it and finish it. Thank you, that will be useful.

 

Oh, and, it's not a novel, it's an helpful text to help a new sympatic guy in Ruby... and yes, it's a daunting task but, it's by scripting that'll be a scripter. :haha:

 

:yes:

 

Oh, and thank for the links. That'll help me to perfection my art. :sweatdrop:

 

Do you have a link about return, HUD, windows and random? And how can I give an item to the player? It's something like: $game_party.actors.gain.item_id?

HUD like the HP on this screenshot:

 

 

x2.jpg

 

Edited by NuKa_BuBble

Share this post


Link to post
Share on other sites
  • 0

I have another error in my script if someone can check for that... :alright:

 

 

################################################################################
#                            Wood cutting system                               #
#                                                                              #
#    By: NuKa_BuBble                                                           #
#    Version: 1.0                                                              #
#    Started: 29/08/2011                                                       #
#                                                                              #
#    You can find me on these websites:                                        #
#    http://gameface101.playogame.com/                                         #
#    http://www.rmxpunlimited.net                                              #
#                                                                              #
#                                                                              #
################################################################################
#                                                                              #
#                        No Graphics needed                                    #
#                                                                              #
################################################################################
#                                                                              #
#                              Instructions                                    #
#                                                                              #
#                  In an event, add this part of script                        #
#                      if the player learned the job                           #
#                        $wc_job_learn = true                                  #
#                                                                              #
#                        Call the script with                                  #
#                          $Woodcutting.new                                    #
#                                                                              #
################################################################################



#------------------------------------------------------------------------------#
#------------------------------- NUKA module ----------------------------------#
#------------------------------------------------------------------------------#

   module NUKA
#-------------Self Switch------------------------------------------------------#
     SELF_SWITCH = $game_self_switches
#-------------Woodcutting Stats------------------------------------------------#
     woodcutting_exp = 0
     woodcutting_lvl = 1
     energie_rem = 100

#-------------The tools for woodcutting----------------------------------------#
     WOODCUTTING_WPN_ID
     {
     6, 7
     }
#-------------Other------------------------------------------------------------#
   can_gain_wc_exp = true
   $wc_job_learn = false

   end

#------------------------------------------------------------------------------#
#---------------------------- End of the module -------------------------------#
#------------------------------------------------------------------------------#




#------------------------------------------------------------------------------#
#-------------------------- Class Woodcutting ---------------------------------#
#------------------------------------------------------------------------------#
class Woodcutting

#------------------------------------------------------------------------------#
#                              Initialize                                      #
#------------------------------------------------------------------------------#
   def initialize
     @logs_number = 0

     @logs_ID = $game_party.actors[0].item_id

     @old_wc_lvl = 1
     @wc_xp_gain
     @wc_next_lvl
     @i = 15
     @random = false

   # If the logs type = to "A",
   #the amount of gain xp is multiplied by the logs number and divided by 2.
     @logs_type = {10, 5, 4, 3, 2, 1.5}
     @logs_type = 0

   # cctt means "Can cut tree type"
   # DO NOT TOUCH THIS PART OF CODE!
   # Set the tree type that can be cut in the "CASE BLOCK"
   @cctt = 1

    tree_type = {
   #(Value = tree_type) => item_ID
   #The value is use for the xp multiplication
   #Here, you add different type of tree for different logs.
     1 => 100,
     2 => 101,
     3 => 102,
     4 => 103,
     5 => 104,
     6 => 105,
     7 => 106,
     8 => 107,
     9 => 108,
     10 => 109
     }

   end #end of define "initialize"

#------------------------------------------------------------------------------#
#------Define woodcutting stats------------------------------------------------#
#------------------------------------------------------------------------------#

   #define the tree type
   def tree_type
   v = tree_type[@logs_ID]
   n = v != nil ? v : v == nil ? 0 : 0
   return n
   end

   #define the woodcutting lvl
   def woodcutting_lvl
     NUKA::woodcutting_lvl = woodcutting_lvl
     woodcutting_lvl = 1
   end

   #define the woodcutting xp
   def woodcutting_exp
     NUKA::woodcutting_exp = woodcutting_xp
     woodcutting_xp = 0
   end

   #define the woodcutting energie
   def energie_rem
     NUKA::energie_rem = energie_rem
     energie_rem = 100
   end

#------------------------------------------------------------------------------#
#-----Define if the player can cut---------------------------------------------#
#------------------------------------------------------------------------------#

   def can_cut
     #if the player energie is more than 100, set the energie to 100.
     #else if the energie is under 0, set it to 0
     if energie_rem > 100
       energie_rem = 100
     else if energie_rem < 0
       energie_rem = 0
     end

# returns the result of the weapon equal to the correct id AND job_learn 
# AND energie_rem greater than 0 AND cctt is greater or equal to tree_type
# if ALL of these are TRUE, the result is TRUE, and therefore the player can_cut
     if ($game_party.actors[0].weapon_id == NUKA::WOODCUTTING_WPN_ID && $wc_job_learn && energie_rem > 0 && @cctt >= tree_type)
       can_cut = true
     else
       return false
     end

   end #end of define "can_cut"

   def help
     if can_cut == false
         if ($game_party.actors[0].weapon_id == NUKA::WOODCUTTING_WPN_ID) == false
           print "You need to be equip with a woodcutting weapon."
         end

         if $wc_job_learn == false
           print "You've not learned the job."
         end

         if energie_rem == 0
           print "You don't have enought energie."
         end

         if (@cctt >= tree_type) == false
           print "You don't have the woodcutting level."
         end
       end
   end

#------------------------------------------------------------------------------#
#-----Define what appens if the player perform an action-----------------------#
#------------------------------------------------------------------------------#
   def cut_tree
     if cut_tree == true
       if NUKA::SELF_SWITCH["C"] != true
       NUKA::SELF_SWITCH[key] = "C"
       $game_party.actors[0].item_id = @logs_ID
       cut_tree = false
       end
     end
   end


#------------------------------------------------------------------------------#
#----Define the woodcutting lvl------------------------------------------------#
#------------------------------------------------------------------------------#

#----Compute the XP gain-------------------------------------------------------#
   def compute_wc_xp
    ((@logs_number * @logs_type)/2) * tree_type = @wc_xp_gain
    woodcutting_xp += @wc_xp_gain
    @wc_xp_gain = 0
    @logs_type = 0
    @logs_number = 0
   end
#----Compute the next lvl------------------------------------------------------#

   def wc_next_lvl
     if @old_wc_lvl != woodcutting_lvl
     @i * 1.75
       woodcutting_lvl + @i = @wc_next_lvl.integer
     end
   end
#----Compute the user lvl------------------------------------------------------#

   def comp_woodcutting_lvl
     if woodcutting_xp >= @wc_next_level
       woodcutting_lvl += 1
       end

     if @old_wc_lvl != woodcutting_lvl
       @old_wc_lvl = woodcutting_lvl
     end

   end

   def conditions

#---If the woodcutting lvl is between 1 and 100, ------------------------------#
#---you can gain woodcutting experience----------------------------------------#
       if woodcutting_lvl < 100 && woodcutting_lvl >= 1
         can_gain_wc_exp = true
       else
         return false
       end

#----If the woodcutting lvl is less or equal 0, set it to 1--------------------#
#----Else if the woodcutting lvl is more than to 100, set it to 100------------#
       if woodcutting_lvl <= 0
         woodcutting_lvl = 1
       else if woodcutting_lvl > 100
         woodcutting_lvl = 100
       end
   end # end of define conditions method
#------------------------------------------------------------------------------#
#----Define what appens if the player lvl is equal to X------------------------#
#------------------------------------------------------------------------------#
 if @random == true
   def gain
     if woodcutting_lvl >= 1 && woodcutting_lvl < 20
     @logs_number + (rand(10) + 1)
      $game_party.gain_item(tree_type, @log_number) 

     else if woodcutting_lvl >= 20 && woodcutting_lvl < 40
     @logs_number + (rand(10) + 2)
      $game_party.gain_item(tree_type, @log_number) 

     else if woodcutting_lvl >= 40 && woodcutting_lvl < 60
     @logs_number + (rand(10) + 3)
      $game_party.gain_item(tree_type, @log_number) 

     else if woodcutting_lvl >= 60 && woodcutting_lvl < 80
     @logs_number + (rand(10) + 4)
      $game_party.gain_item(tree_type, @log_number) 

     else if woodcutting_lvl >= 80 && woodcutting_lvl <= 100
     @logs_number + (rand(10) + 5)
      $game_party.gain_item(tree_type, @log_number) 
     end
   end # end of method gain

   def logs_type_random
   while @logs_type == 0
     if rand(100) == 0 # 1 in 100 chance
       @logs_type = 10
     else if rand(50) == 0 # 1 in 50 chance
       @logs_type = 5
     else if rand(40) == 0 # 1 in 40 chance
       @logs_type = 4
     else if rand(30) == 0 # 1 in 30 chance
       @logs_type = 3
     else if rand(20) == 0 # 1 in 20 chance
       @logs_type = 2
     else if rand(5) == 0
       @logs_type = 1.5
     end
   end # end of while
 end # end of method logs_type
   @random = false
 end # end of if @random
#-----------------------------CASE BLOCK---------------------------------------#
   if can_cut == true
     # If the player woodcutting level is 1 to 9...
   case woodcutting_lvl
     when 1..9
     @cctt = 1
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 10..19
     @cctt = 2
     cut_tree = true
     @random = true
     end

   case woodcutting_lvl
     when 20..29
     @cctt = 3
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 30..39
     @cctt = 4
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 40..49
     @cctt = 5
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 50..59
     @cctt = 6
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 60..69
     @cctt = 7
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 70..79
     @cctt = 8
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 80..89
     @cctt = 9
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 90..100
     @cctt = 10
     cut_tree = true
     @random = true
   end

   end #end of the if statement

#------------------------------------------------------------------------------#
#-----------------------End of the block and class-----------------------------#
#------------------------------------------------------------------------------#
end #class woodcutting end
   $woodcutting_system = $Woodcutting.new

 

 

 

 

 

What I need to do after it's make the player gain logs (@logs_ID) and add logs number (@logs_number) choose at random. ( method is before the "case block")

Edited by NuKa_BuBble

Share this post


Link to post
Share on other sites
  • 0

Hey again,

 

Glad to help where I can :alright:

 

For the return statement, here is a link about ruby methods (return is a part of ruby methods, so naturally information about return statements is always coupled with method information)

http://www.tutorialspoint.com/ruby/ruby_methods.htm

 

It's hard to find actual documentation/info for the rand() function in ruby, this was the best I could find:

http://rubylearning.com/satishtalim/ruby_random_numbers.html

 

As for the HUD, and windows; The problem with RPG Maker scripting (window is part of RGSS, rpg maker's game class library, NOT part of ruby) is that most info about the RGSS classes are just made by users rather than those who made the software. The best place to learn about windows would be the RPG Maker XP help manual. Just search "Window" and it will give you detailed information on each method + attribute.

As for tutorials on them, it is hard to find quality tutorials, but these might help:

http://www.rmxpunlimited.net/forums/topic/100-ultimate-rgss-tutorials-collection/

 

For HUDs, it will be HARD to find tutorials on making one as to create a hud, its a combination of using windows or sprites, drawing information on them and refreshing/updating when necessary. The best way to learn how to make a HUD would probably be to look over HUD scripts made by other scripters and to see how they did it for your own inspiration. If you'd like I could make up a simple HUD script for you to look over.

 

To give the player an item

 $game_party.gain_item(item_id, n) 

item_id being the id # of the item in the database

n being the quantity to give the player.

 

As for what you are trying to do now, if @logs_ID is the ID of an item in the database, after setting a random number to @logs_number just call this:

 $game_party.gain_item(@logs_ID, @log_number) 

Share this post


Link to post
Share on other sites
  • 0

Thank you again :biggrin_002: but, for the error, did you find from where it come? I read, I read but I don't find. :shifty:

 

And do you have a time control tut?

Edited by NuKa_BuBble

Share this post


Link to post
Share on other sites
  • 0

What error message did it give you? If there was an error (in most cases, unless it is a logical error) rpg maker should have given you a somewhat cryptic message and a line number.

 

To be honest, there are still a few errors I see in your code, and unfortunately I am only on a short lunch for work right now; so I won't be able to give you a detailed run through at the moment; but in a couple of hours I will be home for good and can help you a bit more.

 

As for time control tutorial, what do you mean by time control? Do you mean like controlling how long for something to happen etc?

 

Let me know what you mean exactly by time control, and I will help explain what you can do :)

 

Anyways, sorry but I gotta run for now.

 

Either send me a PM or even post here if you want.

Share this post


Link to post
Share on other sites
  • 0

While I did use .inject which can be a bit hard to understand the much more important part is the way I used an uniform distribution function to implement a biased distribution. This is not specific to Ruby or RGSS.

 

First let me go through the problems with your current approach:

def logs_type_random
 while @logs_type == 0
   if rand(100) == 0 # 1 in 100 chance
     @logs_type = 10
   else if rand(50) == 0 # 1 in 50 chance
     @logs_type = 5
   else if rand(40) == 0 # 1 in 40 chance
     @logs_type = 4
   else if rand(30) == 0 # 1 in 30 chance
     @logs_type = 3
   else if rand(20) == 0 # 1 in 20 chance
     @logs_type = 2
   else if rand(5) == 0
     @logs_type = 1.5
   end
 end # end of while
end # end of method logs_type

 

Let me start with some syntactic sugar advice to prevent the syntax errors you would otherwise get.

Use elsif instead of else if as you would otherwise have to put all the extra ends you are currently missing which is pretty tedious.

Doing that the code will look like this:

def logs_type_random
 while @logs_type == 0
   if rand(100) == 0 # 1 in 100 chance
     @logs_type = 10
   elsif rand(50) == 0 # 1 in 50 chance
     @logs_type = 5
   elsif rand(40) == 0 # 1 in 40 chance
     @logs_type = 4
   elsif rand(30) == 0 # 1 in 30 chance
     @logs_type = 3
   elsif rand(20) == 0 # 1 in 20 chance
     @logs_type = 2
   elsif rand(5) == 0
     @logs_type = 1.5
   end
 end # end of while
end # end of method logs_type

 

You have noticed that there are issues with the way you choose the @logs_type because of the loop.

It is not a nice way do to it. There is a big chance that no log type is chosen in the if branch, in fact it's 69.5% with 3 significant digits.

Sure, after 15 iterations there is less than 0.5% of no log type has been chosen, but there is always a chance of it taken a long time. There might also be issues with the pseudo-random number generator which increases the chance of many iterations and there may also be cycles where it never completes.not In practice though speed is probably not a problem. That the actual percentage is different from what you think is.

 

I did some millions of calls to the method and with two significant digits here were the chance of each log type being chosen:

10 => 3.3 %

5 => 6.5 %

4 => 8.0 %

3 => 10 %

2 => 15 %

1.5 => 57 %

 

It may of course differ now and then, but the law of big numbers means that it will very unlikely be a big difference.

You can use my weighted_random method which ensures only one rand() call is needed.

Here's an example where I have:

1 in 100 chance of getting 10

1 in 50 chance of getting 5

1 in 40 chance of getting 4

1 in 30 chance of getting 3

1 in 20 chance of getting 2

517 in 600 chance of getting 1.5 (approximately 86%)

 

The reason for 517 is simple because that was the remainder. (I return the number rather than assigning it to a specific variable)

def logs_type_random
 i = weighted_random([6, 12, 15, 20, 30, 517])
 case i
 when 0
   return 10
 when 1
   return 5
 when 2
   return 4
 when 3
   return 3
 when 4
   return 2
 when 5
   return 1.5
 end
end

 

I hope it helps you understand this random thing better ^_^

 

*hugs*

Share this post


Link to post
Share on other sites
  • 0

Nice! It's more constructive than just shoot a code. :sweatdrop:

 

Now I understand what you did but, just 1 question. What's .inject do? :huh:

 

And are you sure that method return the logs_type value?

 

I wrote elseif... I'll fix that later. :haha:

It's done.

 

 

The script is edited now:

 

################################################################################
#                            Wood cutting system                               #
#                                                                              #
#    By: NuKa_BuBble                                                           #
#    Version: 1.0                                                              #
#    Started: 29/08/2011                                                       #
#                                                                              #
#    You can find me on these websites:                                        #
#    http://gameface101.playogame.com/                                         #
#    http://www.rmxpunlimited.net                                              #
#                                                                              #
#                                                                              #
################################################################################
#                                                                              #
#                        No Graphics needed                                    #
#                                                                              #
################################################################################
#                                                                              #
#                              Instructions                                    #
#                                                                              #
#                  In an event, add this part of script                        #
#                      if the player learned the job                           #
#                        $wc_job_learn = true                                  #
#                                                                              #
#                        Call the script with                                  #
#                          $Woodcutting.new                                    #
#                                                                              #
################################################################################



#------------------------------------------------------------------------------#
#------------------------------- NUKA module ----------------------------------#
#------------------------------------------------------------------------------#

   module NUKA
#-------------Self Switch------------------------------------------------------#
     SELF_SWITCH = $game_self_switches
#-------------Woodcutting Stats------------------------------------------------#
     woodcutting_exp = 0
     woodcutting_lvl = 1
     energie_rem = 100

#-------------The tools for woodcutting----------------------------------------#
     WOODCUTTING_WPN_ID
     {
     6, 7
     }
#-------------Other------------------------------------------------------------#
   can_gain_wc_exp = true
   $wc_job_learn = false

   end

#------------------------------------------------------------------------------#
#---------------------------- End of the module -------------------------------#
#------------------------------------------------------------------------------#




#------------------------------------------------------------------------------#
#-------------------------- Class Woodcutting ---------------------------------#
#------------------------------------------------------------------------------#
class Woodcutting

#------------------------------------------------------------------------------#
#                              Initialize                                      #
#------------------------------------------------------------------------------#
   def initialize
     @logs_number = 0

     @logs_ID = $game_party.actors[0].item_id

     @old_wc_lvl = 1
     @wc_xp_gain
     @wc_next_lvl
     @i = 15
     @random = false

   # If the logs type = to "A",
   #the amount of gain xp is multiplied by the logs number and divided by 2.
     @logs_type = {10, 5, 4, 3, 2, 1.5}
     @logs_type = 0
     logs_type_random = @logs_type

   # cctt means "Can cut tree type"
   # DO NOT TOUCH THIS PART OF CODE!
   # Set the tree type that can be cut in the "CASE BLOCK"
   @cctt = 1

    tree_type = {
   #(Value = tree_type) => item_ID
   #The value is use for the xp multiplication
   #Here, you add different type of tree for different logs.
     1 => 100,
     2 => 101,
     3 => 102,
     4 => 103,
     5 => 104,
     6 => 105,
     7 => 106,
     8 => 107,
     9 => 108,
     10 => 109
     }
     a = 10
     b = 5

   end #end of define "initialize"

#------------------------------------------------------------------------------#
#------Define woodcutting stats------------------------------------------------#
#------------------------------------------------------------------------------#

   #define the tree type
   def tree_type
   v = tree_type[@logs_ID]
   n = v != nil ? v : v == nil ? 0 : 0
   return n
   end

   #define the woodcutting lvl
   def woodcutting_lvl
     NUKA::woodcutting_lvl = woodcutting_lvl
     woodcutting_lvl = 1
   end

   #define the woodcutting xp
   def woodcutting_exp
     NUKA::woodcutting_exp = woodcutting_xp
     woodcutting_xp = 0
   end

   #define the woodcutting energie
   def energie_rem
     NUKA::energie_rem = energie_rem
     energie_rem = 100
   end

   def energie
       if woodcutting_lvl > 1
         if energie_rem > 100 + a
         energie_rem = 100 + a
         elsif energie_rem < 0
         energie_rem = 0
         end
         if woodcutting_lvl >= 50
         energie_rem = (100 - b) + a
         elsif woodcutting_lvl > 70
         energie_rem = a
         end

     elsif woodcutting_lvl == 1
       energie_rem = 100
       if energie_rem < 0
       energie_rem = 0
       end
     end
   end

#------------------------------------------------------------------------------#
#-----Define if the player can cut---------------------------------------------#
#------------------------------------------------------------------------------#

 def can_cut

# returns the result of the weapon equal to the correct id AND job_learn 
# AND energie_rem greater than 0 AND cctt is greater or equal to tree_type
# if ALL of these are TRUE, the result is TRUE, and therefore the player can_cut
       if ($game_party.actors[0].weapon_id == NUKA::WOODCUTTING_WPN_ID && $wc_job_learn && energie_rem > 0 && @cctt >= tree_type)
       can_cut = true
       else
       return false
       end

 end #end of define "can_cut"

   def help
     if can_cut == false
         if ($game_party.actors[0].weapon_id == NUKA::WOODCUTTING_WPN_ID) == false
           print "You need to be equip with a woodcutting weapon."
         end

         if $wc_job_learn == false
           print "You've not learned the job."
         end

         if energie_rem == 0
           print "You don't have enought energie."
         end

         if (@cctt >= tree_type) == false
           print "You don't have the woodcutting level."
         end
       end
   end

#------------------------------------------------------------------------------#
#-----Define what appens if the player perform an action-----------------------#
#------------------------------------------------------------------------------#
   def cut_tree
     if cut_tree == true
       if NUKA::SELF_SWITCH["C"] != true
       NUKA::SELF_SWITCH[key] = "C"
       $game_party.actors[0].item_id = @logs_ID
       cut_tree = false
       end
     end
   end


#------------------------------------------------------------------------------#
#----Define the woodcutting lvl------------------------------------------------#
#------------------------------------------------------------------------------#

#----Compute the XP gain-------------------------------------------------------#
   def compute_wc_xp
    ((@logs_number * @logs_type_random)/2) * tree_type = @wc_xp_gain
    woodcutting_xp += @wc_xp_gain
    @wc_xp_gain = 0
    @logs_type = 0
    @logs_number = 0
   end
#----Compute the next lvl------------------------------------------------------#

   def wc_next_lvl
     if @old_wc_lvl != woodcutting_lvl
     @i * 1.75
       woodcutting_lvl + @i = @wc_next_lvl.integer
     end
   end
#----Compute the user lvl------------------------------------------------------#

   def comp_woodcutting_lvl
     if woodcutting_xp >= @wc_next_level
       woodcutting_lvl += 1
       a += 10
        if woodcutting_lvl >= 50 && woodcutting_lvl <= 71
         b += 5
       end
     end

     if @old_wc_lvl != woodcutting_lvl
       @old_wc_lvl = woodcutting_lvl
     end

   end

   def conditions

#---If the woodcutting lvl is between 1 and 100, ------------------------------#
#---you can gain woodcutting experience----------------------------------------#
       if woodcutting_lvl < 100 && woodcutting_lvl >= 1
         can_gain_wc_exp = true
       else
         return false
       end

#----If the woodcutting lvl is less or equal 0, set it to 1--------------------#
#----Else if the woodcutting lvl is more than to 100, set it to 100------------#
       if woodcutting_lvl <= 0
         woodcutting_lvl = 1
       elsif woodcutting_lvl > 100
         woodcutting_lvl = 100
       end
   end # end of define conditions method
#------------------------------------------------------------------------------#
#----Define what appens if the player lvl is equal to X------------------------#
#------------------------------------------------------------------------------#
def weighted_random(array)
 sum = array.inject {|sum, n| sum + n} 
 n = rand(sum)
 array.each_with_index do |i, index|
   return index if n < i
   n -= i
 end
end

 if @random == true
   def gain
     if woodcutting_lvl >= 1 && woodcutting_lvl < 20
     @logs_number + (rand(10) + 1)
      $game_party.gain_item(tree_type, @log_number) 

     elsif woodcutting_lvl >= 20 && woodcutting_lvl < 40
     @logs_number + (rand(10) + 2)
      $game_party.gain_item(tree_type, @log_number) 

     elsif woodcutting_lvl >= 40 && woodcutting_lvl < 60
     @logs_number + (rand(10) + 3)
      $game_party.gain_item(tree_type, @log_number) 

     elsif woodcutting_lvl >= 60 && woodcutting_lvl < 80
     @logs_number + (rand(10) + 4)
      $game_party.gain_item(tree_type, @log_number) 

     elsif woodcutting_lvl >= 80 && woodcutting_lvl <= 100
     @logs_number + (rand(10) + 5)
      $game_party.gain_item(tree_type, @log_number) 
     end
   end # end of method gain

   def logs_type_random
     i = weighted_random([6, 12, 15, 20, 30, 517])
       case i
       when 0
         return 10
       when 1
         return 5
       when 2
         return 4
       when 3
         return 3
       when 4
         return 2
       when 5
         return 1.5
       end
     end
 end # end of method logs_type
   @random = false
 end # end of if @random
#-----------------------------CASE BLOCK---------------------------------------#
   if can_cut == true
     # If the player woodcutting level is 1 to 9...
   case woodcutting_lvl
     when 1..9
     @cctt = 1
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 10..19
     @cctt = 2
     cut_tree = true
     @random = true
     end

   case woodcutting_lvl
     when 20..29
     @cctt = 3
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 30..39
     @cctt = 4
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 40..49
     @cctt = 5
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 50..59
     @cctt = 6
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 60..69
     @cctt = 7
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 70..79
     @cctt = 8
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 80..89
     @cctt = 9
     cut_tree = true
     @random = true
   end

   case woodcutting_lvl
     when 90..100
     @cctt = 10
     cut_tree = true
     @random = true
   end

   end #end of the if statement

#------------------------------------------------------------------------------#
#-----------------------End of the block and class-----------------------------#
#------------------------------------------------------------------------------#
end #class woodcutting end
   $woodcutting_system = $Woodcutting.new

 

 

*hugs* :biggrin_002:

Edited by NuKa_BuBble

Share this post


Link to post
Share on other sites
  • 0

HEY! I think it's the last error! I don't know if the script work (Something'll certainly not work) but, I worked hard on it! :clap: :jay: :lol: :king: :magictm: :dragonwant:

 

Error screenshot:

 

618310Woodcuttingscript.png

 

 

Script:

 

    ################################################################################
   #                            Wood cutting system                              #
   #                                                                              #
   #    By: NuKa_BuBble                                                          #
   #    Version: 1.0                                                              #
   #    Started: 29/08/2011                                                      #
   #                                                                              #
   #    You can find me on these websites:                                        #
   #    http://gameface101.playogame.com/                                        #
   #    http://www.rmxpunlimited.net                                              #
   #                                                                              #
   #                                                                              #
   ################################################################################
   #                                                                              #
   #                        No Graphics needed                                    #
   #                                                                              #
   ################################################################################
   #                                                                              #
   #                              Instructions                                    #
   #                                                                              #
   #                  In an event, add this part of script                        #
   #                      if the player learned the job                          #
   #                        $wc_job_learn = true                                  #
   #                                                                              #
   #                        Call the script with                                  #
   #                          $Woodcutting.new                                    #
   #                                                                              #
   ################################################################################



   #------------------------------------------------------------------------------#
   #------------------------------- NUKA module ----------------------------------#
   #------------------------------------------------------------------------------#

       module NUKA
   #-------------Self Switch------------------------------------------------------#
         SELF_SWITCH = $game_self_switches
   #-------------Woodcutting Stats------------------------------------------------#
         woodcutting_exp = 0
         woodcutting_lvl = 1
         energie_rem = 100
   #-------------Other------------------------------------------------------------#
       can_gain_wc_exp = true
       $wc_job_learn = false

       end

   #------------------------------------------------------------------------------#
   #---------------------------- End of the module -------------------------------#
   #------------------------------------------------------------------------------#




   #------------------------------------------------------------------------------#
   #-------------------------- Class Woodcutting ---------------------------------#
   #------------------------------------------------------------------------------#
   class Woodcutting

   #------------------------------------------------------------------------------#
   #                              Initialize                                      #
   #------------------------------------------------------------------------------#
       def initialize
         @logs_number = 0

         @logs_ID = $game_party.actors[0].item_id

         @old_wc_lvl = 1
         @wc_xp_gain
         @wc_next_lvl
         @i = 15
         @random = false

       # If the logs type = to "A",
       #the amount of gain xp is multiplied by the logs number and divided by 2.
         @logs_type = {10, 5, 4, 3, 2, 1.5}
         @logs_type = 0
         logs_type_random = @logs_type

       # cctt means "Can cut tree type"
       # DO NOT TOUCH THIS PART OF CODE!
       # Set the tree type that can be cut in the "CASE BLOCK"
       @cctt = 1

       $tree_type = {
       #(Value = tree_type) => item_ID
       #The value is use for the xp multiplication
       #Here, you add different type of tree for different logs.
         1 => 100,
         2 => 101,
         3 => 102,
         4 => 103,
         5 => 104,
         6 => 105,
         7 => 106,
         8 => 107,
         9 => 108,
         10 => 109
         }
         a = 10
         b = 5
         @can_cut = nil
   #-------------The tools for woodcutting----------------------------------------#
         WOODCUTTING_WPN_ID
         {
         6, 7
         }

       end #end of define "initialize"

   #------------------------------------------------------------------------------#
   #------Define woodcutting stats------------------------------------------------#
   #------------------------------------------------------------------------------#

       #define the tree type
       def tree_type
       v = $tree_type[@logs_ID]
       n = v != nil ? v : v == nil ? 0 : 0
       return n
       end

       #define the woodcutting lvl
       def woodcutting_lvl
         NUKA::woodcutting_lvl = woodcutting_lvl
         woodcutting_lvl = 1
       end

       #define the woodcutting xp
       def woodcutting_exp
         NUKA::woodcutting_exp = woodcutting_xp
         woodcutting_xp = 0
       end

       #define the woodcutting energie
       def energie_rem
         NUKA::energie_rem = energie_rem
         energie_rem = 100
       end

       def energie
           if woodcutting_lvl > 1
             if energie_rem > 100 + a
             energie_rem = 100 + a
             elsif energie_rem < 0
             energie_rem = 0
             end

             if woodcutting_lvl >= 50
             energie_rem = (100 - b) + a
             elsif woodcutting_lvl > 70
             energie_rem = a
             end

         elsif woodcutting_lvl == 1
           energie_rem = 100
           if energie_rem < 0
           energie_rem = 0
           end
         end
       end

   #------------------------------------------------------------------------------#
   #-----Define if the player can cut---------------------------------------------#
   #------------------------------------------------------------------------------#

     def can_cut
   # returns the result of the weapon equal to the correct id AND job_learn
   # AND energie_rem greater than 0 AND cctt is greater or equal to tree_type
   # if ALL of these are TRUE, the result is TRUE, and therefore the player can_cut
           if ($game_party.actors[0].weapon_id == WOODCUTTING_WPN_ID && $wc_job_learn && energie_rem > 0 && @cctt >= $tree_type)
           @can_cut = true
           else
           return false
           end

     end #end of define "can_cut"

       def help
         if @can_cut == false
             if ($game_party.actors[0].weapon_id == WOODCUTTING_WPN_ID) == false
               print "You need to be equip with a woodcutting weapon."
             end

             if $wc_job_learn == false
               print "You've not learned the job."
             end

             if energie_rem == 0
               print "You don't have enought energie."
             end

             if (@cctt >= $tree_type) == false
               print "You don't have the woodcutting level."
             end
           end
       end

   #------------------------------------------------------------------------------#
   #-----Define what appens if the player perform an action-----------------------#
   #------------------------------------------------------------------------------#
       def cut_tree
         if cut_tree == true
           if NUKA::SELF_SWITCH["C"] == false
           NUKA::SELF_SWITCH["C"] = true
           $game_party.actors[0].item_id = @logs_ID
           cut_tree = false
           end
         end
       end


   #------------------------------------------------------------------------------#
   #----Define the woodcutting lvl------------------------------------------------#
   #------------------------------------------------------------------------------#

   #----Compute the XP gain-------------------------------------------------------#
       def compute_wc_xp
       ((@logs_number * @logs_type_random)/2) * tree_type = @wc_xp_gain
       woodcutting_xp += @wc_xp_gain
       @wc_xp_gain = 0
       @logs_type = 0
       @logs_number = 0
       end
   #----Compute the next lvl------------------------------------------------------#

       def wc_next_lvl
         if @old_wc_lvl != woodcutting_lvl
         @i * 1.75
           woodcutting_lvl + @i = @wc_next_lvl.integer
         end
       end
   #----Compute the user lvl------------------------------------------------------#

       def comp_woodcutting_lvl
         if woodcutting_xp >= @wc_next_level
           woodcutting_lvl += 1
           a += 10
           if woodcutting_lvl >= 50 && woodcutting_lvl <= 71
             b += 5
           end
         end

         if @old_wc_lvl != woodcutting_lvl
           @old_wc_lvl = woodcutting_lvl
         end

       end # end of define comp_woodcutting_lvl

       def conditions

   #---If the woodcutting lvl is between 1 and 100, ------------------------------#
   #---you can gain woodcutting experience----------------------------------------#
           if woodcutting_lvl < 100 && woodcutting_lvl >= 1
             can_gain_wc_exp = true
           else
             return false
           end

   #----If the woodcutting lvl is less or equal 0, set it to 1--------------------#
   #----Else if the woodcutting lvl is more than to 100, set it to 100------------#
           if woodcutting_lvl <= 0
             woodcutting_lvl = 1
           elsif woodcutting_lvl > 100
             woodcutting_lvl = 100
           end
       end # end of define conditions method
   #------------------------------------------------------------------------------#
   #----Define what appens if the player lvl is equal to X------------------------#
   #------------------------------------------------------------------------------#
   def weighted_random(array)
     sum = array.inject {|sum, n| sum + n}
     n = rand(sum)
     array.each_with_index do |i, index|
       return index if n < i
       n -= i
   end

     if @random == true
       def gain
         if woodcutting_lvl >= 1 && woodcutting_lvl < 20
         @logs_number + (rand(10) + 1)
         $game_party.gain_item(tree_type, @log_number)

         elsif woodcutting_lvl >= 20 && woodcutting_lvl < 40
         @logs_number + (rand(10) + 2)
         $game_party.gain_item(tree_type, @log_number)

         elsif woodcutting_lvl >= 40 && woodcutting_lvl < 60
         @logs_number + (rand(10) + 3)
         $game_party.gain_item(tree_type, @log_number)

         elsif woodcutting_lvl >= 60 && woodcutting_lvl < 80
         @logs_number + (rand(10) + 4)
         $game_party.gain_item(tree_type, @log_number)

         elsif woodcutting_lvl >= 80 && woodcutting_lvl <= 100
         @logs_number + (rand(10) + 5)
         $game_party.gain_item(tree_type, @log_number)
         end
       end # end of method gain

       def logs_type_random
         i = weighted_random([6, 12, 15, 20, 30, 517])
           case i
           when 0
             return 10
           when 1
             return 5
           when 2
             return 4
           when 3
             return 3
           when 4
             return 2
           when 5
             return 1.5
           end
         end
     end # end of method logs_type
       @random = false
     end # end of if @random
   #-----------------------------CASE BLOCK---------------------------------------#
       if @can_cut == true
         # If the player woodcutting level is 1 to 9...
       case woodcutting_lvl
         when 1..9
         @cctt = 1
         cut_tree = true
         @random = true
       end

       case woodcutting_lvl
         when 10..19
         @cctt = 2
         cut_tree = true
         @random = true
         end

       case woodcutting_lvl
         when 20..29
         @cctt = 3
         cut_tree = true
         @random = true
       end

       case woodcutting_lvl
         when 30..39
         @cctt = 4
         cut_tree = true
         @random = true
       end

       case woodcutting_lvl
         when 40..49
         @cctt = 5
         cut_tree = true
         @random = true
       end

       case woodcutting_lvl
         when 50..59
         @cctt = 6
         cut_tree = true
         @random = true
       end

       case woodcutting_lvl
         when 60..69
         @cctt = 7
         cut_tree = true
         @random = true
       end

       case woodcutting_lvl
         when 70..79
         @cctt = 8
         cut_tree = true
         @random = true
       end

       case woodcutting_lvl
         when 80..89
         @cctt = 9
         cut_tree = true
         @random = true
       end

       case woodcutting_lvl
         when 90..100
         @cctt = 10
         cut_tree = true
         @random = true
       end

       end #end of the if statement

   #------------------------------------------------------------------------------#
   #-----------------------End of the block and class-----------------------------#
   #------------------------------------------------------------------------------#
   end #class woodcutting end
   $woodcutting = $Woodcutting.new

 

Edited by NuKa_BuBble

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...