@kornusdj: > Zesh, This doesn't work > If I add : > Dim index as Long, show an RTE 9 > Byval index as Long, show an RTE 13 > > This is my Sub AttackNpc, if I add my code. > > ``` > Sub AttackNpc(ByVal Attacker As Long, _ > ByVal MapNpcNum As Long, _ > ByVal damage As Long) > Dim Name As String > Dim Exp As Long > Dim N As Long, I As Long, x As Long, o As Long > Dim MapNum As Long, NpcNum As Long > > ' Check for subscript out of range > If IsPlaying(Attacker) = False Or MapNpcNum MAX_MAP_NPCS Or damage < 0 Then > Exit Sub > End If > > ' Check for weapon > If GetPlayerWeaponSlot(Attacker) > 0 Then > N = GetPlayerInvItemNum(Attacker, GetPlayerWeaponSlot(Attacker)) > Else > N = 0 > End If > > ' Send this packet so they can see the person attacking > Call SendDataToMap(GetPlayerMap(Attacker), "ATTACKNPC" & SEP_CHAR & Attacker & SEP_CHAR & MapNpcNum & SEP_CHAR & END_CHAR) > MapNum = GetPlayerMap(Attacker) > NpcNum = MapNpc(MapNum, MapNpcNum).num > Name = Trim$(Npc(NpcNum).Name) > MapNpc(MapNum, MapNpcNum).LastAttack = GetTickCount > > If damage >= MapNpc(MapNum, MapNpcNum).HP Then > > ' Check for a weapon and say damage > Call BattleMsg(Attacker, "Zabiłeś/aś a " & Name, BrightRed, 0) > Dim add As String > > add = 0 > > If GetPlayerWeaponSlot(Attacker) > 0 Then > add = add + Item(GetPlayerInvItemNum(Attacker, GetPlayerWeaponSlot(Attacker))).AddEXP > End If > > If GetPlayerArmorSlot(Attacker) > 0 Then > add = add + Item(GetPlayerInvItemNum(Attacker, GetPlayerArmorSlot(Attacker))).AddEXP > End If > > If GetPlayerShieldSlot(Attacker) > 0 Then > add = add + Item(GetPlayerInvItemNum(Attacker, GetPlayerShieldSlot(Attacker))).AddEXP > End If > > If GetPlayerHelmetSlot(Attacker) > 0 Then > add = add + Item(GetPlayerInvItemNum(Attacker, GetPlayerHelmetSlot(Attacker))).AddEXP > End If > > If GetPlayerLegsSlot(Attacker) > 0 Then > add = add + Item(GetPlayerInvItemNum(Attacker, GetPlayerLegsSlot(Attacker))).AddEXP > End If > > If add > 0 Then > If add < 100 Then > If add < 10 Then > add = 0 & ".0" & Right$(add, 2) > Else > add = 0 & "." & Right$(add, 2) > End If > > Else > add = Mid$(add, 1, 1) & "." & Right$(add, 2) > End If > End If > > ' Calculate exp to give attacker > If add > 0 Then > Exp = Npc(NpcNum).Exp + (Npc(NpcNum).Exp * Val(add)) > Else > Exp = Npc(NpcNum).Exp > End If > > ' Make sure we dont get less then 0 > If Exp < 0 Then > Exp = 1 > End If > > If IS_PREMIUM = 1 Then > Call SetPlayerExp(index, GetPlayerExp(index) + Int(Exp * 2)) > Call BattleMsg(index, "Dostałeś/aś " & Int(Exp * 2) & " doświadczenia.", BrightBlue, 0) > Else > Call SetPlayerExp(index, GetPlayerExp(index) + Exp) > Call BattleMsg(index, "Dostałeś/aś " & Exp & " doświadczenia.", BrightBlue, 0) > End If > > For I = 1 To MAX_NPC_DROPS > > ' Drop the goods if they get it > N = Int(Rnd * Npc(NpcNum).ItemNPC(I).Chance) + 1 > > If N = 1 Then > Call SpawnItem(Npc(NpcNum).ItemNPC(I).ItemNum, Npc(NpcNum).ItemNPC(I).ItemValue, MapNum, MapNpc(MapNum, MapNpcNum).x, MapNpc(MapNum, MapNpcNum).y) > End If > > Next > > ' Now set HP to 0 so we know to actually kill them in the server loop (this prevents subscript out of range) > MapNpc(MapNum, MapNpcNum).num = 0 > MapNpc(MapNum, MapNpcNum).SpawnWait = GetTickCount > MapNpc(MapNum, MapNpcNum).HP = 0 > Call SendDataToMap(MapNum, "NPCDEAD" & SEP_CHAR & MapNpcNum & SEP_CHAR & END_CHAR) > > ' Check for level up > Call CheckPlayerLevelUp(Attacker) > > ' Check for level up party member > If Player(Attacker).InParty = YES Then > > For x = 1 To MAX_PARTY_MEMBERS > > If Party(Player(Attacker).PartyID).Member(x) 0 Then > Call CheckPlayerLevelUp(Party(Player(Attacker).PartyID).Member(x)) > End If > > Next > > End If > > Call TakeFromGrid(MapNum, MapNpc(MapNum, MapNpcNum).x, MapNpc(MapNum, MapNpcNum).y) > > ' Check if target is npc that died and if so set target to 0 > If Player(Attacker).TargetType = TARGET_TYPE_NPC And Player(Attacker).Target = MapNpcNum Then > Player(Attacker).Target = 0 > Player(Attacker).TargetType = 0 > End If > > Else > > ' NPC not dead, just do the damage > MapNpc(MapNum, MapNpcNum).HP = MapNpc(MapNum, MapNpcNum).HP - damage > > ' Check for a weapon and say damage > Call BattleMsg(Attacker, "Zadałeś/aś a " & Name & " " & damage & " obrażeń.", White, 0) > > If N = 0 Then > > 'Call PlayerMsg(Attacker, "Zadałeś/aś a " & Name & " for " & obrażeń & " hit points.", White) > Else > > 'Call PlayerMsg(Attacker, "Zadałeś/aś a " & Name & " with a " & Trim$(Item(n).Name) & " for " & obrażeń & " hit points.", White) > End If > > ' Check if we should send a message > If MapNpc(MapNum, MapNpcNum).Target = 0 And MapNpc(MapNum, MapNpcNum).Target Attacker Then > If Trim$(Npc(NpcNum).AttackSay) "" Then > Call PlayerMsg(Attacker, "A " & Trim$(Npc(NpcNum).Name) & " : " & Trim$(Npc(NpcNum).AttackSay) & "", SayColor) > End If > End If > > ' Set the NPC target to the player > MapNpc(MapNum, MapNpcNum).Target = Attacker > MapNpc(MapNum, MapNpcNum).TargetType = TARGET_TYPE_PLAYER > > ' Now check for guard ai and if so have all onmap guards come after'm > If Npc(MapNpc(MapNum, MapNpcNum).num).Behavior = NPC_BEHAVIOR_GUARD Then > > For I = 1 To MAX_MAP_NPCS > > If MapNpc(MapNum, I).num = MapNpc(MapNum, MapNpcNum).num Then > MapNpc(MapNum, I).Target = Attacker > MapNpc(MapNum, I).TargetType = TARGET_TYPE_PLAYER > End If > > Next > > End If > End If > > 'Call SendDataToMap(MapNum, "npchp" & SEP_CHAR & MapNpcNum & SEP_CHAR & MapNpc(MapNum, MapNpcNum).HP & SEP_CHAR & GetNpcMaxHP(MapNpc(MapNum, MapNpcNum).num) & SEP_CHAR & END_CHAR) > ' Reset attack timer > Player(Attacker).AttackTimer = GetTickCount > End Sub > ``` Change your Sub AttackNpc to this: ``` Sub AttackNpc(ByVal Attacker As Long, _ ByVal MapNpcNum As Long, _ ByVal damage As Long) Dim Name As String Dim Exp As Long Dim N As Long, I As Long, x As Long, o As Long Dim MapNum As Long, NpcNum As Long ' Check for subscript out of range If IsPlaying(Attacker) = False Or MapNpcNum MAX_MAP_NPCS Or damage < 0 Then Exit Sub End If ' Check for weapon If GetPlayerWeaponSlot(Attacker) > 0 Then N = GetPlayerInvItemNum(Attacker, GetPlayerWeaponSlot(Attacker)) Else N = 0 End If ' Send this packet so they can see the person attacking Call SendDataToMap(GetPlayerMap(Attacker), "ATTACKNPC" & SEP_CHAR & Attacker & SEP_CHAR & MapNpcNum & SEP_CHAR & END_CHAR) MapNum = GetPlayerMap(Attacker) NpcNum = MapNpc(MapNum, MapNpcNum).num Name = Trim$(Npc(NpcNum).Name) MapNpc(MapNum, MapNpcNum).LastAttack = GetTickCount If damage >= MapNpc(MapNum, MapNpcNum).HP Then ' Check for a weapon and say damage Call BattleMsg(Attacker, "Zabiłeś/aś a " & Name, BrightRed, 0) Dim add As String add = 0 If GetPlayerWeaponSlot(Attacker) > 0 Then add = add + Item(GetPlayerInvItemNum(Attacker, GetPlayerWeaponSlot(Attacker))).AddEXP End If If GetPlayerArmorSlot(Attacker) > 0 Then add = add + Item(GetPlayerInvItemNum(Attacker, GetPlayerArmorSlot(Attacker))).AddEXP End If If GetPlayerShieldSlot(Attacker) > 0 Then add = add + Item(GetPlayerInvItemNum(Attacker, GetPlayerShieldSlot(Attacker))).AddEXP End If If GetPlayerHelmetSlot(Attacker) > 0 Then add = add + Item(GetPlayerInvItemNum(Attacker, GetPlayerHelmetSlot(Attacker))).AddEXP End If If GetPlayerLegsSlot(Attacker) > 0 Then add = add + Item(GetPlayerInvItemNum(Attacker, GetPlayerLegsSlot(Attacker))).AddEXP End If If add > 0 Then If add < 100 Then If add < 10 Then add = 0 & ".0" & Right$(add, 2) Else add = 0 & "." & Right$(add, 2) End If Else add = Mid$(add, 1, 1) & "." & Right$(add, 2) End If End If ' Calculate exp to give attacker If add > 0 Then Exp = Npc(NpcNum).Exp + (Npc(NpcNum).Exp * Val(add)) Else Exp = Npc(NpcNum).Exp End If ' Make sure we dont get less then 0 If Exp < 0 Then Exp = 1 End If If IS_PREMIUM = 1 Then Call SetPlayerExp(Attacker, GetPlayerExp(Attacker) + Int(Exp * 2)) Call BattleMsg(Attacker, "Dostałeś/aś " & Int(Exp * 2) & " doświadczenia.", BrightBlue, 0) Else Call SetPlayerExp(Attacker, GetPlayerExp(Attacker) + Exp) Call BattleMsg(Attacker, "Dostałeś/aś " & Exp & " doświadczenia.", BrightBlue, 0) End If For I = 1 To MAX_NPC_DROPS ' Drop the goods if they get it N = Int(Rnd * Npc(NpcNum).ItemNPC(I).Chance) + 1 If N = 1 Then Call SpawnItem(Npc(NpcNum).ItemNPC(I).ItemNum, Npc(NpcNum).ItemNPC(I).ItemValue, MapNum, MapNpc(MapNum, MapNpcNum).x, MapNpc(MapNum, MapNpcNum).y) End If Next ' Now set HP to 0 so we know to actually kill them in the server loop (this prevents subscript out of range) MapNpc(MapNum, MapNpcNum).num = 0 MapNpc(MapNum, MapNpcNum).SpawnWait = GetTickCount MapNpc(MapNum, MapNpcNum).HP = 0 Call SendDataToMap(MapNum, "NPCDEAD" & SEP_CHAR & MapNpcNum & SEP_CHAR & END_CHAR) ' Check for level up Call CheckPlayerLevelUp(Attacker) ' Check for level up party member If Player(Attacker).InParty = YES Then For x = 1 To MAX_PARTY_MEMBERS If Party(Player(Attacker).PartyID).Member(x) 0 Then Call CheckPlayerLevelUp(Party(Player(Attacker).PartyID).Member(x)) End If Next End If Call TakeFromGrid(MapNum, MapNpc(MapNum, MapNpcNum).x, MapNpc(MapNum, MapNpcNum).y) ' Check if target is npc that died and if so set target to 0 If Player(Attacker).TargetType = TARGET_TYPE_NPC And Player(Attacker).Target = MapNpcNum Then Player(Attacker).Target = 0 Player(Attacker).TargetType = 0 End If Else ' NPC not dead, just do the damage MapNpc(MapNum, MapNpcNum).HP = MapNpc(MapNum, MapNpcNum).HP - damage ' Check for a weapon and say damage Call BattleMsg(Attacker, "Zadałeś/aś a " & Name & " " & damage & " obrażeń.", White, 0) If N = 0 Then 'Call PlayerMsg(Attacker, "Zadałeś/aś a " & Name & " for " & obrażeń & " hit points.", White) Else 'Call PlayerMsg(Attacker, "Zadałeś/aś a " & Name & " with a " & Trim$(Item(n).Name) & " for " & obrażeń & " hit points.", White) End If ' Check if we should send a message If MapNpc(MapNum, MapNpcNum).Target = 0 And MapNpc(MapNum, MapNpcNum).Target Attacker Then If Trim$(Npc(NpcNum).AttackSay) "" Then Call PlayerMsg(Attacker, "A " & Trim$(Npc(NpcNum).Name) & " : " & Trim$(Npc(NpcNum).AttackSay) & "", SayColor) End If End If ' Set the NPC target to the player MapNpc(MapNum, MapNpcNum).Target = Attacker MapNpc(MapNum, MapNpcNum).TargetType = TARGET_TYPE_PLAYER ' Now check for guard ai and if so have all onmap guards come after'm If Npc(MapNpc(MapNum, MapNpcNum).num).Behavior = NPC_BEHAVIOR_GUARD Then For I = 1 To MAX_MAP_NPCS If MapNpc(MapNum, I).num = MapNpc(MapNum, MapNpcNum).num Then MapNpc(MapNum, I).Target = Attacker MapNpc(MapNum, I).TargetType = TARGET_TYPE_PLAYER End If Next End If End If 'Call SendDataToMap(MapNum, "npchp" & SEP_CHAR & MapNpcNum & SEP_CHAR & MapNpc(MapNum, MapNpcNum).HP & SEP_CHAR & GetNpcMaxHP(MapNpc(MapNum, MapNpcNum).num) & SEP_CHAR & END_CHAR) ' Reset attack timer Player(Attacker).AttackTimer = GetTickCount End Sub ``` The "Index" variable is not always referring to the player. In the AttackNpc Sub, Index is passed through it, and it is renamed "Attacker," so instead of referring to the player as "Index," you'd need to refer to the player with the "Attacker" variable.