diff options
| author | Skipper <[email protected]> | 2025-02-13 22:09:59 +0000 |
|---|---|---|
| committer | Skipper <[email protected]> | 2025-02-13 22:09:59 +0000 |
| commit | 1b4f3db2f32ffdef3acb7657f37bca3a51ffe467 (patch) | |
| tree | f84c8878fed17ddf28e1ef1897170c75c681ab2c /plugins/smoke_on_damage | |
| parent | ab9065592f811dcb78c6f1f7fe927d3deadf3695 (diff) | |
Updated plugins and manager
Added smoke on damage as a plugin
And added in ability for plugin manager to use folder plugins (multi file if necessary)
Diffstat (limited to 'plugins/smoke_on_damage')
| -rw-r--r-- | plugins/smoke_on_damage/Plugin.py | 47 | ||||
| -rw-r--r-- | plugins/smoke_on_damage/__init__.py | 2 |
2 files changed, 49 insertions, 0 deletions
diff --git a/plugins/smoke_on_damage/Plugin.py b/plugins/smoke_on_damage/Plugin.py new file mode 100644 index 0000000..b3b4ccd --- /dev/null +++ b/plugins/smoke_on_damage/Plugin.py @@ -0,0 +1,47 @@ +"""TThis plugin will cause the aircraft to emit smoke if it's health is below a certain threshold. +It is also an example of a plugin as a folder/module.""" +from lib.PacketManager.packets import FSNETCMD_AIRCMD, FSNETCMD_AIRPLANESTATE, FSNETCMD_TEXTMESSAGE +from logging import debug +from config import SMOKE_LIFE, SMOKE_PLANE +ENABLED = True + +class Plugin: + def __init__(self): + self.plugin_manager = None + + def register(self, plugin_manager): + self.plugin_manager = plugin_manager + self.plugin_manager.register_hook('on_flight_data', self.on_flight_data) + self.plugin_manager.register_hook('on_weapon_config', self.on_weapon_config) + + def on_flight_data(self, data, player,message_to_client, message_to_server): + """After the initial incoming flight packet, check whether + the health is below the threshold, if so add smoke""" + if ENABLED and SMOKE_PLANE and player.aircraft.life<SMOKE_LIFE: + + #Add smoke to the plane + smoke_packet = FSNETCMD_AIRPLANESTATE(data).smoke() + #forward it on to the server + + message_to_server.append(smoke_packet) + + + + if not player.aircraft.damage_engine_warn_sent: + player.aircraft.damage_engine_warn_sent = True + #Warn the player + message = "Your engine has been damaged! You can't turn on your afterburner!" + message_to_client.append(FSNETCMD_TEXTMESSAGE.encode(message,True)) + + debug(f"Engine damage warning sent to {player.username}") + + message_to_client.append(FSNETCMD_AIRCMD.set_afterburner(player.aircraft.id, False, True)) + + return False + + def on_weapon_config(self, data, player, message_to_client, message_to_server): + if ENABLED: + player.aircraft.just_repaired = True + if player.aircraft.get_initial_config_value("AFTBURNR") == "TRUE": + message_to_client.append(FSNETCMD_AIRCMD.set_afterburner(player.aircraft.id, True, True)) + return True diff --git a/plugins/smoke_on_damage/__init__.py b/plugins/smoke_on_damage/__init__.py new file mode 100644 index 0000000..425d2ad --- /dev/null +++ b/plugins/smoke_on_damage/__init__.py @@ -0,0 +1,2 @@ +from .Plugin import Plugin +from .Plugin import ENABLED
\ No newline at end of file |
