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

Npc Arrows Possible with This Code?


Kamakazi
 Share

Recommended Posts

Ok the following is a Source Tutorial by Anarky77 for Ranged NPC's and Diagonal Attacks. According to someone's post in the forementioned, this can be "easily" used to implement Npc Arrows. Can someone please take a look at the following and help me find a way to make Npc Arrows possible? It would be GREATLY appreciated.  XD

BTW, I'm hopin to have ALL my Npc's use arrows, if that makes it easier…

@Anarky77:

> Hey all, this is my first tutorial on here, and I figured this was something really easy for beginner programmers (like me!)  in EE and also adds a nice improvement to the NPC's.
>
> Ok Im assuming you have VB6, and the source of EE because you are here, so no need to go through all that.
>
> First, Open up the  Server.vbp source in VB6.
>
> Locate the module **ModGameLogic**
>
> Now… you need to find the Function...
>
> **CanNpcAttackPlayer**
>
> Im going to paste my entire Function here, so you are welcome to copy and paste and just use that… but its very simple to see whats going on. Instead of there being just one set for the NPC to attack you, there is 5\. So if you are anywhere between 1 and 5 tiles from the NPC, he will attack you (in ALL directions, and diagonal) so its alot more fun, and gives the NPC a little more bite.
>
> ok...
>
> replace the entire Function **CanNpcAttackPlayer** with this:
>
> ```
> Function CanNpcAttackPlayer(ByVal MapNpcNum As Long, ByVal Index As Long) As Boolean
>     Dim MapNum As Long
>     Dim NPCnum As Long
>
>     If Not IsPlaying(Index) Then
>         Exit Function
>     End If
>
>     ' Make sure the NPC map number isn't out-of-range.
>     If MapNpcNum < 1 Or MapNpcNum > MAX_MAP_NPCS Then
>         Exit Function
>     End If
>
>     ' Make sure that it's a valid NPC.
>     If MapNPC(GetPlayerMap(Index), MapNpcNum).num < 1 Then
>         Exit Function
>     End If
>
>     MapNum = GetPlayerMap(Index)
>     NPCnum = MapNPC(MapNum, MapNpcNum).num
>
>     ' NPC isn't already dead?.
>     If MapNPC(MapNum, MapNpcNum).HP < 1 Then
>         Exit Function
>     End If
>
>     ' NPCs don't attack more then once a second.
>     If GetTickCount < MapNPC(MapNum, MapNpcNum).AttackTimer + 1000 Then
>         Exit Function
>     End If
>
>     'don't attack a player if they are switching maps.
>     If Player(Index).GettingMap = YES Then
>         Exit Function
>     End If
>
>     MapNPC(MapNum, MapNpcNum).AttackTimer = GetTickCount
>
>     If IsPlaying(Index) Then
>         If NPCnum > 0 Then
>           If (GetPlayerY(Index) + 1 = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) = MapNPC(MapNum, MapNpcNum).X) Then
>                 CanNpcAttackPlayer = True
>             Else
>             If (GetPlayerY(Index) - 1 = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) = MapNPC(MapNum, MapNpcNum).X) Then
>                     CanNpcAttackPlayer = True
>                 Else
>                 If (GetPlayerY(Index) = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) + 1 = MapNPC(MapNum, MapNpcNum).X) Then
>                         CanNpcAttackPlayer = True
>                     Else
>                     If (GetPlayerY(Index) = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) - 1 = MapNPC(MapNum, MapNpcNum).X) Then
>                             CanNpcAttackPlayer = True
>                         End If
>                     End If
>                 End If
>             End If
>         End If
>     End If
>
>     '======next set============
>
>     If IsPlaying(Index) Then
>
>         If NPCnum > 0 Then
>             If (GetPlayerY(Index) + 2 = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) = MapNPC(MapNum, MapNpcNum).X) Then
>                 CanNpcAttackPlayer = True
>             Else
>             If (GetPlayerY(Index) - 2 = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) = MapNPC(MapNum, MapNpcNum).X) Then
>                     CanNpcAttackPlayer = True
>                 Else
>                 If (GetPlayerY(Index) = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) + 2 = MapNPC(MapNum, MapNpcNum).X) Then
>                         CanNpcAttackPlayer = True
>                     Else
>                     If (GetPlayerY(Index) = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) - 2 = MapNPC(MapNum, MapNpcNum).X) Then
>                             CanNpcAttackPlayer = True
>                         End If
>                     End If
>                 End If
>             End If
>         End If
>     End If
>    
>     '====next set=============
>
>     If IsPlaying(Index) Then
>         If NPCnum > 0 Then
>           If (GetPlayerY(Index) + 3 = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) = MapNPC(MapNum, MapNpcNum).X) Then
>                 CanNpcAttackPlayer = True
>             Else
>             If (GetPlayerY(Index) - 3 = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) = MapNPC(MapNum, MapNpcNum).X) Then
>                     CanNpcAttackPlayer = True
>                 Else
>                 If (GetPlayerY(Index) = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) + 3 = MapNPC(MapNum, MapNpcNum).X) Then
>                         CanNpcAttackPlayer = True
>                     Else
>                     If (GetPlayerY(Index) = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) - 3 = MapNPC(MapNum, MapNpcNum).X) Then
>                             CanNpcAttackPlayer = True
>                         End If
>                     End If
>                 End If
>             End If
>         End If
>     End If
>
>     '-====next set=============
>     If IsPlaying(Index) Then
>         If NPCnum > 0 Then
>           If (GetPlayerY(Index) + 4 = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) = MapNPC(MapNum, MapNpcNum).X) Then
>                 CanNpcAttackPlayer = True
>             Else
>             If (GetPlayerY(Index) - 4 = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) = MapNPC(MapNum, MapNpcNum).X) Then
>                     CanNpcAttackPlayer = True
>                 Else
>                 If (GetPlayerY(Index) = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) + 4 = MapNPC(MapNum, MapNpcNum).X) Then
>                         CanNpcAttackPlayer = True
>                     Else
>                     If (GetPlayerY(Index) = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) - 4 = MapNPC(MapNum, MapNpcNum).X) Then
>                             CanNpcAttackPlayer = True
>                         End If
>                     End If
>                 End If
>             End If
>         End If
>     End If
>    
>     '======next set ===============
>     If IsPlaying(Index) Then
>         If NPCnum > 0 Then
>             If (GetPlayerY(Index) + 5 = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) = MapNPC(MapNum, MapNpcNum).X) Then
>                 CanNpcAttackPlayer = True
>             Else
>             If (GetPlayerY(Index) - 5 = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) = MapNPC(MapNum, MapNpcNum).X) Then
>                     CanNpcAttackPlayer = True
>                 Else
>                 If (GetPlayerY(Index) = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) + 5 = MapNPC(MapNum, MapNpcNum).X) Then
>                         CanNpcAttackPlayer = True
>                     Else
>                     If (GetPlayerY(Index) = MapNPC(MapNum, MapNpcNum).Y) And (GetPlayerX(Index) - 5 = MapNPC(MapNum, MapNpcNum).X) Then
>                             CanNpcAttackPlayer = True
>                         End If
>                     End If
>                 End If
>             End If
>         End If
>     End If
>
> '-====================
> End Function
> ```
>
> There.. see how its +1, -1, then all +2 -2 etc etc… just means that no matter where you are around the npc, within 5 tiles... you better hit back or run.
>
> Ok. SAVE and run.. you are done.
>
> Now experienced programmers, I know that is probably a horrible way to do it, but it works. Also, you can add as many sets as you want to give your NPC more range.
>
> Thats it, just run I lost and attack your NPC... see how much more aggro he is. NOTE: this will affect ALL your NPC's. So if you want this to be for special NPC's, I suggest adding a scripted NPC line into that function, and simply only use those ranges if it is a scripted NPC. Then all normal NPCS would attack 1 tile away as per usual.
>
> Im going to put a slider in the NPC editor to allow for this range later, as its pretty stable and I would like to have the NPC speed and Range option in the NPCeditor .
>
> You can also make the NPC fire spells back at you using this edited source above. Just script the spell anim and use Dragon Lees ranged spell NPC script, the ideas I got were form there and Barons Main.txt, so thanks to both those guys.
>
> I know this is not technically a ranged attack, as there is no bullet or arrow, but my next tutorial will be on how to make that happen in conjunction with this.
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...