Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Big problem with .avi files

Badi

Member

I have a script :


PHP:
class Scene_Movie 

 def initialize(movie,length) 
   @movie_name = Dir.getwd()+"\\Movies\\"+movie+".avi" 
   @counter = length 
 end 
  
 def main 
    
   Graphics.transition 
   @wnd = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L') 
   @temp = @wnd.call(0,0,nil,"Scripts").to_s 
   @movie = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V') 
   @movie.call("open \""+@movie_name+"\" alias FILE style 1073741824 parent " + @temp.to_s,0,0,0) 
   @movie.call("play FILE",0,0,0) 
   loop do 
     Graphics.update 
     sleep(1) 
     Input.update 
     if Input.trigger?(Input::B) 
       break 
     end 
     @counter = @counter - 1 
     if @counter == 0 
       break 
     end 
   end 
   @movie.call("close FILE",0,0,0) 
   $scene = Scene_Map.new 
   Graphics.freeze 
 end 
end



But when I use it, the game was turning off !!
Help ??
 
Hi there, I'm kinda new at this, but have you tried commenting out the lines with
Code:
Win32API.new
and replacing the values with 'constant' settings instead, like know directories, just an idea, this way you can limit the problem to one or two lines of the code.

Sorry I couldn't be of more help, good luck.
 
The script is incomplete...

Good thing I actually kept a copy of the .html file I got from .net!!!

* - * - * - * - * - * - *


SOUNDSPAWN'S VERSION 5.0 (May 19 2005, 05:52 AM)

Version 5.0
NO LONGER NEEDS PLAYTIME. Automatically plays until the movie is done. Just pass the movies filename minus the extension and it should play just fine.

Back to being simple... just copy the code snippet below and call it as described and it should work just fine.

Code:
class Scene_Movie

def initialize(movie)
@readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
@movie_name = Dir.getwd()+"\\Movies\\"+movie+".avi"
main
end

def main

game_name = "\0" * 256
@readini.call('Game','Title','',game_name,255,".\\Game.ini")
game_name.delete!("\0")
@wnd = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')
@temp = @wnd.call(0,0,nil,game_name).to_s
movie = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')
movie.call("open \""+@movie_name+"\" alias FILE style 1073741824 parent " + @temp.to_s,0,0,0)
@message = Win32API.new('user32','SendMessage','%w(l,l,l,l)','V')

@detector = Win32API.new('user32','GetSystemMetrics','%w(l)','L')
@width = @detector.call(0)
if @width == 640
fullscreen
Graphics.update
sleep(1)
Graphics.update
sleep(1)
Graphics.update
sleep(1)
end

status = " " * 255
movie.call("play FILE",0,0,0)
loop do
sleep(0.1)
@message.call(@temp.to_i,11,0,0)
Graphics.update
@message.call(@temp.to_i,11,1,0)
Input.update
movie.call("status FILE mode",status,255,0)
true_status = status.unpack("aaaa")
if true_status.to_s != "play"
break
end
if Input.trigger?(Input::B)
Input.update
break
end
end
movie.call("close FILE",0,0,0)
bail
end

def bail
if @width == 640
fullscreen
end
end
end

def fullscreen()

$full.call(18,0,0,0)
$full.call(13,0,0,0)
$full.call(18,0,2,0)
$full.call(13,0,2,0)
end
$full = Win32API.new('user32','keybd_event','%w(l,l,l,l)','')

Copy this into a new section of your game. To play a file, move the avi file into a "movies" subdirectory (yourgame\data, yourgame\graphics, yourgame\movies). Then call "Scene_Movie.new(filename)" where filename is your movies actual filename (minus the .avi).

all right, not much has changed here, but it's actually a pretty big deal, so I'm cropping out all that older stuff. To call the script now (you may have just read it above too) just call "Scene_Movie("movie_name")" WITHOUT "$scene = " before it. This will retain the "scene" and the game will just return to the portion of code it left off at when the movie is done. With this seemingly small change, you can now play movies inside battles, or anywhere else. If you want to play multiple movies in a row (for example before the game starts, maybe a "developed by", "produced by", "intro movie" set or something... Go to the "main" section of code and find the line "$scene = Scene_Title.new". Just after that line add:
Code:
Scene_Movie.new("dev_by")
Scene_Movie.new("pro_by")
Scene_Movie.new("intro")
This assumes your movies are "dev_by.avi" for your developed by movie, "pro_by.avi" for your producers movie, and "intro.avi" for your intro movie. Just change those to be the correct filenames and you're set.

To call a movie during a battle, there's actually multiple ways. If you can trap the spot you want the movie (for example through a trigger in the Monster Group tab) just call script "Scene_Movie("moviename")" and you're set. It will play the movie, then return to where the battle left off.

This should also work with CBS', as long as you can trap the spot you want the movie to play. My best advice for trapping spots in code is to type

Code:
print "HEY"
in the code, then when you play, a windows-style popup box will show up when it hits that line. If that's where you want the movie, replace it with the "Scene_Movie.new" line.

To call the movie from an event (for example, everytime you talk to a certain person, a movie plays) make the event, set it's Trigger to "action key" and for the event commands, use call script (last page, bottom right) and type "Scene_Movie.new("moviename")".

FAQ:
1) Can this play wmv/mpg/whatever format files?
If you modify the line
Code:
 @movie_name = Dir.getwd()+"\\Movies\\"+movie+".avi"

to end with ".wmv"/".mpg"/whatever. If the movies are original though, just save them as avis. You can use any codec you want with most formats, I use windows media player 9 encoding on my avis, making them just BARELY larger than wmvs, and it doesn't step on any EULA toes (WMV is the devil).

2) What codec should I use?
In the past the only video codec known NOT to work is an old Divx codec... so if you want to use divx, just make sure you are using the newest codec. If you want something compatible with every windows computer, use Windows Media Player 9 (or 10 if that's out now). As for audio, choose any MP3 codec.

3) Are their any known bugs?
Yes, first off if you are playing in fullscreen mode the movie will actually pull you out of fullscreen before it plays, then return you to fullscreen mode after it completes. This has to do with the workaround I had to do in order to eliminate flicker in the movies.
The biggest bug (and most easially avoidable) only applies if you are running windowed mode with 640x480 resolution. You should know if this is the case, because the game window won't fully fit on your screen (games screen is 640x480, plus the border around the screen and the titlebar make it too big for that resolution). If this is the case, you're going to see some funky stuff... It'll shoot INTO fullscreen mode, play the movie with flicker, and spit you back into windowed mode when the movie is over... Just up your resolution.

4) Can I call this script from anywhere in my game?

Sure can. You can use events (common or not) as well as actual code to play the movie... If using an event, go to the third page of event buttons (you know, three tabs full of labeled buttons...) and click on "Call Script". A text box will appear where you can type Ruby code. Type the code as was described above.
If you want to call it from actual code, just figure out WHERE in your code it needs called from (I recommend inserting pring "HEY" to test). When you find the place, same story.[/b]
...More to come if needed...

* - * - * - * - * - * - *


QUESTION posed by Mirror Man (May 19, 2005)

can wmv. files work? :X

* - * - * - * - * - * - *


REPLY by Soundspawn (May 19, 2005)

If you mean "Windows Media Player 9" codec yes. But the file extension needs to be .avi, not .wmv. You could try modifying the code I gave to have it add ".wmv" instead of ".avi" and give it a try if you like, although there is a remote chance of a problem here (.wmv file format is patented by M$, not going to get into legal details, but if it works, it's legal).

You could potentially change
Code:
@movie_name = Dir.getwd()+"\\Movies\\"+movie+".avi"
to
Code:
@movie_name = Dir.getwd()+"\\Movies\\"+movie
and call
Code:
$scene = Scene_Movie.new("intro.wmv",8)
or
Code:
$scene = Scene_Movie.new("intro.avi",8)
but again if you're making your own videos for the game, you should be able to make them any file extension you wish, so you might as well just make them avi and not mess with the code I provided.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top