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

Code fix


Peter120
 Share

Recommended Posts

Problem: I've some problem with my HealHP and HealMP spells… It not cost mana, (whatever I set) It can be used on Any NPC (and overheal them :O) And there is no cooldown time (whatever I set)

Robin Said:Yeah, it's bugged. Simply take the code which removes MP and add it to the Heal spell switch.

Erwin said:You need some programming knowledge to do it..

I need: A tutorial to do it

Please Help!
Link to comment
Share on other sites

@Robin:

> Yes it is.

I feel as if we should start moving these to Questions & Answers and begin doing requests there as well, for categorization purposes. Most systems have posts in the Tutorials board and I wouldn't have a problem to start requests for those that aren't.

Anyway, back to answering the original question.

* * *

**Everything is server-side.**

**Part 1: Fixing overhealing**
Find:
```
MapNpc(mapNum).Npc(index).Vital(Vitals.HP) = MapNpc(mapNum).Npc(index).Vital(Vitals.HP) + Spell(.Spell).Vital

```
and under that add:
```
If MapNpc(mapNum).Npc(index).Vital(Vitals.HP) > GetNpcMaxVital(MapNpc(mapNum).Npc(index).Num, Vitals.HP) Then MapNpc(mapNum).Npc(index).Vital(Vitals.HP) = GetNpcMaxVital(MapNpc(mapNum).Npc(index).Num, Vitals.HP)

```

>! The line above this sets the NPC's health. However, the next line checks if it is over the maximum amount of health an NPC can have. If it is, it is moved back down.

Find:
```
MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital) + Damage

```
and under it add:
```
If MapNpc(mapNum).Npc(index).Vital(Vital) > GetNpcMaxVital(MapNpc(mapNum).Npc(index).Num, Vital) Then MapNpc(mapNum).Npc(index).Vital(Vital) = GetNpcMaxVital(MapNpc(mapNum).Npc(index).Num, Vital)

```

>! Same logic as the other NPC fix. You'll note that Vitals.HP will change to Vital because the function is generalized.

We can put nicer code in for players because there is already a neat little function for them!

Next find:
```
Player(index).Vital(Vitals.HP) = Player(index).Vital(Vitals.HP) + Spell(.Spell).Vital

```
_and replace(!) it with:_
```
SetPlayerVital index, Vitals.HP, GetPlayerVital(index, Vitals.HP) + Spell(.Spell).Vital

```

>! The SetPlayerVital function already takes care of all this for us, so all we have to do is give it the amount we want to set it to and let it work. For this reason, we don't need the old code that set it.

* * *

_Part 2: Adding mana cost AND fixing cooldown_

The solution here is simple and elegant. Unfortunately many of the lines repeat so it's hard to put it in easy tutorial form. Instead I'll just give you the code to replace.

Find this big chunk of code:
```
                    If targetType = TARGET_TYPE_PLAYER Then
                        If Spell(spellnum).Type = SPELL_TYPE_DAMAGEMP Then
                            If CanPlayerAttackPlayer(index, target, True) Then
                                SpellPlayer_Effect VitalType, increment, target, Vital, spellnum
                            End If
                        Else
                            SpellPlayer_Effect VitalType, increment, target, Vital, spellnum
                        End If
                    Else
                        If Spell(spellnum).Type = SPELL_TYPE_DAMAGEMP Then
                            If CanPlayerAttackNpc(index, target, True) Then
                                SpellNpc_Effect VitalType, increment, target, Vital, spellnum, mapNum
                            End If
                        Else
                            SpellNpc_Effect VitalType, increment, target, Vital, spellnum, mapNum
                        End If
                    End If

```
(hint: modCombat.bas, about line 1316)

And replace it with:
```
                    If targetType = TARGET_TYPE_PLAYER Then
                        If Spell(spellnum).Type = SPELL_TYPE_DAMAGEMP Then
                            If CanPlayerAttackPlayer(index, target, True) Then
                                SpellPlayer_Effect VitalType, increment, target, Vital, spellnum
                                DidCast = True
                            End If
                        Else
                            SpellPlayer_Effect VitalType, increment, target, Vital, spellnum
                            DidCast = True
                        End If
                    Else
                        If Spell(spellnum).Type = SPELL_TYPE_DAMAGEMP Then
                            If CanPlayerAttackNpc(index, target, True) Then
                                SpellNpc_Effect VitalType, increment, target, Vital, spellnum, mapNum
                                DidCast = True
                            End If
                        Else
                            SpellNpc_Effect VitalType, increment, target, Vital, spellnum, mapNum
                            DidCast = True
                        End If
                    End If

```

>! The DidCast flag is used by the other spells to set cooldown and take mana. Unfortunately, the damage MP and heal MP and HP didn't do it.

* * *

**Done!** As always, post if you have problems.
Link to comment
Share on other sites

@Robin:

> Yes it is.

O, sorry, I thought this was Q&A.
Anyways, I think its bad to do all stuff people want for them, it makes then lazy and nobody has made a good game with lazyness so that means we're spending time..
Still, I think its good to help people with their programming questions and learn them the bits of VB6.
Link to comment
Share on other sites

@Erwin:

> O, sorry, I thought this was Q&A.
> Anyways, I think its bad to do all stuff people want for them, it makes then lazy and nobody has made a good game with lazyness so that means we're spending time..
> Still, I think its good to help people with their programming questions and learn them the bits of VB6.

It's amazing how uppity people get when they learn a bit of knowledge. You were the exact same when you started.
Link to comment
Share on other sites

@Robin:

> It's amazing how uppity people get when they learn a bit of knowledge. You were the exact same when you started.

Yes, but I've learned that I shouldnt be lazy and learn programming so I did.

And with: let someone do it for you I meant pay someone for it to do it or find someone who is going to help you, I just want to help you, I was exactly thesame when I started around here, but people said I should learn VB6 and I did, now things are way easier for me.

If you want to do it this way I'm ok with that, but I feelt like I should say to you that it really helped me learning VB6.
Link to comment
Share on other sites

@Peter120:

> I did it correctly

I'm sorry, the blame is partially mine  :embarrassed:. I saw that the player code had a check for it in SetPlayerVital and I assumed the NPC did something similar, so I didn't check it. You could probably figure it out by yourself (it uses the same logic), but this should fix it anyway.

Find:
```
MapNpc(mapNum).Npc(index).Vital(Vital) = MapNpc(mapNum).Npc(index).Vital(Vital) + Damage

```
and under it add:
```
If MapNpc(mapNum).Npc(index).Vital(Vital) > GetNpcMaxVital(MapNpc(mapNum).Npc(index).Num, Vital) Then MapNpc(mapNum).Npc(index).Vital(Vital) = GetNpcMaxVital(MapNpc(mapNum).Npc(index).Num, Vital)

```

>! Same logic as the other NPC fix. You'll note that Vitals.HP will change to Vital because the function is generalized.
Link to comment
Share on other sites

  • 2 weeks 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...