DB Reference
Database tables must be created manually using the file browser. Following function exist to access the database. See Database Examples for examples.
- DB.load(tablename, options, entries => { ... }) - loads an array of DB entries, options specifies the attributes (exact match, or array to match multiple values) and the third parameter is a callback to receive the entries. Options can also include limit, offset (numbers) and orderby of format "column ASC/DESC". Instead of callback you can also use await to return the result. Note that DB.load always returns an array, even if you only expect a single entry.
- DB.save(tablename, options, insertid => { ... }) - inserts or updates an object into the database. Unsupported attributes will make the call fail. Third parameter is an optional callback which is called when the data has been saved. Instead of callback you can also use await to wait for it to finish saving, it will return the inserted id.
- DB.delete(tablename, options, deletedrowcount => { ... }) - deletes DB entries, options specify the attributes (exact match). Third parameter is an optional callback which is called when the data has been deleted. Instead of callback you can also use await to wait for it to finish deleting, it will return the count of deleted rows.
- DB.addplayerscore(playerid:number, type:string [, nr:number]) - adds a player score entry for the current day, can be used by scorestatue npcs, you need to add the type to allowedscores in the main.json config
- DB.getplayerscore(playerid:number, scoretype:string, scoredays:string, (data) => {}) - gets the player score entry for the amount of days. Instead of callback you can also use await to return the result.
- DB.getplayerscores(playerid:number, (data) => { ... }) - gets all playerscores (from main config allowedscores) as one object. Instead of callback you can also use await to return the result.
- DB.addclanscore(clanname:string, type:string [, nr:number]) - adds a clan score entry for the current day
- DB.getclanscores(clanname:string, (data) => { ... }) - gets all scores for a clan as object of format {castle:number, kills:number, spar:number}. Instead of callback you can also use await to return the result.
- DB.getbuilding(buildingname: string) - gets info about a base or castle
- DB.setbuildingstatus(buildingname: string, status: string) - opens/closes the base or castle, status must be "active" or "inactive"
- DB.setbuildingowner(buildingname: string, clanname: string) - sets a new owner for the base or castle
- DB.loadplayer(playerid:number, (player, updatetime) => { }) - returns either the online player or loads from database if offline. Instead of callback you can also use await to return the player object.
- DB.savejobincome(playerid:number, job:string, coins:number) - saves job income for stats
- DB.getjobincome(playerid:number, job:string, coins => { }) - loads the job income of a player and calls a callback. Instead of callback you can also use await to return the result.
- DB.getjobincometoday(playerid:number, job:string, coins => { }) - calculates how many coins the player earned today, for case where you want to limit it. Instead of callback you can also use await to return the result.
- DB.setclanlogo(clanname:string, logo:string, () => { ... }) - updates the clan logo, the logo must be a filename relative to /Files/
- DB.loadstory(storyid, story => { }) - loads the story data and calls a callback. Instead of callback you can also use await to return the result.
- DB.getlikescount(playerid:number, likescount => { ... }) - gets the number of other players who liked this profile, use a callback or await to get the result
- DB.hasliked(playerid:number, otherid:number, liked => { ... }) - if player with playerid likes the other player, use a callback or await to get the result
- DB.addlike(playerid:number, otherid:number, () => { ... }) - remember that player with playerid likes the other player, use a callback or await to wait for it to saved
- DB.removelike(playerid:number, otherid:number, () => { ... }) - remove the like from player with playerid, use a callback or await to wait for the removal to be finished
- DB.getplayerhouses(playerid:number, houses => { ... }) - gets an array of houses, use a callback or await to get the result, the houses have the attributes: houseid:number, map:number, template:number, npcname(id), itemid:string (such as "house3"), x:number, y:number, ani:string, house:string (image), name:string
- DB.getjailinfo(playerid:number, info => { ... }) - get the jail info to check if the player is jailed and for how long, use a callback or await to get the result, the jail info has following attributes: userid:number, map:string, reason:string, jailtime:string, timeleft:numner, adminid:number, adminname:string
- DB.getplayeridsbyip(playerid:number, (ids) => { ... }) - get array of player ids who have the same ip address as the provided player id. Instead of callback you can also use await to return the result.