• Login

Dear visitor, welcome to RPG Studio - Make your World real. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, September 8th 2014, 3:19am

Event läuft zu einem bestimmten Ort

Hey Community :)
gibt es ein script wodurch sich einstellen lässt, dass sihc ein event zu einem bestimmten ort hin bewegt egal von welcher position sie sich befindet? oder habt hir ne idee wie ich so ein problem lösen kann?
lg :)
Still the most beautiful flower ✿
I'm a princess cause my father is king in heaven <3

Playm

RPG Studio Webmaster

  • Send private message

2

Monday, September 8th 2014, 3:24am

Dieses Skripte tragen meistens "Pathfinding" im Namen, mit diesem und den Schlüsselwörtern "RMXP Event" findet man mit einer Internetsuche bestimmt Ergebnisse.

Zum Beispiel dieses Skript: ForeverZer0 - Advanced Pathfinding Version: 1.1

3

Monday, September 8th 2014, 5:02am

oh super danke :)
Still the most beautiful flower ✿
I'm a princess cause my father is king in heaven <3

Reborn

hat beim Stromkonzern schon Rabatt

Motto: Wer noch was vom Wochenende weis, hat es nie erlebt!

  • Send private message

4

Monday, September 8th 2014, 9:46pm

Bei der Gelegenheit (gibt kein schnelleres :) ):
Spoiler: &quot;Script&quot;

Ruby Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
####################################
# Pathfinding by Reborn            |
# v.2.1                            |
####################################
 
################################################################################
# Pathfinding
# Features:
# - very intiligent
# - when no way was found the closest node will be used
# - blocks away dynamic, a new way is calculated (optional)
# - if no new way to calculate, he is waiting for
# - and random pathes (optional) (this features slows the computationally)
# - very very fast by using the A*-Algo in combination with a binary heap
#
# Instructions:
# to send one of events to a way, call:
# charachter.find_path(x, y[, flags])
#
# 
# you can get a character like this:
# character = $game_map.events[id]
# or:
# character = $game_player
# or you call it in a event call script:
# character = event # (for self character)
#
#
# flags are the switches for using the new_calculate and the random - feature
# to use the random feature:
# character.find_path(x, y, Pathfinder::RANDOM)
#
# to use the new_calculate feature:
# character.find_path(x, y, Pathfinder::NEW_CALC)
#
# to use both of them:
# character.find_path(x, y, Pathfinder::RANDOM | Pathfinder::NEW_CALC)
#
################################################################################
 
################################################################################
# Changelog |
################################################################################
# v.2.0
# - revised a star algorithm
# - revised closed list
# - revised passable? - method
# - revised binary heap
################################################################################
 
class Time
  def get_total_time()
    return hour * 60 * 60 * 1000000 + min * 60 * 1000000 + sec * 1000000 + usec
  end
end
 
module Graphics
  class << self
    alias_method(:old_update_28_11_12, :update)
  end
  def self.update()
    old_update_28_11_12()
    @last_frame = Time.now
  end
  def self.last_frame()
    return 0.0 unless @last_frame
    return Time.now() - @last_frame
  end
end
 
module Pathfinder
  class BinaryHeap < Array
    def initialize()
      super()
    end
 
    def replace(index, newObject)
      self[index] = newObject
      sort(index)
    end
 
    def unshift(*args)
      result = super(*args)
      quick_sort()
      return result
    end
 
    def push(*args)
      result = super(*args)
      quick_sort()
      return result
    end
 
    def <<(*args)
      push(*args)
      #unshift(*args)
    end
 
    def remove(index=0)
      temp = self[index]
      if size() > 1
        self[index] = pop()
        sort(index)
      elsif size() == 1
        clear()
      end
      return temp
    end
 
    def sort(y)
      x = y
      keyc = self[x][0]
      if size() > x * 2 + 2
        keyl = self[x * 2 + 1][0]
        keyr = self[x * 2 + 2][0]
        if keyl >= keyr
          if keyc > keyr
            y = x * 2 + 2
          end
        elsif keyc > keyl
          y = x * 2 + 1
        end
      elsif size() > x * 2 + 1
        keyl = self[x * 2 + 1][0]
        if keyc > keyl
          y = x * 1 + 1
        end
      end
      return if x == y
      self[x], self[y] = self[y], self[x]
      sort(y)
    end
 
    def quick_sort()
      return if size() < 2
      index = size() - 1
      while index > 0
        temp = self[index / 2]
        break if self[index][0] > temp[0]
        self[index / 2] = self[index]
        self[index] = temp
        index /= 2
      end
    end
    private :sort, :quick_sort, :[]
  end
 
  RANDOM   = 1  
  NEW_CALC = 2
 
  class Pathfinder
 
    attr_reader :new_calculation, :random
 
    def initialize(character, target_node, flags=0)
      unless target_node[2].between?(0, $game_map.width) || target_node[3].between?(0, $game_map.height)
        raise "X or Y bigger than the mapsize!"
      end
      @character       = character
      @target          = target_node
      @passable_target = @character.passable?(@target[2], @target[3], 0)
      @random          = flags & RANDOM == RANDOM
      @new_calculation = flags & NEW_CALC == NEW_CALC
      @closed_list     = Table.new($game_map.width, $game_map.height)
      @open_list       = BinaryHeap.new()
      @move_route      = Array.new()
    end
 
    def init_closed_list()
      @closed_list = Table.new(@closed_list.xsize, @closed_list.ysize)
      unless $game_player.through
        @closed_list[$game_player.x, $game_player.y] = -1
      end
      $game_map.events.values.each do |i|
        unless i.through
          @closed_list[i.x, i.y] = -1 
        end
      end
    end
 
    def calculate_path()
      init_closed_list()
      @start   = [0, 0, @character.x, @character.y]
      @current = @start
      @open_list.clear()
      @move_route.clear()
      @open_list.push(@current)
      @nearest = [99999999999, 0, 0, 0]
      until @open_list.empty?
        Graphics.update() if Graphics.last_frame > 1
        @current = get_current()
        if @passable_target
          if @current[2, 3] == @target[2, 3]
            create_move_route()
            return
          end
        else
          delta_x = (@current[2] - @target[2]).abs()
          delta_y = (@current[3] - @target[3]).abs()
          if (delta_x + delta_y) == 1
            @target = @current
            create_move_route()
            return
          end
        end
        expand_node()
        if @current[1] > 0
          @nearest = @current if @current[0] - @current[1] <= @nearest[0] - @nearest[1]
        end
      end
      @target = @nearest
      create_move_route()
    end
 
    def get_current()
      return @open_list.remove()
    end
 
    def expand_node()
      get_possible_moves.each do |i|
        @open_list.push(i)
        @closed_list[i[2], i[3]] = i[1]
      end
    end
 
    def get_possible_moves()
      node       = @current
      nodes      = Array.new()
      x, y       = Array.new(), Array.new()
      cost       = node[1] + 1
      x[0], y[0] = node[2], node[3] - 1
      x[1], y[1] = node[2] - 1, node[3]
      x[2], y[2] = node[2] + 1, node[3]
      x[3], y[3] = node[2], node[3] + 1
      score      = Array.new(4) {|i| get_heuristic(x[i], y[i]) + cost}
      nodes_col  = Array.new(4) {|i| [score[i], cost, x[i], y[i]]}
      passables  = Array.new(4) {|i|  passable?(x[i], y[i]) && @closed_list[x[i], y[i]].zero?}
      if @random
        case rand(2)
        when 0 then
          0.upto(3) {|i| nodes << nodes_col[i] if passables[i]}
        when 1 then
          3.downto(0) {|i| nodes << nodes_col[i] if passables[i]}
        end
      else
        0.upto(3)  {|i| nodes << nodes_col[i] if passables[i]}
      end
      return nodes
    end
 
    def passable?(x, y)
      d = get_direction(@current[2], @current[3], x, y)
      return $game_map.map_passable?(x, y, d) && @closed_list[x, y].zero?
    end
 
    def get_direction(x1, y1, x2, y2)
      return 2 if y1 > y2
      return 4 if x1 < x2
      return 6 if x1 > x2
      return 8 if y1 < y2
      return 0
    end
 
    def get_heuristic(x, y)
      return (x - @target[2]).abs() + (y - @target[3]).abs()
    end
 
    def target?(x, y)
      return @target[2] == x && @target[3] == y
    end
 
    def get_next_dir()
      return @move_route[-1]
    end
 
    def pop_last_dir()
      return @move_route.pop()
    end
 
    def create_move_route()
      x, y  = @target[2], @target[3]
      old_x = old_y = -1
      while (a = @start[2] - x).abs() + (b = @start[3] - y).abs() >  1
        break if x == old_x && y == old_y
        old_x, old_y = x, y
        cost          = @closed_list[x, y]
        cmr_cl_col    = Hash.new()
        cmr_cl_col[2] = cmr_cl(x, y - 1, cost)
        cmr_cl_col[4] = cmr_cl(x + 1, y, cost)
        cmr_cl_col[6] = cmr_cl(x - 1, y, cost)
        cmr_cl_col[8] = cmr_cl(x, y + 1, cost)
        if @random
          case rand(2)
          when 0 then
            [2, 4, 6, 8].each do |i|
              if cmr_cl_col[i]
                @move_route << i
                x, y = in_dekrement_xy(i, x, y)
              end
            end
          when 1 then
            [8, 6, 4, 2].each do |i|
              if cmr_cl_col[i]
                @move_route << i
                x, y = in_dekrement_xy(i, x, y)
              end
            end
          end
        else
          [2, 4, 6, 8].each do |i|
            if cmr_cl_col[i]
              @move_route << i
              x, y = in_dekrement_xy(i, x, y)
            end
          end
        end
      end
      @move_route << 2 if b == -1
      @move_route << 4 if a == 1
      @move_route << 6 if a == -1
      @move_route << 8 if b == 1
    end
 
    def in_dekrement_xy(i, x, y)
      case i
      when 2 then return x, y - 1
      when 4 then return x + 1, y
      when 6 then return x - 1, y
      when 8 then return x, y + 1
      end
    end
 
    def cmr_cl(x, y, cost)
      return false unless x.between?(0, @closed_list.xsize - 1)
      return false unless y.between?(0, @closed_list.ysize - 1)
      @closed_list[x, y] > 0 && @closed_list[x, y] == cost - 1
    end
  end
end
 
class Game_Map  
  def map_passable?(x, y, d)
    unless valid?(x, y)
      return false
    end
    bit = (1 << (d / 2 - 1)) & 0x0f
    for i in [2, 1, 0]
      tile_id = data[x, y, i]
      if tile_id.nil?
        return false
      elsif @passages[tile_id] & bit != 0
        return false
      elsif @passages[tile_id] & 0x0f == 0x0f
        return false
      elsif @priorities[tile_id].zero?
        return true
      end
    end
    return true
  end
end
 
class Game_Character
 
  alias nf_pf_game_character_initialize initialize
  alias nf_pf_game_character_update update
 
  def initialize()
    nf_pf_game_character_initialize
    @runpath = false
    @pathfinder = []
  end
 
  def update()
    run_path if @runpath
    nf_pf_game_character_update
  end
 
  def run_path
    return if moving?
    if @pathfinder.target?(@x, @y)
      @runpath = false
      delta_x = @x - @pf_last_x
      delta_y = @y - @pf_last_y
      if delta_x.zero? && delta_y.zero?
        return
      end
      if delta_x.abs() > delta_y.abs()
        delta_x > 0 ? turn_left : turn_right
      else
        delta_y > 0 ? turn_up : turn_down
      end
      return
    end
    dir = @pathfinder.get_next_dir()
    case dir
    when 2 then 
      unless passable?(@x, @y + 1, 0)
        if @pathfinder.new_calculation && !@pathfinder.target?(@x, @y + 1)
          @pathfinder.calculate_path()
        end
        return
      end
      move_down()
    when 4 then
      unless passable?(@x - 1, @y, 0)
        if @pathfinder.new_calculation && !@pathfinder.target?(@x - 1, @y)
          @pathfinder.calculate_path()
        end
        return
      end
      move_left()
    when 6 then
      unless passable?(@x + 1, @y, 0)
        if @pathfinder.new_calculation && !@pathfinder.target?(@x + 1, @y)
          @pathfinder.calculate_path()
        end
        return
      end
      move_right()
    when 8 then
      unless passable?(@x, @y - 1, 0)
        if @pathfinder.new_calculation && !@pathfinder.target?(@x, @y - 1)
          @pathfinder.calculate_path()
        end
        return
      end
      move_up()
    end
    @pathfinder.pop_last_dir()
  end
 
  def find_path(x, y, flags=0)
    @pf_last_x, @pf_last_y = x, y
    @pathfinder = Pathfinder::Pathfinder.new(self, [0, 0, x, y], flags)
    @pathfinder.calculate_path()
    @runpath    = true
  end
 
  def clear_path()
    @runpath = false
    @pathfinder = nil
  end
end
 
class Game_Player
  alias pf_game_player_update update
  def update
    $game_player.clear_path if Input.dir4 != 0
    pf_game_player_update
  end
end
 
class Interpreter
  def event
    return $game_map.events[@event_id]
  end
end
highlight to read
Mehr als a Allgäuer ka a Mensch it wera.


Wie soll ich wissen was ich denke, bevor ich nicht höre was ich sage?


Spoiler: OpenSource-Projects
NES-Emulator - a simple NES-Emulator
ERDL - a embedded Ruby Interpreter with the abilltiy to render images with DirectX ERDL shall be 100% compatible to RPGXP-Ruby Scripts
highlight to read

Social bookmarks