Skip to main content

Python for VC:MP Server Plugin

Project description

Python for VC:MP Server Plugin

GitHub Issues or Pull Requests GitHub Issues or Pull Requests GitHub License GitHub Release GitHub Tag GitHub Repo stars

赞助

许可证

MIT

贡献

如果你有能力,你可以向我们的仓库提交 Pull Request 或 Issue。

开发进度

目前 master 是主分支, rwir 分支上正在将进行 rust 重写的工作, 欢迎贡献

lets RWIR!

注:目前 master 分支暂不维护,目前 Release 版本为 1.2.10.6 处于稳定状态

鸣谢

ysc3839

使用

如果你是 Linux 用户 (Docker)

docker run -d --name vcmp-python -v /path/to/your/server:/app -p 8192:8192 tianxiu2b2t/vcmp-python server

如果你是 Windows 用户

  1. pip 包安装
pip install vcmp-python-plugin
  1. 下载对应的 python 版本 dll 文件,或在 pip 包中寻找对应的 dll 文件
  2. 将 dll 文件放入你的 VCMP 服务器 plugins 文件夹中
  3. 修改 server.cfg 文件,添加以下内容
plugins vcmp-python-plugin-cpy<py_version>-rel64.dll
pythonscript main.py
  1. 启动你的服务器
server.exe

示例脚本

main.py:

import sys
from vcmp import callbacks, run
from vcmp.events.server import ServerInitialiseEvent
from vcmp.events.player import PlayerCommandEvent, PlayerEnterVehicleEvent, PlayerRequestEnterVehicleEvent
from vcmp.callbacks import Matcher
from vcmp.functions import plugin, server, vehicle

from vcmp.instance import get_vehicle_from_id

@callbacks.on()
def server_initialise(event: ServerInitialiseEvent):
    print("Server Loaded")

@callbacks.on()
def _(matcher: Matcher, event: PlayerRequestEnterVehicleEvent):
    matcher.send("You request enter a vehicle.")
    matcher.finish()

@callbacks.on()
def _(matcher: Matcher, event: PlayerEnterVehicleEvent):
    matcher.send("You enter a vehicle.")
    matcher.finish()

@callbacks.on()
def command(matcher: Matcher, event: PlayerCommandEvent):
    cmd = event.cmd.lower()
    text = event.text
    if cmd == "car":
        if not text.isdigit():
            matcher.send("Unable to spawn car. Please enter a valid car id.")
            matcher.finish()

        car_id = int(text)
        player = event.player
        veh = vehicle.create_vehicle(car_id, player.world, player.position, player.angle)
        player.vehicle = veh
        matcher.send(f"Spawned car with id {car_id}.")
        matcher.finish()

    if cmd == "pos":
        player = event.player
        matcher.send(f"Your position is {player.position}.")
        matcher.finish()

    if cmd == "eject":
        player = event.player
        player.vehicle = None

    if cmd == "veh":
        player = event.player
        if not text.isdigit():
            matcher.send("Please enter a valid car index id.")
            matcher.finish()
        
        index = int(text)
        veh = get_vehicle_from_id(index)
        if veh is None:
            matcher.send("Unable to find vehicle.")
            matcher.finish()

        player.vehicle = veh
        matcher.send(f"Teleported to vehicle with index {index}.")
        matcher.finish()

def main():
    #server.set_servername(f"Python Test Server of Python {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
    #print(server.get_server_version(), server.get_servername())
    #print(plugin.get_plugins())
    print(f"Server runs on {server.get_server_version()} version")

if __name__ == '__main__':
    #run(main) # 避免阻塞主线程,也可以在主线程调用 (强烈推荐 run(main) )
    print(
        "Python is running by __main__"
    )

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vcmp_python_plugin-2.0.0.post3.tar.gz (35.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vcmp_python_plugin-2.0.0.post3-py3-none-any.whl (35.5 MB view details)

Uploaded Python 3

File details

Details for the file vcmp_python_plugin-2.0.0.post3.tar.gz.

File metadata

  • Download URL: vcmp_python_plugin-2.0.0.post3.tar.gz
  • Upload date:
  • Size: 35.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for vcmp_python_plugin-2.0.0.post3.tar.gz
Algorithm Hash digest
SHA256 97e870e1a94ee271946b023705337446304990ec2bd7fa2952262c6abe256b4c
MD5 4e7ed0929d73e3f0f2a8c69efaeee7a4
BLAKE2b-256 26ba045e8e72b2230e7b2a8d2a4dc8aced9e475d272d44305a22e1fc8efec4a9

See more details on using hashes here.

File details

Details for the file vcmp_python_plugin-2.0.0.post3-py3-none-any.whl.

File metadata

File hashes

Hashes for vcmp_python_plugin-2.0.0.post3-py3-none-any.whl
Algorithm Hash digest
SHA256 56008560e08dfc3fcdbe2ef927b3d833bba8513cbd9ec1f238f0e6aa09a6798b
MD5 6578cc4e91352fe908c1941f3628622a
BLAKE2b-256 04461d6c8c270bf89c4009a6cb76d502b5c0feb1b01e32d125cadecb331a9e55

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page