Archiv verlassen und diese Seite im Standarddesign anzeigen : Pathfinding Script editieren.
The Black Mole
15.03.2007, 07:30
Hi @ all,
ich habe mir ein Pathfinding Script aus dem folgenden Thread besorgt:
http://www.rpgxp.de/forum/topic.php?id=10400&s=aqoq4moin9la28pl48icv4use0
Es funktioniert an für sich wunderbar, ganz ohne Probleme. Aber es lässt sich nur aufrufen, wenn das Event, welches bewegt werden soll, das Script aufruft (also self.event.find_path(x, y) )
Wie kann ich es editieren (also das Script), dass ich das Pathfinding für die Events auch über ein Common-Event oder per Parallel-Process aufrufen kann? Weil die Eventseite im Event selber würde ich gerne für Messages oder ähnliches freihalten.
class Interpreter
def event(id = @event_id)
return $game_map.events[id]
end
end
Danach setzt du bei CommonEvents eben in das CallScript:
self.event(eventnummer).find_path(x,y)
The Black Mole
15.03.2007, 19:46
mh. Der gibt mir eine Fehlermeldung mit "Syntax-Error on Line: 107"
Habe beim alten Script den class interpreter durch deinen geändert
Nix ändern. Einfach nur als neues Script über Main (und unter dem Pathfinding Script) reinkopieren. Ansonsten quote mal die besagte Zeile (und 1-3 Zeilen drumherum).
The Black Mole
19.03.2007, 18:46
Danke, hat funktioniert =) Kannst du mir noch einen Befehl Scripten, damit das Laufen auch eventuel unterbrochen werden kann? So dass der nicht mehr weiterläuft. Habe zwar per "set move route" und dem Wait versucht die figur beim Laufen anzuhalten aber dies geht nicht. Bei einem speziellen Event sollen die Figuren nämlich ruckartig stehenbleiben, anstatt Ihrem Pfad weiter zu Folgen.
(Bist auf jedenfall schon für die Credits unter "Special Thanks" vorgemerkt)
class Game_Character
def stop!
@stop = true
end
def go!
@stop = false
end
alias stop_run_path run_path
def run_path
unless @stop then stop_run_path end
end
alias update_movement_stop update_movement
def update_movement
unless @stop then update_movement_stop end
end
end
Das wieder unter dem vorherigen Code kopieren.
Mit event.stop! lässt du ein Event anhalten. Mit event.go! läuft es wieder.
Bsp:
self.event.stop! #Das Event, welches den Code ausführt, stoppt
event(2).stop! #das Event mit der ID 2 stoppt
The Black Mole
20.03.2007, 16:40
http://img114.imageshack.us/img114/8937/lkek9.jpg
Das script sieht momentan so aus:
class Interpreter
def event(id = @event_id)
return $game_map.events[id]
end
end
class Game_Character
def stop!
@stop = true
end
def go!
@stop = false
end
alias stop_run_path run_path
def run_path
unless @stop then stop_run_path end
end
alias update_movement_stop update_movement
def update_movement
unless @stop then update_movement_stop end
end
end
*seufz* Ich dachte du hättest das SDK bei dir drauf =( Ohne SDK muss das Script so aussehen:
class Game_Character
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def pf_game_character_update
# Branch with jumping, moving, and stopping
if jumping?
update_jump
elsif moving?
update_move
else
update_stop
end
# If animation count exceeds maximum value
# * Maximum value is move speed * 1 taken from basic value 18
if @anime_count > 18 - @move_speed * 2
# If stop animation is OFF when stopping
if not @step_anime and @stop_count > 0
# Return to original pattern
@pattern = @original_pattern
# If stop animation is ON when moving
else
# Update pattern
@pattern = (@pattern + 1) % 4
end
# Clear animation count
@anime_count = 0
end
# If waiting
if @wait_count > 0
# Reduce wait count
@wait_count -= 1
return
end
# If move route is forced
if @move_route_forcing
# Custom move
move_type_custom
return
end
# When waiting for event execution or locked
if @starting or lock?
# Not moving by self
return
end
unless @stop then
# If stop count exceeds a certain value (computed from move frequency)
if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
# Branch by move type
case @move_type
when 1 # Random
move_type_random
when 2 # Approach
move_type_toward_player
when 3 # Custom
move_type_custom
end
end
end
end
def stop!
@stop = true
end
def go!
@stop = false
true
end
alias stop_run_path run_path
def run_path
unless @stop then stop_run_path end
end
end
The Black Mole
21.03.2007, 14:34
Da zeigt er einen Syntax-Error in Zeile 74. Das ist das letzte "end" in deinem Script Oo
Also wenns wirklich nur mit dem SDK geht, kannst du mir bitte einen Link zu einer SDK Version geben? Es gibt mittlerweile so viele davon dass ich garnicht weiß welche ich nehmen soll.
edit//
Hat sich erledigt, funktioniert ^^
Mal nebenbei. Ich habe versucht per Callscript aus einem Parallelem Prozess folgenden Befehl auszuführen:
@>conditional Branch: The A button is being pressed
@>Control Variables: [1904: Hero-X] Player's Map X
@>Control Variables: [1905: Hero-Y] Player's Map Y
@>Script: self.event(4).find_path($game_variables[1904],
$game_variables[1905])
Akzeptiert der irgendwie net ^^
UND:
Wenn ich den stop befehl mache, kann das event irgendwie danach nicht mehr bewegt werden
Dann hast du an anderer Stelle im Script ein end vergessen/zuviel gemacht. So sieht es vollständig aus:
#==============================================================================
# ¦ 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(id = @event_id)
return $game_map.events[id]
end
end
class Game_Character
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def pf_game_character_update
# Branch with jumping, moving, and stopping
if jumping?
update_jump
elsif moving?
update_move
else
update_stop
end
# If animation count exceeds maximum value
# * Maximum value is move speed * 1 taken from basic value 18
if @anime_count > 18 - @move_speed * 2
# If stop animation is OFF when stopping
if not @step_anime and @stop_count > 0
# Return to original pattern
@pattern = @original_pattern
# If stop animation is ON when moving
else
# Update pattern
@pattern = (@pattern + 1) % 4
end
# Clear animation count
@anime_count = 0
end
# If waiting
if @wait_count > 0
# Reduce wait count
@wait_count -= 1
return
end
# If move route is forced
if @move_route_forcing
# Custom move
move_type_custom
return
end
# When waiting for event execution or locked
if @starting or lock?
# Not moving by self
return
end
unless @stop then
# If stop count exceeds a certain value (computed from move frequency)
if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
# Branch by move type
case @move_type
when 1 # Random
move_type_random
when 2 # Approach
move_type_toward_player
when 3 # Custom
move_type_custom
end
end
end
end
def stop!
@stop = true
end
def go!
@stop = false
true
end
alias stop_run_path run_path
def run_path
unless @stop then stop_run_path end
end
end
Du brauchst dir nicht extra für das Script SDK zulegen. Allerdings sind die meisten SDK Scripte auch äußerst zuverlässig und qualitativ - schaden kann's also nicht ^^ Das es mehrere Versionen des SDK gibt, ist mir neu. Eigentlich darf es nur eine offizielle Version (und deren Updates) geben. Und die findest du hier (http://www.creationasylum.net/index.php?showtopic=7481).
Edit: Hm, kommt irgendeine Fehlermeldung? Ansonsten überprüf mal, ob du die Variablen auch wirklich auf diesen Wert setzt, statt sie beispielsweise zu addieren. Wenn die eingegebenen Koordinaten nicht in der Map vorkommen, wird der Befehl nämlich ohne Fehlermeldung ignoriert.
The Black Mole
21.03.2007, 15:58
Ja, die variablen werden "gesetzt" anstatt addiert. Wenn ich diesen call-script Befehl aufrufe sagt der nur folgendes:
Syntax Error
Ich weiß nur leider nicht wo xD
Habe jetzt das Vollständige Script eingesetzt. Klappt wie vorher auch wunderbar. Nur halt wenn ich den Stop Befehl für das bewegte event aufrufe, macht es keinen einzigen move mehr. Ob nun mit "set move route" oder dem self.event(ID).find_path(x,y)
edit//
Habs jetzt einigermaßen raus... Also die Findpath Befehle muss ich über die Bewegungsroute des Events laufen lassen (also über Movement-Type "Custom"). Sie halten aber nur an, wenn ich über ein fremdes Event (oder dem selben) den stop-befehl für die event-id des betroffenen Events nutze. Das mit dem "go!" Befehl hättest du mir ruhig sagen können =P Das einzige was bei deinem Script nicht geht ist, dass wenn der stop befehl gerufen wird, das Event sein altes Movement (zB Random) wieder fortsetzt. Es bleibt still stehen.
Ansonsten klappts jetzt hervorragend ^^
Jap, ich dachte auch das du es so haben willst XD
Sonst kannst du dir nämlich das Riesenscript sparen und brauchst lediglich den Code
class Game_Character
def stop!
@stop = true
end
def go!
@stop = false
true
end
alias stop_run_path run_path
def run_path
unless @stop then stop_run_path end
end
end
Unter das Pathfinding-Script einfügen.
The Black Mole
21.03.2007, 16:57
Klappt auch so sehr gut , nochmals vielen Dank =) Wie gesagt, bist für Die Credits vorgemerkt ^^
The Black Mole
31.03.2007, 01:29
*push*
Sorry, dass ich den Thread nochmal hochpusche (und au nochma sry für doppelpost).
Aber kann man in deinem Final-Script noch einbauen, dass die figur, die dem wp folgt, die map immer wieder ne3u prüft beim herumlaufen? Denn: Wenn ich das event blockiere, geht der zwar um mich herum, aber stelle ich mir während des Laufens in den Weg, wird der move nicht fortgesetzt. Habe zwar "Ignore if Can't move" angemacht, aber des akz6epiert der auch nicht. Der soll also sich bewegenden events alleine ermitteln und umgehen.
Und dann muss ich nurnoch wissen, wie man die x,y durch call-script aus einer Variable abfragt.
Powered by vBulletin® Version 4.2.3 Copyright ©2025 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.