Script Bindings Progress

Content and general development discussion, including quest scripts and server code. TMW Classic is a project comprising the Legacy tmwAthena server & the designated improved engine server based on evolHercules.


Forum rules

This forum houses many years of development, tracing back to some of the earliest posts that exist on the board.

Its current use is for the continued development of the server and game it has always served: TMW Classic.

Post Reply
User avatar
nym
Novice
Novice
Posts: 116
Joined: 18 Aug 2004, 10:01
Contact:

Script Bindings Progress

Post 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.
YOU ARE READING THIS!
Metalcore
Peon
Peon
Posts: 16
Joined: 06 Nov 2005, 19:32
Location: Georgia

Re: Script Bindings Progress

Post 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}"
Evan
User avatar
nym
Novice
Novice
Posts: 116
Joined: 18 Aug 2004, 10:01
Contact:

Post 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 :)
YOU ARE READING THIS!
Post Reply