-
Notifications
You must be signed in to change notification settings - Fork 150
About revscriptsys
revscriptsys is a branch of OTServ that aims to improve the scripting capabilities. Once released, it will be version 0.7.0 of OTServ. One of the more important changes is that all lua functions and objects are exposed as classes instead of free functions. This allows for neater scripts and a more logical structure.
For examples on how to use it, see the examples page.
In revscriptsys, Items, Players, Tiles etc. are represented as objects. An object can be manipulated through it's member function, for example:
item = createItem(2543) -- Create an Item object, a bolt to be exact
item:setCount(88) -- Set the amount of bolts to 88
Objects can either be created in scripts, as above, or fetched from the enviroment through events or get functions. For example, to get the top item of the tile at the position 1024, 1024, 7:
tile = map:getTile(1024, 1024, 7) -- Get the tile object at 1024, 1024, 7
item = tile:getTopItem() -- Fetches the highest item on the tile
Objects are entirely persistant. Meaning that if you acquire a reference to an object, you will be able to store it and modify it forever and ever (until it is destroyed by natural causes), the only "unnatural" things that destroys an object reference is:
- Stacking items: when two item stacks are merged into one (for example, adding two 10 bolt stacks to one 20 bolt stack), one of the objects is destroyed (which one is undefined).
- Players logging out: If a player logs out and logs in again, all the items that he or she was carrying will lose their references (as they are in fact removed from the game and recreated again).
Methods are called on objects using the : operator. Calling a method on an invalid objects will always cause an exception to be thrown (see Error Handling. You can check for an invalid object using a simple if statement.
item = map:getTile(1024,1024,7):getTopItem()
if item then
-- Item was valid, do something fun!
else
-- No item was fetched. Error?
end
Revscriptsys has a very advanced event system, allowing events to be tied at runtime, and modification of event parameters.
Events are tied using register functions. These functions take a few parameter that specifies how the listener works, and a callback function that will be called when the event occurs. An example is the onSpeak event.
function testCallback(event)
-- Do something fun when the player says "test event"
end
-- The arguments are, in order, type of match (anywhere in the message),
-- cAsE sensitivity, the string to look for and the callback function
registerGenericOnSayListener("substring", false, "test event", testCallback)
All the different event types can be found at List of Event Types.