DB Reference
Database tables must be created manually using the file browser. Following function exist to access the database:
- DB.load(tablename, options, entries => { ... }) - loads an array of DB entries, options specifies the attributes (exact match) 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".
- DB.save(tablename, options, () => { ... }) - 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
- DB.delete(tablename, options) - deletes DB entries, options specify the attributes (exact match)
- 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.addclanscore(clanname:string, type:string [, nr:number]) - adds a clan score entry for the current day
- 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
- 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
- DB.getjobincometoday(playerid:number, job:string, coins => { }) - calculates how many coins the player earned today, for case where you want to limit it