Page 1 of 1

Script Bindings Progress

Posted: 15 Nov 2005, 08:25
by nym
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.

Re: Script Bindings Progress

Posted: 15 Nov 2005, 23:53
by Metalcore
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}"

Posted: 16 Nov 2005, 00:18
by nym
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 :)