Mirage Source
Updated Party/Group - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49)
+---- Thread: Updated Party/Group (/showthread.php?tid=2024)

Pages: 1 2


Re: Updated Party/Group - Rian - 21-08-2008

I think I'll have a go at it. Maybe if I can get something basic enough client side we can get another one of those community based tutorials going with it.


Re: Updated Party/Group - Rian - 21-08-2008

Yeah, I'm gonna take a graphical approach for displaying hp and mp. Though I'll be doing it on a picBox rather than blting it to the game screen.

I started working on it a little bit last night. My first attempt only read the Leader's Name, level, and class. It was like 3:00 a.m. though, so I didn't fiddle with it for too long.


Re: Updated Party/Group - Rian - 21-08-2008

Okay, so I've been playing with this a little more today. Right now, I'm just trying to get everything displaying on plain old labels. Here is what I've done so far code-wise:

Sub HandleData - Client Side
Code:
' :::::::::::::::::
    ' :: Party Stats ::
    ' :::::::::::::::::
    If (LCase(Parse(0)) = "partystats") Then
        X = Val(Parse(1)) ' Total Group Members
        frmMirage.lblLeaderName.Caption = Trim$(Parse(2)) & " " & Val(Parse(4)) ' Leader Name & Level
        frmMirage.lblLeaderClass.Caption = Trim$(Parse(3)) ' Leader Class
        frmMirage.lblLeaderHP = Val(Parse(6)) & "/" & Val(Parse(5)) ' Leader HP
        frmMirage.lblLeaderMP.Caption = Val(Parse(8)) & "/" & Val(Parse(7)) ' Leader MP
        
        n = 9 ' Next Parse In Line
        For i = 1 To X ' MAX_GROUP_NUMBER
            frmMirage.lblGroupName(i - 1).Caption = Trim$(Parse(n)) & " " & Val(Parse(n + 2)) ' Member i Name & Level
            frmMirage.lblGroupClass(i - 1).Caption = Trim$(Parse(n + 1)) ' Member i Class
            frmMirage.lblGroupHP(i - 1).Caption = Val(Parse(n + 4)) & "/" & Val(Parse(n + 3)) ' Member i HP
            frmMirage.lblGroupMP(i - 1).Caption = Val(Parse(n + 6)) & "/" & Val(Parse(n + 5)) ' Member i MP
            n = n + 1
        Next i
    End If
    Exit Sub

modGeneral - Server Side
Code:
Sub SendPartyStats(ByVal GroupID As Long)
Dim Packet As String, party As Long, I As Long, GroupNum As Long

party = FindPlayer(Group(GroupID).GroupLeader)
' Subtracted 1 becuase the GroupLeader is handled seperately
GroupNum = (Group(Player(party).GroupID).GroupNum - 1)

Packet = GetPlayerName(party) & SEP_CHAR & Class(GetPlayerClass(party)).Name & SEP_CHAR & GetPlayerLevel(party) & SEP_CHAR & GetPlayerMaxHP(party) & SEP_CHAR & GetPlayerHP(party) & SEP_CHAR & GetPlayerMaxMP(party) & SEP_CHAR & GetPlayerMP(party) & SEP_CHAR
For I = 1 To GroupNum
    party = FindPlayer(Group(GroupID).GroupMember(I))
    Packet = Packet & GetPlayerName(party) & SEP_CHAR & Class(GetPlayerClass(party)).Name & SEP_CHAR & GetPlayerLevel(party) & SEP_CHAR & GetPlayerMaxHP(party) & SEP_CHAR & GetPlayerHP(party) & SEP_CHAR & GetPlayerMaxMP(party) & SEP_CHAR & GetPlayerMP(party) & SEP_CHAR
Next
Packet = "PARTYSTATS" & SEP_CHAR & GroupNum & SEP_CHAR & Packet & SEP_CHAR & END_CHAR
Call SendDataToParty(GroupID, Packet)

End Sub

It works just fine when I have only 2 people in a party. This is what it looks like when I have 3 people in a party:
[Image: partyss.png]

As you can see, the third party member's stats are all out of order, and the name doesn't show up at all. I can't tell if the For statement client side is just spitting out random stuff, or if those numbers that do show up are actually representing the third party member.

By the way Asrrin, you're missing some SEP_CHARs in SubSendPartyStats. Look between GetPlayerHP & GetPlayerMaxHP. Missing it for the Leader and Group Members.

Does anyone see where this code is flawed? Because I don't :?


Re: Updated Party/Group - Labmonkey - 21-08-2008

try having 4 or 2 people in the party. Is it always messing up on the third, or on the last, or everything after 2?


Re: Updated Party/Group - Rian - 21-08-2008

Seems like it's everything after 2 party members.

[Image: ssparty2.jpg]

My FPS drops to 10 when I open 4 clients. Getting difficult to test :oops:


Re: Updated Party/Group - GIAKEN - 21-08-2008

I'm thinking you're sending the packets wrong or handling them wrong. As you notice after the second one it skips the name and goes to the next parse data like it's skipping a number in a loop.


Re: Updated Party/Group - Rian - 21-08-2008

I know. But I think it's worse than just skipping a parse. In the second pic, my level is where my class should be, and my name displays my class and hp.

I'm about to commence thinking again though. Just got back from a job interview.


Re: Updated Party/Group - Jacob - 21-08-2008

Add :
Code:
Debug.Print Data

Under
Code:
If (LCase(Parse(0)) = "partystats") Then

just so you can see what the actual packet data is.

And instead of
Code:
n = n + 1
Shouldn't it be
Code:
n = n + 7



Re: Updated Party/Group - Rian - 21-08-2008

I'm adding different values to n to retrieve the right parse, then all I have to do is add 1 after it loops through the For statement.

GroupNum always equals 1 though. One step closing to solving this I thinks


Re: Updated Party/Group - Jacob - 21-08-2008

Sonire Wrote:I'm adding different values to n to retrieve the right parse, then all I have to do is add 1 after it loops through the For statement.

GroupNum always equals 1 though. One step closing to solving this I thinks

You're not actually setting the n to those different values though.

You have 7 parses in a loop so n needs to be n = n + 7.


Re: Updated Party/Group - Rian - 21-08-2008

When I change the N + # I get pretty much the exact same results. Jumbled data, and the leader, and first party member working fine.

Asrrin, bars will be easy just as soon as I get the right data sent. Big Grin


Re: Updated Party/Group - Matt - 22-08-2008

Just use shapes. As you can set the images to them and when you change the width, it doesn't stretch them and what not to the width, if it's shorter than the image loaded, it cuts it off.

That's what we all do. >.>


Re: Updated Party/Group - Jacob - 22-08-2008

I figured out the problem:

In :
Code:
' ::::::::::::::::::
    ' :: Party packet ::
    ' ::::::::::::::::::
    If LCase(Parse(0)) = "party" Then
        n = FindPlayer(Parse(1))
      
        ' Prevent partying with self
        If n = index Then
            Exit Sub
        End If
              
       ' Check for a previous party and if so drop it
        If Player(index).InParty = YES Then
            If Player(index).PartyStarter = YES Then
                Call PlayerMsg(index, "Party request has been sent to " & GetPlayerName(n) & ".", Pink)
                Call PlayerMsg(n, GetPlayerName(index) & " wants you to join their party.  Type /join to join, or /leave to decline.", Pink)
                Player(n).PartyPlayer = Player(index).CHAR(Player(index).CharNum).Name
            Else
                Call PlayerMsg(index, "You are already in a party!", Pink)
                Exit Sub
            End If
        End If
      
        If n > 0 Then
            ' Check if its an admin
            If GetPlayerAccess(index) > ADMIN_MONITER Then
                Call PlayerMsg(index, "You can't join a party, you are an admin!", BrightBlue)
                Exit Sub
            End If
      
            If GetPlayerAccess(n) > ADMIN_MONITER Then
                Call PlayerMsg(index, "Admins cannot join parties!", BrightBlue)
                Exit Sub
            End If
          
            ' Make sure they are in right level range
            'If GetPlayerLevel(index) + 5 < GetPlayerLevel(n) Or GetPlayerLevel(index) - 5 > GetPlayerLevel(n) Then
            '    Call PlayerMsg(index, "There is more then a 5 level gap between you two, party failed.", Pink)
            '    Exit Sub
            'End If
          
            ' Check to see if player is already in a party
            If Player(n).InParty = NO Then
                Call PlayerMsg(index, "Party request has been sent to " & GetPlayerName(n) & ".", Pink)
                Call PlayerMsg(n, GetPlayerName(index) & " wants you to join their party.  Type /join to join, or /leave to decline.", Pink)
              
                Player(index).PartyStarter = YES
                Player(index).InParty = YES
                Player(index).GroupID = CreateGroup(index)
                Player(n).PartyPlayer = index
            Else
                Call PlayerMsg(index, "Player is already in a party!", Pink)
            End If
        Else
            Call PlayerMsg(index, "Player is not online.", White)
        End If
        Exit Sub
    End If

Change:
Code:
' Check for a previous party and if so drop it
        If Player(index).InParty = YES Then
            If Player(index).PartyStarter = YES Then
                Call PlayerMsg(index, "Party request has been sent to " & GetPlayerName(n) & ".", Pink)
                Call PlayerMsg(n, GetPlayerName(index) & " wants you to join their party.  Type /join to join, or /leave to decline.", Pink)
                Player(n).PartyPlayer = Player(index).CHAR(Player(index).CharNum).Name
            Else
                Call PlayerMsg(index, "You are already in a party!", Pink)
                Exit Sub
            End If
        End If

to:
Code:
' Check for a previous party and if so drop it
        If Player(index).InParty = YES Then
            If Player(index).PartyStarter = YES Then
                Call PlayerMsg(index, "Party request has been sent to " & GetPlayerName(n) & ".", Pink)
                Call PlayerMsg(n, GetPlayerName(index) & " wants you to join their party.  Type /join to join, or /leave to decline.", Pink)
                Player(n).PartyPlayer = Player(index).Char(Player(index).CharNum).Name
                Player(n).PartyPlayer = index
                Exit Sub
            Else
                Call PlayerMsg(index, "You are already in a party!", Pink)
                Exit Sub
            End If
        End If

The problem was on the server, it kept calling CreateGroup and makeing the groupcount = 0.

You will still need to change N= N + 1 to N= N+7.


Re: Updated Party/Group - Rian - 22-08-2008

[Image: partss3.png]

Getting much closer. It displays the one of the party players twice though. Does the same thing if I have 3 people.

I don't really understand how this makes a difference really though:
Code:
Player(n).PartyPlayer = Player(index).Char(Player(index).CharNum).Name
                Player(n).PartyPlayer = index

Why do we need both of those lines?


Re: Updated Party/Group - Jacob - 22-08-2008

Sonire Wrote:
Code:
Player(n).PartyPlayer = Player(index).Char(Player(index).CharNum).Name
                Player(n).PartyPlayer = index

Why do we need both of those lines?

Opps, you just need:
Code:
Player(n).PartyPlayer = index



Re: Updated Party/Group - NeoZeus - 27-08-2008

Hello,

I've made some minor changes to hopefully fix up the code a bit. First, since we are keeping the leader separate from the members of the group, change
Code:
Type GroupRec
    GroupID As Long
    GroupLeader As String
    GroupNum As Long
    GroupMember(0 To MAX_GROUP_NUMBER) As String
End Type

to
Code:
Type GroupRec
    GroupID As Long
    GroupLeader As String
    GroupNum As Long
    GroupMember(1 To MAX_GROUP_NUMBER) As String
End Type

Now in the Joingroup, leavegroup, Sendgroupstats and Senddatatoparty sub, change all the for loops from
Code:
For I = 0 To MAX_GROUP_NUMBER

To
Code:
For I = 1 To MAX_GROUP_NUMBER

Now in the Leavegroup sub, add an Exit for to the for loop. We only want to assign 1 new group leader when the group leader leave the group so we need to exit after we promote 1 member to leader.
Code:
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) = ""
            n = FindPlayer(Group(Player(index).GroupID).GroupLeader)
            Player(n).PartyStarter = YES
            Call PlayerMsg(n, "You are now the party leader.", Pink)
            Exit For
        End If
    Next
End If

In the Cleargroup sub, add the following line after you clear the group
Code:
CurrentGroupAmount = CurrentGroupAmount - 1
to denote we are 1 group less

Finally, in the CloseSocket Sub find
Code:
If Index > 0 Then

Below that line, add
Code:
If Player(index).InParty = YES Then
     Call LeaveGroup(index, Player(index).PartyPlayer)
End If

This call the leavegroup sub to take a player out of the party when they disconnect from the server.


I think that should be everything. For the client, what Sonire made works fine. My apologies for not mentioning which module the sub are in but I'm working off of 3.07 and I've modified the code a lot so my modules might be different than yours. Just do a search of the project for whatever you can't find. The party system seems to work fine (though it's still rather useless at this point until more features are added). I may have forgotten something typing all this up so if you can't get it working, post back and I'll double check my code.


Re: Updated Party/Group - Matt - 28-08-2008

Asrrin29 Wrote:it is good practice to start arrays at 0 regardless of what is going on outside of them. you can do it that way if you want, but I think I'll keep it started at 0 unless it is causing errors elsewhere in the code.

His changes just stops the group leader from being assigned a group ID, even though either way, it will always be 0 for the group leader. Lol.


Re: Updated Party/Group - NeoZeus - 28-08-2008

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.


Re: Updated Party/Group - DarkC - 14-09-2008

I've tried using this code...And so far I've only put in the Server side part of it, and it is giving me an error when I try compiling it. I'm using MS4 if that matters.

I'm getting the error that says "Method or data member not found", and it's highlighting
Code:
Player(index).PartyPlayer = index

The ".PartyPlayer =" part of the modTypes code above is what it's highlighting...What am I doing wrong?


Re: Updated Party/Group - Rian - 14-09-2008

Server side coding on this tutorial is not fully functional yet. It's also largely written for compatibility with Mirage Source versions 3.0.3 and 3.0.7.


Re: Updated Party/Group - DarkC - 14-09-2008

Oh, alright. Darn, I was hoping I could use this. =/ Oh well, I'll wait.


Re: Updated Party/Group - skillzalot - 20-09-2008

Will this be updated for MSE2 this will be really neat to have


Re: Updated Party/Group - Rian - 20-09-2008

I don't think it would be too difficult for anyone to integrate this into MSE2, as it's nearly identical to MSE1, MS303 and MS307


Re: Updated Party/Group - JadeCurt1ss - 26-09-2008

So, what works, and what doesn't? I'm trying to figure out the portions of the code I should be using, but its a pretty big confusing mess, and further to that, what parts work, and what doesn't?


Re: Updated Party/Group - Rian - 26-09-2008

Sonire Wrote:Server side coding on this tutorial is not fully functional yet. It's also largely written for compatibility with Mirage Source versions 3.0.3 and 3.0.7.