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

Error crash the server


troglodite
 Share

Recommended Posts

Hello! I am having a trouble when I fight a NPC that cast spells, at the moment before he kills me (when I have poor health and no potions/I let him to kill me)

"Run-time error: Subscript out of range"

Debugged line

In NpcSpellPlayer:

```
Select Case Spell(spellnum).Type
```

Its about the [NPC Spells v.2.0.0](http://www.touchofdeathforums.com/community/index.php?/topic/106297-eo-npc-spells-v200/) code that I added

Thx for reading
Link to comment
Share on other sites

> Hover over each variable. And type the contents of each.

The Cases?

Here the cases:

>! ```
>! ' Spell Types
>! Select Case Spell(spellnum).Type
>! ' AOE Healing Spells
>! Case SPELL_TYPE_HEALHP
>! ' Make sure an npc waits for the spell to cooldown
>! MaxHeals = 1 + NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) \ 25
>! If MapNpc(mapNum).NPC(MapNpcNum).Heals >= MaxHeals Then Exit Sub
>! If MapNpc(mapNum).NPC(MapNpcNum).Vital(Vitals.HP) <= NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).HP * 0.3 Then
>! If Spell(spellnum).IsAoE Then
>! For i = 1 To MAX_MAP_NPCS
>! If MapNpc(mapNum).NPC(i).Num > 0 Then
>! If MapNpc(mapNum).NPC(i).Vital(Vitals.HP) > 0 Then
>! If isInRange(Spell(spellnum).AoE, MapNpc(mapNum).NPC(MapNpcNum).x, MapNpc(mapNum).NPC(MapNpcNum).y, MapNpc(mapNum).NPC(i).x, MapNpc(mapNum).NPC(i).y) Then
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>!
>! MapNpc(mapNum).NPC(i).Vital(Vitals.HP) = MapNpc(mapNum).NPC(i).Vital(Vitals.HP) + InitDamage
>! SendActionMsg mapNum, "+" & InitDamage, BrightGreen, 1, (MapNpc(mapNum).NPC(i).x * 32), (MapNpc(mapNum).NPC(i).y * 32)
>! Call SendAnimation(mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_NPC, MapNpcNum)
>!
>! If MapNpc(mapNum).NPC(i).Vital(Vitals.HP) > NPC(MapNpc(mapNum).NPC(i).Num).HP Then
>! MapNpc(mapNum).NPC(i).Vital(Vitals.HP) = NPC(MapNpc(mapNum).NPC(i).Num).HP
>! End If
>!
>! MapNpc(mapNum).NPC(MapNpcNum).Heals = MapNpc(mapNum).NPC(MapNpcNum).Heals + 1
>!
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>! End If
>! Next
>! Else
>! ' Non AOE Healing Spells
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>!
>! MapNpc(mapNum).NPC(MapNpcNum).Vital(Vitals.HP) = MapNpc(mapNum).NPC(MapNpcNum).Vital(Vitals.HP) + InitDamage
>! SendActionMsg mapNum, "+" & InitDamage, BrightGreen, 1, (MapNpc(mapNum).NPC(MapNpcNum).x * 32), (MapNpc(mapNum).NPC(MapNpcNum).y * 32)
>! Call SendAnimation(mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_NPC, MapNpcNum)
>!
>! If MapNpc(mapNum).NPC(MapNpcNum).Vital(Vitals.HP) > NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).HP Then
>! MapNpc(mapNum).NPC(MapNpcNum).Vital(Vitals.HP) = NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).HP
>! End If
>!
>! MapNpc(mapNum).NPC(MapNpcNum).Heals = MapNpc(mapNum).NPC(MapNpcNum).Heals + 1
>!
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>!
>! ' AOE Damaging Spells
>! Case SPELL_TYPE_DAMAGEHP
>! ' Make sure an npc waits for the spell to cooldown
>! If Spell(spellnum).IsAoE Then
>! For i = 1 To Player_HighIndex
>! If IsPlaying(i) Then
>! If GetPlayerMap(i) = mapNum Then
>! If isInRange(Spell(spellnum).AoE, MapNpc(mapNum).NPC(MapNpcNum).x, MapNpc(mapNum).NPC(MapNpcNum).y, GetPlayerX(i), GetPlayerY(i)) Then
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>! Damage = InitDamage - Player(victim).Stat(Stats.intelligence) / 2
>! If Damage <= 0 Then
>! SendActionMsg GetPlayerMap(i), "RESIST!", Pink, 1, (GetPlayerX(i) * 32), (GetPlayerY(i) * 32)
>! Exit Sub
>! Else
>! SpellPlayer_Effect Vitals.HP, False, victim, Damage, spellnum
>! SendAnimation mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_PLAYER, MapNpcNum
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>! End If
>! End If
>! Next
>! ' Non AoE Damaging Spells
>! Else
>! If isInRange(Spell(spellnum).Range, MapNpc(mapNum).NPC(MapNpcNum).x, MapNpc(mapNum).NPC(MapNpcNum).y, GetPlayerX(victim), GetPlayerY(victim)) Then
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>! Damage = InitDamage - Player(victim).Stat(Stats.intelligence) / 2
>! If Damage <= 0 Then
>! SendActionMsg GetPlayerMap(victim), "SIN EFECTO!", Pink, 1, (GetPlayerX(victim) * 32), (GetPlayerY(victim) * 32)
>! Exit Sub
>! Else
>! SpellPlayer_Effect Vitals.HP, False, victim, Damage, spellnum
>! SendAnimation mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_PLAYER, victim
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>! End If
>! Case SPELL_TYPE_DAMAGEMP
>! ' Make sure an npc waits for the spell to cooldown
>! If Spell(spellnum).IsAoE Then
>! For i = 1 To Player_HighIndex
>! If IsPlaying(i) Then
>! If GetPlayerMap(i) = mapNum Then
>! If isInRange(Spell(spellnum).AoE, MapNpc(mapNum).NPC(MapNpcNum).x, MapNpc(mapNum).NPC(MapNpcNum).y, GetPlayerX(i), GetPlayerY(i)) Then
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>! Damage = InitDamage - Player(i).Stat(Stats.willpower)
>! If Damage <= 0 Then
>! SendActionMsg GetPlayerMap(i), "RESIST!", Pink, 1, (GetPlayerX(i) * 32), (GetPlayerY(i) * 32)
>! Exit Sub
>! Else
>! SpellPlayer_Effect Vitals.MP, False, victim, Damage, spellnum
>! SendAnimation mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_PLAYER, MapNpcNum
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>! End If
>! End If
>! Next
>! ' Non AoE DamagingMP Spells
>! Else
>! If isInRange(Spell(spellnum).Range, MapNpc(mapNum).NPC(MapNpcNum).x, MapNpc(mapNum).NPC(MapNpcNum).y, GetPlayerX(victim), GetPlayerY(victim)) Then
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>! Damage = InitDamage - Player(victim).Stat(Stats.willpower)
>! If Damage <= 0 Then
>! SendActionMsg GetPlayerMap(victim), "RESIST!", Pink, 1, (GetPlayerX(victim) * 32), (GetPlayerY(victim) * 32)
>! Exit Sub
>! Else
>! SpellPlayer_Effect Vitals.MP, False, victim, Damage, spellnum
>! SendAnimation mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_PLAYER, victim
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>! End If
>!
>! End Select
>! ```

Here the entire code:

>! ```
>! Sub NpcSpellPlayer(ByVal MapNpcNum As Long, ByVal victim As Long, SpellSlotNum As Long)
>! Dim mapNum As Long
>! Dim i As Long
>! Dim n As Long
>! Dim spellnum As Long
>! Dim Buffer As clsBuffer
>! Dim InitDamage As Long
>! Dim Damage As Long
>! Dim MaxHeals As Long
>! ' Check for subscript out of range
>! If MapNpcNum <= 0 Or MapNpcNum > MAX_MAP_NPCS Or IsPlaying(victim) = False Then
>! Exit Sub
>! End If
>! ' Check for subscript out of range
>! If MapNpc(GetPlayerMap(victim)).NPC(MapNpcNum).Num <= 0 Then
>! Exit Sub
>! End If
>! If SpellSlotNum <= 0 Or SpellSlotNum > MAX_NPC_SPELLS Then Exit Sub
>! ' The Variables
>! mapNum = GetPlayerMap(victim)
>! spellnum = NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Spell(SpellSlotNum)
>! ' Send this packet so they can see the person attacking
>! Set Buffer = New clsBuffer
>! Buffer.WriteLong SNpcAttack
>! Buffer.WriteLong MapNpcNum
>! SendDataToMap mapNum, Buffer.ToArray()
>! Set Buffer = Nothing
>! ' CoolDown Time
>! If MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) > GetTickCount Then Exit Sub
>! ' Spell Types
>! Select Case Spell(spellnum).Type
>! ' AOE Healing Spells
>! Case SPELL_TYPE_HEALHP
>! ' Make sure an npc waits for the spell to cooldown
>! MaxHeals = 1 + NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) \ 25
>! If MapNpc(mapNum).NPC(MapNpcNum).Heals >= MaxHeals Then Exit Sub
>! If MapNpc(mapNum).NPC(MapNpcNum).Vital(Vitals.HP) <= NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).HP * 0.3 Then
>! If Spell(spellnum).IsAoE Then
>! For i = 1 To MAX_MAP_NPCS
>! If MapNpc(mapNum).NPC(i).Num > 0 Then
>! If MapNpc(mapNum).NPC(i).Vital(Vitals.HP) > 0 Then
>! If isInRange(Spell(spellnum).AoE, MapNpc(mapNum).NPC(MapNpcNum).x, MapNpc(mapNum).NPC(MapNpcNum).y, MapNpc(mapNum).NPC(i).x, MapNpc(mapNum).NPC(i).y) Then
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>!
>! MapNpc(mapNum).NPC(i).Vital(Vitals.HP) = MapNpc(mapNum).NPC(i).Vital(Vitals.HP) + InitDamage
>! SendActionMsg mapNum, "+" & InitDamage, BrightGreen, 1, (MapNpc(mapNum).NPC(i).x * 32), (MapNpc(mapNum).NPC(i).y * 32)
>! Call SendAnimation(mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_NPC, MapNpcNum)
>!
>! If MapNpc(mapNum).NPC(i).Vital(Vitals.HP) > NPC(MapNpc(mapNum).NPC(i).Num).HP Then
>! MapNpc(mapNum).NPC(i).Vital(Vitals.HP) = NPC(MapNpc(mapNum).NPC(i).Num).HP
>! End If
>!
>! MapNpc(mapNum).NPC(MapNpcNum).Heals = MapNpc(mapNum).NPC(MapNpcNum).Heals + 1
>!
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>! End If
>! Next
>! Else
>! ' Non AOE Healing Spells
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>!
>! MapNpc(mapNum).NPC(MapNpcNum).Vital(Vitals.HP) = MapNpc(mapNum).NPC(MapNpcNum).Vital(Vitals.HP) + InitDamage
>! SendActionMsg mapNum, "+" & InitDamage, BrightGreen, 1, (MapNpc(mapNum).NPC(MapNpcNum).x * 32), (MapNpc(mapNum).NPC(MapNpcNum).y * 32)
>! Call SendAnimation(mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_NPC, MapNpcNum)
>!
>! If MapNpc(mapNum).NPC(MapNpcNum).Vital(Vitals.HP) > NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).HP Then
>! MapNpc(mapNum).NPC(MapNpcNum).Vital(Vitals.HP) = NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).HP
>! End If
>!
>! MapNpc(mapNum).NPC(MapNpcNum).Heals = MapNpc(mapNum).NPC(MapNpcNum).Heals + 1
>!
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>!
>! ' AOE Damaging Spells
>! Case SPELL_TYPE_DAMAGEHP
>! ' Make sure an npc waits for the spell to cooldown
>! If Spell(spellnum).IsAoE Then
>! For i = 1 To Player_HighIndex
>! If IsPlaying(i) Then
>! If GetPlayerMap(i) = mapNum Then
>! If isInRange(Spell(spellnum).AoE, MapNpc(mapNum).NPC(MapNpcNum).x, MapNpc(mapNum).NPC(MapNpcNum).y, GetPlayerX(i), GetPlayerY(i)) Then
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>! Damage = InitDamage - Player(victim).Stat(Stats.intelligence) / 2
>! If Damage <= 0 Then
>! SendActionMsg GetPlayerMap(i), "RESIST!", Pink, 1, (GetPlayerX(i) * 32), (GetPlayerY(i) * 32)
>! Exit Sub
>! Else
>! SpellPlayer_Effect Vitals.HP, False, victim, Damage, spellnum
>! SendAnimation mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_PLAYER, MapNpcNum
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>! End If
>! End If
>! Next
>! ' Non AoE Damaging Spells
>! Else
>! If isInRange(Spell(spellnum).Range, MapNpc(mapNum).NPC(MapNpcNum).x, MapNpc(mapNum).NPC(MapNpcNum).y, GetPlayerX(victim), GetPlayerY(victim)) Then
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>! Damage = InitDamage - Player(victim).Stat(Stats.intelligence) / 2
>! If Damage <= 0 Then
>! SendActionMsg GetPlayerMap(victim), "SIN EFECTO!", Pink, 1, (GetPlayerX(victim) * 32), (GetPlayerY(victim) * 32)
>! Exit Sub
>! Else
>! SpellPlayer_Effect Vitals.HP, False, victim, Damage, spellnum
>! SendAnimation mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_PLAYER, victim
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>! End If
>! Case SPELL_TYPE_DAMAGEMP
>! ' Make sure an npc waits for the spell to cooldown
>! If Spell(spellnum).IsAoE Then
>! For i = 1 To Player_HighIndex
>! If IsPlaying(i) Then
>! If GetPlayerMap(i) = mapNum Then
>! If isInRange(Spell(spellnum).AoE, MapNpc(mapNum).NPC(MapNpcNum).x, MapNpc(mapNum).NPC(MapNpcNum).y, GetPlayerX(i), GetPlayerY(i)) Then
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>! Damage = InitDamage - Player(i).Stat(Stats.willpower)
>! If Damage <= 0 Then
>! SendActionMsg GetPlayerMap(i), "RESIST!", Pink, 1, (GetPlayerX(i) * 32), (GetPlayerY(i) * 32)
>! Exit Sub
>! Else
>! SpellPlayer_Effect Vitals.MP, False, victim, Damage, spellnum
>! SendAnimation mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_PLAYER, MapNpcNum
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>! End If
>! End If
>! Next
>! ' Non AoE DamagingMP Spells
>! Else
>! If isInRange(Spell(spellnum).Range, MapNpc(mapNum).NPC(MapNpcNum).x, MapNpc(mapNum).NPC(MapNpcNum).y, GetPlayerX(victim), GetPlayerY(victim)) Then
>! InitDamage = Spell(spellnum).Vital + (NPC(MapNpc(mapNum).NPC(MapNpcNum).Num).Stat(Stats.intelligence) / 2)
>! Damage = InitDamage - Player(victim).Stat(Stats.willpower)
>! If Damage <= 0 Then
>! SendActionMsg GetPlayerMap(victim), "RESIST!", Pink, 1, (GetPlayerX(victim) * 32), (GetPlayerY(victim) * 32)
>! Exit Sub
>! Else
>! SpellPlayer_Effect Vitals.MP, False, victim, Damage, spellnum
>! SendAnimation mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_PLAYER, victim
>! MapNpc(mapNum).NPC(MapNpcNum).SpellTimer(SpellSlotNum) = GetTickCount + Spell(spellnum).CDTime * 1000
>! Exit Sub
>! End If
>! End If
>! End If
>!
>! End Select
>! End Sub
>! ```
Link to comment
Share on other sites

> Hover over each variable in the line of code that is erroring. (Spell, SpellNum and Type)
>
> A popup box should appear. Type in their contents here.

Im not sure what you are telling me ![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png) BUT…

I replace the entire "NpcSpellPlayer" and I let an Npc Spell Casting to kill me; I dead like 20 times and didnt get any run time error, hope it get solved, but Im litle frustrated because I didnt know WHY this error appears, hope It will never backs again...!

Anyway, thank Abhi for helping me ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) I will make this topic at "solved"
Link to comment
Share on other sites

OH WELL I think that this is the problem:

I changed this line

NpcAttackPlayer MapNpcNum, Victim, Damage

To this

```
SpellPlayer_Effect Vitals.HP, False, Victim, Damage, SpellNum
```

Because I dont want to hear the Npc sound, only the Spell sound

But NOW, the Npc lows my life to 0!! AND Im still alive!! xD its better because there is no error crashing the server, but I think that I have to leave the code intact, and hear the Npc voice ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)

So… Its Ok ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png), solved ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)

Or maybe somebody can give me a tip to fix it :$ (?)

Thx for reading!
Link to comment
Share on other sites

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...