The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

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 2nd, 2013, 10:08 AM
Peaverin's Avatar
Peaverin
 
Join Date: Sep 2013
Gender: Male
Hi, today I bring you this nice script that makes you able to insert a .swf flash intro before the title screen. This system works also with non-Essentials projects, but the tutorial is for Essentials.
There's also a video to show movies in AVI format, but they're hard to work with and their size is 10x bigger and bad quality, so using flash is the best option.
This is an example of my intro flash:

Okay, let's start:
1. Insert this two scripts above main and DOWNLOAD THIS(click here) and extract it into your root folder(the folder with the game.exe of your project).
Note that the scripts have been adapted to work with Pokemon Essentials. If you want them to work in rpg maker xp but without pokemon essentials engine you'll have to modify some things. PM me if it's your case.
This first one is for the movies to work (additional instructions are inside the script if you want to play a video using an event).
Spoiler:
Code:
#==============================================================================#
# Version 0.3 #
# RPG Maker XP Flash Player #
# #
# Author: ????? Updated by: Dark_Wolf_Warrior/Dahrkael #
# # Peaverin: Adapt to Essentials + tutorial(optional credits)
# How to Use: #
# 1. Create the folder Graphics/Flash and insert there the movies.
# #
# 2. If you want to play a flash at any moment insert: #
# $flash.play("file.swf", button)
# file= the name of the flash to be played
# button= 0(the player can't skip the flash by pressing enter)
# button= 1(the player can skip the flash by prssing enter)
# FOR EXAMPLE: I add a flash called Heya to the flash folder.
# # Then, in a event I call the script:
# # $flash.play("Heya.swf", 0)
# # By this way the flash Heya will be played and you won't be
# # able to skip it by pressing enter.
# Interactive flashes requires RGSS knownledge to make they work #
# #
# Original Keyb module by HoundNinja #
# #
#==============================================================================#



class String

CP_ACP = 0
CP_UTF8 = 65001

def u2s
m2w = Win32API.new("kernel32", "MultiByteToWideChar", "ilpipi", "i")
w2m = Win32API.new("kernel32", "WideCharToMultiByte", "ilpipipp", "i")

len = m2w.call(CP_UTF8, 0, self, -1, nil, 0)
buf = "\0" * (len*2)
m2w.call(CP_UTF8, 0, self, -1, buf, buf.size/2)

len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
ret = "\0" * len
w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)

return ret
end

def s2u
m2w = Win32API.new("kernel32", "MultiByteToWideChar", "ilpipi", "i")
w2m = Win32API.new("kernel32", "WideCharToMultiByte", "ilpipipp", "i")

len = m2w.call(CP_ACP, 0, self, -1, nil, 0);
buf = "\0" * (len*2)
m2w.call(CP_ACP, 0, self, -1, buf, buf.size/2);

len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil);
ret = "\0" * len
w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil);

return ret
end

def s2u!
self[0, length] = s2u
end 

def u2s!
self[0, length] = u2s
end

end

class Bitmap

RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')

def address
buffer, ad = "xxxx", object_id * 2 + 16
RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 8
RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 16
RtlMoveMemory_pi.call(buffer, ad, 4); return buffer.unpack("L")[0]
end

end 

class RMFlash

API_NEW	 = Win32API.new("RMFlash", "_new", "piil", "l")
API_UPDATE	 = Win32API.new("RMFlash", "_update", "l", "v")
API_FREE	 = Win32API.new("RMFlash", "_free", "l", "v")
API_PLAYING = Win32API.new("RMFlash", "_is_playing", "l", "i")
API_PAUSE	 = Win32API.new("RMFlash", "_pause", "l", "v")
API_RESUME	 = Win32API.new("RMFlash", "_resume", "l", "v")
API_BACK	 = Win32API.new("RMFlash", "_back", "l", "v")
API_REWIND	 = Win32API.new("RMFlash", "_rewind", "l", "v")
API_FORWARD	 = Win32API.new("RMFlash", "_forward", "l", "v")
API_CURFRAME	 = Win32API.new("RMFlash", "_cur_frame", "l", "i")
API_TOTALFRAME	= Win32API.new("RMFlash", "_total_frames", "l", "i")
API_GOTOFRAME	 = Win32API.new("RMFlash", "_goto_frame", "li", "v")
API_GETLOOP	 = Win32API.new("RMFlash", "_get_loop", "l", "i")
API_SETLOOP	 = Win32API.new("RMFlash", "_set_loop", "li", "v")
API_CLEARALL	 = Win32API.new("RMFlash", "_clear_all", "v", "v")
API_VALID = Win32API.new("RMFlash", "_valid", "l", "i")
API_SENDMSG = Win32API.new("RMFlash", "_send_message", "liii", "l")

CUR_PATH = Dir.pwd

def self.get_version

end

def self.clear_all
API_CLEARALL.call
end

def self.load(name, width, height, v = nil)
new("#{CUR_PATH}/Graphics/Flash/#{name}".u2s, width, height, v)
end

attr_reader :valid

def initialize(flash_name, flash_width, flash_height, viewport = nil)
@sprite = Sprite.new(viewport)
@sprite.bitmap = Bitmap.new(flash_width, flash_height)
@value = API_NEW.call(flash_name, flash_width, flash_height, @sprite.bitmap.address)
@loop = API_GETLOOP.call(@value) > 0
@valid = API_VALID.call(@value) > 0
end

def viewport
@sprite.viewport
end

def update
API_UPDATE.call(@value)
end

def dispose
API_FREE.call(@sprite.bitmap.address)
end

def playing?
API_PLAYING.call(@value) > 0
end

def pause
API_PAUSE.call(@value)
end

def resume
API_RESUME.call(@value)
end

def back
API_BACK.call(@value)
end

def rewind
API_REWIND.call(@value)
end

def forward
API_FORWARD.call(@value)
end

def current_frame
API_CURFRAME.call(@value)
end

def total_frames
API_TOTALFRAME.call(@value)
end

def goto_frame(goal_frame)
API_GOTOFRAME.call(@value, goal_frame)
end

def x
@sprite.x
end

def x=(v)
@sprite.x = v
end

def y
@sprite.y
end

def y=(v)
@sprite.y = v
end

def z
@sprite.z
end

def z=(v)
@sprite.z = v
end

def width
@sprite.bitmap.width
end

def height
@sprite.bitmap.height
end

def loop?
@loop
end

def loop=(v)
if @loop != v
@loop = v
API_SETLOOP.call(@value, v)
end
end

def msg_to_flash(msg, wParam, lParam)
return API_SENDMSG.call(@value, msg, wParam, lParam)
end

# ?
WM_MOUSEMOVE = 0x0200

def make_long(a, b)
return (a & 0xffff ) | (b & 0xffff) << 16
end

def on_mouse_move(x, y)
return msg_to_flash(WM_MOUSEMOVE, 0, make_long(x, y))
end

end

module Kernel

alias origin_exit exit unless method_defined? :exit

def exit(*args)
RMFlash.clear_all
origin_exit(*args)
end

end

module Keyb
$keys = {}
$keys["Enter"] = 0x0D
GetKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
module_function 
def trigger(rkey) 
GetKeyState.call(rkey) & 0x01 == 1
end
end

class Play

def play(filename, button)
fondo = Sprite.new
fondo.bitmap = Bitmap.new(512, 384)
fondo.bitmap.fill_rect(0, 0, 512, 384, Color.new(0,0,0,255))
fls = RMFlash.load(filename, 512, 384)
fls.loop = 1
fls.z = 999999
@button = button
@fr = Graphics.frame_rate
Graphics.frame_rate = 40

while true
Graphics.update
#Input.update
fls.update
break if @button == 1 and Keyb.trigger($keys["Enter"]) 
break if !fls.playing?
end
fls.dispose
Graphics.frame_rate = @fr
fondo.dispose
end
end

This second script is the script we will call in main to show the video before the title screen:
Spoiler:
Code:
#===============================================================================
#
# * Scene_IntroFlash by Dahrkael using 灼眼的夏娜 Flash Player
#   Adapted to Pokemon Essentials by Peaverin                                                                                                            v1.0
#    Requires the .dll and .ocx
#===============================================================================
class Scene_IntroFlash
 
  def initialize
     # Set the file which will be played
     @file = "intro.swf"
     # Choose if the player can skip the intro (0 => false, 1 => true)
     @button = 1
  end
 
  def main
     # Black background
     @fondo = Sprite.new
     @fondo.bitmap = Bitmap.new(512, 384)
     @fondo.bitmap.fill_rect(0, 0, 512, 384, Color.new(0,0,0,255))
     @fondo.z = -1
     # Set flash video
     fls = RMFlash.load(@file, 512, 384)
     fls.loop = 1
     fls.z = 999999
     # Save frame rate
     @fr = Graphics.frame_rate
     # Set new frame rate
     Graphics.frame_rate = 40
     # Main loop
     Graphics.transition
     while true
        Graphics.update
        #Input.update
        fls.update
        # Skip the video using Enter
        break if @button == 1 and Keyb.trigger($keys["Enter"])
        # Skip when finished
        break if !fls.playing?
     end
     $scene = pbCallTitle
     Graphics.freeze
     # Little solution for frozen images
     fls.z = -2
     fls.dispose
     # Set old frame rate
     Graphics.frame_rate = @fr
  end
end


2.Go to the script Main and by line 35 you'll found something like:
Code:
$scene = pbCallTitle
Erase that line and write instead:
Code:
$scene = Scene_IntroFlash.new
3.Optional:
If you don't wan't any pic to show after the flash and you want the Title Screen with the press start message appear JUST AFTER THE VIDEO(like ruby or emerald), go to the script Scene_Intro and where it appears:
Code:
openPic(self,nil)
Erase or comment out the line(comment out means writing this # before the line) and write instead:
Code:
    @timer=0 # reset the timer
    openSplash(self,nil)
ADDITIONAL NOTES: You can create your intro in .mp4 format with a program like Camtasia Studio 7 or 8 and then use a file converter(search it at google) to convert your mp4 to swf. Remember that the screen size is 512x384, but you can use a smaller video if you want and it will show anyways.

That's all at the moment. I think i don't miss anything. Post any problems here.
__________________
Click Here to enter my project's Webpage!
Hey guys, Im a Spanish boy. It's hard for me to speak completely good in english, but I'll do my best. Please, don't be too bad with me

Last edited by Peaverin; December 1st, 2013 at 05:21 AM.
Reply With Quote
  #2    
Old November 19th, 2013, 01:04 AM
Lanyons's Avatar
Lanyons
Love Type
 
Join Date: Nov 2013
Location: Colorado, USA
Gender: Female
Nature: Bold
This is awesome thanks :D
Reply With Quote
  #3    
Old November 23rd, 2013, 09:40 PM
WinterKirby's Avatar
WinterKirby
 
Join Date: Dec 2012
Age: 2
Gender: Male
Nature: Mild
This is fantastic!

Now if only I could do stuff in Flash...
__________________
X/Y Friend Code: 1349-5852-1728 | Pinkie | Flying | Hoot-Hoot, Pidgey, and Tropius

Reply With Quote
  #4    
Old November 28th, 2013, 05:40 PM
akane159
 
Join Date: Oct 2012
Gender: Female
i have a erro in Main and line 35

Last edited by akane159; November 28th, 2013 at 05:43 PM. Reason: error
Reply With Quote
  #5    
Old November 28th, 2013, 07:34 PM
Dylanrockin's Avatar
Dylanrockin
Mysterious Trainer
 
Join Date: May 2011
Gender: Male
Nature: Timid
Teacher, I have a question! Do I have to create a subfolder called "Flash" in the main section of my folders, or would I put them in the graphics folder? Also, I got this error on startup, I'm not quite sure what it means though. I'm a tad noob-status at this kind of stuff ^.^;

---------------------------
Pokemon: Symphonic Horizon
---------------------------
Exception: NameError

Message: uninitialized constant Scene_IntroFlash

Main:35:in `mainFunctionDebug'

Mainin `mainFunction'

Mainin `pbCriticalCode'

Mainin `mainFunction'

Main:47

Main:46:in `loop'

Main:55



This exception was logged in

C:\Users\Dylan\Saved Games/Pokemon_ Symphonic Horizon/errorlog.txt.

Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK
---------------------------
__________________
Visit my YouTube Channel: http://www.youtube.com/user/Pokemonmaster212
My Pokemon Symphonic Horizon RPG Maker XP Game: http://www.pokecommunity.com/showthr...66#post8016366
Reply With Quote
  #6    
Old November 28th, 2013, 08:05 PM
akane159
 
Join Date: Oct 2012
Gender: Female
Quote:
Originally Posted by Dylanrockin View Post
Teacher, I have a question! Do I have to create a subfolder called "Flash" in the main section of my folders, or would I put them in the graphics folder? Also, I got this error on startup, I'm not quite sure what it means though. I'm a tad noob-status at this kind of stuff ^.^;

---------------------------
Pokemon: Symphonic Horizon
---------------------------
Exception: NameError

Message: uninitialized constant Scene_IntroFlash

Main:35:in `mainFunctionDebug'

Mainin `mainFunction'

Mainin `pbCriticalCode'

Mainin `mainFunction'

Main:47

Main:46:in `loop'

Main:55



This exception was logged in

C:\Users\Dylan\Saved Games/Pokemon_ Symphonic Horizon/errorlog.txt.

Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK
---------------------------
you have to create a subfolder called Flash , but i did that and i have the same error
Reply With Quote
  #7    
Old December 1st, 2013, 05:23 AM
Peaverin's Avatar
Peaverin
 
Join Date: Sep 2013
Gender: Male
Quote:
Originally Posted by Dylanrockin View Post
Teacher, I have a question! Do I have to create a subfolder called "Flash" in the main section of my folders, or would I put them in the graphics folder? Also, I got this error on startup, I'm not quite sure what it means though. I'm a tad noob-status at this kind of stuff ^.^;

---------------------------
Pokemon: Symphonic Horizon
---------------------------
Exception: NameError

Message: uninitialized constant Scene_IntroFlash

Main:35:in `mainFunctionDebug'

Mainin `mainFunction'

Mainin `pbCriticalCode'

Mainin `mainFunction'

Main:47

Main:46:in `loop'

Main:55



This exception was logged in

C:\Users\Dylan\Saved Games/Pokemon_ Symphonic Horizon/errorlog.txt.

Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK
---------------------------
Oh, I made a mistake and I copied the same script two times.
The correct Scene_IntroFlash is this one:
Spoiler:
Code:
#===============================================================================
#
# * Scene_IntroFlash by Dahrkael using 灼眼的夏娜 Flash Player
#   Adapted to Pokemon Essentials by Peaverin                                                                                                            v1.0
#    Requires the .dll and .ocx
#===============================================================================
class Scene_IntroFlash
 
  def initialize
     # Set the file which will be played
     @file = "intro.swf"
     # Choose if the player can skip the intro (0 => false, 1 => true)
     @button = 1
  end
 
  def main
     # Black background
     @fondo = Sprite.new
     @fondo.bitmap = Bitmap.new(512, 384)
     @fondo.bitmap.fill_rect(0, 0, 512, 384, Color.new(0,0,0,255))
     @fondo.z = -1
     # Set flash video
     fls = RMFlash.load(@file, 512, 384)
     fls.loop = 1
     fls.z = 999999
     # Save frame rate
     @fr = Graphics.frame_rate
     # Set new frame rate
     Graphics.frame_rate = 40
     # Main loop
     Graphics.transition
     while true
        Graphics.update
        #Input.update
        fls.update
        # Skip the video using Enter
        break if @button == 1 and Keyb.trigger($keys["Enter"])
        # Skip when finished
        break if !fls.playing?
     end
     $scene = pbCallTitle
     Graphics.freeze
     # Little solution for frozen images
     fls.z = -2
     fls.dispose
     # Set old frame rate
     Graphics.frame_rate = @fr
  end
end

So you have to change the second script by this one. Now it should work without problems.
__________________
Click Here to enter my project's Webpage!
Hey guys, Im a Spanish boy. It's hard for me to speak completely good in english, but I'll do my best. Please, don't be too bad with me
Reply With Quote
  #8    
Old January 2nd, 2014, 10:33 AM
dydd90's Avatar
dydd90
 
Join Date: Dec 2013
Location: Italy
Gender: Male
Awesome :D
I will use it and i will give you credits
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:14 AM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.