0%

Global class service interface api object

api control interface, obtained from the sf_start parameter of the server entry module ServerMain.lua

  1. api.log(…) -> Server output log encapsulation, please do not use print.
  2. api.send(player,data) -> Send data to a single player object. Player is the user object table that receives data, and data is table data.
  3. api.broadcast(data) -> broadcast to game owners, refer to send for parameters
  4. api.timeout(ti, func) -> timer, t is in seconds, supports decimals, func callback method, return returns the function to cancel the timer
  5. api.time() -> Returns the UTC time in seconds (accuracy is two decimal places). The difference between UTC time and Beijing time is 8 hours.
  6. api.getPlayer(uid) -> Get the player table identified by the uid, return value player table, parameters: uid player id.
  7. api.getPlayers() -> Get the list of online users, return value players, an array containing the player table.
  8. api.decreaseGold(player,gold) -> Deduct the player’s gold coins; the parameter player is the player object; the parameter gold is a positive integer, the number of gold coins to be deducted must be passed in; return returns number, 0 means success, 1 means the parameter Error, 2 means it must be a positive integer, 3 means there are not enough gold coins.