项目作者: MrSentex

项目描述 :
Alt:V Client-Server Communication
高级语言: JavaScript
项目地址: git://github.com/MrSentex/communication.git
创建时间: 2020-06-21T14:17:03Z
项目社区:https://github.com/MrSentex/communication

开源协议:MIT License

下载


Communication

Alt:V Client-Server Communication

banner

What does the script do?

The script provides the user with a simple API to make requests to the server and receive an asynchronous response from it, thus making the life of the developers simpler when it comes to receiving information from the server. The API is similar to the ESX API of FiveM so that developers coming from that platform will quickly become familiar with it.

Why use it?

As an Alt:V developer you will need to receive a lot of information from the server and with this script you will save many lines of code and headaches making your scripts more sexy. So… what you wating for? add this fancy script to your server and start to relax with knowing you do not need all this bizarre events you use to use in your scripts.

How do I used it?

As I said it’s quite simple and you’ll understand it quickly.

Commented example:

  1. // Server-Side
  2. import * as communication from "communication"; // Importing the module
  3. // @event - The event you want register
  4. // @player - Alt player object
  5. // @cb - Callback function
  6. // @target argument passed by client (you can add every argument you want but need to be passed by the client, if not the value of the argument will be undefined)
  7. communication.registerServerCallback("player=>get_hwid", (player, cb, target) => {
  8. if (!target) {
  9. target = player; // If not target especified taking self as one
  10. } else {
  11. target = alt.Player.getByID(target); // Getting alt player by ID
  12. }
  13. if (!target) {
  14. cb();
  15. return;
  16. }
  17. cb(target.hwidHash); // Sending hwid back to client
  18. });
  1. // Client-Side
  2. import * as communication from "communication"; // Importing the module
  3. // @event - The event you want to trigger
  4. // @callback - Callback function adding the arguments you want to recieve
  5. // @...args - All arguments you want to pass to the server (No arguments in this example)
  6. communication.triggerServerCallback("player=>get_hwid", (hwid) => {
  7. alt.log("Self hwid: " + hwid); // Writing your hwid in the client console
  8. });
  9. // @event - The event you want to trigger
  10. // @callback - Callback function adding the arguments you want to recieve
  11. // @id - Player ID you want to get its hwid
  12. communication.triggerServerCallback("player=>get_hwid", (hwid) => {
  13. alt.log("Player with ID 1 hwid: " + hwid); // Writing player id 1 hwid in the client console
  14. }, 1);

Exported functions

Functions who are exported from the module.

Server

  • registerServerCallback(event, callback)

    Register a new event who will trigger your callback function when is call.

    Client

  • triggerServerCallback(event, callback, …args)

    Trigger an event you registered in server side passing the arguments and getting the response.