Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updated Party/Group
#18
Yeah, I just wanted to start at 1. 1 or 0 doesn't make a difference as long as you keep the structure throughout. Looking through the code, I see some bugs still. So here's the new Leavegroup sub:
Code:
Sub LeaveGroup(ByVal index As Long, ByVal N As Long)
Dim TempLeader As Long, i As Long, TempGroupID As Long
Dim j As Long
Dim k As Long


If Player(index).PartyStarter = YES Then
    For i = 1 To MAX_GROUP_NUMBER
        If Group(Player(index).GroupID).GroupMember(i)  "" Then
            Group(Player(index).GroupID).GroupLeader = Group(Player(index).GroupID).GroupMember(i)
            Group(Player(index).GroupID).GroupMember(i) = ""
            j = FindPlayer(Group(Player(index).GroupID).GroupLeader)
            Player(j).PartyStarter = YES
            Player(j).PartyPlayer = j
            Call PlayerMsg(j, "You are now the party leader.", Pink)
            Exit For
        End If
    Next
Else
    j = FindPlayer(Group(Player(index).GroupID).GroupLeader)
    For i = 1 To MAX_GROUP_NUMBER
        If Group(Player(index).GroupID).GroupMember(i) = GetPlayerName(index) Then
            Group(Player(index).GroupID).GroupMember(i) = ""
        End If
    Next
End If

For i = 1 To MAX_GROUP_NUMBER - 1
    If Group(Player(index).GroupID).GroupMember(i) = "" Then
        Group(Player(index).GroupID).GroupMember(i) = Group(Player(index).GroupID).GroupMember(i + 1)
        Group(Player(index).GroupID).GroupMember(i + 1) = ""
    End If
    If Group(Player(index).GroupID).GroupMember(i)  "" Then
        k = FindPlayer(Group(Player(index).GroupID).GroupMember(i))
        Player(k).PartyPlayer = j
    End If
Next

Group(Player(index).GroupID).GroupNum = Group(Player(index).GroupID).GroupNum - 1
TempGroupID = Group(Player(index).GroupID).GroupNum
Player(index).PartyPlayer = 0
Player(index).PartyStarter = NO
Player(index).InParty = NO
Player(index).GroupID = 0

Call PlayerMsg(index, "You have left the party.", Pink)
Call PlayerMsg(N, GetPlayerName(index) & " has left the party.", Pink)

If TempGroupID < 2 Then
    Player(N).PartyPlayer = 0
    Player(N).PartyStarter = NO
    Player(N).InParty = NO
    Call ClearGroup(Player(N).GroupID)
    Player(N).GroupID = 0
    Call PlayerMsg(N, "Your group has been disbanded.", Pink)
End If
End Sub

The original code left the members in their original spot in the members array when someone leave the group or DC from the server. That's also fine if you rewrite the code in the sendpartystats to use max_group_number instead of groupnum and just skip over any empty slot in the member array. However, since that sub is called very frequently, it is more efficient just to shift all members in the LeaveGroup Sub. The LeaveGroup sub now also reassign "PartyPlayer" for every group member. If you don't do this, members keep the ID of the leader if he/she DC and you'll error out later when you try to make calls based on that party ID.

On the client side, make sure you clear out your labels when you receive partystats from the server. If you don't, you'll be seeing what looks to be duplicates Smile.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)