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.

Question About an Old Script (Monsta's Radius Script)

In advance, sorry. I'm a noob, I have no idea what I'm doing with scripts, and I just want to be able to get a few in working order so I can make an RPGXP game. I do not understand the scripting process in the slightest, so I'll just give you the raw facts.

Here is the radius script, by Monsta.

#==========Radius Script=========#
#============by Monsta===========#
#=====Version 1.0===24.5.2007====#

# Aufrufen #
# in_radius?(id_sehendes_event,id_gesehendes_event,sichtweite,sichtform,testfenster_anzeigen)

# Der Player hat die ID 0, kann aber auch mit "Player" angegeben werden
# Mit "All" beim gesehenden Event, bekommt man einen Array mit allen gesehenden Events


class Interpreter
RADIUS = [ [[],[0],[-1,0,1],[-1,0,1],[-2,-1,0,1,2],[-2,-1,0,1,2],[-3,-2,-1,0,1,2,3],[-3,-2,-1,0,1,2,3]], # Sicktkegel 1
[[-1,0,1],[-2,-1,0,1,2],[-3,-2,-1,0,1,2,3],[-4,-3,-2,-1,0,1,2,3,4],[-5,-4,-3,-2,-1,0,1,2,3,4,5]] ] # Sicktkegel 2

def in_radius?(id1,id2,radius=7,radius_form=0,windows=false)
@all = false
if windows == true
@radius_windows = {}
delete_radius_windows
end
if (id1.is_a?(String) and id1.downcase == 'player') or id1 == 0
char1 = $game_player
else
char1 = $game_map.events[id1]
end
if id2.is_a?(String)
if id2.downcase == 'player'
char2 = $game_player
elsif id2.downcase == 'all'
@all = []
end
else
char2 = id2 == 0 ? $game_player : $game_map.events[id2]
end
if radius >= RADIUS[radius_form].size
print ("Fehler im Skript: Radius Skript\n\nDer Radius ist größer als die Radiusangabe")
return false
end
for i in 0..radius
for r in RADIUS[radius_form]
case char1.direction
when 2 # Runter
x = char1.x + r
y = char1.y + i
when 4 # Links
x = char1.x - i
y = char1.y - r
when 6 # Rechts
x = char1.x + i
y = char1.y + r
when 8 # Hoch
x = char1.x + r
y = char1.y - i
end
@radius_windows["#{i},#{r}"] = Radius_Color.new(x,y) if $DEBUG and windows
id = $game_map.id_coordinates(x,y)
if @all == false
return true if id == char2.id
else
@all += [id] if id != -1
end
end
end
if @all == false or @all == []
return false
else
return @all
end
end

def delete_radius_windows
@radius_windows.each_value{|w|w.dispose if w != nil and w.disposed? == false} if @radius_windows != nil
end
end

class Game_Map
def id_coordinates(x=0,y=0)
@events.each {|e|return e[1].id if e[1].x == x and e[1].y == y}
return 0 if $game_player.x == x and $game_player.y == y
return -1
end
end

class Radius_Color < Window_Base
def initialize(x,y)
super(x * 32, y * 32, 20, 20)
self.contents = Bitmap.new(width, height)
self.opacity = 170
end
end


Here was what I was told to make an event "see" the player in a range of 6 squares.

"1.) Make an event and set it to Parallel Process.
2.) Make a conditional Branch using the "Script" function.
3.) Insert this piece of code: in_radius?(6,'Player',6,0)
"
When I do so and run the game, the game crashes and gives me this error:

Script 'Radius Script' line 24: NoMethodError occurred.
undefined method 'direction' for nil:NilClass


Now, I downloaded the demo that came with the script (to be found here http://www.mediafire.com/?zishkmzdgyt), and it works fine. Yet whenever I try to use the script in my own game, or even create another room in the demo, copy a given event from said demo room, and try to run the game, it crashes and displays this message.

I have no idea what the significance of Line 24 is, or what I have to edit to get the script running properly. Help would be greatly appreciated.
 
Are you copying exactly "in_radius?(6,'Player',6,0)"? Because if that's the case and you don't have an event with id 6, that's what's making the error.

Basically, the call goes like this "in_radius?(event1, event2, radius_size, radius_form?) [I'm amusing the form is the shape, I'm not sure, didn't read into it too much)
You want event1 to be the id of the event 'seeing' the player. If that event_id doesn't exist, it's going to error.
 

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