mirror of
https://github.com/araxiaonline/docs.git
synced 2026-06-13 03:32:31 -04:00
Added more classes and methods
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
- Getting Started
|
||||
- Configuration
|
||||
- Eluna Classes
|
||||
- [BattleGround](./classes/BattleGround.md)
|
||||
- [Creature](./classes/Creature.md)
|
||||
- [GameObject](./classes/GameObject.md)
|
||||
- [Group](./classes/Group.md)
|
||||
- Events
|
||||
- Enums
|
||||
- Examples
|
||||
|
||||
432
docs/classes/BattleGround.md
Normal file
432
docs/classes/BattleGround.md
Normal file
@@ -0,0 +1,432 @@
|
||||
## GetAlivePlayersCountByTeam
|
||||
Returns the amount of alive players in the BattleGround by the team ID.
|
||||
|
||||
### Parameters
|
||||
* team: [Team](./team.md) - The team ID for which to count the alive players.
|
||||
|
||||
### Returns
|
||||
* number - The number of alive players in the specified team.
|
||||
|
||||
### Example Usage
|
||||
Track alive players in a battleground and display a message when a team reaches a certain threshold.
|
||||
|
||||
```typescript
|
||||
const CHECK_ALIVE_PLAYERS_THRESHOLD = 5;
|
||||
const TEAM_ALLIANCE = Team.ALLIANCE;
|
||||
|
||||
const onBattleGroundTick: battleground_event_on_tick = (event: number, battleground: BattleGround) => {
|
||||
const allianceAlivePlayers = battleground.GetAlivePlayersCountByTeam(TEAM_ALLIANCE);
|
||||
|
||||
if (allianceAlivePlayers >= CHECK_ALIVE_PLAYERS_THRESHOLD) {
|
||||
battleground.SendMessageToAllPlayers("Alliance team reached the threshold of alive players.");
|
||||
}
|
||||
}
|
||||
|
||||
RegisterBattleGroundEvent(BattleGroundEvents.BATTLEGROUND_EVENT_ON_TICK, (...args) => onBattleGroundTick(...args));
|
||||
```
|
||||
|
||||
In this example, the `GetAlivePlayersCountByTeam` method is utilized to monitor the number of alive players in the Alliance team within a battleground. If the threshold defined by `CHECK_ALIVE_PLAYERS_THRESHOLD` is met, a message is sent to all players indicating that the Alliance team has reached the required number of alive players.
|
||||
|
||||
## GetBonusHonorFromKillCount
|
||||
This method calculates the bonus honor that a player will receive based on the number of kills they have in the specific battleground.
|
||||
|
||||
### Parameters
|
||||
* kills: number - The number of kills the player has in the battleground.
|
||||
|
||||
### Returns
|
||||
* number - The bonus honor amount calculated based on the number of kills.
|
||||
|
||||
### Example Usage
|
||||
Calculate and award bonus honor to a player based on kills in a battleground.
|
||||
```typescript
|
||||
const battleground: BattleGround = new BattleGround();
|
||||
const playerKills: number = 10;
|
||||
const bonusHonor: number = battleground.GetBonusHonorFromKillCount(playerKills);
|
||||
|
||||
player.AddHonor(bonusHonor);
|
||||
```
|
||||
|
||||
## GetBracketId
|
||||
|
||||
Returns the bracket ID of the specific battleground.
|
||||
|
||||
### Returns
|
||||
* number - The bracket ID of the battleground.
|
||||
|
||||
### Example Usage:
|
||||
Check if the battleground is in a specific bracket and return the bracket ID.
|
||||
```typescript
|
||||
const BRACKET_ID_10V10 = 3;
|
||||
const BRACKET_ID_15V15 = 4;
|
||||
|
||||
const CheckBracket: player_event_on_battleground_join = (event: number, player: Player, battleground: BattleGround) => {
|
||||
|
||||
const bracketId = battleground.GetBracketId();
|
||||
|
||||
if (bracketId === BRACKET_ID_10V10) {
|
||||
player.SendMessage("You are in the 10v10 bracket.");
|
||||
} else if (bracketId === BRACKET_ID_15V15) {
|
||||
player.SendMessage("You are in the 15v15 bracket.");
|
||||
} else {
|
||||
player.SendMessage("You are in a different battleground bracket.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_BATTLEGROUND_JOIN, (...args) => CheckBracket(...args));
|
||||
```
|
||||
|
||||
## GetEndTime
|
||||
This method returns the end time of the BattleGround.
|
||||
|
||||
### Returns
|
||||
* endTime: number - The timestamp indicating the end time of the BattleGround.
|
||||
|
||||
### Example Usage:
|
||||
Script to display remaining time until the end of the BattleGround.
|
||||
```typescript
|
||||
const displayEndTime: player_event_on_login = (event: number, player: Player) => {
|
||||
const endTime = BattleGround.GetEndTime();
|
||||
const currentTime = Date.now() / 1000;
|
||||
const remainingTime = (endTime - currentTime) / 60; // Convert seconds to minutes
|
||||
|
||||
player.SendNotification(`The BattleGround will end in ${remainingTime.toFixed(2)} minutes.`);
|
||||
}
|
||||
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_LOGIN, (...args) => displayEndTime(...args));
|
||||
```
|
||||
|
||||
This example usage demonstrates how to use the `GetEndTime` method to display the remaining time until the BattleGround ends for a player upon login.
|
||||
|
||||
## GetFreeSlotsForTeam
|
||||
Returns the amount of free slots available for the selected team in the specified battleground.
|
||||
|
||||
### Parameters
|
||||
* team: [Team](./team.md) - The team for which to check the free slots.
|
||||
|
||||
### Returns
|
||||
* number - The number of free slots available for the specified team.
|
||||
|
||||
### Example Usage
|
||||
Query and display the number of available slots for a specific team in the battleground.
|
||||
|
||||
```typescript
|
||||
const CheckTeamSlots: player_event_on_join_bg = (event: number, player: Player, bg: BattleGround, team: Team): void => {
|
||||
const freeSlots = bg.GetFreeSlotsForTeam(team);
|
||||
console.log(`Team ${team} in battleground has ${freeSlots} free slots.`);
|
||||
}
|
||||
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_JOIN_BG, (...args) => CheckTeamSlots(...args));
|
||||
```
|
||||
|
||||
In this example, the `GetFreeSlotsForTeam` method is used to retrieve and log the number of available slots for a specific team in the battleground when a player joins the battleground event.
|
||||
|
||||
## GetInstanceId
|
||||
Returns the instance ID of the BattleGround.
|
||||
|
||||
### Returns
|
||||
number - The instance ID of the BattleGround.
|
||||
|
||||
### Example Usage
|
||||
Retrieve the instance ID of a specific BattleGround:
|
||||
```typescript
|
||||
const bg: BattleGround = new BattleGround();
|
||||
const instanceId: number = bg.GetInstanceId();
|
||||
console.log(`Instance ID of the BattleGround: ${instanceId}`);
|
||||
```
|
||||
|
||||
## GetMap
|
||||
|
||||
Gets the map of the current Battleground.
|
||||
|
||||
### Returns
|
||||
map: [EMap](./emap.md) - The map of the Battleground.
|
||||
|
||||
### Example Usage:
|
||||
Accessing the map of the current Battleground.
|
||||
|
||||
```typescript
|
||||
const onBattlegroundJoin: player_event_on_battleground_join = (event: number, player: Player, bg: BattleGround): void => {
|
||||
|
||||
const map = bg.GetMap();
|
||||
console.log(`Player ${player.GetName()} is in ${map}`);
|
||||
}
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_BATTLEGROUND_JOIN, (...args) => onBattlegroundJoin(...args));
|
||||
```
|
||||
|
||||
By using this method, you can easily retrieve the map of the Battleground the player is currently in.
|
||||
|
||||
## GetMapId
|
||||
Returns the map ID of the BattleGround.
|
||||
|
||||
### Returns
|
||||
mapId: number - The map ID of the BattleGround.
|
||||
|
||||
### Example Usage:
|
||||
In a scenario where you need to retrieve the map ID of a battleground:
|
||||
```typescript
|
||||
const getBattlegroundMapId = (battleground: BattleGround): void => {
|
||||
const mapId = battleground.GetMapId();
|
||||
console.log(`The map ID of the battleground is: ${mapId}`);
|
||||
}
|
||||
|
||||
// Assuming 'battlegroundInstance' is an instance of BattleGround
|
||||
getBattlegroundMapId(battlegroundInstance);
|
||||
```
|
||||
|
||||
This method allows you to fetch the map ID of a specific battleground, providing crucial information needed for further operations related to the battleground instance.
|
||||
|
||||
## GetMaxLevel
|
||||
|
||||
This method returns the maximum allowed player level for the specific battleground.
|
||||
|
||||
### Returns
|
||||
* level: number - The maximum player level allowed in the battleground.
|
||||
|
||||
### Example Usage:
|
||||
Checking if a player meets the level requirements before allowing them to join the battleground.
|
||||
|
||||
```typescript
|
||||
const onPlayerJoinBG: player_event_on_join_bg = (event: number, player: Player, battleground: BattleGround): boolean => {
|
||||
|
||||
const maxLevel: number = battleground.GetMaxLevel();
|
||||
|
||||
if(player.GetLevel() > maxLevel) {
|
||||
console.log(`Player level ${player.GetLevel()} exceeds max level ${maxLevel} for battleground.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_JOIN_BG, (...args) => onPlayerJoinBG(...args));
|
||||
```
|
||||
|
||||
## GetMaxPlayers
|
||||
|
||||
Returns the maximum allowed count of players for the specific battleground.
|
||||
|
||||
### Method Signature
|
||||
```typescript
|
||||
GetMaxPlayers(): number;
|
||||
```
|
||||
|
||||
### Example Usage
|
||||
Retrieve the maximum number of players allowed for a battleground and display it in the console.
|
||||
|
||||
```typescript
|
||||
const displayMaxPlayers = (): void => {
|
||||
const bg: BattleGround = new BattleGround();
|
||||
const maxPlayers: number = bg.GetMaxPlayers();
|
||||
|
||||
console.log(`The maximum number of players allowed for this battleground is: ${maxPlayers}`);
|
||||
}
|
||||
|
||||
displayMaxPlayers();
|
||||
```
|
||||
|
||||
This example demonstrates how to create a new instance of `BattleGround`, call the `GetMaxPlayers` method, and log the result to the console.
|
||||
|
||||
## GetMaxPlayersPerTeam
|
||||
|
||||
Returns the maximum allowed player count per team of the specific BattleGround.
|
||||
|
||||
### Returns
|
||||
number - The maximum number of players per team allowed for this BattleGround.
|
||||
|
||||
### Example Usage
|
||||
|
||||
Retrieve the maximum players per team for a specific BattleGround and display the result:
|
||||
|
||||
```typescript
|
||||
const battleground: BattleGround = new BattleGround();
|
||||
|
||||
const maxPlayersPerTeam: number = battleground.GetMaxPlayersPerTeam();
|
||||
|
||||
console.log(`The maximum number of players per team for this BattleGround is: ${maxPlayersPerTeam}`);
|
||||
```
|
||||
|
||||
### Notes
|
||||
|
||||
- This method is useful for determining the player limit per team in a BattleGround scenario.
|
||||
- Make sure to check for any custom rules or configurations that may affect the maximum player count per team.
|
||||
|
||||
## GetMinLevel
|
||||
Returns the minimum allowed player level required to participate in the specific BattleGround.
|
||||
|
||||
### Returns
|
||||
* number - The minimum player level allowed in the BattleGround.
|
||||
|
||||
### Example Usage
|
||||
Check if a player meets the level requirement before letting them enter the BattleGround.
|
||||
|
||||
```typescript
|
||||
const onPlayerEnterBattleGround: battleground_event_on_enter = (event: number, player: Player, battleground: BattleGround): void => {
|
||||
const minLevel = battleground.GetMinLevel();
|
||||
|
||||
if(player.GetLevel() < minLevel) {
|
||||
player.SendBroadcastMessage(`You must be at least level ${minLevel} to enter this BattleGround.`);
|
||||
} else {
|
||||
// Player can enter the BattleGround
|
||||
}
|
||||
}
|
||||
|
||||
RegisterBattleGroundEvent(BattleGroundEvents.BATTLEGROUND_EVENT_ON_ENTER, (...args) => onPlayerEnterBattleGround(...args));
|
||||
```
|
||||
|
||||
In this example, the GetMinLevel method is used to determine if a player meets the level requirement to enter a specific BattleGround. If the player's level is below the minimum required level, a message is sent notifying the player. Otherwise, the player is allowed to enter the BattleGround.
|
||||
|
||||
## GetMinPlayers
|
||||
Returns the minimum allowed player count for the specific battleground.
|
||||
|
||||
### Returns
|
||||
number - The minimum player count allowed for the battleground.
|
||||
|
||||
### Example Usage:
|
||||
Script to ensure minimum player count before starting a battleground match.
|
||||
```typescript
|
||||
const onPlayerEnterBattleground: bg_event_on_player_enter_battleground = (event: number, bg: BattleGround, player: Player): void => {
|
||||
const minPlayers = bg.GetMinPlayers();
|
||||
const playerCount = bg.GetPlayerCount();
|
||||
|
||||
if (playerCount < minPlayers) {
|
||||
player.SendMessage("Not enough players to start the battleground.");
|
||||
bg.EndMatch();
|
||||
}
|
||||
}
|
||||
RegisterBattlegroundEvent(BattlegroundEvents.BG_EVENT_ON_PLAYER_ENTER, (...args) => onPlayerEnterBattleground(...args));
|
||||
```
|
||||
|
||||
By using this method, you can ensure that the battleground matches in your mod meet the required minimum player count before starting.
|
||||
|
||||
## GetMinPlayersPerTeam
|
||||
|
||||
This method returns the minimum allowed player count per team of the specific battleground.
|
||||
|
||||
### Returns
|
||||
* number - The minimum player count per team for the battleground.
|
||||
|
||||
### Example Usage:
|
||||
Checking if a battleground has enough players per team before starting the game.
|
||||
|
||||
```typescript
|
||||
const CheckPlayersPerTeam: player_event_on_battleground_start = (event: number, battleground: BattleGround, teamPlayers: number[][]): void => {
|
||||
|
||||
const minPlayersPerTeam = battleground.GetMinPlayersPerTeam();
|
||||
|
||||
const team1Players = teamPlayers[0].length;
|
||||
const team2Players = teamPlayers[1].length;
|
||||
|
||||
if (team1Players < minPlayersPerTeam || team2Players < minPlayersPerTeam) {
|
||||
// Not enough players per team, do not start the battleground
|
||||
return;
|
||||
}
|
||||
|
||||
// Start the battleground with enough players per team
|
||||
battleground.Start();
|
||||
}
|
||||
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_BATTLEGROUND_START, (...args) => CheckPlayersPerTeam(...args));
|
||||
```
|
||||
|
||||
## GetName
|
||||
|
||||
This method returns the name of the specific BattleGround instance.
|
||||
|
||||
### Returns
|
||||
* name: string - The name of the BattleGround.
|
||||
|
||||
### Example Usage:
|
||||
```typescript
|
||||
const getBGName = (battleGround: BattleGround): void => {
|
||||
|
||||
const name = battleGround.GetName();
|
||||
console.log(`The name of the BattleGround is: ${name}`);
|
||||
|
||||
}
|
||||
|
||||
const myBattleGround = new BattleGround();
|
||||
getBGName(myBattleGround);
|
||||
```
|
||||
|
||||
In this example, we define a function `getBGName` that takes a `BattleGround` instance as a parameter and retrieves the name of the BattleGround using the `GetName` method. The retrieved name is then logged to the console for display.
|
||||
|
||||
## GetStatus
|
||||
This method returns the current status of the specified BattleGround.
|
||||
|
||||
### Returns
|
||||
status: number - The current status of the BattleGround.
|
||||
|
||||
### Example Usage
|
||||
Check the status of a specific BattleGround and take action accordingly.
|
||||
|
||||
```typescript
|
||||
const checkBattleGroundStatus = (bg: BattleGround): void => {
|
||||
|
||||
const status = bg.GetStatus();
|
||||
|
||||
switch (status) {
|
||||
case 0:
|
||||
console.log("The BattleGround is currently inactive.");
|
||||
break;
|
||||
case 1:
|
||||
console.log("The BattleGround is currently in progress.");
|
||||
break;
|
||||
case 2:
|
||||
console.log("The BattleGround is currently completed.");
|
||||
break;
|
||||
default:
|
||||
console.log("Unknown BattleGround status.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const myBattleGround: BattleGround = new BattleGround();
|
||||
checkBattleGroundStatus(myBattleGround);
|
||||
```
|
||||
|
||||
By utilizing this GetStatus method, you can easily retrieve and monitor the status of a BattleGround in your mod-eluna project on Azerothcore.
|
||||
|
||||
## GetTypeId
|
||||
Get the type ID of the battleground.
|
||||
|
||||
### Returns
|
||||
* typeId: [BattleGroundTypeId](./battlegroundtypeid.md) - The type ID of the battleground.
|
||||
|
||||
### Example Usage:
|
||||
```typescript
|
||||
const getBattlegroundTypeId: () => void => {
|
||||
|
||||
const typeId: BattleGroundTypeId = BattleGround.GetTypeId();
|
||||
|
||||
console.log(`BattleGround Type ID: ${typeId}`);
|
||||
}
|
||||
getBattlegroundTypeId();
|
||||
```
|
||||
|
||||
## GetWinner
|
||||
Return the winning team of the specific battleground.
|
||||
|
||||
### Returns <hr />
|
||||
team: [Team](./team.md) - The winning team of the battleground.
|
||||
|
||||
### Example Usage:
|
||||
Check the winning team of the battleground and reward players accordingly.
|
||||
```typescript
|
||||
const CheckBattleGroundResults: player_event_on_battleground_end = (event: number, player: Player, battleground: BattleGround) => {
|
||||
|
||||
const winningTeam = battleground.GetWinner();
|
||||
|
||||
if(winningTeam === Team.ALLIANCE) {
|
||||
player.AddItem(ITEM_ID_ALLIANCE_REWARD, REWARD_AMOUNT);
|
||||
} else if (winningTeam === Team.HORDE) {
|
||||
player.AddItem(ITEM_ID_HORDE_REWARD, REWARD_AMOUNT);
|
||||
} else {
|
||||
player.AddItem(ITEM_ID_DRAW_REWARD, REWARD_AMOUNT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_BATTLEGROUND_END, (...args) => CheckBattleGroundResults(...args));
|
||||
```
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
662
docs/classes/Group.md
Normal file
662
docs/classes/Group.md
Normal file
@@ -0,0 +1,662 @@
|
||||
## AddMember
|
||||
Adds a player to the group. If the group is full (5 players), the player will not be added.
|
||||
|
||||
### Parameters
|
||||
* player: [Player](./player.md) - The player to add to the group
|
||||
|
||||
### Returns
|
||||
boolean - True if the player was added to the group, false otherwise
|
||||
|
||||
### Example Usage
|
||||
This example demonstrates how to add a player to a group when they enter the world, and send a message to the group if the player was successfully added.
|
||||
|
||||
```typescript
|
||||
const OnLogin: player_event_on_login = (event: number, player: Player) => {
|
||||
const groupId = player.GetGroup();
|
||||
|
||||
if (groupId) {
|
||||
const group = new Group(groupId);
|
||||
const playerName = player.GetName();
|
||||
|
||||
if (group.AddMember(player)) {
|
||||
group.SendGroupMessage(`${playerName} has joined the group!`);
|
||||
|
||||
// Get the leader of the group
|
||||
const leader = group.GetLeader();
|
||||
|
||||
// Announce to the leader that a new player has joined
|
||||
leader.SendBroadcastMessage(`${playerName} has joined your group!`);
|
||||
|
||||
// Set the player's group roles
|
||||
const isHealer = player.GetClass() === Classes.CLASS_PRIEST || player.GetClass() === Classes.CLASS_DRUID;
|
||||
const isTank = player.GetClass() === Classes.CLASS_WARRIOR || player.GetClass() === Classes.CLASS_PALADIN;
|
||||
|
||||
if (isHealer) {
|
||||
group.SetGroupRole(player, GroupRole.Healer);
|
||||
} else if (isBank) {
|
||||
group.SetGroupRole(player, GroupRole.Tank);
|
||||
} else {
|
||||
group.SetGroupRole(player, GroupRole.DPS);
|
||||
}
|
||||
} else {
|
||||
player.SendBroadcastMessage("The group is full. You were not added to the group.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_LOGIN, (...args) => OnLogin(...args));
|
||||
```
|
||||
|
||||
In this example, when a player logs in, the script checks if the player is in a group. If the player is in a group, the script attempts to add the player to the group using the `AddMember` method. If the player is successfully added, a message is sent to the group announcing that the player has joined. Additionally, a message is sent to the group leader to inform them that a new player has joined their group.
|
||||
|
||||
The script also sets the player's group role based on their class. If the player is a priest or druid, they are assigned the healer role. If the player is a warrior or paladin, they are assigned the tank role. Otherwise, they are assigned the DPS role.
|
||||
|
||||
If the group is full and the player cannot be added, a message is sent to the player informing them that the group is full and they were not added.
|
||||
|
||||
## ConvertToRaid
|
||||
Converts the current group to a raid group. This allows the group to have up to 40 members instead of the normal 5.
|
||||
|
||||
### Parameters
|
||||
None
|
||||
|
||||
### Returns
|
||||
None
|
||||
|
||||
### Example Usage
|
||||
This example demonstrates how to convert a group to a raid when a player joins, and then invite additional members.
|
||||
|
||||
```typescript
|
||||
const MAX_RAID_MEMBERS = 40;
|
||||
|
||||
const OnAddMember: group_event_on_add_member = (event: GroupEvents, group: Group, guid: number) => {
|
||||
// Convert to raid when the 5th player joins
|
||||
if (group.GetMembersCount() === 5) {
|
||||
group.ConvertToRaid();
|
||||
group.SendPacket(`The group has been converted to a raid group.`);
|
||||
}
|
||||
|
||||
// If the group is a raid, and there's still room, invite some additional players
|
||||
if (group.isRaidGroup() && group.GetMembersCount() < MAX_RAID_MEMBERS) {
|
||||
// Get some additional player GUIDs to invite (for example from a list of signups)
|
||||
const additionalPlayers = GetAdditionalRaidSignups();
|
||||
|
||||
for (const playerGuid of additionalPlayers) {
|
||||
// Check if the player is online and not already in the raid
|
||||
const player = GetPlayerByGUID(playerGuid);
|
||||
if (player && !group.IsMember(playerGuid)) {
|
||||
// Invite the player to the raid
|
||||
group.AddMember(playerGuid);
|
||||
|
||||
// If the raid is now full, stop inviting
|
||||
if (group.GetMembersCount() >= MAX_RAID_MEMBERS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RegisterGroupEvent(GroupEvents.GROUP_EVENT_ON_MEMBER_JOINED, OnAddMember);
|
||||
```
|
||||
|
||||
In this example:
|
||||
|
||||
1. When the 5th player joins the group, `ConvertToRaid()` is called to upgrade the group to a raid.
|
||||
2. The group is checked to see if it's a raid group using `isRaidGroup()`.
|
||||
3. If the group is a raid and there's still room (less than `MAX_RAID_MEMBERS`), the script tries to invite additional players.
|
||||
4. It gets an array of additional player GUIDs from a hypothetical function `GetAdditionalRaidSignups()`. This function could return GUIDs from a list of players who have signed up for the raid, for example.
|
||||
5. For each additional player GUID, it checks if the player is online and not already in the raid.
|
||||
6. If the player is eligible, they are invited to the raid using `group.AddMember(playerGuid)`.
|
||||
7. If the raid reaches the maximum number of members, it stops inviting players.
|
||||
|
||||
This showcases a potential use case for `ConvertToRaid()` in a mod-eluna script for Azerothcore, demonstrating how to automatically convert a group to a raid and then fill it with additional members.
|
||||
|
||||
## Disband
|
||||
Disbands the current group, removing all members and destroying the group object.
|
||||
|
||||
### Example Usage
|
||||
Here's an example of how to use the `Disband()` method to disband a group after a certain condition is met, such as the group leader leaving the group or the group wiping on a boss encounter.
|
||||
|
||||
```typescript
|
||||
const MAX_WIPES_ALLOWED = 5;
|
||||
let wipeCounter = 0;
|
||||
|
||||
const GroupWipe: group_event_on_wipe = (event: number, group: Group, isRaid: boolean): void => {
|
||||
wipeCounter++;
|
||||
|
||||
if (wipeCounter >= MAX_WIPES_ALLOWED) {
|
||||
group.SendGroupMessage(`The group has wiped ${MAX_WIPES_ALLOWED} times. Disbanding the group.`);
|
||||
group.Disband();
|
||||
} else {
|
||||
group.SendGroupMessage(`The group has wiped. Wipe counter: ${wipeCounter}/${MAX_WIPES_ALLOWED}`);
|
||||
}
|
||||
};
|
||||
|
||||
const LeaderChanged: group_event_on_leader_change = (event: number, group: Group, newLeaderGuid: number, oldLeaderGuid: number): void => {
|
||||
const oldLeader = group.GetMember(oldLeaderGuid);
|
||||
if (oldLeader) {
|
||||
group.SendGroupMessage(`${oldLeader.GetName()} is no longer the group leader. Disbanding the group.`);
|
||||
group.Disband();
|
||||
}
|
||||
};
|
||||
|
||||
RegisterGroupEvent(GroupEvents.GROUP_EVENT_ON_WIPE, (...args) => GroupWipe(...args));
|
||||
RegisterGroupEvent(GroupEvents.GROUP_EVENT_ON_LEADER_CHANGE, (...args) => LeaderChanged(...args));
|
||||
```
|
||||
|
||||
In this example:
|
||||
|
||||
1. We define a constant `MAX_WIPES_ALLOWED` to set the maximum number of wipes allowed before disbanding the group.
|
||||
2. We initialize a variable `wipeCounter` to keep track of the number of wipes.
|
||||
3. We register a callback function `GroupWipe` for the `GROUP_EVENT_ON_WIPE` event.
|
||||
- Inside the callback, we increment the `wipeCounter`.
|
||||
- If the `wipeCounter` reaches or exceeds `MAX_WIPES_ALLOWED`, we send a message to the group and disband it using `group.Disband()`.
|
||||
- If the wipe counter is below the threshold, we send a message to the group indicating the current wipe count.
|
||||
4. We register another callback function `LeaderChanged` for the `GROUP_EVENT_ON_LEADER_CHANGE` event.
|
||||
- Inside the callback, we retrieve the old leader using `group.GetMember(oldLeaderGuid)`.
|
||||
- If the old leader exists (meaning they left the group), we send a message to the group and disband it using `group.Disband()`.
|
||||
|
||||
This script ensures that the group is automatically disbanded if:
|
||||
- The group wipes a certain number of times (defined by `MAX_WIPES_ALLOWED`).
|
||||
- The group leader leaves the group.
|
||||
|
||||
By using the `Disband()` method in combination with group events, you can create more complex scripts to handle group disbandment based on specific conditions or triggers.
|
||||
|
||||
## GetGUID
|
||||
Returns the unique identifier for the group. This identifier is unique across all groups and remains constant throughout the lifetime of the group.
|
||||
|
||||
### Parameters
|
||||
None
|
||||
|
||||
### Returns
|
||||
* number - The unique identifier of the group.
|
||||
|
||||
### Example Usage
|
||||
This example demonstrates how to use the `GetGUID()` method to track the progress of a group through a dungeon. The script listens for the `GROUP_EVENT_ON_DUNGEON_FINISH` event and records the completion time and the group's GUID in a database.
|
||||
|
||||
```typescript
|
||||
const GROUP_EVENT_ON_DUNGEON_FINISH = 1;
|
||||
|
||||
// Function to handle the GROUP_EVENT_ON_DUNGEON_FINISH event
|
||||
const onDungeonFinish: group_event_on_dungeon_finish = (event: number, group: Group, player: Player, dungeonId: number, dungeonName: string) => {
|
||||
// Get the current timestamp
|
||||
const completionTime = os.time();
|
||||
|
||||
// Get the group's GUID
|
||||
const groupGUID = group.GetGUID();
|
||||
|
||||
// Insert the completion record into the database
|
||||
const query = `
|
||||
INSERT INTO dungeon_completions (group_guid, dungeon_id, completion_time)
|
||||
VALUES (${groupGUID}, ${dungeonId}, ${completionTime})
|
||||
`;
|
||||
|
||||
// Execute the database query
|
||||
database.query(query);
|
||||
|
||||
// Announce the dungeon completion to the group
|
||||
const message = `Congratulations! You have completed the dungeon "${dungeonName}" at ${os.date('%Y-%m-%d %H:%M:%S', completionTime)}.`;
|
||||
group.SendPacket(message);
|
||||
};
|
||||
|
||||
// Register the event handler for the GROUP_EVENT_ON_DUNGEON_FINISH event
|
||||
RegisterGroupEvent(GROUP_EVENT_ON_DUNGEON_FINISH, onDungeonFinish);
|
||||
```
|
||||
|
||||
In this example:
|
||||
1. We define a function `onDungeonFinish` to handle the `GROUP_EVENT_ON_DUNGEON_FINISH` event.
|
||||
2. Inside the event handler, we retrieve the current timestamp using `os.time()` to record the completion time.
|
||||
3. We call the `GetGUID()` method on the `group` object to get the group's unique identifier.
|
||||
4. We construct a database query to insert the completion record into a table named `dungeon_completions`, including the group's GUID, the dungeon ID, and the completion time.
|
||||
5. We execute the database query using `database.query()` to store the completion record.
|
||||
6. We generate a congratulatory message that includes the dungeon name and the completion time.
|
||||
7. We send the message to all members of the group using the `SendPacket()` method.
|
||||
8. Finally, we register the `onDungeonFinish` function as the event handler for the `GROUP_EVENT_ON_DUNGEON_FINISH` event using `RegisterGroupEvent()`.
|
||||
|
||||
This script allows you to track the progress of groups through dungeons by recording the completion time and the group's GUID in a database. You can later retrieve this information to analyze group performance, generate leaderboards, or reward players based on their dungeon completions.
|
||||
|
||||
## GetLeaderGUID
|
||||
Returns the GUID (Globally Unique Identifier) of the [Group] leader. The GUID is a unique numerical identifier assigned to each player or creature in the game world.
|
||||
|
||||
### Parameters
|
||||
None
|
||||
|
||||
### Returns
|
||||
* number - The GUID of the [Group] leader.
|
||||
|
||||
### Example Usage
|
||||
Here's an example of how to use the `GetLeaderGUID` method to retrieve the GUID of the group leader and perform actions based on the leader's class:
|
||||
|
||||
```typescript
|
||||
const OnGroupMemberJoin: group_event_on_member_join = (event: number, group: Group, guid: number): void => {
|
||||
const leaderGuid = group.GetLeaderGUID();
|
||||
const leader = GetPlayerByGUID(leaderGuid);
|
||||
|
||||
if (leader) {
|
||||
const leaderClass = leader.GetClass();
|
||||
|
||||
switch (leaderClass) {
|
||||
case Classes.CLASS_WARRIOR:
|
||||
leader.SendBroadcastMessage("The mighty warrior leads the group!");
|
||||
break;
|
||||
case Classes.CLASS_PALADIN:
|
||||
leader.SendBroadcastMessage("The holy paladin guides the group!");
|
||||
break;
|
||||
case Classes.CLASS_HUNTER:
|
||||
leader.SendBroadcastMessage("The skilled hunter leads the pack!");
|
||||
break;
|
||||
case Classes.CLASS_ROGUE:
|
||||
leader.SendBroadcastMessage("The cunning rogue takes charge!");
|
||||
break;
|
||||
case Classes.CLASS_PRIEST:
|
||||
leader.SendBroadcastMessage("The wise priest leads the faithful!");
|
||||
break;
|
||||
case Classes.CLASS_SHAMAN:
|
||||
leader.SendBroadcastMessage("The spiritual shaman guides the group!");
|
||||
break;
|
||||
case Classes.CLASS_MAGE:
|
||||
leader.SendBroadcastMessage("The arcane mage leads the way!");
|
||||
break;
|
||||
case Classes.CLASS_WARLOCK:
|
||||
leader.SendBroadcastMessage("The dark warlock assumes control!");
|
||||
break;
|
||||
case Classes.CLASS_DRUID:
|
||||
leader.SendBroadcastMessage("The nurturing druid leads the group!");
|
||||
break;
|
||||
default:
|
||||
leader.SendBroadcastMessage("A mysterious leader guides the group!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RegisterGroupEvent(GroupEvents.GROUP_EVENT_ON_MEMBER_JOIN, (...args) => OnGroupMemberJoin(...args));
|
||||
```
|
||||
|
||||
In this example, when a new member joins the group, the script retrieves the GUID of the group leader using `GetLeaderGUID()`. It then uses the `GetPlayerByGUID` function to obtain the leader's [Player] object.
|
||||
|
||||
If the leader is found, the script checks the leader's class using `GetClass()` and sends a broadcast message to the leader based on their class. Each class has a unique message tailored to their role and identity.
|
||||
|
||||
This script demonstrates how to utilize the `GetLeaderGUID` method to retrieve the group leader's GUID and perform class-specific actions or notifications based on the leader's class.
|
||||
|
||||
## GetMemberGUID
|
||||
Returns the GUID of a group member by their name. This can be used to interact with or reference a specific group member.
|
||||
|
||||
### Parameters
|
||||
* name: string - The name of the group member to retrieve the GUID for.
|
||||
|
||||
### Returns
|
||||
* GUID: number - The GUID of the specified group member. Returns 0 if the member is not found.
|
||||
|
||||
### Example Usage
|
||||
This example demonstrates how to retrieve a specific group member's GUID and use it to send them a message and summon them to the group leader's location.
|
||||
|
||||
```typescript
|
||||
const sendGroupMemberMessage: CommandFn = (player: Player, command: string, args: string[]) => {
|
||||
const groupMemberName = args[0];
|
||||
|
||||
if (player.IsInGroup()) {
|
||||
const group = player.GetGroup();
|
||||
const memberGUID = group.GetMemberGUID(groupMemberName);
|
||||
|
||||
if (memberGUID !== 0) {
|
||||
const member = GetPlayerByGUID(memberGUID);
|
||||
|
||||
if (member) {
|
||||
// Send a message to the group member
|
||||
member.SendBroadcastMessage(`Hello, ${member.GetName()}! Your group leader has a message for you.`);
|
||||
|
||||
// Summon the group member to the leader's location
|
||||
const leaderMapId = player.GetMapId();
|
||||
const leaderX = player.GetX();
|
||||
const leaderY = player.GetY();
|
||||
const leaderZ = player.GetZ();
|
||||
const leaderO = player.GetO();
|
||||
|
||||
member.SummonPlayer(leaderMapId, leaderX, leaderY, leaderZ, leaderO);
|
||||
|
||||
player.SendBroadcastMessage(`Successfully summoned ${member.GetName()} to your location.`);
|
||||
} else {
|
||||
player.SendBroadcastMessage(`Error: Group member ${groupMemberName} is offline or not found.`);
|
||||
}
|
||||
} else {
|
||||
player.SendBroadcastMessage(`Error: No group member found with the name ${groupMemberName}.`);
|
||||
}
|
||||
} else {
|
||||
player.SendBroadcastMessage("You are not in a group.");
|
||||
}
|
||||
};
|
||||
|
||||
ChatCommands.on("summonmember", sendGroupMemberMessage);
|
||||
```
|
||||
|
||||
In this example:
|
||||
1. The `sendGroupMemberMessage` function is defined as a `CommandFn`, which is triggered by the "summonmember" chat command.
|
||||
2. It checks if the player is in a group using `player.IsInGroup()`.
|
||||
3. If the player is in a group, it retrieves the group object using `player.GetGroup()`.
|
||||
4. It then calls the `GetMemberGUID` method on the group object, passing the desired group member's name as an argument.
|
||||
5. If a valid GUID is returned (not 0), it uses `GetPlayerByGUID` to retrieve the player object for that group member.
|
||||
6. If the member is found, it sends them a broadcast message using `member.SendBroadcastMessage`.
|
||||
7. It then retrieves the group leader's current location using `GetMapId`, `GetX`, `GetY`, `GetZ`, and `GetO`.
|
||||
8. The `SummonPlayer` method is called on the member object to summon them to the leader's location.
|
||||
9. A success message is sent to the group leader using `player.SendBroadcastMessage`.
|
||||
10. If the member is not found or the player is not in a group, appropriate error messages are sent using `player.SendBroadcastMessage`.
|
||||
|
||||
This example showcases how to retrieve a group member's GUID, send them a message, and summon them to the group leader's location using the `GetMemberGUID` method and other related methods from the `Player` and `Group` classes.
|
||||
|
||||
## GetMemberGroup
|
||||
Returns the subgroup ID of a player in the group based on their GUID.
|
||||
|
||||
### Parameters
|
||||
* guid: number - The GUID of the player to check the subgroup ID for.
|
||||
|
||||
### Returns
|
||||
* number - The subgroup ID of the player (0-7). Returns -1 if the player is not found in the group.
|
||||
|
||||
### Example Usage
|
||||
```typescript
|
||||
// Function to handle group invite event
|
||||
const OnGroupInvite: group_event_on_invite = (event: number, group: Group, leader: Player, invitedPlayer: Player): void => {
|
||||
// Get the leader's subgroup ID
|
||||
const leaderSubgroup = group.GetMemberGroup(leader.GetGUID());
|
||||
|
||||
// Assign the invited player to the same subgroup as the leader
|
||||
if (leaderSubgroup !== -1) {
|
||||
group.ChangeMembersGroup(invitedPlayer, leaderSubgroup);
|
||||
}
|
||||
|
||||
// Announce the player's subgroup assignment
|
||||
if (leaderSubgroup === 0) {
|
||||
SendWorldMessage(`${invitedPlayer.GetName()} has joined ${leader.GetName()}'s group as a main tank.`);
|
||||
} else if (leaderSubgroup === 1) {
|
||||
SendWorldMessage(`${invitedPlayer.GetName()} has joined ${leader.GetName()}'s group as an off-tank.`);
|
||||
} else if (leaderSubgroup >= 2 && leaderSubgroup <= 4) {
|
||||
SendWorldMessage(`${invitedPlayer.GetName()} has joined ${leader.GetName()}'s group as a DPS.`);
|
||||
} else if (leaderSubgroup >= 5 && leaderSubgroup <= 7) {
|
||||
SendWorldMessage(`${invitedPlayer.GetName()} has joined ${leader.GetName()}'s group as a healer.`);
|
||||
}
|
||||
};
|
||||
|
||||
RegisterGroupEvent(GroupEvents.GROUP_EVENT_ON_INVITE, OnGroupInvite);
|
||||
```
|
||||
|
||||
In this example, when a player is invited to a group, the script retrieves the subgroup ID of the group leader using `GetMemberGroup()`. If the leader is found in a valid subgroup, the invited player is assigned to the same subgroup using `ChangeMembersGroup()`.
|
||||
|
||||
The script then announces the player's subgroup assignment based on the subgroup ID. Subgroup 0 is considered the main tank, subgroup 1 is considered the off-tank, subgroups 2-4 are considered DPS, and subgroups 5-7 are considered healers.
|
||||
|
||||
This example demonstrates how `GetMemberGroup()` can be used to retrieve the subgroup ID of a player in the group and make decisions based on that information, such as assigning roles or making announcements.
|
||||
|
||||
## GetMembers
|
||||
Returns a table containing all the players currently in the group.
|
||||
|
||||
### Parameters
|
||||
None
|
||||
|
||||
### Returns
|
||||
players: [Player](./player.md)[] - A table of players in the group.
|
||||
|
||||
### Example Usage
|
||||
Reward all players in a group with a special item when the group leader loots a specific boss.
|
||||
|
||||
```typescript
|
||||
const BOSS_ENTRY = 12345;
|
||||
const SPECIAL_ITEM_ENTRY = 54321;
|
||||
const SPECIAL_ITEM_COUNT = 1;
|
||||
|
||||
const BossLoot: player_event_on_loot_item = (event: number, player: Player, item: Item) => {
|
||||
if (item.GetEntry() == BOSS_ENTRY && player.IsInGroup()) {
|
||||
const group = player.GetGroup();
|
||||
|
||||
if (group && player.IsGroupLeader()) {
|
||||
const groupMembers = group.GetMembers();
|
||||
|
||||
for (const member of groupMembers) {
|
||||
if (member.IsInWorld() && member.GetDistance(player) <= 50) {
|
||||
member.AddItem(SPECIAL_ITEM_ENTRY, SPECIAL_ITEM_COUNT);
|
||||
member.SendBroadcastMessage("You have been rewarded with a special item for your group's efforts!");
|
||||
}
|
||||
}
|
||||
|
||||
player.SendBroadcastMessage("Your group has been rewarded for defeating the boss!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_LOOT_ITEM, (...args) => BossLoot(...args));
|
||||
```
|
||||
|
||||
In this example:
|
||||
1. When a player loots an item, the script checks if the looted item is from a specific boss (identified by its entry ID) and if the player is in a group.
|
||||
2. If the player is the group leader, the script retrieves all members of the group using `group.GetMembers()`.
|
||||
3. The script then iterates through each group member and checks if they are in the game world and within a certain distance (50 yards) of the group leader.
|
||||
4. If a group member meets these conditions, they are rewarded with a special item using `member.AddItem()` and sent a broadcast message informing them of the reward.
|
||||
5. Finally, the group leader is sent a broadcast message confirming that the group has been rewarded for defeating the boss.
|
||||
|
||||
This script showcases how `GetMembers()` can be used to retrieve all players in a group and perform actions on them, such as rewarding them with items or sending them messages. It also demonstrates how to check if a player is the group leader and if group members are within a certain distance of each other.
|
||||
|
||||
## GetMembersCount
|
||||
Returns the number of players currently in the group.
|
||||
|
||||
### Parameters
|
||||
None
|
||||
|
||||
### Returns
|
||||
number - The count of players currently in the group.
|
||||
|
||||
### Example Usage
|
||||
This example demonstrates how to use the `GetMembersCount` method to determine the size of a group and adjust the difficulty of an encounter accordingly.
|
||||
|
||||
```typescript
|
||||
const BOSS_ENTRY = 12345;
|
||||
const BOSS_MIN_PLAYERS = 5;
|
||||
const BOSS_MAX_PLAYERS = 10;
|
||||
const BOSS_HEALTH_PER_PLAYER = 100000;
|
||||
|
||||
const AdjustBossDifficulty: creature_event_on_spawn = (event: number, creature: Creature) => {
|
||||
if (creature.GetEntry() === BOSS_ENTRY) {
|
||||
const map = creature.GetMap();
|
||||
const players = map.GetPlayers();
|
||||
|
||||
if (players.length > 0) {
|
||||
const group = players[0].GetGroup();
|
||||
|
||||
if (group) {
|
||||
const memberCount = group.GetMembersCount();
|
||||
|
||||
if (memberCount >= BOSS_MIN_PLAYERS && memberCount <= BOSS_MAX_PLAYERS) {
|
||||
const adjustedHealth = creature.GetMaxHealth() + (memberCount * BOSS_HEALTH_PER_PLAYER);
|
||||
creature.SetMaxHealth(adjustedHealth);
|
||||
creature.SetHealth(adjustedHealth);
|
||||
console.log(`Adjusted boss health to ${adjustedHealth} for ${memberCount} players.`);
|
||||
} else {
|
||||
console.log(`Group size of ${memberCount} is not within the expected range for this encounter.`);
|
||||
}
|
||||
} else {
|
||||
console.log("Players are not in a group. Skipping difficulty adjustment.");
|
||||
}
|
||||
} else {
|
||||
console.log("No players found on the map. Skipping difficulty adjustment.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RegisterCreatureEvent(CreatureEvents.CREATURE_EVENT_ON_SPAWN, (...args) => AdjustBossDifficulty(...args));
|
||||
```
|
||||
|
||||
In this example, when a specific boss creature spawns, the script checks if there are players on the same map. If players are found, it retrieves the group of the first player. Using the `GetMembersCount` method, the script determines the number of players in the group.
|
||||
|
||||
If the group size falls within the predefined range (`BOSS_MIN_PLAYERS` to `BOSS_MAX_PLAYERS`), the script adjusts the boss's health based on the number of players. It increases the boss's maximum health by a fixed amount (`BOSS_HEALTH_PER_PLAYER`) for each player in the group. The adjusted health is then set as the boss's current health.
|
||||
|
||||
If the group size is outside the expected range or if players are not in a group, the script logs a message and skips the difficulty adjustment.
|
||||
|
||||
This example showcases how the `GetMembersCount` method can be used to dynamically scale the difficulty of an encounter based on the number of players in the group, providing a more balanced and engaging experience for different group sizes.
|
||||
|
||||
## HasFreeSlotSubGroup
|
||||
Checks if the specified subgroup in the [Group] has free slots available for new members to join.
|
||||
|
||||
### Parameters
|
||||
* subGroup: number - The subgroup index (0-7) to check for free slots.
|
||||
|
||||
### Returns
|
||||
* boolean - Returns 'true' if the specified subgroup has free slots, 'false' otherwise.
|
||||
|
||||
### Example Usage
|
||||
This example demonstrates how to check if a specific subgroup in a raid has free slots available and invite a player to join that subgroup if there is space.
|
||||
|
||||
```typescript
|
||||
const MAX_RAID_MEMBERS = 40;
|
||||
const HEALER_SUBGROUP = 3;
|
||||
|
||||
const InviteHealerToRaid: player_event_on_login = (event: number, player: Player) => {
|
||||
// Get the player's raid group
|
||||
const raid = player.GetGroup();
|
||||
|
||||
if (raid && raid.IsRaid()) {
|
||||
// Check if the raid has reached the maximum member limit
|
||||
if (raid.GetMembersCount() < MAX_RAID_MEMBERS) {
|
||||
// Check if the healer subgroup has free slots
|
||||
if (raid.HasFreeSlotSubGroup(HEALER_SUBGROUP)) {
|
||||
// Invite the player to join the healer subgroup
|
||||
raid.AddMember(player, HEALER_SUBGROUP);
|
||||
player.SendBroadcastMessage("Welcome to the raid! You have been assigned to the healer subgroup.");
|
||||
} else {
|
||||
player.SendBroadcastMessage("Sorry, the healer subgroup is currently full. Please try again later.");
|
||||
}
|
||||
} else {
|
||||
player.SendBroadcastMessage("The raid is already at maximum capacity. Please try joining another raid group.");
|
||||
}
|
||||
} else {
|
||||
player.SendBroadcastMessage("You are not currently in a raid group. Please join or create a raid before using this feature.");
|
||||
}
|
||||
};
|
||||
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_LOGIN, (...args) => InviteHealerToRaid(...args));
|
||||
```
|
||||
|
||||
In this example:
|
||||
1. We define constants for the maximum number of raid members (40) and the index of the healer subgroup (3).
|
||||
2. When a player logs in, we retrieve their raid group using `player.GetGroup()`.
|
||||
3. We check if the player is in a raid group using `raid.IsRaid()`.
|
||||
4. If the raid has not reached the maximum member limit, we proceed to check if the healer subgroup has free slots using `raid.HasFreeSlotSubGroup(HEALER_SUBGROUP)`.
|
||||
5. If there are free slots in the healer subgroup, we invite the player to join that subgroup using `raid.AddMember(player, HEALER_SUBGROUP)` and send them a welcome message.
|
||||
6. If the healer subgroup is full, we send the player a message informing them that the subgroup is currently full and to try again later.
|
||||
7. If the raid is already at maximum capacity, we send the player a message suggesting they join another raid group.
|
||||
8. If the player is not in a raid group, we send them a message prompting them to join or create a raid before using this feature.
|
||||
|
||||
This example showcases how the `HasFreeSlotSubGroup` method can be used in combination with other group-related methods to manage subgroup assignments and capacity in a raid setting.
|
||||
|
||||
## IsAssistant
|
||||
Checks if the specified player is an assistant in the group.
|
||||
|
||||
### Parameters
|
||||
* guid: number - The GUID of the player to check.
|
||||
|
||||
### Returns
|
||||
* boolean - Returns `true` if the player is an assistant in the group, `false` otherwise.
|
||||
|
||||
### Example Usage
|
||||
This example demonstrates how to check if a player is an assistant in the group and grant them additional rewards for completing a quest.
|
||||
|
||||
```typescript
|
||||
const QUEST_ENTRY = 1234;
|
||||
const ITEM_REWARD_ENTRY = 5678;
|
||||
const ITEM_REWARD_COUNT = 1;
|
||||
const GOLD_REWARD = 100;
|
||||
|
||||
const OnQuestComplete: player_event_on_quest_accept = (event: number, player: Player, quest: Quest) => {
|
||||
if (quest.GetEntry() === QUEST_ENTRY) {
|
||||
const group = player.GetGroup();
|
||||
if (group) {
|
||||
const members = group.GetMembers();
|
||||
for (const member of members) {
|
||||
if (group.IsAssistant(member.GetGUIDLow())) {
|
||||
member.AddItem(ITEM_REWARD_ENTRY, ITEM_REWARD_COUNT);
|
||||
member.ModifyMoney(GOLD_REWARD);
|
||||
member.SendBroadcastMessage("You received an additional reward for being a group assistant!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_QUEST_COMPLETE, (...args) => OnQuestComplete(...args));
|
||||
```
|
||||
|
||||
In this example:
|
||||
1. We define constants for the quest entry, item reward entry, item reward count, and gold reward amount.
|
||||
2. We register a player event for when a quest is completed using `RegisterPlayerEvent` and the `PLAYER_EVENT_ON_QUEST_COMPLETE` event.
|
||||
3. Inside the event handler, we check if the completed quest matches the desired quest entry.
|
||||
4. If the player is in a group, we retrieve the group using `player.GetGroup()`.
|
||||
5. We iterate over the group members using `group.GetMembers()`.
|
||||
6. For each member, we check if they are an assistant in the group using `group.IsAssistant(member.GetGUIDLow())`.
|
||||
7. If a member is an assistant, we grant them additional rewards:
|
||||
- We add the specified item to their inventory using `member.AddItem(ITEM_REWARD_ENTRY, ITEM_REWARD_COUNT)`.
|
||||
- We modify their money by the specified gold reward amount using `member.ModifyMoney(GOLD_REWARD)`.
|
||||
- We send them a broadcast message informing them of the additional reward using `member.SendBroadcastMessage(...)`.
|
||||
|
||||
This example showcases how the `IsAssistant` method can be used in a practical scenario to differentiate rewards based on a player's role within the group. It provides a more complex usage of the method, involving group member iteration and conditional reward distribution.
|
||||
|
||||
## IsBGGroup
|
||||
This method returns a boolean value indicating whether the group is a battleground group or not.
|
||||
|
||||
### Parameters
|
||||
None
|
||||
|
||||
### Returns
|
||||
boolean - Returns `true` if the group is a battleground group, `false` otherwise.
|
||||
|
||||
### Example Usage
|
||||
This example demonstrates how to check if a group is a battleground group and perform different actions based on the result.
|
||||
|
||||
```typescript
|
||||
const OnGroupCreated: group_event_on_create = (event: number, group: Group, leader: Player): void => {
|
||||
if (group.IsBGGroup()) {
|
||||
// Perform actions specific to battleground groups
|
||||
leader.SendBroadcastMessage("You have created a battleground group!");
|
||||
|
||||
// Set the battleground group's objective
|
||||
const objective = "Capture the enemy flag";
|
||||
group.SendGroupMessage(`Your objective is to ${objective}`);
|
||||
|
||||
// Assign roles to group members
|
||||
const members = group.GetMembers();
|
||||
members.forEach((member: Player, index: number) => {
|
||||
if (index === 0) {
|
||||
member.SendBroadcastMessage("You have been assigned the role of flag carrier.");
|
||||
} else if (index === 1) {
|
||||
member.SendBroadcastMessage("You have been assigned the role of defender.");
|
||||
} else {
|
||||
member.SendBroadcastMessage("You have been assigned the role of attacker.");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Perform actions for regular groups
|
||||
leader.SendBroadcastMessage("You have created a regular group!");
|
||||
|
||||
// Set the group's goal
|
||||
const goal = "Complete the dungeon";
|
||||
group.SendGroupMessage(`Your goal is to ${goal}`);
|
||||
|
||||
// Assign roles to group members
|
||||
const members = group.GetMembers();
|
||||
members.forEach((member: Player, index: number) => {
|
||||
if (index === 0) {
|
||||
member.SendBroadcastMessage("You have been assigned the role of tank.");
|
||||
} else if (index === 1) {
|
||||
member.SendBroadcastMessage("You have been assigned the role of healer.");
|
||||
} else {
|
||||
member.SendBroadcastMessage("You have been assigned the role of damage dealer.");
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
RegisterGroupEvent(GroupEvents.GROUP_EVENT_ON_CREATE, (...args) => OnGroupCreated(...args));
|
||||
```
|
||||
|
||||
In this example, when a group is created, the script checks if it is a battleground group using the `IsBGGroup()` method. If it is a battleground group, it performs specific actions such as sending a broadcast message to the leader, setting the group's objective, and assigning roles to group members.
|
||||
|
||||
If the group is not a battleground group, it performs different actions suitable for regular groups, such as sending a different broadcast message to the leader, setting the group's goal, and assigning roles to group members.
|
||||
|
||||
This example showcases how the `IsBGGroup()` method can be used to differentiate between battleground groups and regular groups, allowing you to implement different behaviors and functionalities based on the group type.
|
||||
|
||||
Reference in New Issue
Block a user