Near Fantastica Pathfinding Script -> Warten bis gelaufen
Hallo Liebe RGSS'ler unter euch, ich benutze für mein Projekt zur Zeit das Pathfinding script von Near Fantastica. Es funktioniert auch super und so, allerdings wartet das Script nicht bis die Route fertig gelaufen ist, sondern macht immer sofort weiter, wenn man z.B. auf die nächste Seite switcht, gibt es einen Syntax error.
Eine Antwort im Thread lautete, dass man mit Hilfe dieses Schnipsels, die Wartezeit hinzufügen kann, allerdings wüssteich jetzt nicht wo derhin soll :)
[php]@> Loop
@> Wait 1 Frame
@> Conditional Branch: Script: not $game_map.events[EVENT_ID].runpath
@> Break Loop
@> Repeat above
[/php]
Ich hoffe ihr könnt mir weiterhelfen, ich bedanke mich schonmal im Voraus^^
Lg.
Lunatic
[php]
#==============================================================================
# ■ Path Finding
# By: Near Fantastica
# Date: 24.09.05
# Version: 1
#
# Player :: $game_player.find_path(x,y)
# Event Script Call :: self.event.find_path(x,y)
# Event Movement Script Call :: self.find_path(x,y)
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
alias pf_game_character_initialize initialize
alias pf_game_character_update update
#--------------------------------------------------------------------------
attr_accessor :map
attr_accessor :runpath
#--------------------------------------------------------------------------
def initialize
pf_game_character_initialize
@map = nil
@runpath = false
end
#--------------------------------------------------------------------------
def update
run_path if @runpath == true
pf_game_character_update
end
#--------------------------------------------------------------------------
def run_path
return if moving?
step = @map[@x,@y]
if step == 1
@map = nil
@runpath = false
return
end
dir = rand(2)
case dir
when 0
move_right if @map[@x+1,@y] == step - 1 and step != 0
move_down if @map[@x,@y+1] == step - 1 and step != 0
move_left if @map[@x-1,@y] == step -1 and step != 0
move_up if @map[@x,@y-1] == step - 1 and step != 0
when 1
move_up if @map[@x,@y-1] == step - 1 and step != 0
move_left if @map[@x-1,@y] == step -1 and step != 0
move_down if @map[@x,@y+1] == step - 1 and step != 0
move_right if @map[@x+1,@y] == step - 1 and step != 0
end
end
#--------------------------------------------------------------------------
def find_path(x,y)
sx, sy = @x, @y
result = setup_map(sx,sy,x,y)
@runpath = result[0]
@map = result[1]
@map[sx,sy] = result[2] if result[2] != nil
end
#--------------------------------------------------------------------------
def setup_map(sx,sy,ex,ey)
map = Table.new($game_map.width, $game_map.height)
map[ex,ey] = 1
old_positions = []
new_positions = []
old_positions.push([ex, ey])
depth = 2
depth.upto(100){|step|
loop do
break if old_positions[0] == nil
x,y = old_positions.shift
return [true, map, step] if x == sx and y+1 == sy
if $game_player.passable?(x, y, 2) and map[x,y + 1] == 0
map[x,y + 1] = step
new_positions.push([x,y + 1])
end
return [true, map, step] if x-1 == sx and y == sy
if $game_player.passable?(x, y, 4) and map[x - 1,y] == 0
map[x - 1,y] = step
new_positions.push([x - 1,y])
end
return [true, map, step] if x+1 == sx and y == sy
if $game_player.passable?(x, y, 6) and map[x + 1,y] == 0
map[x + 1,y] = step
new_positions.push([x + 1,y])
end
return [true, map, step] if x == sx and y-1 == sy
if $game_player.passable?(x, y, 8) and map[x,y - 1] == 0
map[x,y - 1] = step
new_positions.push([x,y - 1])
end
end
old_positions = new_positions
new_positions = []
}
return [false, nil, nil]
end
end
class Interpreter
#--------------------------------------------------------------------------
def event
return $game_map.events[@event_id]
end
end
[/php]
#==============================================================================
# ■ Path Finding
# By: Near Fantastica
# Date: 24.09.05
# Version: 1
#
# Player :: $game_player.find_path(x,y)
# Event Script Call :: self.event.find_path(x,y)
# Event Movement Script Call :: self.find_path(x,y)
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
alias pf_game_character_initialize initialize
alias pf_game_character_update update
#--------------------------------------------------------------------------
attr_accessor :map
attr_accessor :runpath
#--------------------------------------------------------------------------
def initialize
pf_game_character_initialize
@map = nil
@runpath = false
end
#--------------------------------------------------------------------------
def update
run_path if @runpath == true
pf_game_character_update
end
#--------------------------------------------------------------------------
def run_path
return if moving?
step = @map[@x,@y]
if step == 1
@map = nil
@runpath = false
return
end
dir = rand(2)
case dir
when 0
move_right if @map[@x+1,@y] == step - 1 and step != 0
move_down if @map[@x,@y+1] == step - 1 and step != 0
move_left if @map[@x-1,@y] == step -1 and step != 0
move_up if @map[@x,@y-1] == step - 1 and step != 0
when 1
move_up if @map[@x,@y-1] == step - 1 and step != 0
move_left if @map[@x-1,@y] == step -1 and step != 0
move_down if @map[@x,@y+1] == step - 1 and step != 0
move_right if @map[@x+1,@y] == step - 1 and step != 0
end
end
#--------------------------------------------------------------------------
def find_path(x,y)
sx, sy = @x, @y
result = setup_map(sx,sy,x,y)
@runpath = result[0]
@map = result[1]
@map[sx,sy] = result[2] if result[2] != nil
end
#--------------------------------------------------------------------------
def setup_map(sx,sy,ex,ey)
map = Table.new($game_map.width, $game_map.height)
map[ex,ey] = 1
old_positions = []
new_positions = []
old_positions.push([ex, ey])
depth = 2
depth.upto(100){|step|
loop do
break if old_positions[0] == nil
x,y = old_positions.shift
return [true, map, step] if x == sx and y+1 == sy
if $game_player.passable?(x, y, 2) and map[x,y + 1] == 0
map[x,y + 1] = step
new_positions.push([x,y + 1])
end
return [true, map, step] if x-1 == sx and y == sy
if $game_player.passable?(x, y, 4) and map[x - 1,y] == 0
map[x - 1,y] = step
new_positions.push([x - 1,y])
end
return [true, map, step] if x+1 == sx and y == sy
if $game_player.passable?(x, y, 6) and map[x + 1,y] == 0
map[x + 1,y] = step
new_positions.push([x + 1,y])
end
return [true, map, step] if x == sx and y-1 == sy
if $game_player.passable?(x, y, 8) and map[x,y - 1] == 0
map[x,y - 1] = step
new_positions.push([x,y - 1])
end
end
old_positions = new_positions
new_positions = []
}
return [false, nil, nil]
end
end
class Interpreter
#--------------------------------------------------------------------------
def event
return $game_map.events[@event_id]
end
end
[/php]
zum Lesen den Text mit der Maus markieren
Eine Antwort im Thread lautete, dass man mit Hilfe dieses Schnipsels, die Wartezeit hinzufügen kann, allerdings wüssteich jetzt nicht wo derhin soll :)
[php]@> Loop
@> Wait 1 Frame
@> Conditional Branch: Script: not $game_map.events[EVENT_ID].runpath
@> Break Loop
@> Repeat above
[/php]
Ich hoffe ihr könnt mir weiterhelfen, ich bedanke mich schonmal im Voraus^^
Lg.
Lunatic
»[lUnAtiC>)] Thomas (09:22 PM) :
nice
Kiwi (09:22 PM) :
nais
»[lUnAtiC>)] Thomas (09:23 PM) :
mais
Kiwi (09:23 PM) :
Reis
»[lUnAtiC>)] Thomas (09:23 PM) :
Fleiß
Kiwi (09:23 PM) :
scheiß
»[lUnAtiC>)] Thomas (09:23 PM) :
Preis
Kiwi (09:23 PM) :
Hais
»[lUnAtiC>)] Thomas (09:23 PM) :
Schwais
Kiwi (09:23 PM) :
BREIS
»[lUnAtiC>)] Thomas (09:23 PM) :
Ist das ein Wort?
Kiwi (09:23 PM) :
ja
Kiwi (09:23 PM) :
Des Breis
Kiwi (09:23 PM) :
Genitiv
»[lUnAtiC>)] Thomas (09:24 PM) :
gut zu wissen
nice
Kiwi (09:22 PM) :
nais
»[lUnAtiC>)] Thomas (09:23 PM) :
mais
Kiwi (09:23 PM) :
Reis
»[lUnAtiC>)] Thomas (09:23 PM) :
Fleiß
Kiwi (09:23 PM) :
scheiß
»[lUnAtiC>)] Thomas (09:23 PM) :
Preis
Kiwi (09:23 PM) :
Hais
»[lUnAtiC>)] Thomas (09:23 PM) :
Schwais
Kiwi (09:23 PM) :
BREIS
»[lUnAtiC>)] Thomas (09:23 PM) :
Ist das ein Wort?
Kiwi (09:23 PM) :
ja
Kiwi (09:23 PM) :
Des Breis
Kiwi (09:23 PM) :
Genitiv
»[lUnAtiC>)] Thomas (09:24 PM) :
gut zu wissen
zum Lesen den Text mit der Maus markieren
»[lUnAtiC>)] Thomas (09:24 PM) :
yay
»[lUnAtiC>)] Thomas (09:24 PM) :
du bist schnell
Kiwi (09:24 PM) :
hm?
Kiwi (09:26 PM) :
wieso`?
»[lUnAtiC>)] Thomas (09:26 PM) :
schon 5 Chars
Kiwi (09:26 PM) :
LOOOOOOOOOOOOOOL
Kiwi (09:26 PM) :
nein
Kiwi (09:26 PM) :
ich hab erst 2
Kiwi (09:27 PM) :
Figure Number 5 ist nur n Lied
Kiwi (09:27 PM) :
xD
zum Lesen den Text mit der Maus markieren
»[lUnAtiC>)] Thomas (08:34 PM) :
Kekspunkte
»[lUnAtiC>)] Thomas (08:34 PM) :
OMGOGMOGMOGMOGMOGMOMGMOGOGOMGMOGOMGOMGM
Kiwi (08:34 PM) :
hm?
»[lUnAtiC>)] Thomas (08:34 PM) :
wenn ich jemals welche bekomme
»[lUnAtiC>)] Thomas (08:34 PM) :
nehm ich schieb sie dem der sie erfunden hat zwischen seine zwei Backen
»[lUnAtiC>)] Thomas (08:34 PM) :
ich scheiß auf Kekspunkte
Kiwi (08:34 PM) :
wer nicht?
»[lUnAtiC>)] Thomas (08:34 PM) :
ich bitte sie, meine zu löschen
»[lUnAtiC>)] Thomas (08:34 PM) :
wenn ich welche hab
Kiwi (08:35 PM) :
ok
Kiwi (08:35 PM) :
ich hab 50
Kiwi (08:35 PM) :
aber mir ist das egal
Kiwi (08:35 PM) :
ob ich die hab oder nicht
»[lUnAtiC>)] Thomas (08:36 PM) :
druck sie dir doch aus
»[lUnAtiC>)] Thomas (08:36 PM) :
und häng sie an die Wand
Kiwi (08:36 PM) :
:-)
Kiwi (08:36 PM) :
ok
»[lUnAtiC>)] Thomas (08:36 PM) :
das wär der sinnvollste Verwendungszweck
zum Lesen den Text mit der Maus markieren
>.< Typisch ich. Hab mich mal wieder von den @'s blenden lassen. Das sind tatsächlich Eventcommands xD
Aber der Thread brauch noch nicht verschoben werden, denn ich habe noch eine andere Frage bitte =)
Ich müsste dann für jeden NPC der das pathfinding nutzt diesen Eventcode hinmachen. Nicht das ich das nicht könnte, aber ich bin schlicht und einfach zu faul >.<
Könnte man das evtl. so machen das es im Script integriert wäre?
Zur verständniss:
Der Maker arbeitet ja
normalerweise so: Er ruft einen Eventscript auf und wartet bis dieser fertig ist und ruft dann den nächsten auf.
Dieser Pathfinding script ruft aber den nächsten eventscript auf sobald er begonnen hat, d.H. er wartet nicht bis der NPC dahin gelaufen ist wo er sollte, er ruft einfach den nächsten event script auf.
Ich würde es aber gerne per RGSS so haben, dass der Eventscript erst wartet bis der NPC an der Stelle ist die ich angegeben haben bevor der Eventscript fortfährt.
Ich hoffe mir kann geholfen werden ^^
Ich bedanke mich schonmal im voraus =)
Lg.
Lunatic
Aber der Thread brauch noch nicht verschoben werden, denn ich habe noch eine andere Frage bitte =)
Ich müsste dann für jeden NPC der das pathfinding nutzt diesen Eventcode hinmachen. Nicht das ich das nicht könnte, aber ich bin schlicht und einfach zu faul >.<
Könnte man das evtl. so machen das es im Script integriert wäre?
Zur verständniss:
Der Maker arbeitet ja
normalerweise so: Er ruft einen Eventscript auf und wartet bis dieser fertig ist und ruft dann den nächsten auf.
Dieser Pathfinding script ruft aber den nächsten eventscript auf sobald er begonnen hat, d.H. er wartet nicht bis der NPC dahin gelaufen ist wo er sollte, er ruft einfach den nächsten event script auf.
Ich würde es aber gerne per RGSS so haben, dass der Eventscript erst wartet bis der NPC an der Stelle ist die ich angegeben haben bevor der Eventscript fortfährt.
Ich hoffe mir kann geholfen werden ^^
Ich bedanke mich schonmal im voraus =)
Lg.
Lunatic
»[lUnAtiC>)] Thomas (09:22 PM) :
nice
Kiwi (09:22 PM) :
nais
»[lUnAtiC>)] Thomas (09:23 PM) :
mais
Kiwi (09:23 PM) :
Reis
»[lUnAtiC>)] Thomas (09:23 PM) :
Fleiß
Kiwi (09:23 PM) :
scheiß
»[lUnAtiC>)] Thomas (09:23 PM) :
Preis
Kiwi (09:23 PM) :
Hais
»[lUnAtiC>)] Thomas (09:23 PM) :
Schwais
Kiwi (09:23 PM) :
BREIS
»[lUnAtiC>)] Thomas (09:23 PM) :
Ist das ein Wort?
Kiwi (09:23 PM) :
ja
Kiwi (09:23 PM) :
Des Breis
Kiwi (09:23 PM) :
Genitiv
»[lUnAtiC>)] Thomas (09:24 PM) :
gut zu wissen
nice
Kiwi (09:22 PM) :
nais
»[lUnAtiC>)] Thomas (09:23 PM) :
mais
Kiwi (09:23 PM) :
Reis
»[lUnAtiC>)] Thomas (09:23 PM) :
Fleiß
Kiwi (09:23 PM) :
scheiß
»[lUnAtiC>)] Thomas (09:23 PM) :
Preis
Kiwi (09:23 PM) :
Hais
»[lUnAtiC>)] Thomas (09:23 PM) :
Schwais
Kiwi (09:23 PM) :
BREIS
»[lUnAtiC>)] Thomas (09:23 PM) :
Ist das ein Wort?
Kiwi (09:23 PM) :
ja
Kiwi (09:23 PM) :
Des Breis
Kiwi (09:23 PM) :
Genitiv
»[lUnAtiC>)] Thomas (09:24 PM) :
gut zu wissen
zum Lesen den Text mit der Maus markieren
»[lUnAtiC>)] Thomas (09:24 PM) :
yay
»[lUnAtiC>)] Thomas (09:24 PM) :
du bist schnell
Kiwi (09:24 PM) :
hm?
Kiwi (09:26 PM) :
wieso`?
»[lUnAtiC>)] Thomas (09:26 PM) :
schon 5 Chars
Kiwi (09:26 PM) :
LOOOOOOOOOOOOOOL
Kiwi (09:26 PM) :
nein
Kiwi (09:26 PM) :
ich hab erst 2
Kiwi (09:27 PM) :
Figure Number 5 ist nur n Lied
Kiwi (09:27 PM) :
xD
zum Lesen den Text mit der Maus markieren
»[lUnAtiC>)] Thomas (08:34 PM) :
Kekspunkte
»[lUnAtiC>)] Thomas (08:34 PM) :
OMGOGMOGMOGMOGMOGMOMGMOGOGOMGMOGOMGOMGM
Kiwi (08:34 PM) :
hm?
»[lUnAtiC>)] Thomas (08:34 PM) :
wenn ich jemals welche bekomme
»[lUnAtiC>)] Thomas (08:34 PM) :
nehm ich schieb sie dem der sie erfunden hat zwischen seine zwei Backen
»[lUnAtiC>)] Thomas (08:34 PM) :
ich scheiß auf Kekspunkte
Kiwi (08:34 PM) :
wer nicht?
»[lUnAtiC>)] Thomas (08:34 PM) :
ich bitte sie, meine zu löschen
»[lUnAtiC>)] Thomas (08:34 PM) :
wenn ich welche hab
Kiwi (08:35 PM) :
ok
Kiwi (08:35 PM) :
ich hab 50
Kiwi (08:35 PM) :
aber mir ist das egal
Kiwi (08:35 PM) :
ob ich die hab oder nicht
»[lUnAtiC>)] Thomas (08:36 PM) :
druck sie dir doch aus
»[lUnAtiC>)] Thomas (08:36 PM) :
und häng sie an die Wand
Kiwi (08:36 PM) :
:-)
Kiwi (08:36 PM) :
ok
»[lUnAtiC>)] Thomas (08:36 PM) :
das wär der sinnvollste Verwendungszweck
zum Lesen den Text mit der Maus markieren

Sven
YAams
Random Signatur