RPGVX.net

  RPG-Maker VX => VX Skripte [Fertiger Code] => Thema gestartet von: Onkel Hell am Mai 02, 2008, 19:11:22

Titel: MapMarker
Beitrag von: Onkel Hell am Mai 02, 2008, 19:11:22
Beschreibung : Das Script zeigt in Areas mit speziellen namen die ihr einstellen könnt ein von euch eingestelltes emote, somit kann zb ein ausrufezeichen automatisch angezeigt werden wenn ein item in der nähe ist

Anmerkung :
Danke an Tally für Idee und Betatesting

Demo v1.2
http://rapidshare.com/files/112128206/MapMarker.rar (http://rapidshare.com/files/112128206/MapMarker.rar)

Anleitung :
#==============================================================================
# F.A.Q.
#==============================================================================
# Benutzt das MARKER-Array um eure Area-Namen einzustellen und die Balloon ID
# für das Emote das ihr haben möchtet. Ihr könnt soviele Zeilen hinzufügen wie ihr
# wollt
#
# Auf der Karte braucht ihr dann nur ein Area zu erstellen mit einem der Namen
# die ihr zuvor eingestellt habt und das emote wird automatisch angezeigt
#
# Um die markierung vom letzten Area zu löschen das ihr betreten habt,
# erstellt ein call script mit diesem darin :
# $game_player.delete_mark
#==============================================================================
# Main config
#==============================================================================
MARKER = [ ["item 1",1],         # [Areaname,Balloon ID]
           ["item 2",2],         # Example 1
           ["item 3",3],         # Example 2
           ["item 4",4],         # Example 3
                    ]

Script v1.2
#==============================================================================
#  Map Marker
#
#  Version : 1.2 - 01.04.08
#  Created by : hellMinor
#  Do NOT redistribute without my permission
#  Description : A little script to show a Emote Icon if you enter an
#                area with specific name
#
#==============================================================================
# F.A.Q.
#==============================================================================
# Use the MARKER-Array to define the Area names and the Balloon ID for the
# emote which should be shown in it. You can add as much lines as you want.
#
# On the map, just make an area with one of the names which you defined and
# the emote will be shown automatically
#
# To delete the mark of the last area you entered just make a call script
# with this in it : $game_player.delete_mark
#==============================================================================
# Main config
#==============================================================================
MARKER = [ ["item 1",1],         # [Areaname,Balloon ID]
           ["item 2",2],         # Example 1
           ["item 3",3],         # Example 2
           ["item 4",4],         # Example 3
                    ]                
#==============================================================================
class Game_Player < Game_Character
#==============================================================================  
  def in_item_area?(area)
    return false if area == nil
    return false if $game_map.map_id != area.map_id
    return false if @x < area.rect.x
    return false if @y < area.rect.y
    return false if @x >= area.rect.x + area.rect.width
    return false if @y >= area.rect.y + area.rect.height
    for i in 0..MARKER.size-1
      if area.name == MARKER[i][0]
        @last_area = area.id
        @mark = MARKER[i][1]
        return true
      end
    end
    return false
  end
#------------------------------------------------------------------------------  
  def auto_exclamation
    for area in $data_areas.values
      $game_player.balloon_id = @mark if in_item_area?(area)
    end
  end
#------------------------------------------------------------------------------
  def delete_mark
    for area in $data_areas.values
      area.name = "mark deleted" if area.id == @last_area
    end
  end
#------------------------------------------------------------------------------
  alias update_nonmoving_auto_exclamation update_nonmoving
  def update_nonmoving(last_moving)
    update_nonmoving_auto_exclamation(last_moving)
    auto_exclamation if last_moving
  end

end
Titel: MapMarker
Beitrag von: ERZENGEL am Mai 02, 2008, 19:21:30
Das ist aber mal ein kurzes Skript mit netten Effekt ^^ Vielen Dank für's posten.

Übrigens ist in Rubyfor i in 0..MARKER.size-1dasselbe wiefor i in 0...MARKER.sizeWelches du verwendet ist aber im Endeffekt sicher egal.
Titel: MapMarker
Beitrag von: woratana am Mai 03, 2008, 02:27:59
Umh, I'm not sure if it's the same :P
because I already has problem in my script with that before.

It will give an error when it run to the last one~ ( MARKER[MARKER.size] )
Titel: MapMarker
Beitrag von: ERZENGEL am Mai 03, 2008, 02:46:27
I'm sure it got the same effect in this case (Maybe in other cases). You can test this:ARRAY = [0, 1, 2, 3, 4, 5]
for i in 0..ARRAY.size-1
  p i
end
for i in 0...ARRAY.size
  p i
end
But I think everybody should write scripts in the way he like it.
Titel: MapMarker
Beitrag von: Talyana Meriweather Rahl am Mai 03, 2008, 03:24:46
Ah du hast es ja gepostet endlich ^__^ hab es schon reingefügt die neue Version ^__~

Ich hoffe dass der Delete Befehl endlich bei mir klappt XD
Titel: MapMarker
Beitrag von: Onkel Hell am Mai 03, 2008, 03:29:41
@woratana: which script do u mean ?o_O
but normally if iterate over arrays the size is everytime +1 the last number
i dont know if the third dot in a loop will automatically do -1 like erzengel tolds but every language is different
Titel: MapMarker
Beitrag von: woratana am Mai 03, 2008, 08:48:41
I agree, Erzengel. Everyone should write script in the way they like :)

However, I tried that script in http://tryruby.hobix.com/ (http://tryruby.hobix.com/), and this is what I got.
>> Array = [0,1,2,3,4,5]                                                
=> [0, 1, 2, 3, 4, 5]                                                  
>> for i in 0..Array.size                                              
>> p i                                                                  
>> end                                                                  
0                                                                      
1                                                                      
2                                                                      
3                                                                      
4                                                                      
5                                                                      
6                                                                      
=> 0..6
You will see that there's 6 in there too, and Array[6] will return nil because there's no value in that index.

Therefore, for i in 0...MARKER.size will not work.

>> Marker = [ ['item 1', 1],                                            
>> ['item 2', 2],                                                      
>> ['item 3', 3],                                                      
>> ['item 4', 4],                                                      
>> ]
Using Marker.size, it gives no MethodError
>> for i in 0..Marker.size                                              
>> if 'item 5' == Marker[i][0]                                          
>> p 'found!' + i.to_s                                                  
>> end                                                                  
>> end                                                                  
NoMethodError: undefined method `[]' for nil:NilClass                  
 from (irb):11                                                          
 from (irb):10:in `each'                                                
 from (irb):10
Marker.size-1 will work fine.
>> for i in 0..Marker.size-1                                            
>> if 'item 5' == Marker[i][0]                                          
>> p' found!' + i.to_s                                                  
>> end                                                                  
>> end                                                                  
=> 0..3
Don't worry, we still have many things we have to learn in Ruby (or RGSS :P).
I'm sure you also knew something that I don't know. :)

@Hellminor
I mean by the script in Erzengel's post~

EDIT:
Save space :3~
Titel: MapMarker
Beitrag von: ERZENGEL am Mai 03, 2008, 12:44:58
Oh ok, vergesst was ich gesagt hab und sorry wegen der Verwirrung ^^
Titel: MapMarker
Beitrag von: Dainreth am Mai 03, 2008, 17:55:33
Klingt sehr gut das Skript, werd's mal ausprobieren, danke für die Arbeit!
SimplePortal 2.3.3 © 2008-2010, SimplePortal