Guest Access
Go to page : 1, 2, 3, 4, 5
The only one
The only one
The only one
profile
NuKa_BuBble
profile
Welcome in my first real script post!
Last edit: 11/10/11 at 19:27
Reason: Polish & fix bug
- Spoiler:
Description:
This script will allow players to cut tree. The self-switch C of the event is turn on when an action is perform. After, the player gain logs and xp at random.
NOTE:
If you find an error, let me know where. I'll fix it.
It's the first script made by myself.
Version 0.9
Special thank:
From http://gameface101.playogame.com
Special thank to G@MeF@Ce & mr_wiggles.
From http://www.rmxpunlimited.net
Special thank to kellessdee and Zeriab.
To add: I'll probably make more jobs and put them in a super jobs suite script with a place in the menu where you can check you're stats.
Graphics:
You don't need graphics but, it's more beautiful if you put one like this:
Put it in the character folder.
***The graphics are not placed equal . You'll need to do that.***
Last edit: 11/10/11 at 19:27
Reason: Polish & fix bug
- Spoiler:
- Code:
################################################################################
# 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_level = 1
energie_rem = 100
#-------------Other------------------------------------------------------------#
can_gain_wc_exp = true
$wc_job_learn = false
end
#------------------------------------------------------------------------------#
#---------------------------- End of the module -------------------------------#
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
#-------------------------- Class Woodcutting ---------------------------------#
#------------------------------------------------------------------------------#
class Woodcutting < Game_Party
#------------------------------------------------------------------------------#
# Initialize #
#------------------------------------------------------------------------------#
def initialize
@logs_number = 0
@logs_ID = $game_party.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 : 0
return n
end
#define the woodcutting lvl
def woodcutting_lvl
NUKA::woodcutting_level = 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
return ($game_party.actors[0].weapon_id == WOODCUTTING_WPN_ID && $wc_job_learn && energie_rem > 0 && @cctt >= tree_type)
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"] != 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 # 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
@cctt = (woodcutting_lvl / 10).ceil
cut_tree = true
@random = true
end
#------------------------------------------------------------------------------#
#-----------------------End of the block and class-----------------------------#
#------------------------------------------------------------------------------#
end #class woodcutting end
class Game_Party
attr_accessor :woodcutting_lvl
alias :woodcutting_init :initialize
def initialize
woodcutting_init
@lumbering = 0
@lumbering = woodcutting_lvl
end
end
The only one
Show Signature
EVENTALIST
EVENTALIST
EVENTALIST
profile
mr_wiggles
profile
Good start but i noticed a few errors.
You have a nice base, you should go back and revise.
- Too many global variables
- Misuse of the Hash class
- You wont be able to save your wood level when loading a game.
You have a nice base, you should go back and revise.
EVENTALIST
Show Signature
EVENTALIST
The only one
The only one
The only one
profile
NuKa_BuBble
profile
It's why I wrote: "I need to polish my script."
Maybe that will take more time than I said. I have 9 hours at school. I'm back at 6h, I can have the computer at max 9h pm...
And,
how I can save when I load?
how to use correctly the hash class? What's wrong with?
OH! and I need to learn more about complex randomization and I can't find any good tutorials about that!
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:...
Maybe that will take more time than I said. I have 9 hours at school. I'm back at 6h, I can have the computer at max 9h pm...
And,
how I can save when I load?
how to use correctly the hash class? What's wrong with?
OH! and I need to learn more about complex randomization and I can't find any good tutorials about that!
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:...
The only one
Show Signature
EVENTALIST
EVENTALIST
EVENTALIST
profile
mr_wiggles
profile
part of learning is trial and error, there is an example of the built in rand() function, just apply it to what you need to get the job done.
EVENTALIST
Show Signature
EVENTALIST
The only one
The only one
The only one
profile
NuKa_BuBble
profile
@mr_wiggles: I found how for the rand
For a number between 1 and 6:
For Character between level 1-9 :
And for chances, you can do this:
But the hash, I did'nt understand!
EDIT: Like that, that 'll be ok?
For a number between 1 and 6:
- Code:
rand(6) + 1 # 1 - 6 inclusive
rand(6) # 0 - 6 exclusive
rand(7) # 0 - 6 inclusive
For Character between level 1-9 :
- Code:
if woodcutting_lvl >= 1 && woodcutting_lvl <= 9
#give character ( rand(4) + 1 ) for the number of items
end
And for chances, you can do this:
- Code:
if rand(100) == 0 # 1 in 100 chance
#code
end
if rand(50) == 0 # 1 in 50 chance
#code
end
But the hash, I did'nt understand!
EDIT: Like that, that 'll be ok?
- Spoiler:
- ################################################################################
# Wood cutting system #
# #
# By: NuKa_BuBble #
# Version: 1.0 #
# Started: 29/08/2011 # #
# http://gameface101.playogame.com/ #
# # #
# #
################################################################################
# #
# 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 C is activated when a tree is cut--------------------#
SELF_SWITCH = $game_self_switches
SELF_SWITCH[key] = "C"
#-------------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
LOGS_ID =
{
#Here, you can add logs ID in the item database for defferent logs type.
100, #It's a normal log
101,
102,
103,
104,
105,
106,
107,
108,
109
}
$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
}
$job_learn = false
end
#------------------------------------------------------------------------------#
#---------------------------- End of the module -------------------------------#
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
#-------------------------- Class Woodcutting ---------------------------------#
#------------------------------------------------------------------------------#
class Woodcutting
#------------------------------------------------------------------------------#
# Initialize #
#------------------------------------------------------------------------------#
def initialize
@logs_gain = false
@logs_number
NUKA::LOGS_ID = $data[item_id]
@logs_ID = NUKA::LOGS_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 = {
A = 10,
B = 5,
C = 4,
D = 3,
E = 2,
F = 1.5
}
# (Can cut tree type)
# DO NOT TOUCH THIS PART OF CODE!
# Set the tree type that can be cut in the "CASE BLOCK"
@cctt = {}
end # end of initialize method
#--------------------------------------------------------------------------#
#------Define the tree type------------------------------------------------#
#--------------------------------------------------------------------------#
alias Woodcutting_logs_initialize initialize
def initialize(item_id)
Woodcutting_logs_initialize(item_id)
tree_type = 0
end
def tree_type
v = NUKA::$tree_type[@item_id]
n = v != nil ? v : v == nil ? 0 : 0
return n
end
The only one
Show Signature
EVENTALIST
EVENTALIST
EVENTALIST
profile
mr_wiggles
profile
What i ment with the hash is that its used to tie tow things together.
See here where you just have one thing, you should change it to an array.
Hash is used when you want to do something like:
cat => feline, dog => canine
dirt => earth, rain => water
its sorta used as a definition of what something is. This is useful for stuff like keyboard character mapping.
- Code:
{
#Here, you can add logs ID in the item database for defferent logs type.
100, #It's a normal log
101,
102,
103,
104,
105,
106,
107,
108,
109
}
See here where you just have one thing, you should change it to an array.
Hash is used when you want to do something like:
cat => feline, dog => canine
dirt => earth, rain => water
its sorta used as a definition of what something is. This is useful for stuff like keyboard character mapping.
EVENTALIST
Show Signature
EVENTALIST
The only one
The only one
The only one
profile
NuKa_BuBble
profile
Can I do something shorter than that?
- Code:
# 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
}
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
- Code:
#----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
The only one
Show Signature
EVENTALIST
EVENTALIST
EVENTALIST
profile
mr_wiggles
profile
SO you basically are checking to see if the players level is high enough to cut the tree?
why not something like this:
This way in an event for the tree you can just run a conditional branch command using the code feature and type can_cut?(wood_level) and then take it from there.
why not something like this:
- Code:
class interpreter
def can_cut?(wood_level)
return ($game_party.wood_cut_level >= wood_level)
end
end
This way in an event for the tree you can just run a conditional branch command using the code feature and type can_cut?(wood_level) and then take it from there.
EVENTALIST
Show Signature
EVENTALIST
The only one
The only one
The only one
profile
NuKa_BuBble
profile
I've edited the script recently. I'll use your trick later. Can you look it? I have an error at the last line with or without the "Woodcutting.new".
The only one
Show Signature
Administrator
Administrator
Administrator
profile
G@MeF@Ce
profile
wow Nuka - you pick up super quick!
at the rate you are learning, you'll be able to script on your own soon.
it's just a guess but try "$Woodcutting = true"
I'll make some time to actually test yours once I'm done with a few scripts that I'm currently working on...
keep up the great work!
I always say it
It's not what and how you start
it's when and the way you finish it ^,^
at the rate you are learning, you'll be able to script on your own soon.
it's just a guess but try "$Woodcutting = true"
I'll make some time to actually test yours once I'm done with a few scripts that I'm currently working on...
keep up the great work!
I always say it
It's not what and how you start
it's when and the way you finish it ^,^
Administrator
Show Signature
Go to page : 1, 2, 3, 4, 5