Hello,
I want to add that when you left the game while you was in a clan, you will be joined in the clan when you come back.
What I have done already is:
I made it that it saves the clan id in the player file.
Something I can't get done is that the clan id = -1 when you leave a clan
only thing I have to do is to make it join the clan again.
I have this code but it doesn't work.
Code:
if (joinedClan >= 0) {
Client c = (Client)PlayerHandler.players[playerId];
Server.clanChat.addToClan(playerId, c.joinedClan);
}
Joined clan is the id of the clan that's saved in the character file.
addToClan
Code:
public void addToClan(int playerId, int clanId) {
if (clans[clanId] != null) {
for (int j = 0; j < clans[clanId].members.length; j++) {
if (clans[clanId].members[j] <= 0) {
Client c = (Client)PlayerHandler.players[playerId];
c.joinedClan = clanId;
clans[clanId].members[j] = playerId;
PlayerHandler.players[playerId].clanId = clanId;
//c.sendMessage("You have joined the clan chat: " + clans[clanId].name);
messageToClan(PlayerHandler.players[playerId].playerName + " has joined the channel.", clanId);
updateClanChat(clanId);
return;
}
}
}
}
Leaveclan
Code:
public void leaveClan(int playerId, int clanId) {
if (clanId < 0) {
Client c = (Client)PlayerHandler.players[playerId];
c.sendMessage("You aren't in a Clan Chat channel");
return;
}
if (clans[clanId] != null) {
if (PlayerHandler.players[playerId] != null) {
Client c = (Client)PlayerHandler.players[playerId];
PlayerHandler.players[playerId].clanId = -1;
c.sendMessage("You have left the channel.");
c.getPA().clearClanChat();
for (int j = 0; j < clans[clanId].members.length; j++) {
if (clans[clanId].members[j] == playerId) {
messageToClan(PlayerHandler.players[playerId].playerName + " has left the channel.", clanId);
clans[clanId].members[j] = -1;
}
}
for (int j = 0; j < clans[clanId].members.length; j++)
if(clans[clanId].members[j] == playerId)
clans[clanId].members[j] = -1;
}
updateClanChat(clanId);
} else {
Client c = (Client)PlayerHandler.players[playerId];
c.sendMessage("You aren't in a Clan Chat channel");
}
}