Fight Module
This module can be used to store player's states about fights while they are online. It allows a player to start a fight against what is called here a NPC. A player can only fight one NPC at a time.
NPCs have a name, power, reward, a boss state (to specify whether they are a boss or not) and are linked to an area. All these properties are purely indicative and are not used by the module. They are sent back to the server when a player win a fight.
Installation
In your wally.toml file, add this to your dependencies:
Import
You have two solutions to import this module, depending if you wish to import the Controller or the Service on your own, or if you let the module give you the right code.
Configuration
A file called FightModule.config.lua is to be created in the folder ReplicatedStorage/Shared/Configs.
Explanation:
NPC_1: The name of the npc.
Name: The name to be displayed in the menus
Area: The zone the NPC belongs into.
Power: The power level of the NPC
Reward: The reward when the npc is defeated.
Boss: Whether the NPC is a both or not.
Usage
Client Side
This method allows you to listen to an event sent by the FightService and run a callback function whenever an event is received.
List of events:
OnFightStarted: Called when a player starts a fight.
OnFightWin: Called when a player wins a fight.
OnFightLoose: Called when a player loses a fight.
OnNpcCreated: Called when a NPC is created.
OnNpcUpdated: Called when a NPC is modified.
Usage
Explanation
name: The name of the event you wish to listen to.
callback: The callback function that will be run whenever this event is received.
Server Side
This method is used to create a NPC object from its configuration. It is automatically called when the server starts, but can be called manually whenever needed.
Usage
Explanation
player: The player for whom the NPC is configured.
npcName: The name of the NPC to be configured, which must be found in the configuration.
config: The NPC configuration for the player, as a table.
This method allows you to configure a NPC for a player. Most of the time, it has to be used when the player join the game, retrieving all NPCs he has beaten in the past and sending those information to the module.
Usage
Explanation
player: The player for whom the NPC is configured.
npcName: The name of the NPC to be configured, which must be found in the configuration.
config: The NPC configuration for the player, as a table.
This method allows you to start a fight for a player with a NPC. When a player is in a fight state, no other fights can be started.
Usage
Explanation
player: The player who will fight the NPC.
npcName: The name of the NPC against which the player will fight, which must be found in the configuration.
This method allows you to stop a fight in which a player is. When the fight is stopped, the NPC is marked as fightable again.
Usage
Explanation
player: The player who is fighting the NPC.
npcName: The name of the NPC against which the player is fighting, which must be found in the configuration.
won: Whether the player has won or not.