23-09-2006, 05:05 PM
Quote:Code:Sub SendIndexWornEquipmentFromMap(ByVal Index As Long)
Dim Packet As String
Dim i As Long
Dim Armor As Long
Dim Helmet As Long
Dim Shield As Long
Dim Weapon As Long
For i = 1 To MAX_PLAYERS
If IsPlaying(i) = True Then
If GetPlayerMap(Index) = GetPlayerMap(i) Then
Armor = 0
Helmet = 0
Shield = 0
Weapon = 0
End If
If GetPlayerArmorSlot(i) > 0 Then
Armor = GetPlayerInvItemNum(i, GetPlayerArmorSlot(i))
End If
If GetPlayerHelmetSlot(i) > 0 Then
Helmet = GetPlayerInvItemNum(i, GetPlayerHelmetSlot(i))
End If
If GetPlayerShieldSlot(i) > 0 Then
Shield = GetPlayerInvItemNum(i, GetPlayerShieldSlot(i))
End If
If GetPlayerWeaponSlot(i) > 0 Then
Weapon = GetPlayerInvItemNum(i, GetPlayerWeaponSlot(i))
End If
Packet = "itemworn" & SEP_CHAR & i & SEP_CHAR & Armor & SEP_CHAR & Weapon & SEP_CHAR & Helmet & SEP_CHAR & Shield & SEP_CHAR & END_CHAR
Call SendDataTo(Index, Packet)
End If
Next i
End Sub
That's much better, but there are two things to do and then it would be perfect (in my sense of style at least).
1. Indent that whole For loop one time. It's much easier to tell where a sub or function starts and ends if the start and end are the only lines that are on the far left side. The next doesn't effect that too much in this example, but any other code not in one of those statements would ruin the effect more.
2. "If IsPlaying(i) Then" looks so much nicer than adding a "= true" and they do the same thing. It's always best to make it logical, so that you can read it out like a sentence. "If this guy is playing then" makes more sense than "If this guy is playing and that is true, then". It's better for variables like "InEditor", because it makes so much more sense. "Do While NotDone" is my favorite...
