Map Reference
You can access the current map or the map of the player by this.map and player.map. The map itself has following attributes and functions. Also check out the Tiled-guide
Attributes
- map.type: string, always "map"
- map.name: string, map name (first parameter in setmap)
- map.template: string, template name (second parameter in setmap)
- map.width: number, width of the map (one unit is 32 pixels
- map.height: number, height of the map
- map.eventinfo: object|null {active:boolean, pk:boolean, warpdead:boolean, ignoretags:boolean, canevent:boolean}, only on server, can be used to control event maps
- map.tiletypeanis: array of strings, only client-side, define the animation displayed as footsteps depending on the tiletype layer
- map.auctioninfo: object, contains info about the current auction
- map.auctioncontrol: NPC, can be used to control auctions with functions getauction(), clearauction(player), createauction(player, {itemid:string, initialbid:number}, callback(success, message)), startauction(player, {finishinminutes:number}, callback(success, message)), finishauction(player, callback(success, message)), bid(player, amount)
- map.sparinfo: object, contains info about the current spar
- map.sparqueue: NPC, can be used to control spars similar to the /spar commands: getspar(), lock(), unlock(), stop(), start(player1, player2), startclan(clanname1, clanname2), setweapons(itemid:string)
- map.properties: object, on client-side, shows Tiled properties such as music or enabledaynight
- map.custommarkers: array of objects, on server-side, can be set to display additional map markers to the map
Functions
- map.iswater(x:number, y:number) - boolean, returns of the specified position is water
- map.iswall(x:number, y:number [, onlytiles:boolean]) - boolean, checks if the specified position is a wall. If onlytiles is true, then it only checks tiles and ignores NPCs
- map.isnopk(x:number, y:number, forplayer:boolean) - boolean, only on server, checks if the specified position is in a nopk area. If forplayer is true, then it checks PvP, otherwise if the NPC can hurt the player
- map.gettile(x:number, y:number, tileset:string) - number, get's the tile of the first layer matching the specified tileset image file at the specified position
- map.gettiletype(x:number, y:number) - number, if the map contains tiletypes layers, then this returns the tiletype at the specified position
- map.matchestiles(x:number, y:number, tiledefs:object) - boolean, checks if at the specified position a layer matches the provided tile definition of format
{"filename":[1,2,3...]}
- map.randompos({x:number, y:number, w:number, h:number}, checkwater:boolean) - object {x:number, y:number}, only on server, tries to find a random position in the specified rectangle which is not colliding and not in water, if checkwater is true
- map.addnpc(obj) - NPC, only on server, adds a NPC with the provided info. You have to provide the initial NPC attributes, including x, y, image or ani, dontsave(boolean), possibly also npcclass, mobtype, hat, head etc. Do add a scriptnpc, provided npcclass:"scriptnpc" and specify scriptclasses (array)
- map.spawnitems(x:number, y:number, spawntype:string) - only on server, spawns items defined in spawns.json at the specified position
- map.setambient(red:number, green:number, blue:number) - only on client-side, values between 0 and 1. Let's you overwrite the ambient (daynight) effect only for the current map
- map.gethouse(houseinfo => { ... }) - loads house info with callback
- map.showkill(player, victim) - It will display in the game when a player kills another player.
- map.collectfurniture(player) - adds furniture objects into the inventory of the player
- map.findpath(fromx, fromy, tox, toy) - server-side, returns an array of point arrays such as
[[1,2],[2,2]]
, finds a path with a*star algorithm to avoid blocking tiles