fix: Removed deleted functions
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
# `function` handle_exception
|
|
||||||
::: g2o.exception.handle_exception
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# `function` set_default_logger
|
|
||||||
::: g2o.exception.set_default_logger
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
#`function` setPlayerAttributes
|
|
||||||
::: g2o.functions.player.setPlayerAttributes
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
#`function` setPlayerTalents
|
|
||||||
::: g2o.functions.player.setPlayerTalents
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
## How to use
|
|
||||||
1. Install [Python 3.13](https://www.python.org/downloads/release/python-3130/)
|
|
||||||
*Optionally, for Windows instead of installing Python, you can download Windows embeddable package from Python download page, and extract ZIP into your server folder*
|
|
||||||
1. Download latest module version from the **Release** page
|
|
||||||
2. Unzip downloaded archive into your server directory (you should now have **PyG2O.xYY.dll** and **g2o/** in your root server directory, or similar `.so` file if you're using linux)
|
|
||||||
3. Place .DLL module in the place you want and connect it with **config.xml**
|
|
||||||
```xml
|
|
||||||
<module src="PyG2O.x64.dll" type="server" />
|
|
||||||
```
|
|
||||||
4. Create **pyg2o_entry/** folder in your server root directory, and put an empty ``__init__.py`` file inside it
|
|
||||||
|
|
||||||
Now, your **pyg2o_entry/** folder is a Python package and serves as an entry point. You can't rename it (at least for now), but inside this folder you can use any file structure you want.
|
|
||||||
|
|
||||||
Your entry point should import PyG2O library:
|
|
||||||
```python
|
|
||||||
import g2o
|
|
||||||
# your code
|
|
||||||
```
|
|
||||||
If you make package that uses PyG2O functions, then this package also should also contain import.
|
|
||||||
|
|
||||||
## How to change entry point name
|
|
||||||
1. Create ``pyg2o.json`` in your root server folder
|
|
||||||
2. Place this content in it and change entry point name
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"entry": "your_entry_name"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## How to add additional packages folder
|
|
||||||
You can create ``.pth`` file in your root server folder and it will be added to your ``sys.path`` before entry point
|
|
||||||
|
|
||||||
## How to launch under venv
|
|
||||||
Create and launch ``.bat`` file with the following content
|
|
||||||
```
|
|
||||||
@echo off
|
|
||||||
CALL <path_to_your_venv>/scripts/activate.bat
|
|
||||||
G2O_Server.x64.exe
|
|
||||||
```
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
You can find default (example) scripts in [this repository](https://github.com/AURUMVORXX/PyG2O-DefaultScripts)
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
|
|
||||||
from g2o.functions.event import addEvent
|
|
||||||
from g2o.functions.event import callEvent
|
|
||||||
from g2o.functions.event import event
|
|
||||||
from g2o.functions.event import removeEventHandler
|
|
||||||
from g2o.functions.event import toggleEvent
|
|
||||||
from g2o.functions.event import removeEvent
|
|
||||||
|
|
||||||
from g2o.classes.packets import Packet
|
|
||||||
from g2o.classes.damage import DamageDescription
|
|
||||||
from g2o.classes.items import ItemGround
|
|
||||||
from g2o.classes.items import ItemsGround
|
|
||||||
from g2o.classes.daedalus import Daedalus
|
|
||||||
from g2o.classes.sky import Sky
|
|
||||||
from g2o.classes.mds import Mds
|
|
||||||
from g2o.classes.way import Way
|
|
||||||
|
|
||||||
from g2o.functions.chat import sendMessageToAll
|
|
||||||
from g2o.functions.chat import sendMessageToPlayer
|
|
||||||
from g2o.functions.chat import sendPlayerMessageToAll
|
|
||||||
from g2o.functions.chat import sendPlayerMessageToPlayer
|
|
||||||
|
|
||||||
from g2o.functions.math import getDistance2d
|
|
||||||
from g2o.functions.math import getDistance3d
|
|
||||||
from g2o.functions.math import getVectorAngle
|
|
||||||
|
|
||||||
from g2o.functions.game import getHostname
|
|
||||||
from g2o.functions.game import getMaxSlots
|
|
||||||
from g2o.functions.game import getPlayersCount
|
|
||||||
from g2o.functions.game import exit
|
|
||||||
from g2o.functions.game import getDayLength
|
|
||||||
from g2o.functions.game import getServerDescription
|
|
||||||
from g2o.functions.game import getServerWorld
|
|
||||||
from g2o.functions.game import getTime
|
|
||||||
from g2o.functions.game import serverLog
|
|
||||||
from g2o.functions.game import setDayLength
|
|
||||||
from g2o.functions.game import setServerDescription
|
|
||||||
from g2o.functions.game import setServerWorld
|
|
||||||
from g2o.functions.game import setTime
|
|
||||||
|
|
||||||
from g2o.functions.npc import clearNpcActions
|
|
||||||
from g2o.functions.npc import createNpc
|
|
||||||
from g2o.functions.npc import destroyNpc
|
|
||||||
from g2o.functions.npc import getNpcAction
|
|
||||||
from g2o.functions.npc import getNpcActions
|
|
||||||
from g2o.functions.npc import getNpcActionsCount
|
|
||||||
from g2o.functions.npc import getNpcHostPlayer
|
|
||||||
from g2o.functions.npc import getNpcLastActionId
|
|
||||||
from g2o.functions.npc import isNpc
|
|
||||||
from g2o.functions.npc import isNpcActionFinished
|
|
||||||
from g2o.functions.npc import npcAttackMelee
|
|
||||||
from g2o.functions.npc import npcAttackRanged
|
|
||||||
from g2o.functions.npc import npcSpellCast
|
|
||||||
from g2o.functions.npc import npcUseClosestMob
|
|
||||||
from g2o.functions.npc import setNpcHostPlayer
|
|
||||||
|
|
||||||
from g2o.functions.player import addBan
|
|
||||||
from g2o.functions.player import applyPlayerOverlay
|
|
||||||
from g2o.functions.player import ban
|
|
||||||
from g2o.functions.player import drawWeapon
|
|
||||||
from g2o.functions.player import equipItem
|
|
||||||
from g2o.functions.player import getPlayerAmulet
|
|
||||||
from g2o.functions.player import getPlayerAngle
|
|
||||||
from g2o.functions.player import getPlayerAni
|
|
||||||
from g2o.functions.player import getPlayerArmor
|
|
||||||
from g2o.functions.player import getPlayerAtVector
|
|
||||||
from g2o.functions.player import getPlayerBelt
|
|
||||||
from g2o.functions.player import getPlayerCameraPosition
|
|
||||||
from g2o.functions.player import getPlayerCollision
|
|
||||||
from g2o.functions.player import getPlayerColor
|
|
||||||
from g2o.functions.player import getPlayerContext
|
|
||||||
from g2o.functions.player import getPlayerDexterity
|
|
||||||
from g2o.functions.player import getPlayerFaceAnis
|
|
||||||
from g2o.functions.player import getPlayerFatness
|
|
||||||
from g2o.functions.player import getPlayerFocus
|
|
||||||
from g2o.functions.player import getPlayerHealth
|
|
||||||
from g2o.functions.player import getPlayerHelmet
|
|
||||||
from g2o.functions.player import getPlayerIP
|
|
||||||
from g2o.functions.player import getPlayerInstance
|
|
||||||
from g2o.functions.player import getPlayerInvisible
|
|
||||||
from g2o.functions.player import getPlayerMacAddr
|
|
||||||
from g2o.functions.player import getPlayerMana
|
|
||||||
from g2o.functions.player import getPlayerMaxHealth
|
|
||||||
from g2o.functions.player import getPlayerMaxMana
|
|
||||||
from g2o.functions.player import getPlayerMeleeWeapon
|
|
||||||
from g2o.functions.player import getPlayerName
|
|
||||||
from g2o.functions.player import getPlayerPing
|
|
||||||
from g2o.functions.player import getPlayerPosition
|
|
||||||
from g2o.functions.player import getPlayerRangedWeapon
|
|
||||||
from g2o.functions.player import getPlayerRespawnTime
|
|
||||||
from g2o.functions.player import getPlayerRing
|
|
||||||
from g2o.functions.player import getPlayerScale
|
|
||||||
from g2o.functions.player import getPlayerSerial
|
|
||||||
from g2o.functions.player import getPlayerShield
|
|
||||||
from g2o.functions.player import getPlayerSkillWeapon
|
|
||||||
from g2o.functions.player import getPlayerSpell
|
|
||||||
from g2o.functions.player import getPlayerStrength
|
|
||||||
from g2o.functions.player import getPlayerTalent
|
|
||||||
from g2o.functions.player import getPlayerVirtualWorld
|
|
||||||
from g2o.functions.player import getPlayerVisual
|
|
||||||
from g2o.functions.player import getPlayerWeaponMode
|
|
||||||
from g2o.functions.player import getPlayerWorld
|
|
||||||
from g2o.functions.player import giveItem
|
|
||||||
from g2o.functions.player import hitPlayer
|
|
||||||
from g2o.functions.player import isPlayerConnected
|
|
||||||
from g2o.functions.player import isPlayerDead
|
|
||||||
from g2o.functions.player import isPlayerSpawned
|
|
||||||
from g2o.functions.player import isPlayerUnconscious
|
|
||||||
from g2o.functions.player import kick
|
|
||||||
from g2o.functions.player import playAni
|
|
||||||
from g2o.functions.player import playFaceAni
|
|
||||||
from g2o.functions.player import readySpell
|
|
||||||
from g2o.functions.player import removeItem
|
|
||||||
from g2o.functions.player import removePlayerOverlay
|
|
||||||
from g2o.functions.player import removeWeapon
|
|
||||||
from g2o.functions.player import setPlayerAngle
|
|
||||||
from g2o.functions.player import setPlayerCollision
|
|
||||||
from g2o.functions.player import setPlayerColor
|
|
||||||
from g2o.functions.player import setPlayerContext
|
|
||||||
from g2o.functions.player import setPlayerDexterity
|
|
||||||
from g2o.functions.player import setPlayerFatness
|
|
||||||
from g2o.functions.player import setPlayerHealth
|
|
||||||
from g2o.functions.player import setPlayerInstance
|
|
||||||
from g2o.functions.player import setPlayerInvisible
|
|
||||||
from g2o.functions.player import setPlayerMana
|
|
||||||
from g2o.functions.player import setPlayerMaxHealth
|
|
||||||
from g2o.functions.player import setPlayerMaxMana
|
|
||||||
from g2o.functions.player import setPlayerName
|
|
||||||
from g2o.functions.player import setPlayerPosition
|
|
||||||
from g2o.functions.player import setPlayerRespawnTime
|
|
||||||
from g2o.functions.player import setPlayerScale
|
|
||||||
from g2o.functions.player import setPlayerSkillWeapon
|
|
||||||
from g2o.functions.player import setPlayerStrength
|
|
||||||
from g2o.functions.player import setPlayerTalent
|
|
||||||
from g2o.functions.player import setPlayerVirtualWorld
|
|
||||||
from g2o.functions.player import setPlayerVisual
|
|
||||||
from g2o.functions.player import setPlayerWeaponMode
|
|
||||||
from g2o.functions.player import setPlayerWorld
|
|
||||||
from g2o.functions.player import spawnPlayer
|
|
||||||
from g2o.functions.player import stopAni
|
|
||||||
from g2o.functions.player import stopFaceAni
|
|
||||||
from g2o.functions.player import unequipItem
|
|
||||||
from g2o.functions.player import unreadySpell
|
|
||||||
from g2o.functions.player import unspawnPlayer
|
|
||||||
from g2o.functions.player import useItem
|
|
||||||
from g2o.functions.player import useItemToState
|
|
||||||
from g2o.functions.player import setPlayerAttributes
|
|
||||||
from g2o.functions.player import setPlayerTalents
|
|
||||||
|
|
||||||
from g2o.functions.streamer import findNearbyPlayers
|
|
||||||
from g2o.functions.streamer import getStreamedPlayersByPlayer
|
|
||||||
from g2o.functions.streamer import getSpawnedPlayersForPlayer
|
|
||||||
|
|
||||||
from g2o.functions.waypoint import getNearestWaypoint
|
|
||||||
from g2o.functions.waypoint import getWaypoint
|
|
||||||
|
|
||||||
from g2o.exception import set_default_logger
|
|
||||||
from g2o.exception import handle_exception
|
|
||||||
|
|
||||||
from g2o.constants import *
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
import sqg2o
|
|
||||||
|
|
||||||
class Packet(sqg2o.Packet):
|
|
||||||
"""
|
|
||||||
This class represents data packet that gets send over the network.
|
|
||||||
Original: [Packet](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-classes/network/Packet/)
|
|
||||||
|
|
||||||
## `int` bitsUsed *(read-only)*
|
|
||||||
Represents the total number of bits used by the script packet data.
|
|
||||||
|
|
||||||
## `int` bytesUsed *(read-only)*
|
|
||||||
Represents the total number of bytes used by the script packet data.
|
|
||||||
"""
|
|
||||||
def __init__(self):
|
|
||||||
return super().__init__()
|
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
"""
|
|
||||||
This method will clear the packet data, making it empty.
|
|
||||||
"""
|
|
||||||
return super().reset()
|
|
||||||
|
|
||||||
def send(self, playerid : int, reliability : int):
|
|
||||||
"""
|
|
||||||
This method will send the packet data to the specified player.
|
|
||||||
**Parameters:**
|
|
||||||
* `int` **playerid**: the id of the player to whom you want to send the packet.
|
|
||||||
* `int` **reliability**: the reliability type, for more information see [Reliability](../../constants/reliability.md).
|
|
||||||
"""
|
|
||||||
return super().send(playerid, reliability)
|
|
||||||
|
|
||||||
def sendToAll(self, reliability : int):
|
|
||||||
"""
|
|
||||||
This method will send the packet data to the specified player.
|
|
||||||
**Parameters:**
|
|
||||||
* `int` **reliability**: the reliability type, for more information see [Reliability](../../constants/reliability.md).
|
|
||||||
"""
|
|
||||||
return super().send(reliability)
|
|
||||||
|
|
||||||
def writeInt8(self, value : int):
|
|
||||||
"""
|
|
||||||
This method will append signed int8 value to the packet. (1 byte)
|
|
||||||
**Parameters:**
|
|
||||||
* `int` **value**: the number value in range -128 to 127.
|
|
||||||
"""
|
|
||||||
return super().writeInt8(value)
|
|
||||||
|
|
||||||
def writeUInt8(self, value : int):
|
|
||||||
"""
|
|
||||||
This method will append unsigned int8 value to the packet. (1 byte)
|
|
||||||
**Parameters:**
|
|
||||||
* `int` **value**: the number value in range 0 to 255.
|
|
||||||
"""
|
|
||||||
return super().writeInt8(value)
|
|
||||||
|
|
||||||
def writeInt16(self, value : int):
|
|
||||||
"""
|
|
||||||
This method will append signed int16 value to the packet. (2 bytes)
|
|
||||||
**Parameters:**
|
|
||||||
* `int` **value**: the number value in range -32768 to 32767.
|
|
||||||
"""
|
|
||||||
return super().writeInt16(value)
|
|
||||||
|
|
||||||
def writeUInt16(self, value : int):
|
|
||||||
"""
|
|
||||||
This method will append unsigned int16 value to the packet. (2 bytes)
|
|
||||||
**Parameters:**
|
|
||||||
* `int` **value**: the number value in range 0 to 65535.
|
|
||||||
"""
|
|
||||||
return super().writeInt16(value)
|
|
||||||
|
|
||||||
def writeInt32(self, value : int):
|
|
||||||
"""
|
|
||||||
This method will append signed int32 value to the packet. (4 bytes)
|
|
||||||
**Parameters:**
|
|
||||||
* `int` **value**: the number value in range -2147483648 to 2147483647.
|
|
||||||
"""
|
|
||||||
return super().writeInt32(value)
|
|
||||||
|
|
||||||
def writeUInt32(self, value : int):
|
|
||||||
"""
|
|
||||||
!!! note
|
|
||||||
By default squirrel uses int32 values, which means that this method behaves exactly the same as [writeInt32](Packet.md#g2o.classes.packets.Packet.writeInt32) in scripts.
|
|
||||||
This method will append unsigned int32 value to the packet. (4 bytes)
|
|
||||||
**Parameters:**
|
|
||||||
* `int` **value**: the number value in range 0 to 4294967295.
|
|
||||||
"""
|
|
||||||
return super().writeInt32(value)
|
|
||||||
|
|
||||||
def writeBool(self, value : bool):
|
|
||||||
"""
|
|
||||||
This method will append boolean value to the packet. (1 bit)
|
|
||||||
**Parameters:**
|
|
||||||
* `bool` **value**: the boolean value.
|
|
||||||
"""
|
|
||||||
return super().writeBool(value)
|
|
||||||
|
|
||||||
def writeFloat(self, value : float):
|
|
||||||
"""
|
|
||||||
This method will append float value to the packet. (4 bytes)
|
|
||||||
**Parameters:**
|
|
||||||
* `float` **value**: the number value.
|
|
||||||
"""
|
|
||||||
return super().writeFloat(value)
|
|
||||||
|
|
||||||
def writeString(self, value : str):
|
|
||||||
"""
|
|
||||||
!!! note
|
|
||||||
The amount of bytes appended to the packet depends on the length of string, 1 byte = 1 char.
|
|
||||||
This method will append string value to the packet.
|
|
||||||
**Parameters:**
|
|
||||||
* `str` **value**: the text value.
|
|
||||||
"""
|
|
||||||
return super().writeString(value)
|
|
||||||
|
|
||||||
def readInt8(self,) -> int:
|
|
||||||
"""
|
|
||||||
This method will get signed int8 value from the packet. (1 byte)
|
|
||||||
**Returns `int`:**
|
|
||||||
the number value in range -128 to 127.
|
|
||||||
"""
|
|
||||||
return super().readInt8()
|
|
||||||
|
|
||||||
def readUInt8(self,) -> int:
|
|
||||||
"""
|
|
||||||
This method will get unsigned int8 value from the packet. (1 byte)
|
|
||||||
**Returns `int`:**
|
|
||||||
the number value in range 0 to 255.
|
|
||||||
"""
|
|
||||||
return super().readInt8()
|
|
||||||
|
|
||||||
def readInt16(self) -> int:
|
|
||||||
"""
|
|
||||||
This method will get signed int16 value from the packet. (2 bytes)
|
|
||||||
**Returns `int`:**
|
|
||||||
the number value in range -32768 to 32767.
|
|
||||||
"""
|
|
||||||
return super().readInt16()
|
|
||||||
|
|
||||||
def readUInt16(self) -> int:
|
|
||||||
"""
|
|
||||||
This method will get unsigned int16 value from the packet. (2 bytes)
|
|
||||||
**Returns `int`:**
|
|
||||||
the number value in range 0 to 65535.
|
|
||||||
"""
|
|
||||||
return super().readInt16()
|
|
||||||
|
|
||||||
def readInt32(self) -> int:
|
|
||||||
"""
|
|
||||||
This method will get signed int32 value from the packet. (4 bytes)
|
|
||||||
**Returns `int`:**
|
|
||||||
the number value in range -2147483648 to 2147483647.
|
|
||||||
"""
|
|
||||||
return super().readInt32()
|
|
||||||
|
|
||||||
def readUInt32(self) -> int:
|
|
||||||
"""
|
|
||||||
This method will get unsigned int32 value from the packet. (4 bytes)
|
|
||||||
**Returns `int`:**
|
|
||||||
the number value in range 0 to 4294967295.
|
|
||||||
"""
|
|
||||||
return super().readInt32()
|
|
||||||
|
|
||||||
def readBool(self) -> bool:
|
|
||||||
"""
|
|
||||||
This method will get signed int8 value from the packet. (1 byte)
|
|
||||||
**Returns `bool`:**
|
|
||||||
the boolean value.
|
|
||||||
"""
|
|
||||||
return super().readBool()
|
|
||||||
|
|
||||||
def readFloat(self) -> float:
|
|
||||||
"""
|
|
||||||
This method will get float value from the packet. (4 bytes)
|
|
||||||
**Returns `float`:**
|
|
||||||
the number value.
|
|
||||||
"""
|
|
||||||
return super().readFloat()
|
|
||||||
|
|
||||||
def readString(self) -> str:
|
|
||||||
"""
|
|
||||||
!!! note
|
|
||||||
The amount of bytes appended to the packet depends on the length of string, 1 byte = 1 char.
|
|
||||||
This method will get string value from the packet.
|
|
||||||
**Returns `str`:**
|
|
||||||
the text value.
|
|
||||||
"""
|
|
||||||
return super().readString()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def bitsUsed(self):
|
|
||||||
return super().bitsUsed
|
|
||||||
|
|
||||||
@property
|
|
||||||
def bytesUsed(self):
|
|
||||||
return super().bytesUsed
|
|
||||||
@@ -1,267 +0,0 @@
|
|||||||
from g2o.exception import handle_exception
|
|
||||||
|
|
||||||
eventList = {}
|
|
||||||
disabledEventList = []
|
|
||||||
|
|
||||||
@handle_exception
|
|
||||||
def callEvent(evtName : str, **kwargs : dict):
|
|
||||||
"""
|
|
||||||
!!! note
|
|
||||||
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
|
|
||||||
This function will notify (call) every handler bound to specified event.
|
|
||||||
Original: [callEvent](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/callEvent/)
|
|
||||||
|
|
||||||
## Declaration
|
|
||||||
```python
|
|
||||||
def callEvent(evtName : str, **kwargs : dict)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
* `str` **name**: the name of the event
|
|
||||||
* `**dict` **kwargs**: the variable number of arguments.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
```python
|
|
||||||
import g2o
|
|
||||||
|
|
||||||
g2o.addEvent('testEvt')
|
|
||||||
|
|
||||||
@g2o.event('testEvt')
|
|
||||||
def onTestEvent(**kwargs):
|
|
||||||
print(f'{kwargs['name']} called my beautiful test event')
|
|
||||||
|
|
||||||
g2o.callEvent('testEvt', name = 'Diego')
|
|
||||||
```
|
|
||||||
"""
|
|
||||||
|
|
||||||
isEventCancelled = False
|
|
||||||
|
|
||||||
if evtName in eventList and evtName not in disabledEventList:
|
|
||||||
for event in eventList[evtName]:
|
|
||||||
|
|
||||||
event['function'].eventName = evtName
|
|
||||||
event['function'].cancelled = isEventCancelled
|
|
||||||
result = event['function'](**kwargs)
|
|
||||||
|
|
||||||
if result != None:
|
|
||||||
isEventCancelled = not result
|
|
||||||
|
|
||||||
return isEventCancelled
|
|
||||||
|
|
||||||
@handle_exception
|
|
||||||
def addEvent(name : str):
|
|
||||||
"""
|
|
||||||
!!! note
|
|
||||||
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
|
|
||||||
This function will register a new event with specified name.
|
|
||||||
Events can be used to notify function(s) when something will happen, like player joins the server, etc.
|
|
||||||
Original: [addEvent](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/addEvent/)
|
|
||||||
|
|
||||||
## Declaration
|
|
||||||
```python
|
|
||||||
def addEvent(name)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
* `str` **name**: the name of the event
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
```python
|
|
||||||
import g2o
|
|
||||||
|
|
||||||
g2o.addEvent('testEvt')
|
|
||||||
```
|
|
||||||
"""
|
|
||||||
if not name in eventList:
|
|
||||||
eventList[name] = []
|
|
||||||
|
|
||||||
@handle_exception
|
|
||||||
def event(name : str, priority : int = 9999):
|
|
||||||
"""
|
|
||||||
!!! note
|
|
||||||
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
|
|
||||||
This function will bind function to specified event.
|
|
||||||
Original: [addEventHandler](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/addEventHandler/)
|
|
||||||
|
|
||||||
## Declaration
|
|
||||||
```python
|
|
||||||
def event(name : str, priority : int = 9999)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
* `str` **name**: the name of the event
|
|
||||||
* `int` **priority**: the function priority. The lower the value, the sooner the function/handler will be called.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
```python
|
|
||||||
import g2o
|
|
||||||
|
|
||||||
@g2o.event('onInit')
|
|
||||||
def onInitEventHandler(**kwargs):
|
|
||||||
print('Called onInit event')
|
|
||||||
```
|
|
||||||
"""
|
|
||||||
def inlineEvt(func):
|
|
||||||
if name not in eventList:
|
|
||||||
return None
|
|
||||||
|
|
||||||
eventList[name].append({'function': func, 'priority': priority})
|
|
||||||
eventList[name].sort(key = lambda x: x['priority'])
|
|
||||||
return func
|
|
||||||
return inlineEvt
|
|
||||||
|
|
||||||
@handle_exception
|
|
||||||
def removeEventHandler(name : str, func : object):
|
|
||||||
"""
|
|
||||||
!!! note
|
|
||||||
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
|
|
||||||
This function will unbind function from specified event.
|
|
||||||
Original: [removeEventHandler](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/removeEventHandler/)
|
|
||||||
|
|
||||||
## Declaration
|
|
||||||
```python
|
|
||||||
def removeEventHandler(name : str, func : object)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
* `str` **name**: the name of the event
|
|
||||||
* `object` **func**: the reference to a function which is currently bound to specified event.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
```python
|
|
||||||
import g2o
|
|
||||||
|
|
||||||
@g2o.event('onTime')
|
|
||||||
def onTimeEvt(**kwargs):
|
|
||||||
print('Calling only once')
|
|
||||||
g2o.removeEventHandler('onTime', onTimeEvt)
|
|
||||||
```
|
|
||||||
"""
|
|
||||||
if not name in eventList:
|
|
||||||
pass
|
|
||||||
|
|
||||||
for index, item in enumerate(eventList[name]):
|
|
||||||
if item['function'] == func:
|
|
||||||
del eventList[name][index]
|
|
||||||
|
|
||||||
@handle_exception
|
|
||||||
def toggleEvent(name : str, toggle : bool):
|
|
||||||
'''
|
|
||||||
!!! note
|
|
||||||
By default every event is toggled `on` (enabled).
|
|
||||||
!!! note
|
|
||||||
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
|
|
||||||
|
|
||||||
This function will toggle event (enable or disable it globally). By toggling event off, you can completely disable certain event from calling it's handlers.
|
|
||||||
Original: [toggleEvent](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/toggleEvent/)
|
|
||||||
|
|
||||||
## Declaration
|
|
||||||
```python
|
|
||||||
def toggleEvent(name : str, toggle : bool)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
* `str` **name**: the name of the event
|
|
||||||
* `bool` **toggle**: `false` if you want to disable the event, otherwise true.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
```python
|
|
||||||
import g2o
|
|
||||||
|
|
||||||
@g2o.event('onTime')
|
|
||||||
def onTimeEvt(**kwargs):
|
|
||||||
print('Calling only once')
|
|
||||||
g2o.toggleEvent('onTime', false)
|
|
||||||
```
|
|
||||||
'''
|
|
||||||
if not toggle and name not in disabledEventList:
|
|
||||||
disabledEventList.append(name)
|
|
||||||
elif toggle and name in disabledEventList:
|
|
||||||
disabledEventList.remove(name)
|
|
||||||
|
|
||||||
@handle_exception
|
|
||||||
def removeEvent(name : str):
|
|
||||||
'''
|
|
||||||
!!! warning
|
|
||||||
Removing an event also cause all event handlers to unregister.
|
|
||||||
!!! note
|
|
||||||
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
|
|
||||||
This function will unregister an event with specified name.
|
|
||||||
Original: [removeEvent](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/removeEvent/)
|
|
||||||
|
|
||||||
## Declaration
|
|
||||||
```python
|
|
||||||
def removeEvent(name : str)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
* `str` **name**: the name of the event
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
```python
|
|
||||||
import g2o
|
|
||||||
|
|
||||||
@g2o.event('onTime')
|
|
||||||
def onTimeEvt(**kwargs):
|
|
||||||
print('Calling only once')
|
|
||||||
g2o.removeEvent('onTime')
|
|
||||||
```
|
|
||||||
'''
|
|
||||||
if name in eventList:
|
|
||||||
eventList.pop(name)
|
|
||||||
|
|
||||||
## registering default events
|
|
||||||
|
|
||||||
addEvent('onInit')
|
|
||||||
addEvent('onExit')
|
|
||||||
addEvent('onTick')
|
|
||||||
addEvent('onTime')
|
|
||||||
addEvent('onBan')
|
|
||||||
addEvent('onUnban')
|
|
||||||
|
|
||||||
addEvent('onPlayerChangeColor')
|
|
||||||
addEvent('onPlayerChangeFocus')
|
|
||||||
addEvent('onPlayerChangeHealth')
|
|
||||||
addEvent('onPlayerChangeMana')
|
|
||||||
addEvent('onPlayerChangeMaxHealth')
|
|
||||||
addEvent('onPlayerChangeMaxMana')
|
|
||||||
addEvent('onPlayerChangeWeaponMode')
|
|
||||||
addEvent('onPlayerChangeWorld')
|
|
||||||
|
|
||||||
addEvent('onPlayerCommand')
|
|
||||||
addEvent('onPlayerDamage')
|
|
||||||
addEvent('onPlayerDead')
|
|
||||||
addEvent('onPlayerDisconnect')
|
|
||||||
addEvent('onPlayerDropItem')
|
|
||||||
addEvent('onPlayerEnterWorld')
|
|
||||||
addEvent('onPlayerJoin')
|
|
||||||
addEvent('onPlayerMessage')
|
|
||||||
addEvent('onPlayerMobInteract')
|
|
||||||
addEvent('onPlayerRespawn')
|
|
||||||
addEvent('onPlayerShoot')
|
|
||||||
addEvent('onPlayerSpellCast')
|
|
||||||
addEvent('onPlayerSpellSetup')
|
|
||||||
addEvent('onPlayerTakeItem')
|
|
||||||
addEvent('onPlayerTeleport')
|
|
||||||
addEvent('onPlayerToggleFaceAni')
|
|
||||||
|
|
||||||
addEvent('onPlayerEquipAmulet')
|
|
||||||
addEvent('onPlayerEquipArmor')
|
|
||||||
addEvent('onPlayerEquipBelt')
|
|
||||||
addEvent('onPlayerEquipHandItem')
|
|
||||||
addEvent('onPlayerEquipHelmet')
|
|
||||||
addEvent('onPlayerEquipMeleeWeapon')
|
|
||||||
addEvent('onPlayerEquipRangedWeapon')
|
|
||||||
addEvent('onPlayerEquipRing')
|
|
||||||
addEvent('onPlayerEquipShield')
|
|
||||||
addEvent('onPlayerEquipSpell')
|
|
||||||
|
|
||||||
addEvent('onPacket')
|
|
||||||
|
|
||||||
addEvent('onPlayerUseCheat')
|
|
||||||
|
|
||||||
addEvent('onNpcActionFinished')
|
|
||||||
addEvent('onNpcActionSent')
|
|
||||||
addEvent('onNpcChangeHostPlayer')
|
|
||||||
addEvent('onNpcCreated')
|
|
||||||
addEvent('onNpcDestroyed')
|
|
||||||
@@ -153,7 +153,4 @@ from .classes.damage import DamageDescription
|
|||||||
from .classes.items import ItemGround
|
from .classes.items import ItemGround
|
||||||
from .classes.items import ItemsGround
|
from .classes.items import ItemsGround
|
||||||
from .classes.mds import Mds
|
from .classes.mds import Mds
|
||||||
from .classes.sky import Sky
|
from .classes.sky import Sky
|
||||||
|
|
||||||
# from exception import set_default_logger
|
|
||||||
# from exception import handle_exception
|
|
||||||
Reference in New Issue
Block a user