Script Bindings Progress

Content and general development discussion, including maps, quests, and server code from the development team.
Post Reply
User avatar
nym
Novice
Novice
Posts: 116
Joined: Wed Aug 18, 2004 11:01 am
Contact:

Script Bindings Progress

Post by nym » Tue Nov 15, 2005 8:25 am

Some of you may know i have been working on some scripting bindings for TMW server, and as requested by an individual I will post an update on the forums :)

Currently you are able to create Ruby scripts which provide some basic functionality for the server. Many of the reasons that some things are not hugely functional is because the feature has not been totally implemented with the server. The only part which is fully usable via Ruby scripts are "message handlers", which allows you to redefine and extend the server's protocol.

Here is a small example:

Code: Select all

class EquipHandler < Tmw::MessageHandler
  def initialize()
    super
  end

  def receiveMessage(computer, message)
    print "Message ID: ", message.getId(), "\n"
    item = message.readLong()
    slot = message.readByte()
    print "Trying to equip ", item, " at ", slot.to_i(), "\n"

    result = Tmw::MessageOut.new()
    result.writeShort(Tmw::SMSG_EQUIP_RESPONSE)
    result.writeByte(Tmw::EQUIP_OK)
    computer.send(result.getPacket())
  end
end

Tmw::connectionHandler.registerHandler(Tmw::CMSG_EQUIP, EquipHandler.new())
This small script will override the default action which is taken when a client tries to equip an item.

Now i will be working on making everything work nicely and interact in the game world, and providing support for scripted enemies & items.
YOU ARE READING THIS!
Metalcore
Peon
Peon
Posts: 16
Joined: Sun Nov 06, 2005 8:32 pm
Location: Georgia
Contact:

Re: Script Bindings Progress

Post by Metalcore » Tue Nov 15, 2005 11:53 pm

an individual, eh? >_>

for the record, a different way to include variables in a string is using #{}
also, you don't need the final ()'s in function calls when there's no arguments.
and i tend to see puts being used more than print in Ruby, although there's very little difference, AFAICT
so instead of

Code: Select all

 print "Trying to equip ", item, " at ", slot.to_i(), "\n"
you'd have

Code: Select all

 puts "Trying to equip #{item} at #{slot.to_i}"
Evan
User avatar
nym
Novice
Novice
Posts: 116
Joined: Wed Aug 18, 2004 11:01 am
Contact:

Post by nym » Wed Nov 16, 2005 12:18 am

Hehe, ok. I haven't really used Ruby for anything. Im more of a Perl guy (Tcl is good too) ;)

I know you can leave out the parentheses from functions, except sometimes they help for clarity :)
YOU ARE READING THIS!
Post Reply