[EO 2.0] Fixing HP-healing spells increasing NPCs' max health

There’s a bug in EO that causes NPCs’ health to increase above their max health. All of this code is serverside.

Replace your Sub SpellNPC_Effect with this:

Public Sub SpellNpc_Effect(ByVal Vital As Byte, ByVal increment As Boolean, ByVal index As Long, ByVal Damage As Long, ByVal spellnum As Long, ByVal mapNum As Long)

Dim sSymbol As String * 1

Dim Colour As Long

    If Damage > 0 Then

	    If increment Then

		    sSymbol = "+"

		    If Vital = Vitals.HP Then Colour = BrightGreen

		    If Vital = Vitals.mp Then Colour = BrightBlue

	    Else

		    sSymbol = "-"

		    Colour = Blue

	    End If

	    SendAnimation mapNum, Spell(spellnum).SpellAnim, 0, 0, TARGET_TYPE_NPC, index

	    SendActionMsg mapNum, sSymbol & Damage, Colour, ACTIONMSG_SCROLL, MapNpc(mapNum).Npc(index).x * 32, MapNpc(mapNum).Npc(index).y * 32

	    ' send the sound

	    SendMapSound index, MapNpc(mapNum).Npc(index).x, MapNpc(mapNum).Npc(index).y, SoundEntity.seSpell, spellnum

	    If increment Then

		    If MapNpc(mapNum).Npc(index).Vital(Vital) + Damage <= GetNpcMaxVital(index, Vitals.HP) Then

			    MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital) + Damage

		    Else

			    MapNpc(mapNum).Npc(index).Vital(Vital) = GetNpcMaxVital(index, Vitals.HP)

		    End If

		    If Spell(spellnum).Duration > 0 Then

			    AddHoT_Npc mapNum, index, spellnum

		    End If

	    ElseIf Not increment Then

		    MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital) - Damage

	    End If

    End If

End Sub

And your HandleHoT_NPC with this:

Public Sub HandleHoT_Npc(ByVal mapNum As Long, ByVal index As Long, ByVal hotNum As Long)

    With MapNpc(mapNum).Npc(index).HoT(hotNum)

	    If .Used And .Spell > 0 Then

		    ' time to tick?

		    If GetTickCount > .Timer + (Spell(.Spell).Interval * 1000) Then

			    If Spell(.Spell).Type = SPELL_TYPE_HEALHP Then

				    SendActionMsg mapNum, "+" & Spell(.Spell).Vital, BrightGreen, ACTIONMSG_SCROLL, MapNpc(mapNum).Npc(index).x * 32, MapNpc(mapNum).Npc(index).y * 32

				    MapNpc(mapNum).Npc(index).Vital(Vitals.HP) = MapNpc(mapNum).Npc(index).Vital(Vitals.HP) + Spell(.Spell).Vital

				    If MapNpc(mapNum).Npc(index).Vital(Vitals.HP) > GetNpcMaxVital(index, Vitals.HP) Then

					    MapNpc(mapNum).Npc(index).Vital(Vitals.HP) = GetNpcMaxVital(index, Vitals.HP)

				    End If

			    Else

				    SendActionMsg mapNum, "+" & Spell(.Spell).Vital, BrightBlue, ACTIONMSG_SCROLL, MapNpc(mapNum).Npc(index).x * 32, MapNpc(mapNum).Npc(index).y * 32

				    MapNpc(mapNum).Npc(index).Vital(Vitals.mp) = MapNpc(mapNum).Npc(index).Vital(Vitals.mp) + Spell(.Spell).Vital

				    If MapNpc(mapNum).Npc(index).Vital(Vitals.mp) > GetNpcMaxVital(index, Vitals.mp) Then

					    MapNpc(mapNum).Npc(index).Vital(Vitals.mp) = GetNpcMaxVital(index, Vitals.mp)

				    End If

			    End If

			    .Timer = GetTickCount

			    ' check if DoT is still active - if NPC died it'll have been purged

			    If .Used And .Spell > 0 Then

				    ' destroy hoT if finished

				    If GetTickCount - .StartTime >= (Spell(.Spell).Duration * 1000) Then

					    .Used = False

					    .Spell = 0

					    .Timer = 0

					    .Caster = 0

					    .StartTime = 0

				    End If

			    End If

		    End If

	    End If

    End With

End Sub

I love you.

A long time bug I believe. And a long awaited fix also.

This fix work on ea ?

Variabe not defined

(mapNum)

Probably but I’m not going to help you fix a broken mess.

A better way of doing it is this:

If MapNpc(mapNum).Npc(index).Vital(Vital) + Damage > then

MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital)

else

MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital) + Damage

End If

Else it wouldn’t heal anything is the full heal will go over the NPC’s max health. ;)

Oh yeah, woops, didn’t notice that. Thanks xD.

A better way of doing it is this:

If MapNpc(mapNum).Npc(index).Vital(Vital) + Damage > then

MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital)

else

MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital) + Damage

End If

Else it wouldn’t heal anything is the full heal will go over the NPC’s max health. ;)

Syntax error on

If MapNpc(mapNum).NPC(index).Vital(Vital) + Damage > then

You meant

A better way of doing it is this:

If MapNpc(mapNum).Npc(index).Vital(Vital) + Damage > MapNpc(mapNum).Npc(index).Vital(Vital) then

MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital)

else

MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital) + Damage

End If

EDIT: Which doesn’t work

Trying to figure out how to put GetNpcMaxVital(npcNum, Vitals.HP) in there

Dangit, sorry for double post. No delete button I can find.

Would this work?

MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital) + Damage

If MapNpc(mapNum).NPC(index).Vital(Vitals.HP) > GetNpcMaxVital(npcNum, Vitals.HP) Then

MapNpc(mapNum).NPC(index).Vital(Vitals.HP) = GetNpcMaxVital(npcNum, Vitals.HP)

Nope…GRRRRR…

FINAL EDIT IN RAGE.

Okay, I got tired of ducking around with it, so I edited Case 2 'targetted in CastSpell and did this

If targetType = TARGET_TYPE_PLAYER Then

x = GetPlayerX(target)

y = GetPlayerY(target)

Else

Exit Sub

End If

So you can’t heal NPCs at all.

I also commented out the AoE heal part just above it:

'For i = 1 To MAX_MAP_NPCS

’ If MapNpc(mapNum).NPC(i).Num > 0 Then

’ If MapNpc(mapNum).NPC(i).Vital(HP) > 0 Then

’ If isInRange(AoE, x, y, MapNpc(mapNum).NPC(i).x, MapNpc(mapNum).NPC(i).y) Then

’ SpellNpc_Effect VitalType, increment, i, Vital, spellnum, mapNum

’ End If

’ End If

’ End If

'Next


If MapNpc(mapNum).NPC(index).Vital(Vitals.HP) > GetNpcMaxVital(index, Vitals.HP) Then

Would work. I’ll edit the post later with a rewritten sub.

EDIT: Updated.

Very thanx for this fix

Nicely done.

Good, I liked, I love fix

Log in to reply