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

Block If Without End If


Rydo
 Share

Recommended Posts

@DrunkenHyena:

> Means you're missing an end if to match one of your ifs. In this case the If missing an end if is,
>
> ```
> if Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_
>
> ```
> As well as an end if for the two if statements above it.

I basically took half of that in. So basically some of the Ifs are missing End If? Also where about would I put the End If's since there are more needed?
Link to comment
Share on other sites

```
If NpcX = GetPlayerX(Attacker) Then
                If NpcY = GetPlayerY(Attacker) Then
                    If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_MANAGER Then 'House Editor
                        CanPlayerAttackNpc = True
                    Else
                        'House Editor
                        If Npc(npcNum).Behaviour = NPC_BEHAVIOUR_MANAGER Then
                            Call SendInitManager(Attacker, CInt(GetVar(App.Path & "\data\accounts\houses.ini", "OPTIONS", "" & Player(Attacker).Name)), Npc(npcNum).HMapNum, Npc(npcNum).HBuy, Npc(npcNum).HSell)
                            End If
                        '/House Editor

                        If Len(Trim$(Npc(npcNum).AttackSay)) > 0 Then
                            PlayerMsg Attacker, Trim$(Npc(npcNum).Name) & ": " & Trim$(Npc(npcNum).AttackSay), White
                        End If
      End Function
```
Link to comment
Share on other sites

```
Public Function CanPlayerAttackNpc(ByVal Attacker As Long, ByVal mapNpcNum As Long, Optional ByVal IsSpell As Boolean = False) As Boolean
    Dim mapNum As Long
    Dim npcNum As Long
    Dim NpcX As Long
    Dim NpcY As Long
    Dim attackspeed As Long

    ' Check for subscript out of range
    If IsPlaying(Attacker) = False Or mapNpcNum <= 0 Or mapNpcNum > MAX_MAP_NPCS Then
        Exit Function
    End If

    ' Check for subscript out of range
    If MapNpc(GetPlayerMap(Attacker)).Npc(mapNpcNum).Num <= 0 Then
        Exit Function
    End If

    mapNum = GetPlayerMap(Attacker)
    npcNum = MapNpc(mapNum).Npc(mapNpcNum).Num

    ' Make sure the npc isn't already dead
    If MapNpc(mapNum).Npc(mapNpcNum).Vital(Vitals.HP) <= 0 Then
        If Npc(MapNpc(mapNum).Npc(mapNpcNum).Num).Behaviour <> NPC_BEHAVIOUR_FRIENDLY Then
            If Npc(MapNpc(mapNum).Npc(mapNpcNum).Num).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER Then
                Exit Function
            End If
        End If
    End If

    ' Make sure they are on the same map
    If IsPlaying(Attacker) Then

        ' exit out early
                    If IsSpell Then
                If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_MANAGER Then
                    CanPlayerAttackNpc = True
                    Exit Function
                End If
            End If
            If npcNum > 0 Then
                If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER Then
                    Dim petowner As Long
                    TempPlayer(Attacker).targetType = TARGET_TYPE_NPC
                    TempPlayer(Attacker).target = mapNpcNum
                    SendTarget Attacker
                    CanPlayerAttackNpc = True
                    Exit Function
                End If
            End If
        End If

    If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        petowner = MapNpc(mapNum).Npc(mapNpcNum).PetData.Owner
        If Attacker = petowner Then
            Call PlayerMsg(Attacker, "You can't attack your own pet.", BrightRed)
            Exit Function
        End If
    End If

If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        If Not Map(GetPlayerMap(Attacker)).Moral = MAP_MORAL_NONE Then
            Call PlayerMsg(Attacker, "This is a safe zone! You can't attack other player's pet.", BrightRed)
            Exit Function
        End If
    End If

    If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        petowner = MapNpc(mapNum).Npc(mapNpcNum).PetData.Owner
        If GetPlayerAccess(petowner) > ADMIN_MONITOR Then
            Call PlayerMsg(Attacker, "You can't attack " & GetPlayerName(petowner) & "'s pet!", BrightRed)
            Exit Function
        End If
    End If

    If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        If GetPlayerAccess(Attacker) > ADMIN_MONITOR Then
            Call PlayerMsg(Attacker, "Admins can't attack other player's pet.", Yellow)
            Exit Function
        End If
    End If

    If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        petowner = MapNpc(mapNum).Npc(mapNpcNum).PetData.Owner
        If GetPlayerLevel(petowner) < 10 Then
            Call PlayerMsg(Attacker, GetPlayerName(petowner) & " is below level 10, you can't attack his pet!", BrightRed)
            Exit Function
        End If
    End If

    If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        If GetPlayerLevel(Attacker) < 10 Then
            Call PlayerMsg(Attacker, "You are below level 10, you can't attack players with your pet yet!", BrightRed)
            Exit Function
        End If
    End If
        ' attack speed from weapon
        If GetPlayerEquipment(Attacker, Weapon) > 0 Then
            attackspeed = Item(GetPlayerEquipment(Attacker, Weapon)).Speed
        Else
            attackspeed = 1000
        End If

        If npcNum > 0 And GetTickCount > TempPlayer(Attacker).AttackTimer + attackspeed Then
            ' Check if at same coordinates
            Select Case GetPlayerDir(Attacker)
                Case DIR_UP
                    NpcX = MapNpc(mapNum).Npc(mapNpcNum).x
                    NpcY = MapNpc(mapNum).Npc(mapNpcNum).y + 1
                Case DIR_DOWN
                    NpcX = MapNpc(mapNum).Npc(mapNpcNum).x
                    NpcY = MapNpc(mapNum).Npc(mapNpcNum).y - 1
                Case DIR_LEFT
                    NpcX = MapNpc(mapNum).Npc(mapNpcNum).x + 1
                    NpcY = MapNpc(mapNum).Npc(mapNpcNum).y
                Case DIR_RIGHT
                    NpcX = MapNpc(mapNum).Npc(mapNpcNum).x - 1
                    NpcY = MapNpc(mapNum).Npc(mapNpcNum).y
            End Select

            If NpcX = GetPlayerX(Attacker) Then
                If NpcY = GetPlayerY(Attacker) Then
                    If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_MANAGER Then 'House Editor
                        CanPlayerAttackNpc = True
                    Else
                        'House Editor
                        If Npc(npcNum).Behaviour = NPC_BEHAVIOUR_MANAGER Then
                            Call SendInitManager(Attacker, CInt(GetVar(App.Path & "\data\accounts\houses.ini", "OPTIONS", "" & Player(Attacker).Name)), Npc(npcNum).HMapNum, Npc(npcNum).HBuy, Npc(npcNum).HSell)
                            End If
                        '/House Editor

                        If Len(Trim$(Npc(npcNum).AttackSay)) > 0 Then
                            PlayerMsg Attacker, Trim$(Npc(npcNum).Name) & ": " & Trim$(Npc(npcNum).AttackSay), White
                        End If
      End Function
```
Link to comment
Share on other sites

```
Public Function CanPlayerAttackNpc(ByVal Attacker As Long, ByVal mapNpcNum As Long, Optional ByVal IsSpell As Boolean = False) As Boolean
    Dim mapNum As Long
    Dim npcNum As Long
    Dim NpcX As Long
    Dim NpcY As Long
    Dim attackspeed As Long

    ' Check for subscript out of range
    If IsPlaying(Attacker) = False Or mapNpcNum <= 0 Or mapNpcNum > MAX_MAP_NPCS Then
        Exit Function
    End If

    ' Check for subscript out of range
    If MapNpc(GetPlayerMap(Attacker)).Npc(mapNpcNum).Num <= 0 Then
        Exit Function
    End If

    mapNum = GetPlayerMap(Attacker)
    npcNum = MapNpc(mapNum).Npc(mapNpcNum).Num

    ' Make sure the npc isn't already dead
    If MapNpc(mapNum).Npc(mapNpcNum).Vital(Vitals.HP) <= 0 Then
        If Npc(MapNpc(mapNum).Npc(mapNpcNum).Num).Behaviour <> NPC_BEHAVIOUR_FRIENDLY Then
            If Npc(MapNpc(mapNum).Npc(mapNpcNum).Num).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER Then
                Exit Function
            End If
        End If
    End If

    ' Make sure they are on the same map
    If IsPlaying(Attacker) Then

        ' exit out early
                    If IsSpell Then
                If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_MANAGER Then
                    CanPlayerAttackNpc = True
                    Exit Function
                End If
            End If
            If npcNum > 0 Then
                If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER Then
                    Dim petowner As Long
                    TempPlayer(Attacker).targetType = TARGET_TYPE_NPC
                    TempPlayer(Attacker).Target = mapNpcNum
                    SendTarget Attacker
                    CanPlayerAttackNpc = True
                    Exit Function
                End If
            End If
        End If

    If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        petowner = MapNpc(mapNum).Npc(mapNpcNum).PetData.Owner
        If Attacker = petowner Then
            Call PlayerMsg(Attacker, "You can't attack your own pet.", BrightRed)
            Exit Function
        End If
    End If

If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        If Not Map(GetPlayerMap(Attacker)).Moral = MAP_MORAL_NONE Then
            Call PlayerMsg(Attacker, "This is a safe zone! You can't attack other player's pet.", BrightRed)
            Exit Function
        End If
    End If

    If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        petowner = MapNpc(mapNum).Npc(mapNpcNum).PetData.Owner
        If GetPlayerAccess(petowner) > ADMIN_MONITOR Then
            Call PlayerMsg(Attacker, "You can't attack " & GetPlayerName(petowner) & "'s pet!", BrightRed)
            Exit Function
        End If
    End If

    If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        If GetPlayerAccess(Attacker) > ADMIN_MONITOR Then
            Call PlayerMsg(Attacker, "Admins can't attack other player's pet.", Yellow)
            Exit Function
        End If
    End If

    If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        petowner = MapNpc(mapNum).Npc(mapNpcNum).PetData.Owner
        If GetPlayerLevel(petowner) < 10 Then
            Call PlayerMsg(Attacker, GetPlayerName(petowner) & " is below level 10, you can't attack his pet!", BrightRed)
            Exit Function
        End If
    End If

    If MapNpc(mapNum).Npc(mapNpcNum).IsPet = YES Then
        If GetPlayerLevel(Attacker) < 10 Then
            Call PlayerMsg(Attacker, "You are below level 10, you can't attack players with your pet yet!", BrightRed)
            Exit Function
        End If
    End If
        ' attack speed from weapon
        If GetPlayerEquipment(Attacker, Weapon) > 0 Then
            attackspeed = Item(GetPlayerEquipment(Attacker, Weapon)).Speed
        Else
            attackspeed = 1000
        End If

        If npcNum > 0 And GetTickCount > TempPlayer(Attacker).AttackTimer + attackspeed Then
            ' Check if at same coordinates
            Select Case GetPlayerDir(Attacker)
                Case DIR_UP
                    NpcX = MapNpc(mapNum).Npc(mapNpcNum).x
                    NpcY = MapNpc(mapNum).Npc(mapNpcNum).y + 1
                Case DIR_DOWN
                    NpcX = MapNpc(mapNum).Npc(mapNpcNum).x
                    NpcY = MapNpc(mapNum).Npc(mapNpcNum).y - 1
                Case DIR_LEFT
                    NpcX = MapNpc(mapNum).Npc(mapNpcNum).x + 1
                    NpcY = MapNpc(mapNum).Npc(mapNpcNum).y
                Case DIR_RIGHT
                    NpcX = MapNpc(mapNum).Npc(mapNpcNum).x - 1
                    NpcY = MapNpc(mapNum).Npc(mapNpcNum).y
            End Select

            If NpcX = GetPlayerX(Attacker) Then
                If NpcY = GetPlayerY(Attacker) Then
                    If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_MANAGER Then 'House Editor
                        CanPlayerAttackNpc = True
                    Else
                        'House Editor
                        If Npc(npcNum).Behaviour = NPC_BEHAVIOUR_MANAGER Then
                            Call SendInitManager(Attacker, CInt(GetVar(App.Path & "\data\accounts\houses.ini", "OPTIONS", "" & Player(Attacker).Name)), Npc(npcNum).HMapNum, Npc(npcNum).HBuy, Npc(npcNum).HSell)
                        End If
                        '/House Editor

                        If Len(Trim$(Npc(npcNum).AttackSay)) > 0 Then
                            PlayerMsg Attacker, Trim$(Npc(npcNum).Name) & ": " & Trim$(Npc(npcNum).AttackSay), White
                        End If
                    End If
                End If
            End If
      End Function

```
Try now…
Link to comment
Share on other sites

Use your old code you had, and with your old problem code, replace it with this:

```
If NpcX = GetPlayerX(Attacker) Then
    If NpcY = GetPlayerY(Attacker) Then
        If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_MANAGER Then 'House Editor
            CanPlayerAttackNpc = True
        Else
            'House Editor
            If Npc(npcNum).Behaviour = NPC_BEHAVIOUR_MANAGER Then
                Call SendInitManager(Attacker, CInt(GetVar(App.Path & "\data\accounts\houses.ini", "OPTIONS", "" & Player(Attacker).Name)), Npc(npcNum).HMapNum, Npc(npcNum).HBuy, Npc(npcNum).HSell)
                End If
            '/House Editor

            If Len(Trim$(Npc(npcNum).AttackSay)) > 0 Then
                PlayerMsg Attacker, Trim$(Npc(npcNum).Name) & ": " & Trim$(Npc(npcNum).AttackSay), White
            End If
        End If
    End If
End If
```
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...