Print Page | Close Window

Spell Range.

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=174
Printed Date: 20 December 2006 at 5:52pm
Software Version: Web Wiz Forums 8.01 - http://www.webwizforums.com


Topic: Spell Range.
Posted By: Sync
Subject: Spell Range.
Date Posted: 11 February 2006 at 3:16pm
This is my very first tut. I know this is very easy but yeah maybe someone will use it. This makes it so your spells will have range, it might have some bugs but I didn't notice any. This only works on npc's right now but could change that with no trouble.

Server side, modDatabase.
Find Sub SaveSpell
Under
 
Call PutVar(FileName, "SPELL" & SpellNum, "Type", Trim(Spell(SpellNum).Type))
add
Call PutVar(FileName, "spell" & SpellNum, "Range", Trim(Spell(SpellNum).Type))
Now goto sub  LoadSpells
under
Spell(i).Type = Val(GetVar(FileName, "SPELL" & i, "Type"))

add
Spell(i).Range = Val(GetVar(FileName, "spell" & i, "range"))
Now goto modGameLogic
Find sub CastSpell
replace all with
Sub CastSpell(ByVal Index As Long, ByVal SpellSlot As Long)
Dim SpellNum As Long, MPReq As Long, i As Long, n As Long, Damage As Long, Range As Long
Dim Casted As Boolean


    Casted = False



    ' Prevent subscript out of range
    If SpellSlot <= 0 Or SpellSlot > MAX_PLAYER_SPELLS Then
        Exit Sub
    End If
    
    SpellNum = GetPlayerSpell(Index, SpellSlot)
   
    ' Make sure player has the spell
    If Not HasSpell(Index, SpellNum) Then
        Call PlayerMsg(Index, "You do not have this spell!", BrightRed)
        Exit Sub
    End If
   
    i = GetSpellReqLevel(Index, SpellNum)
    MPReq = (i + Spell(SpellNum).Data1 + Spell(SpellNum).Data2 + Spell(SpellNum).Data3)
   
    ' Check if they have enough MP
    If GetPlayerMP(Index) < MPReq Then
        Call PlayerMsg(Index, "Not enough mana points!", BrightRed)
        Exit Sub
    End If
       
    ' Make sure they are the right level
    If i > GetPlayerLevel(Index) Then
        Call PlayerMsg(Index, "You must be level " & i & " to cast this spell.", BrightRed)
        Exit Sub
    End If
   
    ' Check if timer is ok
    If GetTickCount < Player(Index).AttackTimer + 1000 Then
        Exit Sub
    End If
   
    ' Check if the spell is a give item and do that instead of a stat modification
    If Spell(SpellNum).Type = SPELL_TYPE_GIVEITEM Then
        n = FindOpenInvSlot(Index, Spell(SpellNum).Data1)
       
        If n > 0 Then
             Call GiveItem(Index, Spell(SpellNum).Data1, Spell(SpellNum).Data2)
             Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " casts " & Trim(Spell(SpellNum).Name) & ".", BrightBlue)
            
             ' Take away the mana points
             Call SetPlayerMP(Index, GetPlayerMP(Index) - MPReq)
             Call SendMP(Index)
             Casted = True
        Else
             Call PlayerMsg(Index, "Your inventory is full!", BrightRed)
        End If
       
        Exit Sub
    End If

    n = Player(Index).Target
               'Make sure the player is close enough to the npc
    If GetPlayerName(n) <> GetPlayerName(Index) Then
    If CInt(Sqr((GetPlayerX(Index) - MapNpc(GetPlayerMap(Index), n).X) ^ 2 + ((GetPlayerY(Index) - MapNpc(GetPlayerMap(Index), n).Y) ^ 2))) > Spell(SpellNum).Range Then
    Call PlayerMsg(Index, "You are too far away to hit the target.", BrightRed)
             Exit Sub
    End If
    End If
   
    If Player(Index).TargetType = TARGET_TYPE_PLAYER Then
        If IsPlaying(n) Then
             If GetPlayerHP(n) > 0 And GetPlayerMap(Index) = GetPlayerMap(n) And GetPlayerLevel(Index) >= 10 And GetPlayerLevel(n) >= 10 And Map(GetPlayerMap(Index)).Moral = MAP_MORAL_NONE And GetPlayerAccess(Index) <= 0 And GetPlayerAccess(n) <= 0 Then
'                  If GetPlayerLevel(n) + 5 >= GetPlayerLevel(Index) Then
'                      If GetPlayerLevel(n) - 5 <= GetPlayerLevel(Index) Then
                           Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " casts " & Trim(Spell(SpellNum).Name) & " on " & GetPlayerName(n) & ".", BrightBlue)
                
                           Select Case Spell(SpellNum).Type
                               Case SPELL_TYPE_SUBHP
                          
                                   Damage = (Int(GetPlayerMAGI(Index) / 4) + Spell(SpellNum).Data1) - GetPlayerProtection(n)
                                   If Damage > 0 Then
                                         Call AttackPlayer(Index, n, Damage)
                                   Else
                                         Call PlayerMsg(Index, "The spell was to weak to hurt " & GetPlayerName(n) & "!", BrightRed)
                                   End If
                    
                               Case SPELL_TYPE_SUBMP
                                   Call SetPlayerMP(n, GetPlayerMP(n) - Spell(SpellNum).Data1)
                                   Call SendMP(n)
                
                               Case SPELL_TYPE_SUBSP
                                   Call SetPlayerSP(n, GetPlayerSP(n) - Spell(SpellNum).Data1)
                                   Call SendSP(n)
                           End Select
'                      Else
'                            Call PlayerMsg(Index, GetPlayerName(n) & " is far to powerful to even consider attacking.", BrightBlue)
'                      End If
'                  Else
'                      Call PlayerMsg(Index, GetPlayerName(n) & " is to weak to even bother with.", BrightBlue)
'                  End If
            
                 ' Take away the mana points
                 Call SetPlayerMP(Index, GetPlayerMP(Index) - MPReq)
                 Call SendMP(Index)
                 Casted = True
             Else
                 If GetPlayerMap(Index) = GetPlayerMap(n) And Spell(SpellNum).Type >= SPELL_TYPE_ADDHP And Spell(SpellNum).Type <= SPELL_TYPE_ADDSP Then
                     Select Case Spell(SpellNum).Type
                    
                           Case SPELL_TYPE_ADDHP
                               Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " casts " & Trim(Spell(SpellNum).Name) & " on " & GetPlayerName(n) & ".", BrightBlue)
                               Call SetPlayerHP(n, GetPlayerHP(n) + Spell(SpellNum).Data1)
                               Call SendHP(n)
                                        
                           Case SPELL_TYPE_ADDMP
                               Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " casts " & Trim(Spell(SpellNum).Name) & " on " & GetPlayerName(n) & ".", BrightBlue)
                               Call SetPlayerMP(n, GetPlayerMP(n) + Spell(SpellNum).Data1)
                               Call SendMP(n)
                    
                           Case SPELL_TYPE_ADDSP
                               Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " casts " & Trim(Spell(SpellNum).Name) & " on " & GetPlayerName(n) & ".", BrightBlue)
                               Call SetPlayerMP(n, GetPlayerSP(n) + Spell(SpellNum).Data1)
                               Call SendMP(n)
                     End Select
                    
                     ' Take away the mana points
                     Call SetPlayerMP(Index, GetPlayerMP(Index) - MPReq)
                     Call SendMP(Index)
                     Casted = True
                 Else
                     Call PlayerMsg(Index, "Could not cast spell!", BrightRed)
                 End If
             End If
        Else
             Call PlayerMsg(Index, "Could not cast spell!", BrightRed)
        End If
    Else
        If Npc(MapNpc(GetPlayerMap(Index), n).Num).Behavior <> NPC_BEHAVIOR_FRIENDLY And Npc(MapNpc(GetPlayerMap(Index), n).Num).Behavior <> NPC_BEHAVIOR_SHOPKEEPER Then
             Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " casts " & Trim(Spell(SpellNum).Name) & " on a " & Trim(Npc(MapNpc(GetPlayerMap(Index), n).Num).Name) & ".", BrightBlue)
            
             Select Case Spell(SpellNum).Type
                 Case SPELL_TYPE_ADDHP
                     MapNpc(GetPlayerMap(Index), n).HP = MapNpc(GetPlayerMap(Index), n).HP + Spell(SpellNum).Data1
                
                 Case SPELL_TYPE_SUBHP
                    
                     Damage = (Int(GetPlayerMAGI(Index) / 4) + Spell(SpellNum).Data1) - Int(Npc(MapNpc(GetPlayerMap(Index), n).Num).DEF / 2)
                     If Damage > 0 Then
                           Call AttackNpc(Index, n, Damage)
                     Else
                           Call PlayerMsg(Index, "The spell was to weak to hurt " & Trim(Npc(MapNpc(GetPlayerMap(Index), n).Num).Name) & "!", BrightRed)
                     End If
                    
                 Case SPELL_TYPE_ADDMP
                     MapNpc(GetPlayerMap(Index), n).MP = MapNpc(GetPlayerMap(Index), n).MP + Spell(SpellNum).Data1
                
                 Case SPELL_TYPE_SUBMP
                     MapNpc(GetPlayerMap(Index), n).MP = MapNpc(GetPlayerMap(Index), n).MP - Spell(SpellNum).Data1
            
                 Case SPELL_TYPE_ADDSP
                     MapNpc(GetPlayerMap(Index), n).SP = MapNpc(GetPlayerMap(Index), n).SP + Spell(SpellNum).Data1
                
                 Case SPELL_TYPE_SUBSP
                     MapNpc(GetPlayerMap(Index), n).SP = MapNpc(GetPlayerMap(Index), n).SP - Spell(SpellNum).Data1
             End Select
       
             ' Take away the mana points
             Call SetPlayerMP(Index, GetPlayerMP(Index) - MPReq)
             Call SendMP(Index)
             Casted = True
        Else
             Call PlayerMsg(Index, "Could not cast spell!", BrightRed)
        End If
    End If

    If Casted = True Then
        Player(Index).AttackTimer = GetTickCount
        Player(Index).CastedSpell = YES
    End If
End Sub

Now move on to modServerTCP
Find
' Update the spell
And under
Spell(n).LevelReq = Val(Parse(4))

add
Spell(n).Range = Val(Parse(5))

Now find sub SendEditSpellTo
and replace all with
Sub SendEditSpellTo(ByVal Index As Long, ByVal SpellNum As Long)
Dim packet As String

    packet = "EDITSPELL" & SEP_CHAR & SpellNum & SEP_CHAR & Trim(Spell(SpellNum).Name) & SEP_CHAR & Spell(SpellNum).ClassReq & SEP_CHAR & Spell(SpellNum).LevelReq & SEP_CHAR & Spell(SpellNum).Range & SEP_CHAR & Spell(SpellNum).Type & SEP_CHAR & Spell(SpellNum).Data1 & SEP_CHAR & Spell(SpellNum).Data2 & SEP_CHAR & Spell(SpellNum).Data3 & SEP_CHAR & END_CHAR
    Call SendDataTo(Index, packet)
End Sub

Now on to modTypes
replace
Type SpellRec
    Name As String * NAME_LENGTH
    ClassReq As Byte
    LevelReq As Byte
    Type As Byte
    Data1 As Integer
    Data2 As Integer
    Data3 As Integer
End Type

with
Type SpellRec
    Name As String * NAME_LENGTH
    ClassReq As Byte
    LevelReq As Byte
    Range As Byte
    Type As Byte
    Data1 As Integer
    Data2 As Integer
    Data3 As Integer
End Type

Now for the Client Side
First go to frmSpellEditor
Add a Label and set the caption to Range
Now add a scroll bar and set the name to scrlRange and the max to 25
Now add another label and set the name to lblRange and the caption to 1
Now in the frmSpellEditor code add this
Private Sub scrlRange_Change()
    lblRange.Caption = STR(scrlRange.Value)
End Sub

Now go to modClientTCP
Find ' :: Edit spell packet ::
Under
Spell(n).LevelReq = Val(Parse(4)

add
Spell(n).Range = Val(Parse(5))

Now replace Sub SendSaveSpell with
Sub SendSaveSpell(ByVal SpellNum As Long)
Dim Packet As String

    Packet = "SAVESPELL" & SEP_CHAR & SpellNum & SEP_CHAR & Trim(Spell(SpellNum).Name) & SEP_CHAR & Spell(SpellNum).ClassReq & SEP_CHAR & Spell(SpellNum).LevelReq & SEP_CHAR & Spell(SpellNum).Range & SEP_CHAR & Spell(SpellNum).Type & SEP_CHAR & Spell(SpellNum).Data1 & SEP_CHAR & Spell(SpellNum).Data2 & SEP_CHAR & Spell(SpellNum).Data3 & SEP_CHAR & END_CHAR
    Call SendData(Packet)
End Sub

Now got to modGameLogic
Find Public Sub SpellEditorInit() and replace it with
Public Sub SpellEditorInit()
On Error Resume Next

Dim i As Long

    frmSpellEditor.cmbClassReq.AddItem "All Classes"
    For i = 0 To Max_Classes
        frmSpellEditor.cmbClassReq.AddItem Trim(Class(i).Name)
    Next i
   
    frmSpellEditor.txtName.Text = Trim(Spell(EditorIndex).Name)
    frmSpellEditor.cmbClassReq.ListIndex = Spell(EditorIndex).ClassReq
    frmSpellEditor.scrlLevelReq.Value = Spell(EditorIndex).LevelReq
    frmSpellEditor.scrlRange.Value = Spell(EditorIndex).Range
       
    frmSpellEditor.cmbType.ListIndex = Spell(EditorIndex).Type
    If Spell(EditorIndex).Type <> SPELL_TYPE_GIVEITEM Then
        frmSpellEditor.fraVitals.Visible = True
        frmSpellEditor.fraGiveItem.Visible = False
        frmSpellEditor.scrlVitalMod.Value = Spell(EditorIndex).Data1
    Else
        frmSpellEditor.fraVitals.Visible = False
        frmSpellEditor.fraGiveItem.Visible = True
        frmSpellEditor.scrlItemNum.Value = Spell(EditorIndex).Data1
        frmSpellEditor.scrlItemValue.Value = Spell(EditorIndex).Data2
    End If
       
    frmSpellEditor.Show vbModal
End Sub
Now find Public Sub SpellEditorOk() and replace it with
Public Sub SpellEditorOk()
    Spell(EditorIndex).Name = frmSpellEditor.txtName.Text
    Spell(EditorIndex).ClassReq = frmSpellEditor.cmbClassReq.ListIndex
    Spell(EditorIndex).LevelReq = frmSpellEditor.scrlLevelReq.Value
    Spell(EditorIndex).Range = frmSpellEditor.scrlRange.Value
    Spell(EditorIndex).Type = frmSpellEditor.cmbType.ListIndex
    If Spell(EditorIndex).Type <> SPELL_TYPE_GIVEITEM Then
        Spell(EditorIndex).Data1 = frmSpellEditor.scrlVitalMod.Value
    Else
        Spell(EditorIndex).Data1 = frmSpellEditor.scrlItemNum.Value
        Spell(EditorIndex).Data2 = frmSpellEditor.scrlItemValue.Value
    End If
    Spell(EditorIndex).Data3 = 0
   
    Call SendSaveSpell(EditorIndex)
    InSpellEditor = False
    Unload frmSpellEditor
End Sub

Now go to modTypes and find
Type SpellRec

and under
LevelReq As Byte

add
Range As Byte

There you go, you now have spell range. Please tell me what you think.



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