Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Please help me with this

Im trying to make my first script after learning a bit RGSS.
It's a woodcutting script and I need to know a few things;

1) How do I add an item (to add the wood logs)
2) When I did:
Code:
if @wcexp >= 80 
   @wclvl += 1
it gives me an error about the ">" and the "+", what I did wrong?

Here is the whole script if you need to see it:
Code:
class Woodcutting
  attr_accessor :wclvl
  attr_accessor :wcexp
 def initialize
  @wclvl = 1 #The level
  @wcexp = 0 #The exp
 end
#--Leveling up-- 
 if @wcexp >= 80 
   @wclvl += 1
   p 'you leveled up at wc'
 end
#--The system--
 if wclvl <= 5
   x = rand(100)
  until x <= 30
   p 'you got logs' #add logs
   wcexp += 5
  end
 elsif wclvl <= 10
  x = rand(100)
  until x <= 40
   p 'you got logs' #add logs
   wcexp += 5
  end
 elsif wclvl <= 20
  x = rand(100)
  until x <= 50
   p 'you got logs' #add logs
   wcexp += 5
  end
 elsif wclvl <= 30
  x = rand(100)
  until x <= 60
   p 'you got logs' #add logs
   wcexp += 5
  end
 elsif wclvl <= 50
  x = rand(100)
  until x <= 70
   p 'you got logs' #add logs
   wcexp += 5
 end
end
end
 
1) To give the party an item/armor/weapon by script you can use this:
Code:
$game_party.gain_item(item_id, n)
$game_party.gain_armor(armor_id, n)
$game_party.gain_weapon(weapon_id, n)

And replace "item_id", "armor_id" and "weapon_id" with the id in the database.
And replace "n" with the number of items/armors/weapons you want to give the player.


2) You forgot to put your code inside a method.
Code:
def method # you can change "method" to something else that suits you.
  if @wcexp >= 80
    @wclvl += 1
  end
end

So the code should look something like this:
Code:
#==============================================================================
# ** Woodcutting
#------------------------------------------------------------------------------
#  This class performsthe woodcutting
#==============================================================================
class Woodcutting
  attr_accessor :wclvl
  attr_accessor :wcexp

  #--------------------------------------------------------------------------
  # * Initialization
  #--------------------------------------------------------------------------
  def initialize
    @wclvl = 1 #The level
    @wcexp = 0 #The exp
  end

  #--------------------------------------------------------------------------
  # * Method
  #--------------------------------------------------------------------------
  def method # You can change the name of this method to whatever you want.
    #--Leveling up-- 
    if @wcexp >= 80 
      @wclvl += 1
      p 'you leveled up at wc'
    end
    #--The system--
    if wclvl <= 5
      x = rand(100)
      until x <= 30
        p 'you got logs' #add logs
        wcexp += 5
      end
    elsif wclvl <= 10
      x = rand(100)
      until x <= 40
        p 'you got logs' #add logs
        wcexp += 5
      end
    elsif wclvl <= 20
      x = rand(100)
      until x <= 50
        p 'you got logs' #add logs
        wcexp += 5
      end
    elsif wclvl <= 30
      x = rand(100)
      until x <= 60
        p 'you got logs' #add logs
        wcexp += 5
      end
    elsif wclvl <= 50
      x = rand(100)
      until x <= 70
        p 'you got logs' #add logs
        wcexp += 5
      end
    end
  end
end

I hope you don't mind that i cleaned it up a bit. :P
Good luck! :thumb:

Over and out - Gando
 
thanks!
this is how the script looks now after I added enother varible that shows how many logs left on the tree:
Code:
#==============================================================================
# ** Woodcutting
#------------------------------------------------------------------------------
#  This class performsthe woodcutting
#==============================================================================
class Woodcutting
  attr_accessor :wclvl
  attr_accessor :wcexp
  attr_accessor :logsleft

  #--------------------------------------------------------------------------
  # * Initialization
  #--------------------------------------------------------------------------
  def initialize
    @wclvl = 1 #The level
    @wcexp = 0 #The exp
    @logsleft = 5 #Logs avalible
  end

  #--------------------------------------------------------------------------
  # * Method
  #--------------------------------------------------------------------------
  def method # You can change the name of this method to whatever you want.
    #--Leveling up-- 
    if @wcexp >= 80 
      @wclvl += 1
      p 'you leveled up at woodcutting'
      @wcexp = 0
    end
    #--The system--
    if @logsleft > 0
      if wclvl <= 5
      x = rand(100)
      until x <= 20
        p 'you got logs'
        $game_party.gain_item(24, 1)#add logs
        wcexp += 5
        logsleft -=1
      end
    elsif wclvl <= 10
      x = rand(100)
      until x <= 30
        p 'you got logs' 
        $game_party.gain_item(24, 1)#add logs
        wcexp += 5
        logsleft -=1
      end
    elsif wclvl <= 20
      x = rand(100)
      until x <= 40
        p 'you got logs' 
        $game_party.gain_item(24, 1)#add logs
        wcexp += 5
        logsleft -=1
      end
    elsif wclvl <= 30
      x = rand(100)
      until x <= 50
        p 'you got logs' 
        $game_party.gain_item(24, 1)#add logs
        wcexp += 5
        logsleft -=1
      end
    elsif wclvl <= 50
      x = rand(100)
      until x <= 60
        p 'you got logs' 
        $game_party.gain_item(24, 1)#add logs
        wcexp += 5
        logsleft -=1
      end
    elsif wclvl <= 60
      until x <= 70
        p 'you got logs' 
        $game_party.gain_item(24, 1)#add logs
        wcexp +=5
        logsleft -=1
      end
    end
  end
end
end
I have some more questions
1) How do I call this script through an event?
2) How I can change the graphic of the event through the script?
3) How do I show an 'in-game' messege
Im so noob with scripts @_@..
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top