Print Page | Close Window

Guild system.

Printed From: Mirage Source
Category: Tutorials
Forum Name: Temporary Archive (Read Only)
Forum Discription: Temporary 3.0.3 archive tutorials, will be deleted when converted.
URL: http://ms.shannaracorp.com/backup-forums/forum_posts.asp?TID=222
Printed Date: 20 December 2006 at 5:53pm
Software Version: Web Wiz Forums 8.01 - http://www.webwizforums.com


Topic: Guild system.
Posted By: Sync
Subject: Guild system.
Date Posted: 11 February 2006 at 3:38pm
Ok I'm posting a tutorial for how to make a Guild System.

First, Server side,

modDatabase
Find:

FileName = App.Path & "\accounts\" & Trim(Player(Index).Login) & ".ini"


Scroll down untill you see:
Call PutVar(FileName, "CHAR" & I, "PK", STR(Player(Index).Char(I).PK))


And below that place:
Call PutVar(FileName, "CHAR" & I, "Guild", Trim(Player(Index).Char(I).Guild))


Then find:

Player(Index).Char(I).PK = Val(GetVar(FileName, "CHAR" & I, "PK"))


Below add:

Player(Index).Char(I).Guild = GetVar(FileName, "CHAR" & I, "Guild")


Then in modHandleData
Place:
' :::::::::::::::::::::::::
    ' :: Create Guild packet ::
    ' :::::::::::::::::::::::::
    If LCase(Parse(0)) = "createguild" Then
    Dim Z As String
    
      ' Prevent hacking
        If GetPlayerAccess(Index) < ADMIN_CREATOR Then
             Call HackingAttempt(Index, "Trying to use powers not available")
             Exit Sub
        End If
       
        ' The Player
        N = FindPlayer(Parse(1))
        ' The Guild
        Z = Trim(Parse(2))
       
        Call CreateGuild(N, Z)
        Call SetPlayerGuildAccess(N, 4)
        Call SendPlayerData(N)
        Call GlobalMsg(GetPlayerName(N) & " has joined the ranks of " & Z & ".", Black)
        Call AddLog(GetPlayerName(N) & " has joined the ranks of " & Z & ".", ADMIN_LOG)
        Exit Sub
    End If
   
    ' :::::::::::::::::::::::::
    ' :: Create Guild packet ::
    ' :::::::::::::::::::::::::
    If LCase(Parse(0)) = "guildpromote" Then
       
        ' The Player
        N = FindPlayer(Parse(1))
        ' The Guild
        Z = Trim(Parse(2))
        If GetPlayerGuild(N) = GetPlayerGuild(Index) Then
       
        Select Case GetPlayerGuildAccess(N)
        Case Is = 6
             Call PlayerMsg(Index, "You cannot promote a guild member beyond level 6!", Black)
       
        Case Is = 1
        If GetPlayerLevel(N) < 30 Then
             Call PlayerMsg(Index, "That player is not yet level 30, and cannot be promoted!", Black)
        Else
             Call SetPlayerGuildAccess(N, GetPlayerGuildAccess(N) + 1)
             Call SendPlayerData(N)
             Call GlobalMsg(GetPlayerName(N) & " has been promoted in " & GetPlayerGuild(N) & ".", Black)
             Call AddLog(GetPlayerName(N) & " has been promoted in " & GetPlayerGuild(N) & ".", ADMIN_LOG)
        End If
       
        Case Is = 2
        If GetPlayerLevel(N) < 40 Then
             Call PlayerMsg(Index, "That player is not yet level 40, and cannot be promoted!", Black)
        Else
             Call SetPlayerGuildAccess(N, GetPlayerGuildAccess(N) + 1)
             Call SendPlayerData(N)
             Call GlobalMsg(GetPlayerName(N) & " has been promoted in " & GetPlayerGuild(N) & ".", Black)
             Call AddLog(GetPlayerName(N) & " has been promoted in " & GetPlayerGuild(N) & ".", ADMIN_LOG)
        End If
       
        Case Is = 3
        If GetPlayerLevel(N) < 50 Then
             Call PlayerMsg(Index, "That player is not yet level 50, and cannot be promoted!", Black)
        Else
             Call SetPlayerGuildAccess(N, GetPlayerGuildAccess(N) + 1)
             Call SendPlayerData(N)
             Call GlobalMsg(GetPlayerName(N) & " has been promoted in " & GetPlayerGuild(N) & ".", Black)
             Call AddLog(GetPlayerName(N) & " has been promoted in " & GetPlayerGuild(N) & ".", ADMIN_LOG)
        End If
       
        Case Is = 4
        If Not GetPlayerName(Index) = "CyberBoy" Then
        If GetPlayerLevel(N) < 60 Then
             Call PlayerMsg(Index, "That player is not yet level 60, and cannot be promoted!", Black)
        Else
             Call SetPlayerGuildAccess(N, GetPlayerGuildAccess(N) + 1)
             Call SendPlayerData(N)
             Call GlobalMsg(GetPlayerName(N) & " has been promoted in " & GetPlayerGuild(N) & ".", Black)
             Call AddLog(GetPlayerName(N) & " has been promoted in " & GetPlayerGuild(N) & ".", ADMIN_LOG)
        End If
        Else
             Call SetPlayerGuildAccess(N, GetPlayerGuildAccess(N) + 1)
             Call SendPlayerData(N)
             Call GlobalMsg(GetPlayerName(N) & " has been promoted in " & GetPlayerGuild(N) & ".", Black)
             Call AddLog(GetPlayerName(N) & " has been promoted in " & GetPlayerGuild(N) & ".", ADMIN_LOG)
        End If
       
        End Select
        End If
        Exit Sub
    End If
   
    ' :::::::::::::::::::::::::
    ' :: Create Guild packet ::
    ' :::::::::::::::::::::::::
    If LCase(Parse(0)) = "guilddemote" Then
       
        ' The Player
        N = FindPlayer(Parse(1))
        ' The Guild
        Z = Trim(Parse(2))
       
        If GetPlayerGuild(Index) = GetPlayerGuild(N) Then
        If GetPlayerGuildAccess(N) > 0 Then
             Call SetPlayerGuildAccess(N, GetPlayerGuildAccess(N) - 1)
             Call SendPlayerData(N)
        Else
             Call PlayerMsg(Index, "That Player is not in your guild anymore", Black)
        End If
        If GetPlayerGuildAccess(N) = 0 Then
             Call GlobalMsg(GetPlayerName(N) & " has been kicked out of " & GetPlayerGuild(N) & ".", Black)
             Call AddLog(GetPlayerName(N) & " has been kicked out of " & GetPlayerGuild(N) & ".", ADMIN_LOG)
             Call CreateGuild(N, "")
        Else
             Call GlobalMsg(GetPlayerName(N) & " has been demoted in " & GetPlayerGuild(N) & ".", Black)
             Call AddLog(GetPlayerName(N) & " has been demoted in " & GetPlayerGuild(N) & ".", ADMIN_LOG)
        End If
        End If
        Exit Sub
     End If
   
    ' :::::::::::::::::::
    ' :: Guild Request ::
    ' :::::::::::::::::::
    If LCase(Parse(0)) = "guildrequest" 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).InGuild = YES Then
             Call PlayerMsg(Index, "You are already in a guild!", Black)
             Exit Sub
        End If
       
        If N > 0 Then
             ' Check to see if player is already in a party
             If Player(N).InGuild = NO Then
             If GetPlayerLevel(N) >= 15 Then
                 Call PlayerMsg(Index, "Guild request has been sent to " & GetPlayerName(N) & ".", Black)
                 Call PlayerMsg(N, GetPlayerName(Index) & " wants you to join their guild.  Type /accept to join, or /cancel to decline.", Black)
            
                 Player(Index).GuildStarter = YES
                 Player(Index).GuildPlayer = N
                 Player(N).GuildPlayer = Index
             Else
                 Call PlayerMsg(Index, "Player is not level 15!", Black)
             End If
             Else
                 Call PlayerMsg(Index, "Player is already in a guild!", Black)
             End If
        Else
             Call PlayerMsg(Index, "Player is not online.", Black)
        End If
        Exit Sub
    End If

    ' :::::::::::::::::::::::::
    ' :: Cancel guild packet ::
    ' :::::::::::::::::::::::::
    If LCase(Parse(0)) = "cancelguild" Then
        N = Player(Index).GuildPlayer
       
        If N > 0 Then
             If Player(Index).InGuild = NO Then
                 Call PlayerMsg(Index, "Declined guild request.", Black)
                 Call PlayerMsg(N, GetPlayerName(Index) & " declined your request.", Black)
                 Player(N).InGuild = NO
             End If
        Else
             Call PlayerMsg(Index, "You are not in a guild!", Black)
        End If
        Exit Sub
    End If
   
    ' :::::::::::::::::::::::
    ' :: Join guild packet ::
    ' :::::::::::::::::::::::
    If LCase(Parse(0)) = "joinguild" Then
       N = Player(Index).GuildPlayer
       
        If N > 0 Then
             ' Check to make sure they aren't the starter
             If Player(Index).GuildStarter = NO Then
                 ' Check to make sure that each of there party players match
                 If Player(N).GuildPlayer = Index Then
                     Call GlobalMsg(GetPlayerName(Index) & " has joined the ranks of " & GetPlayerGuild(N) & ".", Black)
                    
                     Call CreateGuild(Index, GetPlayerGuild(N))
                     Call SetPlayerGuildAccess(Index, 1)
                     Call SendPlayerData(Index)
                     Player(Index).InGuild = YES
                 Else
                     Call PlayerMsg(Index, "Guild failed.", Black)
                 End If
             Else
                 Call PlayerMsg(Index, "You have not been invited to join a guild!", Black)
             End If
        Else
             Call PlayerMsg(Index, "You have not been invited into a guild!", Black)
        End If
        Exit Sub
    End If
            
    ' ::::::::::::::::::::::::
    ' :: Leave Guild packet ::
    ' ::::::::::::::::::::::::
    If LCase(Parse(0)) = "leaveguild" Then
       
        ' The Player
        N = FindPlayer(Parse(1))
       
        Call GlobalMsg(GetPlayerName(Index) & " has resigned from the ranks of " & GetPlayerGuild(Index) & ".", Black)
        Call AddLog(GetPlayerName(Index) & " has resigned the ranks of " & GetPlayerGuild(Index) & ".", ADMIN_LOG)
        Call CreateGuild(Index, "")
        Call SetPlayerGuildAccess(Index, 0)
        Call SendPlayerData(Index)
        Player(Index).InGuild = NO
        Exit Sub
    End If
   
    ' ::::::::::::::::::::::::
    ' :: Leave Guild packet ::
    ' ::::::::::::::::::::::::
    If LCase(Parse(0)) = "kickguild" Then
       
        ' The Player
        N = FindPlayer(Parse(1))
       
        If GetPlayerGuild(Index) = GetPlayerGuild(N) Then
        Call GlobalMsg(GetPlayerName(N) & " has been kicked out of " & GetPlayerGuild(N) & ".", Black)
        Call AddLog(GetPlayerName(N) & " has been kicked out of " & GetPlayerGuild(N) & ".", ADMIN_LOG)
        Call CreateGuild(N, "")
        Call SetPlayerGuildAccess(N, 0)
        Call SendPlayerData(N)
        Player(N).InGuild = NO
        Else
        Call PlayerMsg(Index, GetPlayerName(N) & " is not in " & GetPlayerGuild(Index), Black)
        End If
        Exit Sub
    End If



Find:

' Send all players on current map to index


Replace all with:

' Send all players on current map to index
    For I = 1 To MAX_PLAYERS
        If IsPlaying(I) And I <> Index And GetPlayerMap(I) = GetPlayerMap(Index) Then
             Packet = Packet & "PLAYERDATA" & SEP_CHAR & I & SEP_CHAR & GetPlayerName(I) & SEP_CHAR & GetPlayerSprite(I) & SEP_CHAR & GetPlayerMap(I) & SEP_CHAR & GetPlayerX(I) & SEP_CHAR & GetPlayerY(I) & SEP_CHAR & GetPlayerDir(I) & SEP_CHAR & GetPlayerAccess(I) & SEP_CHAR & GetPlayerPK(I) & SEP_CHAR & GetPlayerGuild(I) & SEP_CHAR & GetPlayerGuildAccess(I) & SEP_CHAR & END_CHAR
             Call SendDataTo(Index, Packet)
        End If
    Next I



Then go to modServerTCP
find:

' Send index's player data to everyone on the map including himself


Replace all with:

    ' Send index's player data to everyone on the map including himself
    Packet = "PLAYERDATA" & SEP_CHAR & Index & SEP_CHAR & GetPlayerName(Index) & SEP_CHAR & GetPlayerSprite(Index) & SEP_CHAR & GetPlayerMap(Index) & SEP_CHAR & GetPlayerX(Index) & SEP_CHAR & GetPlayerY(Index) & SEP_CHAR & GetPlayerDir(Index) & SEP_CHAR & GetPlayerAccess(Index) & SEP_CHAR & GetPlayerPK(Index) & SEP_CHAR & GetPlayerGuild(Index) & SEP_CHAR & GetPlayerGuildAccess(Index) & SEP_CHAR & END_CHAR
    Call SendDataToMap(GetPlayerMap(Index), Packet)
End Sub


Then find:

' Send index's player data to everyone on the map including himself


Replace all with:

    ' Send index's player data to everyone on the map including himself
    Packet = "PLAYERDATA" & SEP_CHAR & Index & SEP_CHAR & GetPlayerName(Index) & SEP_CHAR & GetPlayerSprite(Index) & SEP_CHAR & GetPlayerMap(Index) & SEP_CHAR & GetPlayerX(Index) & SEP_CHAR & GetPlayerY(Index) & SEP_CHAR & GetPlayerDir(Index) & SEP_CHAR & GetPlayerAccess(Index) & SEP_CHAR & GetPlayerPK(Index) & SEP_CHAR & GetPlayerGuild(Index) & SEP_CHAR & GetPlayerGuildAccess(Index) & SEP_CHAR & END_CHAR
    Call SendDataToMap(GetPlayerMap(Index), Packet)
End Sub


In modTypes
Find:

' Guild Constants


Replace all with:

' Guild constants
Public Const GUILD_TRAINEE = 1
Public Const GUILD_MEMBER = 2
Public Const GUILD_ELITEMEMBER = 3
Public Const GUILD_GUARDIAN = 4
Public Const GUILD_LEADER = 5


This was all for Server Side,
Now the Client side.


open modClientTCP

Place this sub somewhere.

Sub CreateGuild(ByVal Name As String, ByVal Guild As String)
Dim Packet As String
   
    Packet = "CREATEGUILD" & SEP_CHAR & Name & SEP_CHAR & Guild & SEP_CHAR & END_CHAR
    Call SendData(Packet)
End Sub


Then go to modGameLogic
Find:

' Lock the backbuffer so we can draw text and names


In there find:

Call BltPlayerName(I)


Place below:

If GetPlayerGuildAccess(I) >= 1 Then
                 Call BltGuildName(I)
             End If


Then place this sub somewhere:

Sub BltGuildName(ByVal Index As Long)
Dim TextX As Long
Dim TextY As Long
Dim TextZ As Long
Dim Color As Long
   
    ' Check access level
        Select Case GetPlayerGuildAccess(Index)
             Case 0
                 Color = QBColor(Brown)
             Case 1
                 Color = QBColor(White)
             Case 2
                 Color = QBColor(BrightGreen)
             Case 3
                 Color = QBColor(BrightBlue)
             Case 4
                 Color = QBColor(Yellow)
             Case 5
                 Color = QBColor(Red)
        End Select
   
       
    ' Draw name
    TextX = GetPlayerX(Index) * PIC_X + Player(Index).XOffset + Int(PIC_X / 2) - ((Len(GetPlayerName(Index)) / 2) * 8)
    TextY = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - Int(PIC_Y / 2) - 4
    TextZ = GetPlayerX(Index) * PIC_X + Player(Index).XOffset + Int(PIC_X / 2) - ((Len(GetPlayerGuild(Index)) / 2) * 8)
    Call DrawText(TexthDC, TextZ, TextY - 12, GetPlayerGuild(Index), Color)
End Sub


Then under the
' Leave party
thingy place:

        ' Join guild
        If LCase(Mid(MyText, 1, 7)) = "/accept" Then
             Call JoinGuild
             MyText = ""
             Exit Sub
        End If
       
        ' Cancel guild
        If LCase(Mid(MyText, 1, 7)) = "/cancel" Then
             Call CancelGuild
             MyText = ""
             Exit Sub
        End If
       
        ' // Trainee Guild Commands //
        If GetPlayerGuildAccess(MyIndex) > 0 Then
        ' Quit Guild
             If LCase(Mid(MyText, 1, 7)) = "/resign" Then
                 Call LeaveGuild
                 MyText = ""
                 Exit Sub
             End If
          End If
         
        ' // Creator Guild Commands //
        If GetPlayerGuildAccess(MyIndex) >= 3 Then
        ' Guild request
        If LCase(Mid(MyText, 1, 6)) = "/guild" Then
             frmGuildCP.Visible = True
             MyText = ""
             Exit Sub
        End If
       
        ' Kicking a player from guild
             If LCase(Mid(MyText, 1, 9)) = "/disgrace" Then
                 If Len(MyText) > 9 Then
                     MyText = Mid(MyText, 10, Len(MyText) - 9)
                     Call GuildRemoval(MyText)
                 End If
                 MyText = ""
                 Exit Sub
             End If
       
        ' Promoting a player
             If LCase(Mid(MyText, 1, 8)) = "/promote" Then
                 If Len(MyText) > 8 Then
                     MyText = Mid(MyText, 9, Len(MyText) - 8)
                     Call GuildPromotion(MyText)
                 End If
                 MyText = ""
                 Exit Sub
             End If
       
        ' Demoting a player
             If LCase(Mid(MyText, 1, 7)) = "/demote" Then
                 If Len(MyText) > 8 Then
                     MyText = Mid(MyText, 9, Len(MyText) - 8)
                     Call GuildDemotion(MyText)
                 End If
                 MyText = ""
                 Exit Sub
             End If
        End If


Then go to modTypes
Find:

' Guild Constants


Replace all with:

' Guild constants
Public Const GUILD_TRAINEE = 1
Public Const GUILD_MEMBER = 2
Public Const GUILD_ELITEMEMBER = 3
Public Const GUILD_GUARDIAN = 4
Public Const GUILD_LEADER = 5


Then find:

PK As Byte


Below add:

Guild As String * NAME_LENGTH


Then find:

Player(Index).PK = NO


Below add:

Player(Index).Guild = ""




Print Page | Close Window

Bulletin Board Software by Web Wiz Forums version 8.01 - http://www.webwizforums.com
Copyright ©2001-2006 Web Wiz Guide - http://www.webwizguide.info