Results 1 to 5 of 5

Thread: NPC Attack not working Properly

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    19

    NPC Attack not working Properly

    Hi, My battle system Code for My MMORPG seems to be bugged, and I can't seem to find the problem.

    vb Code:
    1. Public Sub BattleNPCAI(ByVal BattleSlot As Long, ByVal NpcSlot As Byte)
    2. Dim Target As Long
    3. Dim Damage As Long
    4. Dim X As Long
    5. Dim NpcNum As Long
    6. Dim Index As Long
    7.  
    8.     Dim Name As String
    9.     Dim EXP As Long
    10.     Dim MapNum As Long
    11.  
    12.  
    13. With Battle(BattleSlot)
    14.  
    15. If Not .Npc(NpcSlot).NpcNum > 0 Then
    16.     Exit Sub
    17. End If
    18.  
    19. 'let's find a target huh?
    20. If PlayersInBattle(BattleSlot) = 3 Then
    21.     Target = Rand(1, 3)
    22. ElseIf PlayersInBattle(BattleSlot) = 2 Then
    23.     'there are two players... find the combinations?
    24.     Target = Rand(1, 2)
    25.        
    26.     If Target = 1 Then
    27.         If .Player(1).Index > 0 Then
    28.             Target = 1
    29.         ElseIf .Player(2).Index > 0 Then
    30.             Target = 2
    31.         End If
    32.     End If
    33.    
    34.     If Target = 2 Then
    35.         If .Player(3).Index > 0 Then
    36.             Target = 3
    37.         ElseIf .Player(2).Index > 0 Then
    38.             Target = 2
    39.         End If
    40.     End If
    41.    
    42. ElseIf PlayersInBattle(BattleSlot) = 1 Then
    43.     If .Player(1).Index > 0 Then
    44.         Target = 1
    45.     ElseIf .Player(2).Index > 0 Then
    46.         Target = 2
    47.     ElseIf .Player(3).Index > 0 Then
    48.         Target = 3
    49.     End If
    50.    
    51. Else
    52.     Call Cle*****tle(BattleSlot)
    53. End If
    54.  
    55. 'let's start the attack...
    56.  
    57. 'display that the npc is attackign someone...
    58.     Index = Battle(BattleSlot).Player(Target).Index
    59.     NpcNum = Battle(BattleSlot).Npc(NpcSlot).NpcNum
    60.     Name = Trim$(Npc(NpcNum).Name)
    61.     Damage = Npc(NpcNum).STR - GetPlayerProtection(Target)
    62.    
    63.     If Not IsPlaying(Index) Then
    64.         Call LeaveBattle(Index)
    65.         Exit Sub
    66.     End If
    67.     Call SendDataToBattle(BattleSlot, "NPCBATTLEATTACKPLAYER" & SEP_CHAR & NpcSlot & END_CHAR)
    68.    
    69.     If Damage <= 0 Then
    70.         Damage = 1
    71.     End If
    72.    
    73.     If Damage >= GetPlayerHP(Index) Then
    74.         Call GlobalMsg(GetPlayerName(Index) & " was defeated by " & Name, BRIGHTRED)
    75.         Call LeaveBattle(Index)
    76.         If Map(GetPlayerMap(Index)).Moral <> MAP_MORAL_NO_PENALTY Then
    77.             If SCRIPTING = 1 Then
    78.                 MyScript.ExecuteStatement "Scripts\main.ess", "DropItems " & Index
    79.             Else
    80.                 If GetPlayerWeaponSlot(Index) > 0 Then
    81.                     Call PlayerMapDropItem(Index, GetPlayerWeaponSlot(Index), 0)
    82.                 End If
    83.  
    84.                 If GetPlayerArmorSlot(Index) > 0 Then
    85.                     Call PlayerMapDropItem(Index, GetPlayerArmorSlot(Index), 0)
    86.                 End If
    87.  
    88.                 If GetPlayerHelmetSlot(Index) > 0 Then
    89.                     Call PlayerMapDropItem(Index, GetPlayerHelmetSlot(Index), 0)
    90.                 End If
    91.  
    92.                 If GetPlayerShieldSlot(Index) > 0 Then
    93.                     Call PlayerMapDropItem(Index, GetPlayerShieldSlot(Index), 0)
    94.                 End If
    95.  
    96.                 If GetPlayerShieldSlot(Index) > 0 Then
    97.                     Call PlayerMapDropItem(Index, GetPlayerShieldSlot(Index), 0)
    98.                 End If
    99.  
    100.                 If GetPlayerLegsSlot(Index) > 0 Then
    101.                     Call PlayerMapDropItem(Index, GetPlayerLegsSlot(Index), 0)
    102.                 End If
    103.  
    104.                 If GetPlayerRingSlot(Index) > 0 Then
    105.                     Call PlayerMapDropItem(Index, GetPlayerRingSlot(Index), 0)
    106.                 End If
    107.             End If
    108.  
    109.             ' Calculate exp to give attacker
    110.             EXP = Int(GetPlayerExp(Index) / 3)
    111.  
    112.             ' Make sure we dont get less then 0
    113.             If EXP < 0 Then
    114.                 EXP = 0
    115.             End If
    116.         End If
    117.  
    118.         ' Warp player away
    119.         If SCRIPTING = 1 Then
    120.             MyScript.ExecuteStatement "Scripts\main.ess", "OnDeath " & Index
    121.         Else
    122.             If Map(GetPlayerMap(Index)).BootMap > 0 Then
    123.                 Call PlayerWarp(Index, Map(GetPlayerMap(Index)).BootMap, Map(GetPlayerMap(Index)).BootX, Map(GetPlayerMap(Index)).BootY)
    124.             Else
    125.                 Call PlayerWarp(Index, START_MAP, START_X, START_Y)
    126.             End If
    127.         End If
    128.  
    129.         ' Restore vitals
    130.         Call SetPlayerHP(Index, GetPlayerMaxHP(Index))
    131.         Call SetPlayerMP(Index, GetPlayerMaxMP(Index))
    132.         Call SetPlayerSP(Index, GetPlayerMaxSP(Index))
    133.         Call SendHP(Index)
    134.         Call SendMP(Index)
    135.         Call SendSP(Index)
    136.  
    137.         ' If the player the attacker defeated was a pk then take it away
    138.         If GetPlayerPK(Index) = YES Then
    139.             Call SetPlayerPK(Index, NO)
    140.             Call SendPlayerData(Index)
    141.         End If
    142.     Else
    143.         Call SetPlayerHP(Index, GetPlayerHP(Index) - Damage)
    144.         Call SendHP(Index)
    145.     End If
    146.    
    147.     Call SendBattleDamage(BattleSlot, Damage, Target, 0)
    148.     Call SendBattleData(BattleSlot)
    149.     Call SendDataToBattle(BattleSlot, "sound" & SEP_CHAR & "pain" & SEP_CHAR & Player(Index).Char(Player(Index).CharNum).Sex & END_CHAR)
    150.  
    151.  
    152. End With
    153.  
    154. End Sub
    155.  
    156. Function GetPlayerProtection(ByVal Index As Long) As Long
    157.     Dim ArmorSlot As Long, HelmSlot As Long, ShieldSlot As Long, LegsSlot As Long
    158.  
    159.     'GetPlayerProtection = 0
    160.  
    161.     ' Check for subscript out of range
    162.     If IsPlaying(Index) = False Or Index <= 0 Or Index > MAX_PLAYERS Then
    163.         Exit Function
    164.     End If
    165.  
    166.     ArmorSlot = GetPlayerArmorSlot(Index)
    167.     HelmSlot = GetPlayerHelmetSlot(Index)
    168.     ShieldSlot = GetPlayerShieldSlot(Index)
    169.     LegsSlot = GetPlayerLegsSlot(Index)
    170.     GetPlayerProtection = GetPlayerDEF(Index) ' / 5
    171.  
    172.     If ArmorSlot > 0 Then
    173.         GetPlayerProtection = GetPlayerProtection + Item(GetPlayerInvItemNum(Index, ArmorSlot)).Data2
    174.         If GetPlayerInvItemDur(Index, ArmorSlot) > -1 Then
    175.             Call SetPlayerInvItemDur(Index, ArmorSlot, GetPlayerInvItemDur(Index, ArmorSlot) - 1)
    176.  
    177.             If GetPlayerInvItemDur(Index, ArmorSlot) = 0 Then
    178.                 Call BattleMsg(Index, "Your " & Trim$(Item(GetPlayerInvItemNum(Index, ArmorSlot)).Name) & " has broken.", YELLOW, 0)
    179.                 Call TakeItem(Index, GetPlayerInvItemNum(Index, ArmorSlot), 0)
    180.             Else
    181.                 If GetPlayerInvItemDur(Index, ArmorSlot) <= 10 Then
    182.                     Call BattleMsg(Index, "Your " & Trim$(Item(GetPlayerInvItemNum(Index, ArmorSlot)).Name) & " is about to break! Dur: " & GetPlayerInvItemDur(Index, ArmorSlot) & "/" & Trim$(Item(GetPlayerInvItemNum(Index, ArmorSlot)).Data1), YELLOW, 0)
    183.                 End If
    184.             End If
    185.         End If
    186.     End If
    187.  
    188.     If HelmSlot > 0 Then
    189.         GetPlayerProtection = GetPlayerProtection + Item(GetPlayerInvItemNum(Index, HelmSlot)).Data2
    190.         If GetPlayerInvItemDur(Index, HelmSlot) > -1 Then
    191.             Call SetPlayerInvItemDur(Index, HelmSlot, GetPlayerInvItemDur(Index, HelmSlot) - 1)
    192.  
    193.             If GetPlayerInvItemDur(Index, HelmSlot) <= 0 Then
    194.                 Call BattleMsg(Index, "Your " & Trim$(Item(GetPlayerInvItemNum(Index, HelmSlot)).Name) & " has broken.", YELLOW, 0)
    195.                 Call TakeItem(Index, GetPlayerInvItemNum(Index, HelmSlot), 0)
    196.             Else
    197.                 If GetPlayerInvItemDur(Index, HelmSlot) <= 10 Then
    198.                     Call BattleMsg(Index, "Your " & Trim$(Item(GetPlayerInvItemNum(Index, HelmSlot)).Name) & " " & Trim$(Item(GetPlayerInvItemNum(Index, ArmorSlot)).Name) & " is about to break! Dur: " & GetPlayerInvItemDur(Index, HelmSlot) & "/" & Trim$(Item(GetPlayerInvItemNum(Index, HelmSlot)).Data1), YELLOW, 0)
    199.                 End If
    200.             End If
    201.         End If
    202.     End If
    203.  
    204.     If ShieldSlot > 0 Then
    205.         GetPlayerProtection = GetPlayerProtection + Item(GetPlayerInvItemNum(Index, ShieldSlot)).Data2
    206.         If GetPlayerInvItemDur(Index, ShieldSlot) > -1 Then
    207.             Call SetPlayerInvItemDur(Index, ShieldSlot, GetPlayerInvItemDur(Index, ShieldSlot) - 1)
    208.  
    209.             If GetPlayerInvItemDur(Index, ShieldSlot) <= 0 Then
    210.                 Call BattleMsg(Index, "Your " & Trim$(Item(GetPlayerInvItemNum(Index, ShieldSlot)).Name) & " has broken.", YELLOW, 0)
    211.                 Call TakeItem(Index, GetPlayerInvItemNum(Index, ShieldSlot), 0)
    212.             Else
    213.                 If GetPlayerInvItemDur(Index, ShieldSlot) <= 10 Then
    214.                     Call BattleMsg(Index, "Your " & Trim$(Item(GetPlayerInvItemNum(Index, ShieldSlot)).Name) & " is about to break! Dur: " & GetPlayerInvItemDur(Index, ShieldSlot) & "/" & Trim$(Item(GetPlayerInvItemNum(Index, ShieldSlot)).Data1), YELLOW, 0)
    215.                 End If
    216.             End If
    217.         End If
    218.     End If
    219.  
    220.     If LegsSlot > 0 Then
    221.         GetPlayerProtection = GetPlayerProtection + Item(GetPlayerInvItemNum(Index, LegsSlot)).Data2
    222.         If GetPlayerInvItemDur(Index, LegsSlot) > -1 Then
    223.             Call SetPlayerInvItemDur(Index, LegsSlot, GetPlayerInvItemDur(Index, LegsSlot) - 1)
    224.  
    225.             If GetPlayerInvItemDur(Index, LegsSlot) <= 0 Then
    226.                 Call BattleMsg(Index, "Your " & Trim$(Item(GetPlayerInvItemNum(Index, LegsSlot)).Name) & " has broken.", YELLOW, 0)
    227.                 Call TakeItem(Index, GetPlayerInvItemNum(Index, LegsSlot), 0)
    228.             Else
    229.                 If GetPlayerInvItemDur(Index, LegsSlot) <= 10 Then
    230.                     Call BattleMsg(Index, "Your " & Trim$(Item(GetPlayerInvItemNum(Index, LegsSlot)).Name) & " " & Trim$(Item(GetPlayerInvItemNum(Index, ArmorSlot)).Name) & " is about to break! Dur: " & GetPlayerInvItemDur(Index, LegsSlot) & "/" & Trim$(Item(GetPlayerInvItemNum(Index, LegsSlot)).Data1), YELLOW, 0)
    231.                 End If
    232.             End If
    233.         End If
    234.     End If
    235. End Function
    236.  
    237. Function GetPlayerDEF(ByVal Index As Long) As Long
    238.     Dim Add As Long
    239.     Add = 0
    240.     If GetPlayerWeaponSlot(Index) > 0 Then
    241.         Add = Item(GetPlayerInvItemNum(Index, GetPlayerWeaponSlot(Index))).AddDef
    242.     End If
    243.     If GetPlayerArmorSlot(Index) > 0 Then
    244.         Add = Add + Item(GetPlayerInvItemNum(Index, GetPlayerArmorSlot(Index))).AddDef
    245.     End If
    246.     If GetPlayerShieldSlot(Index) > 0 Then
    247.         Add = Add + Item(GetPlayerInvItemNum(Index, GetPlayerShieldSlot(Index))).AddDef
    248.     End If
    249.     If GetPlayerHelmetSlot(Index) > 0 Then
    250.         Add = Add + Item(GetPlayerInvItemNum(Index, GetPlayerHelmetSlot(Index))).AddDef
    251.     End If
    252.     If GetPlayerLegsSlot(Index) > 0 Then
    253.         Add = Add + Item(GetPlayerInvItemNum(Index, GetPlayerLegsSlot(Index))).AddDef
    254.     End If
    255.     If GetPlayerRingSlot(Index) > 0 Then
    256.         Add = Add + Item(GetPlayerInvItemNum(Index, GetPlayerRingSlot(Index))).AddDef
    257.     End If
    258.     If GetPlayerNecklaceSlot(Index) > 0 Then
    259.         Add = Add + Item(GetPlayerInvItemNum(Index, GetPlayerNecklaceSlot(Index))).AddDef
    260.     End If
    261.     GetPlayerDEF = Player(Index).Char(Player(Index).CharNum).DEF + Add
    262. End Function

    In Battle, no matter how much DEF you got, Damage = NPC STR. Instead of Damage = NPC.STR - GetPlayerProtection. Any Help?
    Last edited by Nickpop123; Dec 30th, 2011 at 05:16 PM.
    Paper Mario Online!
    A Visual Basic 6 Project Im Currently Making!

    Includes all 3 Paper Mario games!
    Download Link:http://www.mediafire.com/?awjn280n800n4dw

    Also try my friend MegaShark21 and I's SMO Remake 2010 Client: http://www.mediafire.com/?fxv3kni85doxg03

    Server is,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width