Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[EO] NPC Spells v.2.0.0


DJMaxus
 Share

Recommended Posts

  • Replies 188
  • Created
  • Last Reply

Top Posters In This Topic

So I finished the the server side and got it to compile.
But after doing the client side and trying to compile it I got this.

>! ![](http://i30.photobucket.com/albums/c345/valiustrigger/Temppichelp.jpg)

I'm using Starlight custom version.
I think the ModificationS Nove 2.6 Pet's and Quests is messing with it. the pets part.
I added show NPC levels.
Took out drop items on death.
I think that's all.

I think this will be a long night for me…..
Any help guys?
Link to comment
Share on other sites

>! ![](http://i30.photobucket.com/albums/c345/valiustrigger/Temppichelp-1.jpg)
Should I put a large number in place of "MAX_NPC_SPELLS" ?

Edit!
Hey DJ Maxus, I haven't even said thanks for sharing and replying, to fix that last problem I added

As per-Ryoku Hasu in previous post (page five I think.)

>! In modConstants
Find:
Code: [Select]
>! Public Const MAX_PARTY_MEMBERS As Long = 4
>! Underneath it, add:
Code: [Select]
Code: [Select]
>! ' NPC Spells
Public Const MAX_NPC_SPELLS As Long = 5
Link to comment
Share on other sites

Ok!  Phew! Finally got it all to compile…. Bring up no error's... But now I can't get it to run correctly.
I get run time error 9\. Server side looks like.

>! ![](http://i30.photobucket.com/albums/c345/valiustrigger/new.jpg)

Also if I don't hit ok, and try to walk around none of the NPC move on their own, atttack, or anything; however, I can talk to them.
Link to comment
Share on other sites

Edit: just in case I should have said something, this error comes up after I try to run the client with the server. So when I open the server via run on VB6 on its own it is fine. Then when I try to run the client after that, it brings up that run time error 9\. The server will actually run fine on its own.
Just thought I'd make that clear. 

npcNum=0

i=1

Another Edit:
If I move the yellow arrow on the left down and highlight x, it says x=2 and mapnum=11.

Thanks for helping me with this much! Next time I have troubles I'll know to do all this stuff before asking questions.
Link to comment
Share on other sites

>! Private Sub UpdateMapLogic()
    Dim i As Long, x As Long, mapnum As Long, n As Long, x1 As Long, y1 As Long
    Dim TickCount As Long, Damage As Long, DistanceX As Long, DistanceY As Long, npcNum As Long
    Dim target As Long, targetType As Byte, DidWalk As Boolean, Buffer As clsBuffer, Resource_index As Long
    Dim TargetX As Long, TargetY As Long, target_verify As Boolean, y As Long
>!     For mapnum = 1 To MAX_MAPS
        ' items appearing to everyone
        For i = 1 To MAX_MAP_ITEMS
            If MapItem(mapnum, i).Num > 0 Then
                If MapItem(mapnum, i).playerName <> vbNullString Then
                    ' make item public?
                    If MapItem(mapnum, i).playerTimer < GetTickCount Then
                        ' make it public
                        MapItem(mapnum, i).playerName = vbNullString
                        MapItem(mapnum, i).playerTimer = 0
                        ' send updates to everyone
                        SendMapItemsToAll mapnum
                    End If
                    ' despawn item?
                    If MapItem(mapnum, i).canDespawn Then
                        If MapItem(mapnum, i).despawnTimer < GetTickCount Then
                            ' despawn it
                            ClearMapItem i, mapnum
                            ' send updates to everyone
                            SendMapItemsToAll mapnum
                        End If
                    End If
                End If
            End If
        Next

        '  Close the doors
        If TickCount > TempTile(mapnum).DoorTimer + 5000 Then
            For x1 = 0 To Map(mapnum).MaxX
                For y1 = 0 To Map(mapnum).MaxY
                    If Map(mapnum).Tile(x1, y1).Type = TILE_TYPE_KEY And TempTile(mapnum).DoorOpen(x1, y1) = YES Then
                        TempTile(mapnum).DoorOpen(x1, y1) = NO
                        SendMapKeyToMap mapnum, x1, y1, 0
                    End If
                Next
            Next
        End If

        ' check for DoTs + hots
        For i = 1 To MAX_MAP_NPCS
            If MapNpc(mapnum).Npc(i).Num > 0 Then
                For x = 1 To MAX_DOTS
                    HandleDoT_Npc mapnum, i, x
                    HandleHoT_Npc mapnum, i, x
                Next
            End If
        Next
>!         ' Respawning Resources
        If ResourceCache(mapnum).Resource_Count > 0 Then
            For i = 0 To ResourceCache(mapnum).Resource_Count
                Resource_index = Map(mapnum).Tile(ResourceCache(mapnum).ResourceData(i).x, ResourceCache(mapnum).ResourceData(i).y).Data1
>!                 If Resource_index > 0 Then
                    If ResourceCache(mapnum).ResourceData(i).ResourceState = 1 Or ResourceCache(mapnum).ResourceData(i).cur_health < 1 Then  ' dead or fucked up
                        If ResourceCache(mapnum).ResourceData(i).ResourceTimer + (Resource(Resource_index).RespawnTime * 1000) < GetTickCount Then
                            ResourceCache(mapnum).ResourceData(i).ResourceTimer = GetTickCount
                            ResourceCache(mapnum).ResourceData(i).ResourceState = 0 ' normal
                            ' re-set health to resource root
                            ResourceCache(mapnum).ResourceData(i).cur_health = Resource(Resource_index).health
                            SendResourceCacheToMap mapnum, i
                        End If
                    End If
                End If
            Next
        End If
>!         If PlayersOnMap(mapnum) = YES Then
            TickCount = GetTickCount

            For x = 1 To MAX_MAP_NPCS
                npcNum = MapNpc(mapnum).Npc(x).Num
>!                 ' /////////////////////////////////////////
                ' // This is used for ATTACKING ON SIGHT //
                ' /////////////////////////////////////////
                ' Make sure theres a npc with the map
                If Map(mapnum).Npc(x) > 0 And MapNpc(mapnum).Npc(x).Num > 0 Then
>!                     ' If the npc is a attack on sight, search for a player on the map
                    If Npc(npcNum).Behaviour = NPC_BEHAVIOUR_ATTACKONSIGHT Or Npc(npcNum).Behaviour = NPC_BEHAVIOUR_GUARD Then

                        ' make sure it's not stunned
                        If Not MapNpc(mapnum).Npc(x).StunDuration > 0 Then

                            For i = 1 To Player_HighIndex
                                If IsPlaying(i) Then
                                    If GetPlayerMap(i) = mapnum And MapNpc(mapnum).Npc(x).target = 0 And GetPlayerAccess(i) <= ADMIN_MONITOR Then
                                        n = Npc(npcNum).Range
                                        DistanceX = MapNpc(mapnum).Npc(x).x - GetPlayerX(i)
                                        DistanceY = MapNpc(mapnum).Npc(x).y - GetPlayerY(i)

                                        ' Make sure we get a positive value
                                        If DistanceX < 0 Then DistanceX = DistanceX * -1
                                        If DistanceY < 0 Then DistanceY = DistanceY * -1

                                        ' Are they in range?  if so GET'M!
                                        If DistanceX <= n And DistanceY <= n Then
                                            If Npc(npcNum).Behaviour = NPC_BEHAVIOUR_ATTACKONSIGHT Or GetPlayerPK(i) = YES Then
                                                If Len(Trim$(Npc(npcNum).AttackSay)) > 0 Then
                                                    Call PlayerMsg(i, Trim$(Npc(npcNum).Name) & " says: " & Trim$(Npc(npcNum).AttackSay), SayColor)
                                                End If
                                                MapNpc(mapnum).Npc(x).targetType = 1 ' player
                                                MapNpc(mapnum).Npc(x).target = i
                                            End If
                                        End If
                                    End If
                                End If
                            Next
                        End If
                    End If
                End If

                target_verify = False
>!                 ' /////////////////////////////////////////////
                ' // This is used for NPC walking/targetting //
                ' /////////////////////////////////////////////
                ' Make sure theres a npc with the map
                If Map(mapnum).Npc(x) > 0 And MapNpc(mapnum).Npc(x).Num > 0 Then
                    If MapNpc(mapnum).Npc(x).StunDuration > 0 Then
                        ' check if we can unstun them
                        If GetTickCount > MapNpc(mapnum).Npc(x).StunTimer + (MapNpc(mapnum).Npc(x).StunDuration * 1000) Then
                            MapNpc(mapnum).Npc(x).StunDuration = 0
                            MapNpc(mapnum).Npc(x).StunTimer = 0
                        End If
                    Else

                        target = MapNpc(mapnum).Npc(x).target
                        targetType = MapNpc(mapnum).Npc(x).targetType

                        ' Check to see if its time for the npc to walk
                        If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER Then

                            If targetType = 1 Then ' player

                                ' Check to see if we are following a player or not
                                If target > 0 Then

                                    ' Check if the player is even playing, if so follow'm
                                    If IsPlaying(target) And GetPlayerMap(target) = mapnum Then
                                        DidWalk = False
                                        target_verify = True
                                        TargetY = GetPlayerY(target)
                                        TargetX = GetPlayerX(target)
                                    Else
                                        MapNpc(mapnum).Npc(x).targetType = 0 ' clear
                                        MapNpc(mapnum).Npc(x).target = 0
                                    End If
                                End If

                            ElseIf targetType = 2 Then 'npc

                                If target > 0 Then

                                    If MapNpc(mapnum).Npc(target).Num > 0 Then
                                        DidWalk = False
                                        target_verify = True
                                        TargetY = MapNpc(mapnum).Npc(target).y
                                        TargetX = MapNpc(mapnum).Npc(target).x
                                    Else
                                        MapNpc(mapnum).Npc(x).targetType = 0 ' clear
                                        MapNpc(mapnum).Npc(x).target = 0
                                    End If
                                End If
                            End If

                            If target_verify Then

                                i = Int(Rnd * 5)

                                ' Lets move the npc
                                Select Case i
                                    Case 0

                                        ' Up
                                        If MapNpc(mapnum).Npc(x).y > TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_UP) Then
                                                Call NpcMove(mapnum, x, DIR_UP, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Down
                                        If MapNpc(mapnum).Npc(x).y < TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_DOWN) Then
                                                Call NpcMove(mapnum, x, DIR_DOWN, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Left
                                        If MapNpc(mapnum).Npc(x).x > TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_LEFT) Then
                                                Call NpcMove(mapnum, x, DIR_LEFT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Right
                                        If MapNpc(mapnum).Npc(x).x < TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_RIGHT) Then
                                                Call NpcMove(mapnum, x, DIR_RIGHT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                    Case 1

                                        ' Right
                                        If MapNpc(mapnum).Npc(x).x < TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_RIGHT) Then
                                                Call NpcMove(mapnum, x, DIR_RIGHT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Left
                                        If MapNpc(mapnum).Npc(x).x > TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_LEFT) Then
                                                Call NpcMove(mapnum, x, DIR_LEFT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Down
                                        If MapNpc(mapnum).Npc(x).y < TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_DOWN) Then
                                                Call NpcMove(mapnum, x, DIR_DOWN, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Up
                                        If MapNpc(mapnum).Npc(x).y > TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_UP) Then
                                                Call NpcMove(mapnum, x, DIR_UP, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                    Case 2

                                        ' Down
                                        If MapNpc(mapnum).Npc(x).y < TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_DOWN) Then
                                                Call NpcMove(mapnum, x, DIR_DOWN, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Up
                                        If MapNpc(mapnum).Npc(x).y > TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_UP) Then
                                                Call NpcMove(mapnum, x, DIR_UP, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Right
                                        If MapNpc(mapnum).Npc(x).x < TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_RIGHT) Then
                                                Call NpcMove(mapnum, x, DIR_RIGHT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Left
                                        If MapNpc(mapnum).Npc(x).x > TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_LEFT) Then
                                                Call NpcMove(mapnum, x, DIR_LEFT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                    Case 3

                                        ' Left
                                        If MapNpc(mapnum).Npc(x).x > TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_LEFT) Then
                                                Call NpcMove(mapnum, x, DIR_LEFT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Right
                                        If MapNpc(mapnum).Npc(x).x < TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_RIGHT) Then
                                                Call NpcMove(mapnum, x, DIR_RIGHT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Up
                                        If MapNpc(mapnum).Npc(x).y > TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_UP) Then
                                                Call NpcMove(mapnum, x, DIR_UP, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Down
                                        If MapNpc(mapnum).Npc(x).y < TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_DOWN) Then
                                                Call NpcMove(mapnum, x, DIR_DOWN, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                End Select

                                ' Check if we can't move and if Target is behind something and if we can just switch dirs
                                If Not DidWalk Then
                                    If MapNpc(mapnum).Npc(x).x - 1 = TargetX And MapNpc(mapnum).Npc(x).y = TargetY Then
                                        If MapNpc(mapnum).Npc(x).Dir <> DIR_LEFT Then
                                            Call NpcDir(mapnum, x, DIR_LEFT)
                                        End If

                                        DidWalk = True
                                    End If

                                    If MapNpc(mapnum).Npc(x).x + 1 = TargetX And MapNpc(mapnum).Npc(x).y = TargetY Then
                                        If MapNpc(mapnum).Npc(x).Dir <> DIR_RIGHT Then
                                            Call NpcDir(mapnum, x, DIR_RIGHT)
                                        End If

                                        DidWalk = True
                                    End If

                                    If MapNpc(mapnum).Npc(x).x = TargetX And MapNpc(mapnum).Npc(x).y - 1 = TargetY Then
                                        If MapNpc(mapnum).Npc(x).Dir <> DIR_UP Then
                                            Call NpcDir(mapnum, x, DIR_UP)
                                        End If

                                        DidWalk = True
                                    End If

                                    If MapNpc(mapnum).Npc(x).x = TargetX And MapNpc(mapnum).Npc(x).y + 1 = TargetY Then
                                        If MapNpc(mapnum).Npc(x).Dir <> DIR_DOWN Then
                                            Call NpcDir(mapnum, x, DIR_DOWN)
                                        End If

                                        DidWalk = True
                                    End If

                                    ' We could not move so Target must be behind something, walk randomly.
                                    If Not DidWalk Then
                                        i = Int(Rnd * 2)

                                        If i = 1 Then
                                            i = Int(Rnd * 4)

                                            If CanNpcMove(mapnum, x, i) Then
                                                Call NpcMove(mapnum, x, i, MOVING_WALKING)
                                            End If
                                        End If
                                    End If
                                End If

                            Else
                                i = Int(Rnd * 4)

                                If i = 1 Then
                                    i = Int(Rnd * 4)

                                    If CanNpcMove(mapnum, x, i) Then
                                        Call NpcMove(mapnum, x, i, MOVING_WALKING)
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
>!                 ' /////////////////////////////////////////////
                ' // This is used for npcs to attack targets //
                ' /////////////////////////////////////////////
                ' Make sure theres a npc with the map
If Map(mapnum).Npc(x) > 0 And MapNpc(mapnum).Npc(x).Num > 0 Then
                    target = MapNpc(mapnum).Npc(x).target
                    targetType = MapNpc(mapnum).Npc(x).targetType
>!                     ' Check if the npc can attack the targeted player player
                    If target > 0 Then

                        If targetType = 1 Then ' player
                            ' Is the target playing and on the same map?
                            If IsPlaying(target) And GetPlayerMap(target) = mapnum Then
                                TryNpcAttackPlayer x, target
                            Else
                                ' Player left map or game, set target to 0
                                MapNpc(mapnum).Npc(x).target = 0
                                MapNpc(mapnum).Npc(x).targetType = 0 ' clear
                            End If
                        ElseIf targetType = 2 Then
                            ' lol no npc combat :( DATS WAT YOU THINK

                            If Map(mapnum).Npc(x) > 0 And MapNpc(mapnum).Npc(x).Num > 0 Then
                            If Npc(MapNpc(mapnum).Npc(x).Num).Behaviour = NPC_BEHAVIOUR_PET And Npc(MapNpc(mapnum).Npc(target).Num).Behaviour = NPC_BEHAVIOUR_PET Then
                            If CanNpcAttackNpc(mapnum, x, MapNpc(mapnum).Npc(x).target) = True Then
                            Call PetAttackPet(mapnum, x, MapNpc(mapnum).Npc(x).target, Npc(Map(mapnum).Npc(x)).Damage)
                            End If
                            ElseIf Npc(MapNpc(mapnum).Npc(x).Num).Behaviour = NPC_BEHAVIOUR_PET Then
                            If CanNpcAttackNpc(mapnum, x, MapNpc(mapnum).Npc(x).target) = True Then
                            Call PetAttackNpc(mapnum, x, MapNpc(mapnum).Npc(x).target, Npc(Map(mapnum).Npc(x)).Damage)
                            End If
                            End If
                            End If

                            If Map(mapnum).Npc(target) > 0 And MapNpc(mapnum).Npc(target).Num > 0 Then
                            If Npc(MapNpc(mapnum).Npc(target).Num).Behaviour = NPC_BEHAVIOUR_PET And Npc(MapNpc(mapnum).Npc(x).Num).Behaviour = NPC_BEHAVIOUR_PET Then
                            MapNpc(mapnum).Npc(target).target = x
                            MapNpc(mapnum).Npc(target).targetType = TARGET_TYPE_NPC
                            If CanNpcAttackNpc(mapnum, target, MapNpc(mapnum).Npc(target).target) = True Then
                            Call PetAttackPet(mapnum, target, MapNpc(mapnum).Npc(target).target, Npc(Map(mapnum).Npc(target)).Damage)
                            End If
                            ElseIf Npc(MapNpc(mapnum).Npc(target).Num).Behaviour <> NPC_BEHAVIOUR_PET Then
                            MapNpc(mapnum).Npc(target).target = x
                            MapNpc(mapnum).Npc(target).targetType = TARGET_TYPE_NPC
                            If CanNpcAttackNpc(mapnum, target, MapNpc(mapnum).Npc(target).target) = True Then
                          Call NpcAttackPet(mapnum, target, MapNpc(mapnum).Npc(target).target, Npc(Map(mapnum).Npc(target)).Damage)
                          End If
                          End If
                          End If
                          End If
                          End If
                          Else

                      End If
                      ' Spell Casting
                                For i = 1 To MAX_NPC_SPELLS
                                    If Npc(npcNum).Spell(i) > 0 Then
                                        If MapNpc(mapnum).Npc(x).SpellTimer(i) + (Spell(Npc(npcNum).Spell(i)).CastTime * 1000) < GetTickCount Then
                                            NpcSpellPlayer x, target, i
                                        End If
                                    End If
                                Next

                ' ////////////////////////////////////////////
                ' // This is used for regenerating NPC's HP //
                ' ////////////////////////////////////////////
                ' Check to see if we want to regen some of the npc's hp
                If Not MapNpc(mapnum).Npc(x).stopRegen Then
                    If MapNpc(mapnum).Npc(x).Num > 0 And TickCount > GiveNPCHPTimer + 10000 Then
                        If MapNpc(mapnum).Npc(x).Vital(Vitals.HP) > 0 Then
                            MapNpc(mapnum).Npc(x).Vital(Vitals.HP) = MapNpc(mapnum).Npc(x).Vital(Vitals.HP) + GetNpcVitalRegen(npcNum, Vitals.HP)

                            ' Check if they have more then they should and if so just set it to max
                            If MapNpc(mapnum).Npc(x).Vital(Vitals.HP) > GetNpcMaxVital(npcNum, Vitals.HP) Then
                                MapNpc(mapnum).Npc(x).Vital(Vitals.HP) = GetNpcMaxVital(npcNum, Vitals.HP)
                            End If
                        End If
                    End If
                End If
>!                 ' ////////////////////////////////////////////////////////
                ' // This is used for checking if an NPC is dead or not //
                ' ////////////////////////////////////////////////////////
                ' Check if the npc is dead or not
                'If MapNpc(y, x).Num > 0 Then
                '    If MapNpc(y, x).HP <= 0 And Npc(MapNpc(y, x).Num).STR > 0 And Npc(MapNpc(y, x).Num).DEF > 0 Then
                '        MapNpc(y, x).Num = 0
                '        MapNpc(y, x).SpawnWait = TickCount
                '  End If
                'End If

                ' //////////////////////////////////////
                ' // This is used for spawning an NPC //
                ' //////////////////////////////////////
                ' Check if we are supposed to spawn an npc or not
                If MapNpc(mapnum).Npc(x).Num = 0 And Map(mapnum).Npc(x) > 0 Then
                    If TickCount > MapNpc(mapnum).Npc(x).SpawnWait + (Npc(Map(mapnum).Npc(x)).SpawnSecs * 1000) Then
                        Call SpawnNpc(x, mapnum)
                    End If
                End If
>!             Next
>!         End If
>!         DoEvents
    Next
>!     ' Make sure we reset the timer for npc hp regeneration
    If GetTickCount > GiveNPCHPTimer + 10000 Then
        GiveNPCHPTimer = GetTickCount
    End If
>!     ' Make sure we reset the timer for door closing
    If GetTickCount > KeyTimer + 15000 Then
        KeyTimer = GetTickCount
    End If
>! End Sub
Link to comment
Share on other sites

Kay, I've a problem.

I'm using clean [almost] copy of EO 2.0, so far I have added only the quest system [works flawlessly].

I did the whole tutorial, also the parts that aren't here for some reason [like adding MAX_SPELLS constant to the client source], and copied the forms exactly like they are in the form the author has added.

When I try to compile, it says 'Variable not defined', and points at this line of code:
(I didn't add the code tag purposely - with the tag, it would not highlight the thing it points at)

–--
Private Sub scrlSpell_Change()
    lblSpellNum.Caption = "Num: " & scrlSpell.Value
    If scrlSpell.Value > 0 Then
        lblSpellName.Caption = "Spell: " & Trim$(Spell(scrlSpell.Value).Name)
    Else
        lblSpellName.Caption = "Spell: None"
    End If
    NPC(EditorIndex).Spell(**SpellIndex**) = scrlSpell.Value
End Sub
–--

I have tried to add the following in the NpcRec sub:
```
SpellIndex As Long
```
But it didn't work [yes, I have no idea why would this work, but it was just common sense]

**Edit:**
Problem solved, I have missed an answer that was already here.

**For anyone with this error:**

@DJMaxus:

> At the very top of your frmEditor_NPC, under Option Explicit, add:
> ```
> Private SpellIndex As Long
> ```
Link to comment
Share on other sites

  • 2 weeks later...
@eric9:

> Here you go, sorry tired of uploading to photobucket.
> If it bugs anyone much, I'll go back to uploading.
>
> ![](http://www.touchofdeathforums.com/smf/index.php?action=dlattach;topic=59564.0;attach=19389)

I'm getting this same error when adding this to Rithy's Modifications 2.6\. This is what the Sub looks like up until that point…

```
Private Sub UpdateMapSpawnItems()
    Dim x As Long
    Dim y As Long

    ' ///////////////////////////////////////////
    ' // This is used for respawning map items //
    ' ///////////////////////////////////////////
    For y = 1 To MAX_MAPS

        ' Make sure no one is on the map when it respawns
        If Not PlayersOnMap(y) Then

            ' Clear out unnecessary junk
            For x = 1 To MAX_MAP_ITEMS
                Call ClearMapItem(x, y)
            Next

            ' Spawn the items
            Call SpawnMapItems(y)
            Call SendMapItemsToAll(y)
        End If

        DoEvents
    Next

End Sub

Private Sub UpdateMapLogic()
    Dim i As Long, x As Long, mapnum As Long, n As Long, x1 As Long, y1 As Long
    Dim TickCount As Long, Damage As Long, DistanceX As Long, DistanceY As Long, npcNum As Long
    Dim target As Long, targetType As Byte, DidWalk As Boolean, Buffer As clsBuffer, Resource_index As Long
    Dim TargetX As Long, TargetY As Long, target_verify As Boolean, y As Long

    For mapnum = 1 To MAX_MAPS
        ' items appearing to everyone
        For i = 1 To MAX_MAP_ITEMS
            If MapItem(mapnum, i).Num > 0 Then
                If MapItem(mapnum, i).playerName <> vbNullString Then
                    ' make item public?
                    If MapItem(mapnum, i).playerTimer < GetTickCount Then
                        ' make it public
                        MapItem(mapnum, i).playerName = vbNullString
                        MapItem(mapnum, i).playerTimer = 0
                        ' send updates to everyone
                        SendMapItemsToAll mapnum
                    End If
                    ' despawn item?
                    If MapItem(mapnum, i).canDespawn Then
                        If MapItem(mapnum, i).despawnTimer < GetTickCount Then
                            ' despawn it
                            ClearMapItem i, mapnum
                            ' send updates to everyone
                            SendMapItemsToAll mapnum
                        End If
                    End If
                End If
            End If
        Next

        '  Close the doors
        If TickCount > TempTile(mapnum).DoorTimer + 5000 Then
            For x1 = 0 To Map(mapnum).MaxX
                For y1 = 0 To Map(mapnum).MaxY
                    If Map(mapnum).Tile(x1, y1).Type = TILE_TYPE_KEY And TempTile(mapnum).DoorOpen(x1, y1) = YES Then
                        TempTile(mapnum).DoorOpen(x1, y1) = NO
                        SendMapKeyToMap mapnum, x1, y1, 0
                    End If
                Next
            Next
        End If

        ' check for DoTs + hots
        For i = 1 To MAX_MAP_NPCS
            If MapNpc(mapnum).Npc(i).Num > 0 Then
                For x = 1 To MAX_DOTS
                    HandleDoT_Npc mapnum, i, x
                    HandleHoT_Npc mapnum, i, x
                Next
            End If
        Next

        ' Respawning Resources
        If ResourceCache(mapnum).Resource_Count > 0 Then
            For i = 0 To ResourceCache(mapnum).Resource_Count
                Resource_index = Map(mapnum).Tile(ResourceCache(mapnum).ResourceData(i).x, ResourceCache(mapnum).ResourceData(i).y).Data1

                If Resource_index > 0 Then
                    If ResourceCache(mapnum).ResourceData(i).ResourceState = 1 Or ResourceCache(mapnum).ResourceData(i).cur_health < 1 Then  ' dead or ducked up
                        If ResourceCache(mapnum).ResourceData(i).ResourceTimer + (Resource(Resource_index).RespawnTime * 1000) < GetTickCount Then
                            ResourceCache(mapnum).ResourceData(i).ResourceTimer = GetTickCount
                            ResourceCache(mapnum).ResourceData(i).ResourceState = 0 ' normal
                            ' re-set health to resource root
                            ResourceCache(mapnum).ResourceData(i).cur_health = Resource(Resource_index).health
                            SendResourceCacheToMap mapnum, i
                        End If
                    End If
                End If
            Next
        End If

        If PlayersOnMap(mapnum) = YES Then
            TickCount = GetTickCount

            For x = 1 To MAX_MAP_NPCS
                npcNum = MapNpc(mapnum).Npc(x).Num

                ' /////////////////////////////////////////
                ' // This is used for ATTACKING ON SIGHT //
                ' /////////////////////////////////////////
                ' Make sure theres a npc with the map
                If Map(mapnum).Npc(x) > 0 And MapNpc(mapnum).Npc(x).Num > 0 Then

                    ' If the npc is a attack on sight, search for a player on the map
                    If Npc(npcNum).Behaviour = NPC_BEHAVIOUR_ATTACKONSIGHT Or Npc(npcNum).Behaviour = NPC_BEHAVIOUR_GUARD Then

                        ' make sure it's not stunned
                        If Not MapNpc(mapnum).Npc(x).StunDuration > 0 Then

                            For i = 1 To Player_HighIndex
                                If IsPlaying(i) Then
                                    If GetPlayerMap(i) = mapnum And MapNpc(mapnum).Npc(x).target = 0 And GetPlayerAccess(i) <= ADMIN_MONITOR Then
                                        n = Npc(npcNum).Range
                                        DistanceX = MapNpc(mapnum).Npc(x).x - GetPlayerX(i)
                                        DistanceY = MapNpc(mapnum).Npc(x).y - GetPlayerY(i)

                                        ' Make sure we get a positive value
                                        If DistanceX < 0 Then DistanceX = DistanceX * -1
                                        If DistanceY < 0 Then DistanceY = DistanceY * -1

                                        ' Are they in range?  if so GET'M!
                                        If DistanceX <= n And DistanceY <= n Then
                                            If Npc(npcNum).Behaviour = NPC_BEHAVIOUR_ATTACKONSIGHT Or GetPlayerPK(i) = YES Then
                                                If Len(Trim$(Npc(npcNum).AttackSay)) > 0 Then
                                                    Call PlayerMsg(i, Trim$(Npc(npcNum).Name) & " says: " & Trim$(Npc(npcNum).AttackSay), SayColor)
                                                End If
                                                MapNpc(mapnum).Npc(x).targetType = 1 ' player
                                                MapNpc(mapnum).Npc(x).target = i
                                            End If
                                        End If
                                    End If
                                End If
                            Next
                        End If
                    End If
                End If

                target_verify = False

                ' /////////////////////////////////////////////
                ' // This is used for NPC walking/targetting //
                ' /////////////////////////////////////////////
                ' Make sure theres a npc with the map
                If Map(mapnum).Npc(x) > 0 And MapNpc(mapnum).Npc(x).Num > 0 Then
                    If MapNpc(mapnum).Npc(x).StunDuration > 0 Then
                        ' check if we can unstun them
                        If GetTickCount > MapNpc(mapnum).Npc(x).StunTimer + (MapNpc(mapnum).Npc(x).StunDuration * 1000) Then
                            MapNpc(mapnum).Npc(x).StunDuration = 0
                            MapNpc(mapnum).Npc(x).StunTimer = 0
                        End If
                    Else

                        target = MapNpc(mapnum).Npc(x).target
                        targetType = MapNpc(mapnum).Npc(x).targetType

                        ' Check to see if its time for the npc to walk
                        If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER Then

                            If targetType = 1 Then ' player

                                ' Check to see if we are following a player or not
                                If target > 0 Then

                                    ' Check if the player is even playing, if so follow'm
                                    If IsPlaying(target) And GetPlayerMap(target) = mapnum Then
                                        DidWalk = False
                                        target_verify = True
                                        TargetY = GetPlayerY(target)
                                        TargetX = GetPlayerX(target)
                                    Else
                                        MapNpc(mapnum).Npc(x).targetType = 0 ' clear
                                        MapNpc(mapnum).Npc(x).target = 0
                                    End If
                                End If

                            ElseIf targetType = 2 Then 'npc

                                If target > 0 Then

                                    If MapNpc(mapnum).Npc(target).Num > 0 Then
                                        DidWalk = False
                                        target_verify = True
                                        TargetY = MapNpc(mapnum).Npc(target).y
                                        TargetX = MapNpc(mapnum).Npc(target).x
                                    Else
                                        MapNpc(mapnum).Npc(x).targetType = 0 ' clear
                                        MapNpc(mapnum).Npc(x).target = 0
                                    End If
                                End If
                            End If

                            If target_verify Then

                                i = Int(Rnd * 5)

                                ' Lets move the npc
                                Select Case i
                                    Case 0

                                        ' Up
                                        If MapNpc(mapnum).Npc(x).y > TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_UP) Then
                                                Call NpcMove(mapnum, x, DIR_UP, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Down
                                        If MapNpc(mapnum).Npc(x).y < TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_DOWN) Then
                                                Call NpcMove(mapnum, x, DIR_DOWN, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Left
                                        If MapNpc(mapnum).Npc(x).x > TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_LEFT) Then
                                                Call NpcMove(mapnum, x, DIR_LEFT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Right
                                        If MapNpc(mapnum).Npc(x).x < TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_RIGHT) Then
                                                Call NpcMove(mapnum, x, DIR_RIGHT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                    Case 1

                                        ' Right
                                        If MapNpc(mapnum).Npc(x).x < TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_RIGHT) Then
                                                Call NpcMove(mapnum, x, DIR_RIGHT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Left
                                        If MapNpc(mapnum).Npc(x).x > TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_LEFT) Then
                                                Call NpcMove(mapnum, x, DIR_LEFT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Down
                                        If MapNpc(mapnum).Npc(x).y < TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_DOWN) Then
                                                Call NpcMove(mapnum, x, DIR_DOWN, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Up
                                        If MapNpc(mapnum).Npc(x).y > TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_UP) Then
                                                Call NpcMove(mapnum, x, DIR_UP, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                    Case 2

                                        ' Down
                                        If MapNpc(mapnum).Npc(x).y < TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_DOWN) Then
                                                Call NpcMove(mapnum, x, DIR_DOWN, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Up
                                        If MapNpc(mapnum).Npc(x).y > TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_UP) Then
                                                Call NpcMove(mapnum, x, DIR_UP, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Right
                                        If MapNpc(mapnum).Npc(x).x < TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_RIGHT) Then
                                                Call NpcMove(mapnum, x, DIR_RIGHT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Left
                                        If MapNpc(mapnum).Npc(x).x > TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_LEFT) Then
                                                Call NpcMove(mapnum, x, DIR_LEFT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                    Case 3

                                        ' Left
                                        If MapNpc(mapnum).Npc(x).x > TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_LEFT) Then
                                                Call NpcMove(mapnum, x, DIR_LEFT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Right
                                        If MapNpc(mapnum).Npc(x).x < TargetX And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_RIGHT) Then
                                                Call NpcMove(mapnum, x, DIR_RIGHT, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Up
                                        If MapNpc(mapnum).Npc(x).y > TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_UP) Then
                                                Call NpcMove(mapnum, x, DIR_UP, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                        ' Down
                                        If MapNpc(mapnum).Npc(x).y < TargetY And Not DidWalk Then
                                            If CanNpcMove(mapnum, x, DIR_DOWN) Then
                                                Call NpcMove(mapnum, x, DIR_DOWN, MOVING_WALKING)
                                                DidWalk = True
                                            End If
                                        End If

                                End Select

                                ' Check if we can't move and if Target is behind something and if we can just switch dirs
                                If Not DidWalk Then
                                    If MapNpc(mapnum).Npc(x).x - 1 = TargetX And MapNpc(mapnum).Npc(x).y = TargetY Then
                                        If MapNpc(mapnum).Npc(x).Dir <> DIR_LEFT Then
                                            Call NpcDir(mapnum, x, DIR_LEFT)
                                        End If

                                        DidWalk = True
                                    End If

                                    If MapNpc(mapnum).Npc(x).x + 1 = TargetX And MapNpc(mapnum).Npc(x).y = TargetY Then
                                        If MapNpc(mapnum).Npc(x).Dir <> DIR_RIGHT Then
                                            Call NpcDir(mapnum, x, DIR_RIGHT)
                                        End If

                                        DidWalk = True
                                    End If

                                    If MapNpc(mapnum).Npc(x).x = TargetX And MapNpc(mapnum).Npc(x).y - 1 = TargetY Then
                                        If MapNpc(mapnum).Npc(x).Dir <> DIR_UP Then
                                            Call NpcDir(mapnum, x, DIR_UP)
                                        End If

                                        DidWalk = True
                                    End If

                                    If MapNpc(mapnum).Npc(x).x = TargetX And MapNpc(mapnum).Npc(x).y + 1 = TargetY Then
                                        If MapNpc(mapnum).Npc(x).Dir <> DIR_DOWN Then
                                            Call NpcDir(mapnum, x, DIR_DOWN)
                                        End If

                                        DidWalk = True
                                    End If

                                    ' We could not move so Target must be behind something, walk randomly.
                                    If Not DidWalk Then
                                        i = Int(Rnd * 2)

                                        If i = 1 Then
                                            i = Int(Rnd * 4)

                                            If CanNpcMove(mapnum, x, i) Then
                                                Call NpcMove(mapnum, x, i, MOVING_WALKING)
                                            End If
                                        End If
                                    End If
                                End If

                            Else
                                i = Int(Rnd * 4)

                                If i = 1 Then
                                    i = Int(Rnd * 4)

                                    If CanNpcMove(mapnum, x, i) Then
                                        Call NpcMove(mapnum, x, i, MOVING_WALKING)
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If

                ' /////////////////////////////////////////////
                ' // This is used for npcs to attack targets //
                ' /////////////////////////////////////////////
                ' Make sure theres a npc with the map
If Map(mapnum).Npc(x) > 0 And MapNpc(mapnum).Npc(x).Num > 0 Then
                    target = MapNpc(mapnum).Npc(x).target
                    targetType = MapNpc(mapnum).Npc(x).targetType

                    ' Check if the npc can attack the targeted player player
                    If target > 0 Then

                        If targetType = 1 Then ' player
                            ' Is the target playing and on the same map?
                            If IsPlaying(target) And GetPlayerMap(target) = mapnum Then
                                TryNpcAttackPlayer x, target
                            Else
                                ' Player left map or game, set target to 0
                                MapNpc(mapnum).Npc(x).target = 0
                                MapNpc(mapnum).Npc(x).targetType = 0 ' clear
                            End If
                        ElseIf targetType = 2 Then
                            ' lol no npc combat :( DATS WAT YOU THINK

                            If Map(mapnum).Npc(x) > 0 And MapNpc(mapnum).Npc(x).Num > 0 Then
                            If Npc(MapNpc(mapnum).Npc(x).Num).Behaviour = NPC_BEHAVIOUR_PET And Npc(MapNpc(mapnum).Npc(target).Num).Behaviour = NPC_BEHAVIOUR_PET Then
                            If CanNpcAttackNpc(mapnum, x, MapNpc(mapnum).Npc(x).target) = True Then
                            Call PetAttackPet(mapnum, x, MapNpc(mapnum).Npc(x).target, Npc(Map(mapnum).Npc(x)).Damage)
                            End If
                            ElseIf Npc(MapNpc(mapnum).Npc(x).Num).Behaviour = NPC_BEHAVIOUR_PET Then
                            If CanNpcAttackNpc(mapnum, x, MapNpc(mapnum).Npc(x).target) = True Then
                            Call PetAttackNpc(mapnum, x, MapNpc(mapnum).Npc(x).target, Npc(Map(mapnum).Npc(x)).Damage)
                            End If
                            End If
                            End If

                            If Map(mapnum).Npc(target) > 0 And MapNpc(mapnum).Npc(target).Num > 0 Then
                            If Npc(MapNpc(mapnum).Npc(target).Num).Behaviour = NPC_BEHAVIOUR_PET And Npc(MapNpc(mapnum).Npc(x).Num).Behaviour = NPC_BEHAVIOUR_PET Then
                            MapNpc(mapnum).Npc(target).target = x
                            MapNpc(mapnum).Npc(target).targetType = TARGET_TYPE_NPC
                            If CanNpcAttackNpc(mapnum, target, MapNpc(mapnum).Npc(target).target) = True Then
                            Call PetAttackPet(mapnum, target, MapNpc(mapnum).Npc(target).target, Npc(Map(mapnum).Npc(target)).Damage)
                            End If
                            ElseIf Npc(MapNpc(mapnum).Npc(target).Num).Behaviour <> NPC_BEHAVIOUR_PET Then
                            MapNpc(mapnum).Npc(target).target = x
                            MapNpc(mapnum).Npc(target).targetType = TARGET_TYPE_NPC
                            If CanNpcAttackNpc(mapnum, target, MapNpc(mapnum).Npc(target).target) = True Then
                          Call NpcAttackPet(mapnum, target, MapNpc(mapnum).Npc(target).target, Npc(Map(mapnum).Npc(target)).Damage)
                          End If
                          End If
                          End If
                          End If
                          End If
                          Else

                      End If

                      ' Spell Casting
                                For i = 1 To MAX_NPC_SPELLS
                                    If Npc(npcNum).Spell(i) > 0 Then
                                        If MapNpc(mapnum).Npc(x).SpellTimer(i) + (Spell(Npc(npcNum).Spell(i)).CastTime * 1000) < GetTickCount Then
                                            NpcSpellPlayer x, target, i
                                        End If
                                    End If
                                Next
```
If someone could tell me why thatd be awesome!

Edit: Solved! I just had to move this code:

```
' Spell Casting
                                For i = 1 To MAX_NPC_SPELLS
                                    If Npc(npcNum).Spell(i) > 0 Then
                                        If MapNpc(mapnum).Npc(x).SpellTimer(i) + (Spell(Npc(npcNum).Spell(i)).CastTime * 1000) < GetTickCount Then
                                            NpcSpellPlayer x, target, i
                                        End If
                                    End If
                                Next
```
Above the line that says:

```
ElseIf targetType = 2 Then
                            ' lol no npc combat :( DATS WAT YOU THINK
```
Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×
×
  • Create New...