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

Auto-Target NPC & Player


m4hud17
 Share

Recommended Posts

Hei guys, this is my first post and also my first mod :D

This mod, allow you to targetting the enemy without click the enemy. This mod was tested in EO TFF(EO 3.0).

These all just edit the server

okay, there's three kind :

1\. auto-target Npc when it attack you.

First, in modCombat :

```
Sub NpcAttackPlayer
```
find,

```
TempPlayer(victim).stopRegenTimer = GetTickCount
```
under that, add :

```
If TempPlayer(victim).targetType = 0 And TempPlayer(victim).target = 0 Then

TempPlayer(victim).targetType = 2 'NPC

    TempPlayer(victim).target = MapNpcNum

    SendTarget victim

End If
```
2\. auto-target Npc when you use non AoE spell and don't have any target.

Find :

```
Public Sub BufferSpell(ByVal index As Long, ByVal spellslot As Long)
```
Then find :

```
If Not target > 0 Then
    PlayerMsg index, "You do not have a target.", BrightRed
End If
```
Change it into :

```
If Not target > 0 Then
    TempPlayer(index).targetType = TARGET_TYPE_NPC
    TempPlayer(index).target = FindNPCInRange(index, mapnum, Range)
    SendTarget index
    targetType = TempPlayer(index).targetType
    target = TempPlayer(index).target
    'if it's still 0
    If target = 0 Then
        PlayerMsg index, "No enemies nearby.", BrightRed
        SendClearSpellBuffer index
        Exit Sub
    End If
End If
```

3\. The last, it's auto-target when Npc targetting you

first, in modServerLoop find
```
Private Sub UpdateMapLogic()
```
Then, under it add :

```
Dim index As Long
```
then, find :

```
    MapNpc(mapnum).NPC(x).targetType = 1 ' player
    MapNpc(mapnum).NPC(x).target = I
End If
```

change it into :

```
    MapNpc(mapnum).NPC(x).targetType = 1 ' player
    MapNpc(mapnum).NPC(x).target = I
    For index = 1 To MAX_PLAYERS
        If TempPlayer(index).targetType = 0 And TempPlayer(index).target = 0 Then
           TempPlayer(index).targetType = 2 'npc
           TempPlayer(index).target = x
           SendTarget index
        End If
    Next index
End If
```
Finish, Sorry for my bad english  :P  :P  :P

You can auto target when you attack, it's also work with projectiles

first, in modCombat, CanPlayerAttackNpc find

```
                           If Map(GetPlayerMap(attacker)).Tile(GetPlayerX(attacker) + pX, GetPlayerY(attacker) + pY).Type <> TILE_TYPE_BLOCKED And Map(GetPlayerMap(attacker)).Tile(GetPlayerX(attacker) + pX, GetPlayerY(attacker) + pY).Type <> TILE_TYPE_RESOURCE Then
                                CanPlayerAttackNpc = True
                            End If
```
change it to

```
                               If Map(GetPlayerMap(attacker)).Tile(GetPlayerX(attacker) + pX, GetPlayerY(attacker) + pY).Type <> TILE_TYPE_BLOCKED And Map(GetPlayerMap(attacker)).Tile(GetPlayerX(attacker) + pX, GetPlayerY(attacker) + pY).Type <> TILE_TYPE_RESOURCE Then
If TempPlayer(attacker).target = 0 Then
                                TempPlayer(attacker).targetType = TARGET_TYPE_NPC
                                TempPlayer(attacker).target = MapNpcNum
                                SendTarget attacker
End If
                                CanPlayerAttackNpc = True
                            End If
```
For auto targeting player

in CanPlayerAttackPlayer, above the end function add

```
If TempPlayer(attacker).target = 0 Then
    TempPlayer(attacker).targetType = TARGET_TYPE_PLAYER
    TempPlayer(attacker).target = victim
    SendTarget attacker
End If
If TempPlayer(victim).target = 0 Then
    TempPlayer(victim).targetType = TARGET_TYPE_PLAYER
    TempPlayer(victim).target = attacker
    SendTarget victim
End If
```
Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...
Ah it's auto-target when you use non AOE spell, but still, i want it to target the nearest NPC, or at last NPC in spell range.

or maybe you know how to do AoE spell doesn't require auto-target?

ps:

Missed code (in modgamelogic):

```
Function FindNPCInRange(ByVal Index As Long, ByVal mapnum As Long, ByVal Range As Long)
Dim x As Long, y As Long
Dim npcX As Long, npcY As Long
Dim i As Long

FindNPCInRange = 0

For i = 1 To MAX_MAP_NPCS
x = GetPlayerX(Index)
y = GetPlayerY(Index)
npcX = MapNpc(mapnum).NPC(i).x
npcY = MapNpc(mapnum).NPC(i).y

If isInRange(Range, x, y, npcX, npcY) Then
If MapNpc(mapnum).NPC(i).Num > 0 Then
If NPC(MapNpc(mapnum).NPC(i).Num).Behaviour = NPC_BEHAVIOUR_ATTACKONSIGHT Or NPC(MapNpc(mapnum).NPC(i).Num).Behaviour = NPC_BEHAVIOUR_ATTACKWHENATTACKED Then
FindNPCInRange = i
Exit Function
End If
End If
End If

Next i

End Function

```
Link to comment
Share on other sites

  • 2 weeks later...
```
Function FindNPCInRange(ByVal Index As Long, ByVal mapnum As Long, ByVal Range As Long)
Dim x As Long, y As Long
Dim npcX As Long, npcY As Long
Dim i As Long

FindNPCInRange = 0
x = GetPlayerX(Index)
y = GetPlayerY(Index)

For i = 1 To MAX_MAP_NPCS

npcX = MapNpc(mapnum).NPC(i).x
npcY = MapNpc(mapnum).NPC(i).y

If isInRange(Range, x, y, npcX, npcY) Then
If MapNpc(mapnum).NPC(i).Num > 0 Then
If NPC(MapNpc(mapnum).NPC(i).Num).Behaviour = NPC_BEHAVIOUR_ATTACKONSIGHT Or NPC(MapNpc(mapnum).NPC(i).Num).Behaviour = NPC_BEHAVIOUR_ATTACKWHENATTACKED Then
FindNPCInRange = i
Exit Function
End If
End If
End If

Next i

End Function

```
Use this instead. There's no reason to calculate the player's x/y position every iteration.
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...