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

Only hurt by certain wep?


Zarnick123
 Share

Recommended Posts

```
Sub OnAttack(Index, Damage)
  If Int(Damage) > 0 Then
      If Int(GetPlayerTarget(Index)) > 0 Then
        Target = GetPlayerTarget(Index)
        Call DamagePlayer(Index, Target, Damage)
      Else
        Target = GetPlayerTargetNPC(Index)
        Call DamageNPC(Index, Target, Damage)
      End If
  End If
End Sub
```
Here's the default OnAttack sub. The first thing you'll need to do is incorporate Admiral's weapon check. This can go at the top of the sub:

```
If GetPlayerWeaponSlot(index) > 0 Then
  Weapon = Int(GetPlayerInvItemNum(index, GetPlayerWeaponSlot(index)))
Else
  Weapon = 0
End If

```

Now, NPC damaging comes after the Else in this sub, so start there. The DamageNPC line is the only line you'll need to enclose with If-statements. You'll have two checks to do. The first is a check on the target number, and the second is a check on the weapon. I'll assume you'll be doing checks on targets more, so we'll use the target as our Select Case switch. You'll need to make cases for each target that you'll check on, COMBINED with conditionals for the weapons, like so:

```
Select Case Target
  Case 1 and Weapon = 5 'NPC 1 takes only half damage from weapon 5, for example
    Damage = Int(Damage /  2)
  Case 5 and (Weapon = 4 or weapon = 7) 'NPC 5 is immune to both weapon 4 and 7
    Damage = 0
  Case 5 and Weapon = 6 'NPC 5 is weak against weapon 6, though
    Damage = Damage * 2
End Select

```
This will go above the damage line. I've provided examples of how to use the cases for various things and how to check multiple items for a single NPC, if necessary.

All together, your new sub looks something like so:

```
Sub OnAttack(Index, Damage)
  If GetPlayerWeaponSlot(index) > 0 Then
      Weapon = Int(GetPlayerInvItemNum(index, GetPlayerWeaponSlot(index)))
  Else
      Weapon = 0
  End If

  If Int(Damage) > 0 Then
      If Int(GetPlayerTarget(Index)) > 0 Then
        Target = GetPlayerTarget(Index)
        Call DamagePlayer(Index, Target, Damage)
      Else
        Target = GetPlayerTargetNPC(Index)

        Select Case Target
            Case 1 and Weapon = 5 'NPC 1 takes only half damage from weapon 5, for example
              Damage = Damage  2
            Case 5 and (Weapon = 4 or weapon = 7) 'NPC 5 is immune to both weapon 4 and 7
              Damage = 0
            Case 5 and Weapon = 6 'NPC 5 is weak against weapon 6, though
              Damage = Damage * 2
        End Select

        Call DamageNPC(Index, Target, Damage)
      End If
  End If
End Sub

```
Oddly enough, I think I just wrote _my_ new OnAttack sub. I like what I've done here.  :P
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...