Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials

Notices
For all updates, view the main page.

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.



Reply
 
Thread Tools
  #1    
Old November 11th, 2013 (06:13 AM). Edited November 20th, 2013 by Badhaas.
Badhaas's Avatar
Badhaas
 
Join Date: Jul 2013
Gender: Male
What is it?
I noticed that when leaving behind the partner trainer (the dependent event), it disappears and there's nothing in it's place. Thus I wrote a small script which allows you to place an event anywhere (copying an event from one map). This allows you to place a trainer on the location where a dependent event/partner trainer is left behind.

Features
- Place an event in front of the player, facing the player.
- Place an event on a different x and y position (facing the player, or a predefined direction).
- Events will remain there, even after leaving the map.
- Events can be moved (using the same function as placing them).
- Events can be removed.
- UPDATE v1.1: Events can now be placed on other maps than the current map.
- UPDATE v1.2: Events can now also be placed on adjacent maps (fixed a bug when trying this).

note: if you're not using the latest version you might want to replace the script to include all features.

How to use:
- Place the script above main.
- Place "pbPlacedEvents(self,@map_id)" in Game_Map, above the line "@common_events = {}"
- Create an empty map, which will contain all events placed by this script. (fill in the map ID at line 45 in the script).
- Create the desired events on the map and use the script to place them. (the functions are explained in the script)

The script:
Spoiler:

Code:
=begin
    ######################
    EVENT PLACEMENT SCRIPT
    ######################
- by Badhaas
- v 1.2
- 19-11-2013

This script allows you to place an event on all maps (based on a template event
created on a specific map). This can, for example, be used to put an event on the
location where a partner trainer/dependent event is left behind.

Version history:
1.2: A fix which now allows placing events on adjacent maps
1.1: Added placing events on other maps than the current map
1.0: original script

    ############
    INSTALATION:

- Place the script above Main.
- Place "pbPlacedEvents(self,@map_id)" in Game_Map, above the line
  "@common_events = {}"
- Create an empty map, which will contain all events placed by this script.
  (fill in the map ID at line 45 in the script).
- Create the desired events on the map and use the script to place them.

    ###########
    HOW TO USE:

Create all 'template' event (which will be placed using this script) in the map
with the same map ID as CHAR_TEMPLATE_MAP_ID (set below). Then use the functions
explained below to place and remove the events.

    ##########
    FUNCTIONS:

pbPlaceEvent(id,x,y,f) > place an event (or change it's position, when already
                         placed somewhere)
  id = the event id in the template map
  x & y = the x and y position
  f = facing direction (6=right, 4=left, 2=down, 8=up)
  when x, y, and f are left blank, the event is placed in front of the player

pbRemovePlacedEvent(id) > removes the event


Place events on other maps than the current map:
  pbPlaceEventMap(id,map id,x,y,direction)
    id = the event ID in the template.
    map id = the id of the map where the event should be placed.
    x, y = the x and y position respectively of the event on the map.
    direction = facing direction of the event (4=left, 8=up, 6=right, 2=down)
=end

module Char_Events
  CHAR_TEMPLATE_MAP_ID = 22     # MAP ID FOR THE TEMPLATE EVENTS
  
  map_id = CHAR_TEMPLATE_MAP_ID
  map = load_data(sprintf("Data/Map%03d.%s", map_id,$RPGVX ? "rvdata" : "rxdata"))
  $events = map.events
  
end


def pbPlaceEvent(id,x=nil,y=nil,f=nil)
  # create array if it doesn't exist
  if $PlacedEvents == nil
    $PlacedEvents = []
  end
  $PlacedEvents[id] = []
  # set position
  if x
    x2 = x
  else
    if $game_player.direction == 6
      x2 = $game_player.x + 1
    elsif $game_player.direction == 4
      x2 = $game_player.x - 1
    else
      x2 = $game_player.x
    end
  end
  if y
    y2 = y
  else
    if $game_player.direction == 2
      y2 = $game_player.y + 1
    elsif $game_player.direction == 8
      y2 = $game_player.y - 1
    else
      y2 = $game_player.y
    end
  end
  if f
    f2 = f
  else
    f2 = 2 if $game_player.direction == 8
    f2 = 8 if $game_player.direction == 2
    f2 = 4 if $game_player.direction == 6
    f2 = 6 if $game_player.direction == 4
  end
  $PlacedEvents[id][1] = [$game_map.map_id,x2,y2,f2]
  # create event based of the template
  $PlacedEvents[id][0] = CharacterEvent.new(id,$game_map,[x2,y2,f2])
  $game_map.events[$game_map.events.length+1] = $PlacedEvents[id][0]
  # refresh the map, etc.
  $scene.disposeSpritesets
  $scene.createSpritesets
  
end

def pbPlaceEventMap(id,map,x,y,f)
  if $PlacedEvents == nil
    $PlacedEvents = []
  end
  if $PlacedEvents[id] == nil
    $PlacedEvents[id] = []
  end
  $PlacedEvents[id][1] = [map,x,y,f]
  #fix for adjacent maps:
  if $MapFactory.hasMap?(map)
    index = $MapFactory.getMapIndex(map)
    $PlacedEvents[id][0] = CharacterEvent.new(id,$MapFactory.maps[index],[x,y,f])
    $MapFactory.maps[index].events[$MapFactory.maps[index].events.length+1] = $PlacedEvents[id][0]
    $scene.disposeSpritesets
    $scene.createSpritesets
  end
end

def pbRemovePlacedEvent(id)
  if $PlacedEvents[id]  #check if it actually exists
    if $PlacedEvents[id][1][0] == $game_map.map_id
      $PlacedEvents[id][0].erase
    end
    $PlacedEvents[id]=nil
  end
end

def pbPlacedEvents(map,mapid)
  # create array if it doesn't exist
  if $PlacedEvents == nil
    $PlacedEvents = []
  end
  #check for events that should be on the map
  for i in 0...$PlacedEvents.length
    if $PlacedEvents[i]
      if $PlacedEvents[i][1][0] == mapid
        $PlacedEvents[i][0] = CharacterEvent.new(i,map,[$PlacedEvents[i][1][1],
                                                        $PlacedEvents[i][1][2],
                                                        $PlacedEvents[i][1][3]])
        map.events[map.events.length+1] = $PlacedEvents[i][0]
      end
    end
  end #end loop
end #end pbPlacedEvents



class CharacterEvent < Game_Event
  
  attr_accessor :event
  
  def initialize(char_id,map,position)
    original_event = $events[char_id]
    return if original_event == nil
    @event = original_event.dup
    @event.x = position[0]
    @event.y = position[1]
    @event.pages[0].graphic.direction = position[2]
    @event.id = map.events.length+1
    super(map.map_id,@event,map)
  end
end


Example: place event when leaving behind a partner trainer
- Copy the partner event and place it in the new map.
- Go to the Common Events (in the database); the "Brendan dependent event" (which is used for the original partner trainer).
- Then place script: "pbPlaceEvent(1)" above the text "\bI'll stay here" (take in mind that the 1 is the event id of the event in the new map)


Please give credit when used. If you have any comments or question, feel free to post them below.
__________________

View my profile page for scripts/tutorials made by me, even ones which aren't posted yet.

Postponed (pm me if you're interested in this):
- A script/tutorial on conversations similar to the mass effect series and telltale games (The walking dead, The Wolf Among Us, etc.).
Reply With Quote
  #2    
Old November 13th, 2013 (06:19 AM).
AlexTCGPro's Avatar
AlexTCGPro
 
Join Date: Oct 2013
Gender: Male
Nature: Timid
OMG, thank you this is going to be very useful :D
Reply With Quote
  #3    
Old November 14th, 2013 (04:10 PM).
Badhaas's Avatar
Badhaas
 
Join Date: Jul 2013
Gender: Male
Thanks, if you find any bugs or improvements, please let me know.
__________________

View my profile page for scripts/tutorials made by me, even ones which aren't posted yet.

Postponed (pm me if you're interested in this):
- A script/tutorial on conversations similar to the mass effect series and telltale games (The walking dead, The Wolf Among Us, etc.).
Reply With Quote
  #4    
Old November 15th, 2013 (07:28 AM).
AlexTCGPro's Avatar
AlexTCGPro
 
Join Date: Oct 2013
Gender: Male
Nature: Timid
It works as intended, no bugs found, thank you ;D
Reply With Quote
  #5    
Old November 18th, 2013 (03:16 PM).
Alesteir
 
Join Date: Oct 2013
Gender: Male
Can this script be used to place an event in an adjacent map?

To better explain myself, I have two maps "chained" together, can this script make the event go from map 1 to map 2? I thought so at the beginning reading the description but after giving it a better look the purpose seems to not be this.


-edit-
I can get that viceversa can be done though, i.e. moving an event (or a template of the event) from a map to the one the player stands in but I was wondering if there's some way to do it viceversa? It usually doesn't make much sense but it could be useful in some areas where two maps are chained and you want an event to move from a border to another.
Reply With Quote
  #6    
Old November 19th, 2013 (04:39 AM). Edited November 19th, 2013 by Badhaas.
Badhaas's Avatar
Badhaas
 
Join Date: Jul 2013
Gender: Male
This script actually assumes that the player never enters the map containing all template events, as that map is only there to create get all data from for each of the events. Using the script to actually place events on the template map might cause undesired complications (as the script isn't meant to be used that way).

You can move an event from one map to another using this script. It would work as follows;
- Create the template event in the template map (this event is actually never removed, just copied).
- Place the event on the map where you want it to start (though with the current script the player would have to be on that map to place the event there, thus needed a map transfer back and forth).
- When needed place the event again at the second map (this automatically removes the event on the first map).

I do notice that it might be useful to also be able to place events on other maps (maps the player currently isn't on). I'll look into it, and probably post it later today.

EDIT:
I updated the script in the first posted, having added the functionality of placing an event on a map other that the current map.
Use "pbPlaceEventMap(id,map,x,y,f)" in a script to place the event on another map, where:
id = the event's id on the template map
map = the map's id, of where the event should be placed
x and y = the x and y position where the event should be
f = the direction the event should be facing (4=left, 8=up, 6=right, 2=down)
(Note that this is also explained within the script.)
__________________

View my profile page for scripts/tutorials made by me, even ones which aren't posted yet.

Postponed (pm me if you're interested in this):
- A script/tutorial on conversations similar to the mass effect series and telltale games (The walking dead, The Wolf Among Us, etc.).
Reply With Quote
  #7    
Old November 20th, 2013 (01:59 AM).
Alesteir
 
Join Date: Oct 2013
Gender: Male
Thanks :D it works perfectly, there's only a (really small) problem:

I made a test event, with the script "pbPlaceEventMap(1, 29, 55, 0, 2)", I made it near the border (so my field of vision has both map 29 and map 41 [the one where I stand]), right away it does nothing (at first I thought it didn't work) but then I noticed if I walk away and then come back the event is there so it works as intended.

I don't even have to enter the map 29, just walk a little north so the map 29 gets out of vision and then walk south again and the event will be there, so I thought by setting it as parallel or do a "$game_map.refresh" would solve it but didn't.

Just wanted to point it out in case there's an easy solution to that small problem, otherwise it's perfect as it is :D Thanks again!
Reply With Quote
  #8    
Old November 20th, 2013 (04:55 AM). Edited November 20th, 2013 by Badhaas.
Badhaas's Avatar
Badhaas
 
Join Date: Jul 2013
Gender: Male
Yes, I was afraid something like that would happen. How it works is, that if an event is placed on the same map, it adds the event to the map's events and then does some refreshing things. While if an event is on another map, it gets placed on map creation. Though adjacent maps are either fully, or partially, already created, thus the event would have to be added using the same method as if it was on the same map (with some checks and stuff, to see when this should be done). It's not hard to fix, yet it's also not easy (mainly because I first have to find out when events are loaded for adjacent maps).

To avoid the problem, either make sure the other map isn't on screen when placing the event, or make the map a little bit larger to include the desired area. Though if you want the event to walk from the far end of one map to the far end of the other, you'd want it to be fixed. I'll probably still look into it.

EDIT:
I just fixed it, it was easier than expected. The script in the first post is updated. Just replace the script and it should work.

Do note that events on the edge of a map cannot be interacted with from the other map. Unfortunately this is a limitation of essentials (if you have a fix for this, and also for rendering cutting off at the map edge, then please let me know).
__________________

View my profile page for scripts/tutorials made by me, even ones which aren't posted yet.

Postponed (pm me if you're interested in this):
- A script/tutorial on conversations similar to the mass effect series and telltale games (The walking dead, The Wolf Among Us, etc.).
Reply With Quote
  #9    
Old November 20th, 2013 (02:02 PM).
Alesteir
 
Join Date: Oct 2013
Gender: Male
Wow!
You got awesome scripting skills.
Thanks a lot =).

I think that problem may just easily be fixed with eventing, i.e. turning the old NPC in the map before invisible (and thus walkable through) and have him in the border [Temporarely, the delay it takes for the other NPC to walk away] so that if the player attempts to talk to the other NPC, he will trigger the invisible NPC copy dialogue instead, of course the other NPC wouldn't turn but that's not necessarely bad, not everyone turns to talk after all, especially if they're doing something else like walking away, added to the fact that players won't chase every single NPC I say that that "problem" will not be noticeable at all.
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 09:33 AM.