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

Ranged Weapon Script (Work In Progress)


ZeoWorks
 Share

Recommended Posts

Hello everyone! :)
My name is Sean, I live in the UK and I have noticed that there are no ranged weapon scripts for EO (yet).

So I have decided to work on a ranged weapon script to share with you all.  :cheesy:
However durning the progress of making the script I am facing a problem..

When the script checks if the NPC is within 5 tiles or less near the player then the player is ment to fire the ranged weapon it will damage the npc when he/she presses the CTRL key.  But here is the problem, The npc HAS to be 5 tiles away from the player or the player can't attack the npc.

Here is the part of the script were I get this bug:

```
          Case DIR_UP         
                    NpcX = MapNpc(mapNum).Npc(mapNpcNum).x
                    NpcY = MapNpc(mapNum).Npc(mapNpcNum).y + 5             
```
I thought if I changed it to this it would work, But I was wrong:
```
          Case DIR_UP         
                    NpcX = MapNpc(mapNum).Npc(mapNpcNum).x
                    NpcY = MapNpc(mapNum).Npc(mapNpcNum).y + 1 Or 2 Or 3 Or 4 Or 5       
```
Could someone please tell me how to make the script check that if the npc is 5 tiles or less away from the player? I will send you guys the script once its done. Thanks!  :cheesy:
Link to comment
Share on other sites

Try it like this:

Get the players Y and X coordinates. (GetPlayerX/Y(index)) Then NpcY minus PlayerY. Then check if the difference is more than 5\. If its more then do the damage.
EDIT: sry iforgot to add, it can be negative too, so check if its lower than -5 too.
Link to comment
Share on other sites

```
' ...
' Makes our code look pretty:
Dim NpcX As Long
Dim NpcY As Long
NpcX = MapNpc(mapNum).Npc(mapNpcNum).x
NpcY = MapNpc(mapNum).Npc(mapNpcNum).y

' Choose the player's direction.
Select Case GetPlayerDir(index)
Case DIR_UP
If GetPlayerX(index) = NpcX AND GetPlayerY(index) - NpcY <= 5 AND GetPlayerY(index) - NpcY > 0 Then
' Make sure their X is the same.
' Make sure the difference between their Y's is less than or equal to 5 (in shooting range)
' Make sure the difference between their Y's is more than 0 (they are not on the same spot or the Npc is behind the player.
Call ArrowStuff (GetPlayerX(index), GetPlayerY(index)) ' No idea how your function is set up. Change.
End If
Case DIR_DOWN
If GetPlayerX(index) = NpcX AND NpcY - GetPlayerY(index) <= 5 AND NpcY - GetPlayerY(index) > 0 Then
' Flip the equation around, is the NpcY minus the PlayerY less than or equal to 5 (in shooting range)
' Make sure they're not at the same spot.
Call ArrowStuff (GetPlayerX(index), GetPlayerY(index)) ' No idea how your function is set up. Change.
End If

' The other cases are left as an exercise to the reader. You should be able to apply the above to your own formulation.
End Select
' Do the rest of the function

```
This code isn't complete (read through the comments). If you read it you should be able to understand it (I think), if not, I'm willing to help.

* * *

@Octohunter:

> Use a loop.
> ```
> For i = 1 to 5
>     Case DIR_UP         
>             NpcX = MapNpc(mapNum).Npc(mapNpcNum).x
>             NpcY = MapNpc(mapNum).Npc(mapNpcNum).y + i
> Next             
>
> ```

That is incorrect in two senses. You are not allowed to put a case in a loop, (or it shouldn't let you, because that's very weird). And also the code is unclear and slower than just doing checks.
Link to comment
Share on other sites

@Octohunter:

> The select case part is supposed to be in there too, it's just that I didn't add it.  Also, what do you mean by unclear?

Look at your code, let me cut out the fat:
```
For i = 1 To 5 ' This part would never be executed, it has no case.
    Case 0
Next ' Therefore this /should/ draw an error, although I can't guarantee it will in VB6.

```
See what you just did? It should be:
```
    Case 0
    For i = 1 To 5 ' This part will be executed when x is 0.
    Next ' And this is normal.

```
The unclear part is quite simple:
```
    Case DIR_UP       
            For i = 1 to 5
                NpcX = MapNpc(mapNum).Npc(mapNpcNum).x
                NpcY = MapNpc(mapNum).Npc(mapNpcNum).y + i
            Next 

```
Think about what you're doing. You're adding i to your interpretation of the Npc's Y. What is that supposed to do?

XXNXX
XXRXX
XXRXX
XXRXX
XXPXX
XXXXX

Where N is the NPC, P is the player (assumed north) and R is the range of the arrow (implied NPC point).

In this diagram, incrementing the NPC Y does… what? Do you plan to check against the player's Y? That's slow and unreasonable. I hope you plan to check the Player's X as well, because you could end up with the player's x being different than the NPC's.

I think this should very well make my point, if you really need continuation I could run some speed tests for you.
Link to comment
Share on other sites

  • 3 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...