http://www.perlmonks.org?node_id=293663

Dragonfly has asked for the wisdom of the Perl Monks concerning the following question:

Anybody have any experience trying to use Perl as a kind of "scripting engine overlay", that could be used to send and receive text into say a 3D online video game?

I'm not too ashamed to admit that I sometimes use Windows and I found a fun 3D MMORPG recently that allows you to send keystrokes to the application that make your avatar "emote" different moves. For instance, to make your avatar smile, you just preface the command "smile" with a single quote.

I'd basically like to see if I can run Perl as a daemon on Windows and have it wait for certain function keys, and perhaps make some more complex loops so I could, for instance, type another character's name into the command, and it would incorporate that into a little song + dance routine. (Maybe find an automatic rhyme generator? heh.)

If I can get this to work, it'd open up a whole new realm of possibilities for my character - some people have suggested I use commercial macros packages instead, but I think this way would be far more rewarding (and hopefully I'd learn enough about Win32 Perl that I could use the knowledge in the future to automate my other apps.)

I've seen a few other avatars using the macros apps and they're frankly kind of limited in what they can accomplish.

I know I'll have to work with the Win32::OLE automation stuff probably, I was just hoping perhaps some of you would have had experience with this and could give me a jump start.

I have worked with Expect a while back to script a few routines for a MUD, but this is a totally different ball o' wax I think.

Thanks!

- Mark Beihoffer, Network Architect (and video gamer evidently.)

Replies are listed 'Best First'.
Re: Scripting for Video Games
by sandfly (Beadle) on Sep 23, 2003 at 23:47 UTC
    One obvious problem is that the game has to expose an OLE API. If it does, you need to figure out what the correct program ID string is. There are a couple of OLE browsers available which are invaluable. Check out this node.

    If you have access to MS Office, I recommend trying the examples in the Win32::OLE documentation. Outlook and Excel both work really well.

    Depending on how well the API is documented, it might be a trivial task, or you might have no luck at all.

Re: Scripting for Video Games
by kelan (Deacon) on Sep 24, 2003 at 13:52 UTC

    You might want to look at Win32::GuiTest. It can be used to send keystrokes to windows and other neat stuff.

    kelan


    Perl6 Grammar Student

Re: Scripting for Video Games
by Solo (Deacon) on Sep 24, 2003 at 16:56 UTC
    One problem you'll encounter with scripting 3D games on Win32 is that the DirectInput drivers/interface sits below the windows message queue for keystrokes. The SendKeys API (which Win32::Setupsup and Win32::GuiTest use) will only work with mouse events and not with keyboard events for games that use DirectInput--i.e. almost all of them.

    This has been a problem for me in non-game applications where developers used DirectX/DirectInput for basic input.

    An updated Win32 API call exists to provide the needed functionality. I think if you googled DirectInput and SendKeys you'd get some useful info about it. It would require some real work with Win32::API, though.

    --Solo

    --
    I think my eyes are getting better. Instead of a big dark blur, I see a big light blur.
Re: Scripting for Video Games
by Mr. Muskrat (Canon) on Sep 23, 2003 at 21:32 UTC

    There are a plentitude of Win32 modules that could assist you in such an endeavor. I think that the real question is: Should you do it? Ask a lawyer before you try this because you very well may be violating the license of Perl and/or the game (and/or it's terms of service)!

      Well, there is nothing in the member's terms of service that prohibit the use of scripting, macros, or other forms of character automation, so presumably (since other players are doing it with Windows-only macro products) it's allowed. They even teach classes in-game on how to use macros. =P

      I fail to see how using Perl to automate a Windows app would violate the Artistic License - could you tell me where you see a problem with that? I'm curious!

      There have been all sorts of Win32::OLE automation modules already, including ones to automate Excel, Outlook, and Word - I guess I just don't see how this would be any different. Is it because it's an online application?

      LWP does the same thing with web sites, and they're online...

        I guess I should have added the usual 'IANAL'.

        Many games have in-game macros that the developers want you to use. But when it comes to using external macros with games (especially MMORPGs), many people (myself included) view it as cheating. The in-game macros make it more difficult to use them for cheating by limiting the things that you can do with them.

      I would very much like to know where you got the notion that
      automating a windows application or any other application for
      that matter is violating the Perl license?

      Please explain it to this community.

      Or were you just trying to be otiose?

        I misread the Artistic License. Once again I think that I should stress that IANAL!

        And what meaning do you give the word 'otiose'? To me it means lazy. I don't see that definition would apply.