mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2026-06-18 14:41:21 +00:00
Update en translation
This commit is contained in:
@@ -0,0 +1,245 @@
|
|||||||
|
Sure, here's a translation of the text:
|
||||||
|
|
||||||
|
# Passed Classes
|
||||||
|
|
||||||
|
## Worth looking at
|
||||||
|
|
||||||
|
1. What are `*args` and `**kwargs`? -> [Post on Habr (RU)](https://habr.com/ru/companies/ruvds/articles/482464/)
|
||||||
|
|
||||||
|
## KuiToi
|
||||||
|
_`kt = KuiToi("PluginName"")`_
|
||||||
|
|
||||||
|
### kt.log
|
||||||
|
_Constant_\
|
||||||
|
Returns a pre-configured logger
|
||||||
|
|
||||||
|
### kt.name
|
||||||
|
_Constant_\
|
||||||
|
Returns the name of the plugin
|
||||||
|
|
||||||
|
### kt.dir
|
||||||
|
_Constant_\
|
||||||
|
Returns the directory of the plugin
|
||||||
|
|
||||||
|
### kt.open()
|
||||||
|
_Parameters are the same as for open()_\
|
||||||
|
Opens a file in kt.dir
|
||||||
|
|
||||||
|
### kt.register_event(event_name: str, event_func: function)
|
||||||
|
_`event_name: str` -> The name of the event that `event_func` will be called on._\
|
||||||
|
_`event_func: function` -> The function that will be called._
|
||||||
|
|
||||||
|
In `event_func`, you can pass both regular functions and async functions - you don't need to make them async beforehand.\
|
||||||
|
You can also create your own events with your own names.\
|
||||||
|
You can register an unlimited number of events.
|
||||||
|
|
||||||
|
### kt.call_event(event_name: str, *args, **kwargs) -> list:
|
||||||
|
_`event_name: str` -> The name of the event to call._\
|
||||||
|
_`*args, **kwargs` -> Arguments to be passed to the function._
|
||||||
|
|
||||||
|
### **async** kt.call_async_event(event_name: str, *args, **kwargs) -> list:
|
||||||
|
_`event_name: str` -> The name of the event to call._\
|
||||||
|
_`*args, **kwargs` -> Arguments to be passed to the function._\
|
||||||
|
_Must be called with `await`_
|
||||||
|
|
||||||
|
###### _I recommend familiarizing yourself with *args, **kwargs_, there is a link at the beginning
|
||||||
|
Data is passed to all events in the form of: `{"event_name": event_name, "args": args, "kwargs": kwargs}`\
|
||||||
|
`args: list` -> Represents an array of data passed to the event\
|
||||||
|
`kwargs: dict` -> Represents a dictionary of data passed to the event
|
||||||
|
The data will be returned from all successful attempts in an array.
|
||||||
|
|
||||||
|
### kt.call_lua_event(event_name: str, *args) -> list:
|
||||||
|
_`event_name: str` -> The name of the event to call._\
|
||||||
|
_`*args` -> Arguments to be passed to the function._
|
||||||
|
|
||||||
|
Added to support backward compatibility.\
|
||||||
|
The lua function is called with a direct transmission of arguments `lua_func(*args)`
|
||||||
|
|
||||||
|
### kt.get_player([pid: int], [nick: str]) -> Player | None:
|
||||||
|
_`pid: int` -> Player ID - The identifier of the player._\
|
||||||
|
_`nick: str` -> Player Nickname - The name of the player._
|
||||||
|
|
||||||
|
The method returns a player object by their `pid` or `nick`.\
|
||||||
|
If the player cannot be found, `None` will be returned.
|
||||||
|
|
||||||
|
### kt.get_players() -> List[Player] | list:
|
||||||
|
|
||||||
|
The method returns an array with all players.\
|
||||||
|
The array will be empty if there are no players.
|
||||||
|
|
||||||
|
### kt.players_counter() -> int:
|
||||||
|
|
||||||
|
The method returns the number of players currently online.
|
||||||
|
|
||||||
|
### kt.is_player_connected([pid: int], [nick: str]) -> bool:
|
||||||
|
_`pid: int` -> Player ID - The identifier of the player._\
|
||||||
|
_`nick: str` -> Player Nickname - The name of the player._
|
||||||
|
|
||||||
|
The method returns a player object by their `pid` or `nick`.
|
||||||
|
|
||||||
|
## Player (or Client)
|
||||||
|
_`pl = kt.get_player()`_\
|
||||||
|
_`pl = event_data['kwargs']['player']`_
|
||||||
|
|
||||||
|
### pl.log -> Logger
|
||||||
|
_Constant_\
|
||||||
|
Returns a pre-configured logger
|
||||||
|
|
||||||
|
### pl.addr -> str
|
||||||
|
_Constant_\
|
||||||
|
Returns the IP address of the player
|
||||||
|
|
||||||
|
### pl.pid -> int
|
||||||
|
### pl.cid -> int
|
||||||
|
_Constant_\
|
||||||
|
Returns the client ID _(pid: PlayerId = cid: ClientId)_
|
||||||
|
|
||||||
|
### pl.key -> str
|
||||||
|
_Constant_\
|
||||||
|
Returns the key passed during authentication
|
||||||
|
|
||||||
|
### pl.nick -> str
|
||||||
|
_Variable_\
|
||||||
|
The nickname passed during authentication from the BeamMP server, can be changed, consequences are untested
|
||||||
|
|
||||||
|
### pl.roles -> str
|
||||||
|
_Variable_\
|
||||||
|
The role passed during authentication from the BeamMP server, can be changed (if an incorrect role is set, unexpected things may happen.)
|
||||||
|
|
||||||
|
### pl.guest -> bool
|
||||||
|
_Constant_\
|
||||||
|
Returns whether the player is a guest, passed during authentication from the BeamMP server
|
||||||
|
|
||||||
|
### pl.identifiers -> dict
|
||||||
|
_Constant_\
|
||||||
|
Identifiers passed during authentication from the BeamMP server.
|
||||||
|
|
||||||
|
### pl.ready -> bool
|
||||||
|
_Constant, changed by the core_\
|
||||||
|
Returns a bool value, if True -> the player has downloaded all resources, loaded on the map
|
||||||
|
|
||||||
|
### pl.cars -> dict
|
||||||
|
_Constant, changed by the core_\
|
||||||
|
Returns a dictionary of cars like thisSure, here's the translation:
|
||||||
|
|
||||||
|
# Passed Classes
|
||||||
|
|
||||||
|
## Worth looking at
|
||||||
|
|
||||||
|
1. What are `*args` and `**kwargs`? -> [Post on Habr ↗](https://habr.com/ru/companies/ruvds/articles/482464/)
|
||||||
|
|
||||||
|
## KuiToi
|
||||||
|
_`kt = KuiToi("PluginName"")`_
|
||||||
|
|
||||||
|
### kt.log
|
||||||
|
_Constant_\
|
||||||
|
Returns a pre-configured logger
|
||||||
|
|
||||||
|
### kt.name
|
||||||
|
_Constant_\
|
||||||
|
Returns the name of the plugin
|
||||||
|
|
||||||
|
### kt.dir
|
||||||
|
_Constant_\
|
||||||
|
Returns the directory of the plugin
|
||||||
|
|
||||||
|
### kt.open()
|
||||||
|
_Parameters are the same as for open()_\
|
||||||
|
Opens a file in kt.dir
|
||||||
|
|
||||||
|
### kt.register_event(event_name: str, event_func: function)
|
||||||
|
_`event_name: str` -> The name of the event that `event_func` will be called on._\
|
||||||
|
_`event_func: function` -> The function that will be called._
|
||||||
|
|
||||||
|
In `event_func`, you can pass both regular functions and async functions - you don't need to make them async beforehand.\
|
||||||
|
You can also create your own events with your own names.\
|
||||||
|
You can register an unlimited number of events.
|
||||||
|
|
||||||
|
### kt.call_event(event_name: str, *args, **kwargs) -> list:
|
||||||
|
_`event_name: str` -> The name of the event to call._\
|
||||||
|
_`*args, **kwargs` -> Arguments to be passed to the function._
|
||||||
|
|
||||||
|
### **async** kt.call_async_event(event_name: str, *args, **kwargs) -> list:
|
||||||
|
_`event_name: str` -> The name of the event to call._\
|
||||||
|
_`*args, **kwargs` -> Arguments to be passed to the function._\
|
||||||
|
_Must be called with `await`_
|
||||||
|
|
||||||
|
###### _I recommend familiarizing yourself with *args, **kwargs_, there is a link at the beginning
|
||||||
|
Data is passed to all events in the form of: `{"event_name": event_name, "args": args, "kwargs": kwargs}`\
|
||||||
|
`args: list` -> Represents an array of data passed to the event\
|
||||||
|
`kwargs: dict` -> Represents a dictionary of data passed to the event
|
||||||
|
The data will be returned from all successful attempts in an array.
|
||||||
|
|
||||||
|
### kt.call_lua_event(event_name: str, *args) -> list:
|
||||||
|
_`event_name: str` -> The name of the event to call._\
|
||||||
|
_`*args` -> Arguments to be passed to the function._
|
||||||
|
|
||||||
|
Added to support backward compatibility.\
|
||||||
|
The lua function is called with a direct transmission of arguments `lua_func(*args)`
|
||||||
|
|
||||||
|
### kt.get_player([pid: int], [nick: str]) -> Player | None:
|
||||||
|
_`pid: int` -> Player ID - The identifier of the player._\
|
||||||
|
_`nick: str` -> Player Nickname - The name of the player._
|
||||||
|
|
||||||
|
The method returns a player object by their `pid` or `nick`.\
|
||||||
|
If the player cannot be found, `None` will be returned.
|
||||||
|
|
||||||
|
### kt.get_players() -> List[Player] | list:
|
||||||
|
|
||||||
|
The method returns an array with all players.\
|
||||||
|
The array will be empty if there are no players.
|
||||||
|
|
||||||
|
### kt.players_counter() -> int:
|
||||||
|
|
||||||
|
The method returns the number of players currently online.
|
||||||
|
|
||||||
|
### kt.is_player_connected([pid: int], [nick: str]) -> bool:
|
||||||
|
_`pid: int` -> Player ID - The identifier of the player._\
|
||||||
|
_`nick: str` -> Player Nickname - The name of the player._
|
||||||
|
|
||||||
|
The method returns a player object by their `pid` or `nick`.
|
||||||
|
|
||||||
|
## Player (or Client)
|
||||||
|
_`pl = kt.get_player()`_\
|
||||||
|
_`pl = event_data['kwargs']['player']`_
|
||||||
|
|
||||||
|
### pl.log -> Logger
|
||||||
|
_Constant_\
|
||||||
|
Returns a pre-configured logger
|
||||||
|
|
||||||
|
### pl.addr -> str
|
||||||
|
_Constant_\
|
||||||
|
Returns the IP address of the player
|
||||||
|
|
||||||
|
### pl.pid -> int
|
||||||
|
### pl.cid -> int
|
||||||
|
_Constant_\
|
||||||
|
Returns the client ID _(pid: PlayerId = cid: ClientId)_
|
||||||
|
|
||||||
|
### pl.key -> str
|
||||||
|
_Constant_\
|
||||||
|
Returns the key passed during authentication
|
||||||
|
|
||||||
|
### pl.nick -> str
|
||||||
|
_Variable_\
|
||||||
|
The nickname passed during authentication from the BeamMP server, can be changed, consequences are untested
|
||||||
|
|
||||||
|
### pl.roles -> str
|
||||||
|
_Variable_\
|
||||||
|
The role passed during authentication from the BeamMP server, can be changed (if an incorrect role is set, unexpected things may happen.)
|
||||||
|
|
||||||
|
### pl.guest -> bool
|
||||||
|
_Constant_\
|
||||||
|
Returns whether the player is a guest, passed during authentication from the BeamMP server
|
||||||
|
|
||||||
|
### pl.identifiers -> dict
|
||||||
|
_Constant_\
|
||||||
|
Identifiers passed during authentication from the BeamMP server.
|
||||||
|
|
||||||
|
### pl.ready -> bool
|
||||||
|
_Constant, changed by the core_\
|
||||||
|
Returns a bool value, if True -> the player has downloaded all resources, loaded on the map
|
||||||
|
|
||||||
|
### pl.cars -> dict
|
||||||
|
_Constant, changed by the core_\
|
||||||
|
Returns a dictionary of cars like this
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# List of available events
|
||||||
|
|
||||||
|
Most events will receive `pl = data['kwargs']['player']`, you can find a description [here](./classes.md)
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
print("example.lua")
|
||||||
|
|
||||||
|
--CreateTimer Testing
|
||||||
|
local mytimer = MP.CreateTimer()
|
||||||
|
--.--.--.--.--.--.--.
|
||||||
|
|
||||||
|
--GetOSName Testing
|
||||||
|
print("OS Name: "..MP.GetOSName())
|
||||||
|
--.--.--.--.--.--.-
|
||||||
|
|
||||||
|
--GetServerVersion Testing
|
||||||
|
local major, minor, patch = MP.GetServerVersion()
|
||||||
|
print("Server Version: "..major.."."..minor.."."..patch)
|
||||||
|
--.--.--.--.--.--.--.--.--
|
||||||
|
|
||||||
|
--Events Testing--
|
||||||
|
function handleChat(player_id, player_name, message)
|
||||||
|
print("Lua handleChat:", player_id, player_name, message, "; Uptime: "..mytimer:GetCurrent())
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
MP.RegisterEvent("onChatMessage", "handleChat")
|
||||||
|
--.--.--.--.--.--.
|
||||||
|
|
||||||
|
function onInit()
|
||||||
|
print("Initializing ready!")
|
||||||
|
end
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# Providing Backward Compatibility for BeamMP Lua
|
||||||
|
|
||||||
|
KiuToi provides almost full support for lua plugins with BeamMP. All necessary methods have been created, and testing has revealed the following nuances:
|
||||||
|
|
||||||
|
KiuToi does not support: `MP.Set()`
|
||||||
|
|
||||||
|
#### Economic Rework V2.0 (Paid, Discord (RU): [Hlebushek](https://discordapp.com/users/449634697593749516))
|
||||||
|
|
||||||
|
1. To obtain `pluginPath`, use: `debug.getinfo(1).source:gsub("\\","/")` => `debug.getinfo(1).source:gsub("\\","/"):gsub("@", "")` as the path returns with `@`, which broke the plugin.
|
||||||
|
|
||||||
|
#### Cobalt Essentials V1.7.5 (Free, [github](https://github.com/prestonelam2003/CobaltEssentials/))
|
||||||
|
|
||||||
|
1. To obtain `pluginPath`, use: `debug.getinfo(1).source:gsub("\\","/")` => `debug.getinfo(1).source:gsub("\\","/"):gsub("@", "")` as the path returns with `@`, which broke the plugin.
|
||||||
|
2. All `require()` statements had to be moved after `onInit`.
|
||||||
|
3. In some cases, `MP.RegisterEvent` had to be moved after the function declaration, i.e.:
|
||||||
|
```lua
|
||||||
|
--This is incorrect, registration may fail
|
||||||
|
MP.RegisterEvent("onPlayerAuth","onPlayerAuth")
|
||||||
|
function onPlayerAuth(name, role, isGuest)
|
||||||
|
-- Some plugin code
|
||||||
|
end
|
||||||
|
|
||||||
|
--This is the correct version
|
||||||
|
MP.RegisterEvent("onPlayerAuth","onPlayerAuth")
|
||||||
|
```
|
||||||
|
|
||||||
|
### A Little About How it Works
|
||||||
|
|
||||||
|
Plugin loading goes through several stages:
|
||||||
|
|
||||||
|
1. The `plugins/` folder is scanned.
|
||||||
|
2. If the folder is not in PyPlugins and there are `*.lua` files in the folder, then it is added as a plugin folder, let's say it will be `plugins/LuaPlugin`
|
||||||
|
3. Next, `lua.loadfile({filename})` is performed from this folder (this is the standard method in lua).
|
||||||
|
4. Finally, the `onInit()` function is called, and an event is triggered.
|
||||||
|
5. If no errors occur during the execution of `onInit()`, you can see the message `Lua plugins: LuaPlugin:ok` through the `lua_plugins` command.
|
||||||
+30
-22
@@ -1,12 +1,18 @@
|
|||||||
# Plugin System
|
Это описание системы плагинов для KuiToi сервера на Python:
|
||||||
|
|
||||||
## Installing the Library with "Stubs"
|
## Events
|
||||||
###### (This means that it will not work without a server, but the IDE will suggest the API)
|
### Events list: [here](./events_list.md)
|
||||||
###### (The library is still under development)
|
|
||||||
|
## Classes
|
||||||
|
### Classes list: [here](./classes.md)
|
||||||
|
|
||||||
|
## Installing the library with "stubs"
|
||||||
|
###### (This means it won't work without the server, but your IDE will suggest the API)
|
||||||
|
###### (The library is still in development)
|
||||||
|
|
||||||
* Using pip:\
|
* Using pip:\
|
||||||
`$ pip install KuiToi`
|
`$ pip install KuiToi`
|
||||||
* From source code:\
|
* From source:\
|
||||||
`git clone https://github.com/KuiToi/KuiToi-PyLib`
|
`git clone https://github.com/KuiToi/KuiToi-PyLib`
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
@@ -17,7 +23,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
kt = KuiToi("Example")
|
kt = KuiToi("ExamplePlugin")
|
||||||
log = kt.log
|
log = kt.log
|
||||||
|
|
||||||
def my_event_handler(event_data):
|
def my_event_handler(event_data):
|
||||||
@@ -25,14 +31,14 @@ def my_event_handler(event_data):
|
|||||||
|
|
||||||
def load():
|
def load():
|
||||||
# Plugin initialization
|
# Plugin initialization
|
||||||
ev.register_event("my_event", my_event_handler)
|
kt.register_event("my_event", my_event_handler)
|
||||||
log.info("Plugin loaded successfully.")
|
log.info("Plugin loaded successfully.")
|
||||||
|
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
# Running plugin processes
|
# Starting plugin processes
|
||||||
ev.call_event("my_event")
|
kt.call_event("my_event")
|
||||||
ev.call_event("my_event", "Some data", data="some data too")
|
kt.call_event("my_event", "Some data", data="some data too")
|
||||||
log.info("Plugin started successfully.")
|
log.info("Plugin started successfully.")
|
||||||
|
|
||||||
|
|
||||||
@@ -41,15 +47,17 @@ def unload():
|
|||||||
log.info("Plugin unloaded successfully.")
|
log.info("Plugin unloaded successfully.")
|
||||||
```
|
```
|
||||||
|
|
||||||
* It is recommended to use `open()` after `load()`. Otherwise, use `kt.load()` - creates a file in the `plugin/<plugin_name>/<filename>` folder.
|
A more comprehensive example can also be found in [example.py](examples/example.py)
|
||||||
* Creating your own event: `kt.register_event("my_event", my_event_function)`
|
|
||||||
|
* It is recommended to use `open()` after `load()`, otherwise use `kt.load()` - It creates a file in the `plugin/<plugin_name>/<filename>` folder.
|
||||||
|
* Creating your own event: `kt.register_event("my_event", my_event_function)` -
|
||||||
* Calling an event: `kt.call_event("my_event")`
|
* Calling an event: `kt.call_event("my_event")`
|
||||||
* Calling an event with data: `kt.call_event("my_event", data, data2=data2)`
|
* Calling an event with data: `kt.call_event("my_event", data, data2=data2)`
|
||||||
* Basic events: _Will write later_
|
* Base events: _To be added later_
|
||||||
|
|
||||||
## Async Functions
|
## Async functions
|
||||||
|
|
||||||
Async support is available.
|
Async support is available
|
||||||
|
|
||||||
```python
|
```python
|
||||||
try:
|
try:
|
||||||
@@ -67,14 +75,14 @@ async def my_event_handler(event_data):
|
|||||||
|
|
||||||
async def load():
|
async def load():
|
||||||
# Plugin initialization
|
# Plugin initialization
|
||||||
ev.register_event("my_event", my_event_handler)
|
kt.register_event("my_event", my_event_handler)
|
||||||
log.info("Plugin loaded successfully.")
|
log.info("Plugin loaded successfully.")
|
||||||
|
|
||||||
|
|
||||||
async def start():
|
async def start():
|
||||||
# Running plugin processes
|
# Starting plugin processes
|
||||||
await ev.call_async_event("my_event")
|
await kt.call_async_event("my_event")
|
||||||
await ev.call_async_event("my_event", "Some data", data="some data too")
|
await kt.call_async_event("my_event", "Some data", data="some data too")
|
||||||
log.info("Plugin started successfully.")
|
log.info("Plugin started successfully.")
|
||||||
|
|
||||||
|
|
||||||
@@ -84,9 +92,9 @@ async def unload():
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
A more extensive example can also be found in [async_example.py](./async_example.py).
|
A more comprehensive example can also be found in [async_example.py](examples/async_example.py)
|
||||||
|
|
||||||
* Creating your own event: `kt.register_event("my_event", my_event_function)` (register_event checks for function)
|
* Creating your own event: `kt.register_event("my_event", my_event_function)` (register_event has a function check)
|
||||||
* Calling an async event: `kt.call_async_event("my_event")`
|
* Calling an async event: `kt.call_async_event("my_event")`
|
||||||
* Calling an async event with data: `kt.call_async_event("my_event", data, data2=data2)`
|
* Calling an async event with data: `kt.call_async_event("my_event", data, data2=data2)`
|
||||||
* Basic async events: _Will write later_
|
* Base async events: _To be added later_
|
||||||
+7
-6
@@ -1,9 +1,10 @@
|
|||||||
# Documentation for KuiToi Server
|
# Documentation for KuiToi Server
|
||||||
|
|
||||||
### The documentation is not perfect yet, but it will be one day
|
### The documentation is not yet perfect, but someday it will be.
|
||||||
|
|
||||||
1. Setup and Start server - [here](setup)
|
1. Setup and Launching the Server - [here](./setup)
|
||||||
2. Plugins and Events system - [here](plugins)
|
2. Plugins and Event System - [here](./plugins)
|
||||||
3. MultiLanguage - [here](./multilanguage)
|
3. Nuances of Working with Lua - [here](./plugins/lua)
|
||||||
4. KuiToi WebAPI - [here](./web)
|
4. Multilanguage Support - [here](./multilanguage)
|
||||||
5. Something new...
|
5. KuiToi WebAPI - [here](./web)
|
||||||
|
6. Something new will be added here soon...
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# Choose your language
|
# Choose your language
|
||||||
|
|
||||||
### [English](./en)
|
|
||||||
### [Русский](./ru)
|
### [Русский](./ru)
|
||||||
|
### [English](./en) (AI translation)
|
||||||
|
|||||||
Reference in New Issue
Block a user