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.

Script problems... again...

Sorry for the indescriptive title, but I don't think if I'd written 'Beacon Script problems', you wouldn't been informed better ^_^

Anyway, I tried to make a Beacon script... and as it's the first time somebody attempts this (AFAIK), I'll explain it's purpose shortly:
Events on the map marked with a 'Beacon' comment have an opacity of 0 until the player comes near them. Depending on how close the main character gets, the opacity raises and becomes 255 if the player is above the object. If he gets further away, the opacity decreases again. Of course, this should work with multiple objects on a map simultaneously.

Well, that's the theory... my tries to get this thing to work ended like this:

PHP:
class Beacon
  #--------------------------------------------------------------------------
  attr_accessor :character
  #--------------------------------------------------------------------------
  def initialize(character=nil)
    @character = character
  end
  #--------------------------------------------------------------------------
  def main
    # checks for the comments inside the event
    if (character.is_a?(Game_Event) and character.list!=nil and
      character.list[0].code == 108 and 
      character.list[0].parameters == ["Beacon"])
      # checks for distance between player and event
      d=Math.sqrt(dx.abs**2+dy.abs**2)
      # changes the event's opacity relative to the distance
      character.opacity = [255-d*80,0].max
    end
  end
  #--------------------------------------------------------------------------
end

This is the first version which doesn't brings up any errors, but the events simply don't care about the script ^_^. I commented the 'action' lines for you guys so you can see what I was trying to do, but I have no clue how to go on from here... help would be very apprechiated... :D

Thanks in advance
 
Well, to be honest, I have no idea what it does... I've seen it several times like that in no-window classes, so I think it's just a initialization constant. In fact, I've copied the whole definition out of Retaime's reflection script ^_^ (I guess that's what the error is... 'character' is simply not defined... but Retaime didn't define it, too... O_o )
 
"super" finds the method of the same name in the parent class. For example:

Code:
class Parent_Class
  def initialize(argument)
    p 'Parent_Class Initialize'
  end
end

class Child_Class < Parent_Class
  def initialize
  p 'Child_Class Initialize'
    super(argument) # Call's Parent_Class's initialize method
  end
end

Child_Class.new

This would call both initialize methods.

And are you adding the "Beacon" characters in the setup method of Game_Map?
 
Ah, good thing to know... *deletes 'super'* ^_^

And I haven't done anything outside this script, everything I did besides the comment inside the event is in the first post.
Counter-question: Do I have to add anything in Scene_Map? :D
 
First you would need to create an instance of that class for each event that add that coment.
For that you would need an hash like
Code:
$beacon[id] = {}
id being the event id that add that comment on it.
You would need also a way to get the event id to that script.
In scene_map you would need to update that script
with:
Code:
for i in 0...999
next if $beacon[i] == nil
$beacon[i].main

If you neeed further help add me on msn chaosg1@hotmail.com

Edit: If you want a step by step tutorial I might do it, but it will take a while...
 
Sorry, I don't have MSN... but shouldn't it be Chaosg1? ^_^

And I do need further help, as I have no idea on where to place these script pieces... well, besides the last one what'd give me nothing without the previous stuff :P
Fir the event ID, I've seen scripts that worked with a comment in the event alone, not needing any event ID input...
 
Working on it... I will post it here when I am finish.
Edit: But if anyone does this first than me fell free to post it...

EDIT: Srry The Edit Button Wasn't Working for me, So i double posted, I have reported my self lol
Just finished it.
I have commented the script so that you understand what's going on:
Code:
#============================================================================
 # Beacon Script
 #--------------------------
 # Version 1.0
 # Author :Chaosg1
 # Requested by: BlueScope
 # 08-26-2006
 #=============================================================================
 #===============================
 #** Class Event 
 #===============================
 class Game_Event < Game_Character
    attr_reader :id
    attr_accessor :opacity
    attr_accessor :through
    #===============
    #* Alias
    #===============
    alias chaosg1_update update
    #===============
    #returns name
    #===============
    def name
      return @event.name
    end
    #===============
    #*return id
    #===============
    def id
      return @id
    end
    #================
    #*Frame update
    #================
    def update
      chaosg1_update    
      $decode.decode(self)
      return
    end
  end
  #==================
  #**Class decode
  #=================
  class Decode
    #=======================
    #* Object initialization
    #========================
    def initialize
      #declares the hash to hold the beacons events
      $beacon = {}
    end
    #====================
    #*Checks the comments
    #====================
    def decode(event)
      eventid = $game_map.events[event.id]
      # checks for the comments inside the event
      if eventid.list!=nil and
        eventid.list[0].code == 108 and 
        eventid.list[0].parameters == ["Beacon"]
        # creates a new instance of the class
        $beacon[event.id] = Beacon.new
        #sends the information relative to the evnet
        $beacon[event.id].x = eventid.x # event x
        $beacon[event.id].y = eventid.y # event y
        $beacon[event.id].id = event.id # event id
      end
    end
  end
  #====================
  #**Class Beacon
  #====================
  class Beacon
    attr_accessor :x
    attr_accessor :y
    attr_accessor :id
    #===========================
    #*Object Initialization
    #==========================
    def initialize
      @id = 0
      @x = 0
      @y = 0
    end
    #==========================
    #*Frame update
    #==========================
    def update
      # calculate the x distance
      dx = $game_player.x - @x
      #calculate the y distance
      dy = $game_player.y - @y
      # calculates the tru distance
      d=Math.sqrt(dx.abs**2+dy.abs**2)
      # changes the event's opacity relative to the distance
      $game_map.events[@id].opacity = 255-d*80
    end
  end
#------------------------------------------------------------------------------
#**Class Game Player
#------------------------------------------------------------------------------   
  class Scene_Map
    alias chaosg1_update update
    def update
      chaosg1_update
      #updates the Beacons
      for g in 1..999
        $beacon[g].update if $beacon[g] != nil
      end
    end
  end
#============================================================================
# â–  Scene Title
#============================================================================
 class Scene_Title
    #--------------------------------------------------------------------------
    alias chaosg1_Platformer_scene_title_cng command_new_game
    #--------------------------------------------------------------------------
    def command_new_game
      #creates the instance variables
      $decode = Decode.new
      chaosg1_Platformer_scene_title_cng
    end
  end

Hope you like it!

If you don't know something, just ask I will gladly answer.

Note: There could be another easier/another way to do this... But I Am still learning how to script... Hope you like!
 
Just for trivial information: It's BlueScope, not Blue Scope. It isn't supposed to be Blue Scope. Just BlueScope. Thanks :D

For the script, it isn't working for me... did you tested it? Or do I have to put anything inside the event's comment besides the string 'beacon'? ^_^

PS: I guess I overestimated RGSS... so much lines for an actually very simple process...

Code:
#==============================================================================
# Beacon Module
#------------------------------------------------------------------------------
# Script by Chaosg1
#==============================================================================

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  attr_reader :id
  attr_accessor :opacity
  attr_accessor :through
  #--------------------------------------------------------------------------
  alias chaosg1_update update
  #--------------------------------------------------------------------------
  def name
    return @event.name
  end
  #--------------------------------------------------------------------------
  def id
    return @id
  end
  #--------------------------------------------------------------------------
  def update
    chaosg1_update    
    $decode.decode(self)
    return
  end
  #--------------------------------------------------------------------------
end

class Decode
  #--------------------------------------------------------------------------
  def initialize
    #declares the hash to hold the beacons events
    $beacon = {}
  end
  #--------------------------------------------------------------------------
  def decode(event)
    event_id = $game_map.events[event.id]
    # checks for the comments inside the event
    if event_id.list!=nil and
      event_id.list[0].code == 108 and 
      event_id.list[0].parameters == ["Beacon"]
      # creates a new instance of the class
      $beacon[event.id] = Beacon.new
      # sends the information relative to the event
      $beacon[event.id].x = event_id.x # event x
      $beacon[event.id].y = event_id.y # event y
      $beacon[event.id].id = event.id # event id
    end
  end
  #--------------------------------------------------------------------------
end

class Beacon
  #--------------------------------------------------------------------------
  attr_accessor :x
  attr_accessor :y
  attr_accessor :id
  #--------------------------------------------------------------------------
  def initialize
    @id = 0
    @x = 0
    @y = 0
  end
  #--------------------------------------------------------------------------
  def update
    # calculate the x distance
    dx = $game_player.x - @x
    #calculate the y distance
    dy = $game_player.y - @y
    # calculates the tru distance
    d=Math.sqrt(dx.abs**2+dy.abs**2)
    # changes the event's opacity relative to the distance
    $game_map.events[@id].opacity = 255-d*80
  end
  #--------------------------------------------------------------------------
end

class Scene_Map
  #--------------------------------------------------------------------------
  alias chaosg1_update update
  #--------------------------------------------------------------------------
  def update
    chaosg1_update
    #updates the Beacons
    for g in 1..$beacon.size
      $beacon[g].update if $beacon[g] != nil
    end
  end
  #--------------------------------------------------------------------------
end

class Scene_Title
  #--------------------------------------------------------------------------
  alias chaosg1_Platformer_scene_title_cng command_new_game
  #--------------------------------------------------------------------------
  def command_new_game
    #creates the instance variables
    $decode = Decode.new
    chaosg1_Platformer_scene_title_cng
  end
  #--------------------------------------------------------------------------
end
 
It isn't working?? It was working for me...

Btw The string must be "Beacon" or it won't work...
Probably there is/are other ways of doing this but, This was the fastest way I could remeber lol
 
I did put 'Beacon', I know that RGSS is case-sensitive since yesterday XD Well, I met MeisMe in chat just now, and he said the problem is that $beacon has never been initialized... he also said that it's easier to get everything into Game_Event rather than in several classes... and he said that he's going to do it now ^_^ But I guess he gave up meanwhile XD
 
Okay, it works in your demo, but neither in my game nor in a new project as I tried before... but I found an error which might be the key to everything... delete the comment out of the beacon event with ID 001 and you'll notice...

EDIT: It doesn't work for me putting the first event to Beacon, too... there is also a little error in your version: The Beacons appear shortly while the map still is fading in... I'd be glad if you could fix that.
 
Try this one.
#============================================================================
# Beacon Script
#--------------------------
# Version 1.0
# Author :Chaosg1
# Requested by: BlueScope
# 08-26-2006
#=============================================================================
#===============================
#** Class Event
#===============================
class Game_Event < Game_Character
attr_reader :id
attr_accessor :eek:pacity
attr_accessor :through
#===============
#* Alias
#===============
alias chaosg1_update update
#===============
#returns name
#===============
def name
return @event.name
end
#===============
#*return id
#===============
def id
return @id
end
#================
#*Frame update
#================
def update
chaosg1_update
$decode.decode(self)
return
end
end
#==================
#**Class decode
#=================
class Decode
#=======================
#* Object initialization
#========================
def initialize
#declares the hash to hold the beacons events
$beacon = {}
end
#====================
#*Checks the comments
#====================
def decode(event)
eventid = $game_map.events[event.id]
# checks for the comments inside the event
if eventid.list!=nil and
eventid.list[0].code == 108 and
eventid.list[0].parameters == ["Beacon"]
# creates a new instance of the class
$beacon[event.id] = Beacon.new
#sends the information relative to the evnet
$beacon[event.id].x = eventid.x # event x
$beacon[event.id].y = eventid.y # event y
$beacon[event.id].id = event.id # event id
end
end
end
#====================
#**Class Beacon
#====================
class Beacon
attr_accessor :x
attr_accessor :y
attr_accessor :id
#===========================
#*Object Initialization
#==========================
def initialize
@id = 0
@x = 0
@y = 0
end
#==========================
#*Frame update
#==========================
def update
# calculate the x distance
dx = $game_player.x - @x
#calculate the y distance
dy = $game_player.y - @y
# calculates the tru distance
d=Math.sqrt(dx.abs**2+dy.abs**2)
# changes the event's opacity relative to the distance
$game_map.events[@id].opacity = 255-d*80
end
end
#------------------------------------------------------------------------------
#**Class Game Player
#------------------------------------------------------------------------------
class Scene_Map
alias chaosg1_update update
def update
chaosg1_update
#updates the Beacons
for g in 1..999
$beacon[g].update if $beacon[g] != nil
end
end
end
#============================================================================
# â–  Scene Title
#============================================================================
class Scene_Title
#--------------------------------------------------------------------------
alias chaosg1_Platformer_scene_title_cng command_new_game
#--------------------------------------------------------------------------
def command_new_game
#creates the instance variables
$decode = Decode.new
chaosg1_Platformer_scene_title_cng
end
end

The other one I dunno what are you saying... could you explain?
 
It works... though I wonder how you did it ^_^

There's still one problem... Look at the events directly after you enter the map. They appear for a short time (until update definition is triggered) and then disappear, but sadly, that's too late ^_^

EDIT: Thanks for the 'BlueScope', I really apprechiate it :D
 
I just changed a line, I will see what I can do About the ghost events lol:
You are welcome...

I changed this line:
for g in 1...$beacon.size
$beacon[g].update if $beacon[g] != nil

to
for g in 1...999
$beacon[g].update if $beacon[g] != nil

It gives a little bit of lag but It was the best way I could find...
 
Couldn't you use Near's View Range script.

for event in $game_map.events.values
if in_range?($game_player, event, 4)
event.opacity = 250
else
event.opacity = 0
end
end

you can get the in_range? method from Near's ABS
 
no it doesn't make sense.. I don't think you understand how it works.

Here is the whole script;
Code:
module Beacon
  #--------------------------------------------------------------------------
  # * Fram Update- Called from Scene_Map Update
  #--------------------------------------------------------------------------
  def self.update
    #Get all the events on map
    for event in $game_map.events.values
      #If the event is in range
      if in_range?($game_player, event, 4)
        #Make the opacity 250
        event.opacity = 250
      else #If not in range
        #Make the opacity 0
        event.opacity = 0
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Checks if an object is in range.
  #--------------------------------------------------------------------------
  def self.in_range?(element, object, range)
    x = (element.x - object.x) * (element.x - object.x)
    y = (element.y - object.y) * (element.y - object.y)
    r = x + y
    if r <= (range * range)
      return true
    else
      return false
    end
  end
end

class Game_Character
  attr_accessor :opacity
end
 

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