Map
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
- map.hidelayer: boolean, on client-side, allows certain tile layers (with
hidelayerproperty set to true) to be dynamically hidden or become transparent based on player overlap. - map.cutouthole: boolean, on client-side, default false, enables a light around the player and darkness outside of the radius
- map.cutoutholeradius: number, on client-side, radius of the light around the player
- map.cutoutholenodaynight: boolean, on client-side, default false, makes only a circle around the player visible if daynight mode is disabled
Camera Zones (client-side)#
Camera zones can be applied from client scripts using player.setcamerazoom(params), or implemented directly in Tiled using the camera NPC class.
Implementing via Tiled#
To create a camera zone on your map without scripting:
- Create an Object Layer in Tiled.
- Draw a rectangle covering the area where the camera should change.
- Set the object's
Typeproperty toNPC. - Add the following custom properties:
npcclass:camera(Required)cameraType:zoomorstatic(Default isstatic)zoom: number (e.g.2.0for 2x zoom)speed: number (e.g.0.05for camera pan/zoom transition speed)blend: number (e.g.0.22for position blend duration in seconds)lockX/lockY: number (optional, forstaticcameras. Defaults to the center of the Tiled object if omitted).
When a player enters this NPC's bounding box, the camera zone activates. When they leave, it resets.
Implementing via Script (player.setcamerazoom(params))#
Two modes are available when using player.setcamerazoom(params) directly:
Zoom mode — adjust zoom while the camera continues following the player:
| Parameter | Type | Default | Description |
|---|---|---|---|
| zoom | number | 1.0 | Target zoom level (0.25–4.0) |
| speed | number | 0.05 | Transition speed (0.001–1.0) |
| zoomSpeed | number | speed | Override speed for zoom only |
| instant | boolean | false | Skip transition |
| priority | number | 0 | Zone priority (higher wins) |
| blend | number | 0.22 | Position blend duration in seconds (0–2.0) |
Static mode — lock the camera to a fixed position:
| Parameter | Type | Default | Description |
|---|---|---|---|
| x | number | — | Target camera X tile position |
| y | number | — | Target camera Y tile position |
| zoom | number | current | Target zoom while static |
| speed | number | 0.05 | Camera pan speed |
| zoomSpeed | number | speed | Zoom transition speed |
| instant | boolean | false | Skip transition |
| blend | number | 0.22 | Blend duration in seconds |
Use player.resetcamerazoom() to restore the camera to its pre-script zoom level.
Functions#
- map.iswater(x:number, y:number) - boolean, returns of the specified position is water
- map.isladder(x:number, y:number) - boolean, client-side, returns if the specified position is a ladder
- 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 [, dynamic:boolean]) - 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. Optional dynamic parameter enables dynamic pathfinding