The small library for easy using API of OWOP + Guide.
For many scripters it's really hard to found how to use the API of OWOP. This is free library with documentation. It has all needed for making scripts
To install the lib you need just to paste this to your script.
var ojs = document.createElement('script');
ojs.src = "https://raw.githack.com/dimdenGD/OWOP.js/master/OWOP.js";
document.getElementsByTagName('head')[0].appendChild(ojs);
ojs.onload = function() {
// Your code ...
};
TO use the library you need to write OJS tag.
Getting id of player:
OJS.player.id();
- returns 15683.
Getting nickname of player:
OJS.player.name();
- returns "dimden".
Getting player rank:
OJS.player.rank()
- returns 1.
Getting tool that player using right now:
OJS.player.tool()
- returns "fill".
Getting colour that player using right now:
OJS.player.color()
- returns array [13, 54, 63].
Getting tool list of player:
OJS.tool.list()
- returns object with tools.
You can create your own ranks.
OJS.rank.create(rankName, id)
Example:
OJS.rank.create("VIP", 4);
To get rank use:
OJS.rank.get(rankName)
Example:
OJS.rank.get("ADMIN"); // returns 3
To set rank use:
OJS.rank.set(rankName, id)
Example:
OJS.rank.set("NONE", 5) // Now NONE rank have 5 id
You can get all windows:
OJS.window.all()
- returns object with all windows.
You can delete window:
OJS.window.delete(windowTitle)
Example:
OJS.window.delete("OWOP Radio"); // OWOP Radio will be deleted
Creating window in vanilla OWOP API:
function testWindow() {
OWOP.windowSys.addWindow(new OWOP.windowSys.class.window('Test Window', {}, function(win) {
win.addObj(document.createTextNode(`This is test text in cool window`));
win.container.style.height = 'auto';
win.container.style.width = 'auto';
win.container.style.overflow = 'hidden';
}).move(window.innerWidth - 1200, 32))
}
if (typeof OWOP != 'undefined') testWindow();
window.addEventListener('load', function() {
setTimeout(testWindow, 1300);
});
You can get the last message WITHOUT nickname:
OJS.chat.lastMessage()
- returns "Test Message".
You can get the last message WITH nickname:
OJS.chat.lastMessageFull()
- returns "[12932] dimden: Test Message".
You can get first message:
OJS.chat.firstMessage()
- returns "[Server] Joined world: "main", your ID is: 12932!".
You can send message to chat:
OJS.chat.sendMessage(Message)
Example:
OJS.chat.sendMessage("Test Msg");
You can send LOCAL message:
OJS.chat.localMessage(Message);
Example:
OJS.chat.localMessage("Test Msg");
You can clear chat:
OJS.chat.clearChat()
- chat will be cleared.
You can get the message that will be sended:
OJS.chat.getSendMessage()
Example how to create your own commands:
OJS.chat.getSendMessage(msg => {
if(msg == "!test") {
OJS.chat.localMessage("Test was successfull!");
return msg;
} else {
return msg;
}
})
You can set pixel:
OJS.world.setPixel(x, y, colourFromPallete)
Example:
OJS.world.setPixel(0,0,1);
You can get pixel:
OJS.world.getPixel(x, y)
- returns array with RGB.
You can get coordinates:
OJS.world.coordinates.x()
;
OJS.world.coordinates.y()
;
You can get last coordinates:
OJS.world.coordinates.last_x()
;
OJS.world.coordinates.last_y()
;
You can get tile coordinates:
OJS.world.coordinates.tile_x()
;
OJS.world.coordinates.tile_y()
;
You can get camera coordinates:
OJS.world.coordinates.camera_x()
;
OJS.world.coordinates.camera_y()
;
You can disconnect:
OJS.world.disconnect()
- Lost connection with server.
You can reconnect:
OJS.world.reconnect()
OJS.options.set.defaultWorld(WorldName)
;
OJS.options.set.defaultZoom(Value)
;
OJS.options.set.sounds(TrueFalse)
;
OJS.options.set.maxChatMessages(Value)
;
OJS.options.set.minGrid(Zoom)
;
OJS.options.set.cameraSpeed(Value)
;
OJS.options.set.toolsetURL(LinkOrFile)
;
OJS.options.set.zoomMax(Value)
;
OJS.options.set.zoomMin(Value)
;
OJS.options.get.defaultWorld()
;
OJS.options.get.defaultZoom()
;
OJS.options.get.sounds()
;
OJS.options.get.maxChatMessages()
;
OJS.options.get.minGrid()
;
OJS.options.get.cameraSpeed()
;
OJS.options.get.toolsetURL()
;
OJS.options.get.zoomMax()
;
OJS.options.get.zoomMin()
;
You can get toolset of player:
OJS.tool.list()
- returns object with tools.
You can delete tool:
OJS.tool.remove(tool)
Example:
OJS.tool.remove("cursor") // Cursor will be deleted
You can get local storage of OWOP:
OJS.localStorage
I'm not owner of ourworldofpixels.com. This library is free for use.