From 18706e982cf7b139660d0b2f541b808183d6c88e Mon Sep 17 00:00:00 2001 From: AURUMVORXX Date: Mon, 16 Jun 2025 17:13:24 +0300 Subject: [PATCH] feat: Update for G2O 0.3.2.0 --- include/events.nut | 24 ++++++++++++++++ pyproject.toml | 2 +- src/pyg2o/__init__.py | 8 ++++++ src/pyg2o/classes/items.py | 52 +++++++++++++++++++++++++++++++++++ src/pyg2o/functions/event.py | 5 +++- src/pyg2o/functions/game.py | 35 +++++++++++++++++++++-- src/pyg2o/functions/player.py | 49 +++++++++++++++++++++++++++++---- 7 files changed, 165 insertions(+), 10 deletions(-) diff --git a/include/events.nut b/include/events.nut index bbe0f9f..fe6f838 100644 --- a/include/events.nut +++ b/include/events.nut @@ -568,6 +568,30 @@ addEventHandler("onPlayerToggleFaceAni", function(playerid, aniName, toggle) toggle = toggle } + if (_globalInstance != -1) + _globalInstance._send("event", data); +}); + +addEventHandler("onPlayerSpawnForPlayer", function(playerid, spawnid) +{ + local data = { + event = "onPlayerSpawnForPlayer", + playerid = playerid, + spawnid = spawnid + } + + if (_globalInstance != -1) + _globalInstance._send("event", data); +}); + +addEventHandler("onPlayerUnspawnForPlayer", function(playerid, spawnid) +{ + local data = { + event = "onPlayerUnspawnForPlayer", + playerid = playerid, + spawnid = spawnid + } + if (_globalInstance != -1) _globalInstance._send("event", data); }); \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 89e09e1..05f8ec4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "PyG2O" -version = "2.2.0" +version = "2.3.0" description = "" authors = ["AURUMVORAX "] diff --git a/src/pyg2o/__init__.py b/src/pyg2o/__init__.py index 56bc3fe..b75e935 100644 --- a/src/pyg2o/__init__.py +++ b/src/pyg2o/__init__.py @@ -12,6 +12,7 @@ from .functions.math import getVectorAngle from .functions.game import getHostname from .functions.game import getMaxSlots +from .functions.game import getServerPublic from .functions.game import getPlayersCount from .functions.game import exit from .functions.game import getDayLength @@ -22,6 +23,7 @@ from .functions.game import serverLog from .functions.game import setDayLength from .functions.game import setServerDescription from .functions.game import setServerWorld +from .functions.game import setServerPublic from .functions.game import setTime from .functions.npc import clearNpcActions @@ -48,6 +50,7 @@ from .functions.player import equipItem from .functions.player import getPlayerAmulet from .functions.player import getPlayerAngle from .functions.player import getPlayerAni +from .functions.player import getPlayerOverlays from .functions.player import getPlayerArmor from .functions.player import getPlayerAtVector from .functions.player import getPlayerBelt @@ -96,6 +99,7 @@ from .functions.player import isPlayerUnconscious from .functions.player import kick from .functions.player import playAni from .functions.player import playFaceAni +from .functions.player import fadeOutAni from .functions.player import readySpell from .functions.player import removeItem from .functions.player import removePlayerOverlay @@ -174,6 +178,7 @@ __all__ = [ "getHostname", "getMaxSlots", + "getServerPublic", "getPlayersCount", "exit", "getDayLength", @@ -184,6 +189,7 @@ __all__ = [ "setDayLength", "setServerDescription", "setServerWorld", + "setServerPublic", "setTime", "clearNpcActions", @@ -210,6 +216,7 @@ __all__ = [ "getPlayerAmulet", "getPlayerAngle", "getPlayerAni", + "getPlayerOverlays", "getPlayerArmor", "getPlayerAtVector", "getPlayerBelt", @@ -258,6 +265,7 @@ __all__ = [ "kick", "playAni", "playFaceAni", + "fadeOutAni", "readySpell", "removeItem", "removePlayerOverlay", diff --git a/src/pyg2o/classes/items.py b/src/pyg2o/classes/items.py index 8db6046..2759a08 100644 --- a/src/pyg2o/classes/items.py +++ b/src/pyg2o/classes/items.py @@ -104,6 +104,58 @@ class ItemGround: """ return self._rotation + async def setPosition(self, x: float, y: float, z: float): + """ + This method will set the item ground position in the world. + **Parameters:** + * `float` **x**: the position in the world on the x axis. + * `float` **y**: the position in the world on the y axis. + * `float` **z**: the position in the world on the z axis. + """ + data = f'return ItemsGround.getById({self.id}).setPosition({x}, {y}, {z})' + + server = await PythonWebsocketServer.get_server() + result = await server.make_request(data) + return result + + async def setRotation(self, x: float, y: float, z: float): + """ + This method will set the item ground rotation in the world. + **Parameters:** + * `float` **x**: the rotation in the world on the x axis. + * `float` **y**: the rotation in the world on the y axis. + * `float` **z**: the rotation in the world on the z axis. + """ + data = f'return ItemsGround.getById({self.id}).setRotation({x}, {y}, {z})' + + server = await PythonWebsocketServer.get_server() + result = await server.make_request(data) + return result + + async def get_physicsEnabled(self) -> bool: + """ + This method will get the item ground physicsEnabled flag. + **Returns:** + * `bool`: ``true`` if physics is enabled, otherwise ``false`` + """ + data = f'return ItemsGround.getById({self.id}).physicsEnabled' + + server = await PythonWebsocketServer.get_server() + result = await server.make_request(data) + return result + + async def set_physicsEnabled(self, enabled: bool): + """ + This method will set the item ground physicsEnabled flag. + **Parameters:** + * `bool` **enabled**: represents the state of physicsEnabled flag + """ + data = f'return ItemsGround.getById({self.id}).physicsEnabled = {enabled}' + + server = await PythonWebsocketServer.get_server() + result = await server.make_request(data) + return result + @property def id(self) -> int: return self._id diff --git a/src/pyg2o/functions/event.py b/src/pyg2o/functions/event.py index b084dbd..2d05118 100644 --- a/src/pyg2o/functions/event.py +++ b/src/pyg2o/functions/event.py @@ -59,7 +59,7 @@ def addEvent(name : str): g2o.addEvent('testEvt') ``` """ - if not name in eventList: + if name not in eventList: eventList[name] = [] def event(event_name: str, priority: int = 9999) -> None: @@ -213,6 +213,9 @@ addEvent('onPlayerEquipRing') addEvent('onPlayerEquipShield') addEvent('onPlayerEquipSpell') +addEvent('onPlayerSpawnForPlayer') +addEvent('onPlayerUnspawnForPlayer') + addEvent('onPacket') addEvent('onPlayerUseCheat') diff --git a/src/pyg2o/functions/game.py b/src/pyg2o/functions/game.py index 7e5ca97..773712b 100644 --- a/src/pyg2o/functions/game.py +++ b/src/pyg2o/functions/game.py @@ -29,8 +29,6 @@ async def getHostname() -> str: result = await server.make_request(data) return result - - async def getMaxSlots() -> int: """ This function will get the max number of slots available on the server. @@ -85,6 +83,23 @@ async def getPlayersCount() -> int: result = await server.make_request(data) return result +async def getServerPublic() -> bool: + """ + This function will get the publicity state of the server. + + ## Declaration + ```python + async def getServerPublic() -> bool + ``` + ## Returns + `bool`: ``true`` if server is publicly available, otherwise ``false`` + """ + data = f'return {get_call_repr()}' + + server = await PythonWebsocketServer.get_server() + result = await server.make_request(data) + return result + async def exit(exitCode : int = 0): """ This function will close the server with specified exit code. @@ -258,6 +273,22 @@ async def setServerWorld(world : str): result = await server.make_request(data) return result +async def setServerPublic(public : str): + """ + This function will change the publicity state of the server. + + ## Declaration + ```python + async def setServerPublic(public : str) + ``` + ## Parameters + `bool` **public**: server public state. + """ + data = f'return {get_call_repr()}' + + server = await PythonWebsocketServer.get_server() + result = await server.make_request(data) + return result async def setTime(hour : int, min : int, day : int = 0): """ diff --git a/src/pyg2o/functions/player.py b/src/pyg2o/functions/player.py index b626d11..52f24bf 100644 --- a/src/pyg2o/functions/player.py +++ b/src/pyg2o/functions/player.py @@ -29,18 +29,18 @@ async def addBan(info : dict) -> bool: result = await server.make_request(data) return result -async def applyPlayerOverlay(id : int, overlayId : int) -> bool: +async def applyPlayerOverlay(id : int, overlay : str) -> bool: """ This function will apply animation overlay on player for all players. Original: [applyPlayerOverlay](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/player/applyPlayerOverlay/) ## Declaration ```python - async def applyPlayerOverlay(id : int, overlayId : int) -> bool + async def applyPlayerOverlay(id : int, overlay : str) -> bool ``` ## Parameters `int` **id**: the player id. - `int` **overlayId**: the overlay id from `mds.xml` file, e.g: `Mds.id("HUMANS_MILITIA.MDS")` + `str` **overlay**: the overlay Mds name, e.g. 'HUMANS_MILITIA.MDS' ## Returns `bool`: `true` if animation overlay was successfully applied on player, otherwise `false`. """ @@ -173,6 +173,25 @@ async def getPlayerAni(id : int) -> str: result = await server.make_request(data) return result +async def getPlayerOverlays(id : int) -> list[str]: + """ + This function will get the player/npc active animations overlays. + + ## Declaration + ```python + async def getPlayerAni(id : int) -> str + ``` + ## Parameters + `int` **id**: the player id. + ## Returns + `list[str]`: the list of animation overlays as strings or ``None`` if player isn't created. + """ + data = f'return {get_call_repr()}' + + server = await PythonWebsocketServer.get_server() + result = await server.make_request(data) + return result + async def getPlayerArmor(id : int) -> str: """ This function will get the equipped player armor. @@ -1148,6 +1167,24 @@ async def playFaceAni(id : int, aniName : str): result = await server.make_request(data) return result +async def fadeOutAni(id : int, aniName : str): + """ + This function is used to gracefully stop played animation on player/npc for all players. + + ## Declaration + ```python + async def playFaceAni(id : int, aniName : str) + ``` + ## Parameters + `int` **id**: the player id. + `str` **aniName**: the name of the animation that you want to stop. The default value is empty string, which means that the first active ani will be stopped. + """ + data = f'return {get_call_repr()}' + + server = await PythonWebsocketServer.get_server() + result = await server.make_request(data) + return result + async def readySpell(id : int, slotId : int, manaInvested : int): """ This function will cause player to ready equipped spell. @@ -1188,18 +1225,18 @@ async def removeItem(id : int, instance : str, amount : int): result = await server.make_request(data) return result -async def removePlayerOverlay(id : int, overlayId : int) -> bool: +async def removePlayerOverlay(id : int, overlay : str) -> bool: """ This function will remove animation overlay from player for all players. Original: [removePlayerOverlay](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/player/removePlayerOverlay/) ## Declaration ```python - async def removePlayerOverlay(id : int, overlayId : int) -> bool + async def removePlayerOverlay(id : int, overlay : str) -> bool: ``` ## Parameters `int` **id**: the player id. - `int` **overlayId**: the overlay id from `mds.xml` file, e.g: `Mds.id("HUMANS_MILITIA.MDS")` + `str` **overlay**: the overlay Mds name, e.g. 'HUMANS_MILITIA.MDS' ## Returns `bool`: `true` if animation overlay was successfully removed from player, otherwise `false`. """