Little drop problem with pet system

So my code is really annoying me cuz i tried everything to make my drop code work and npcs also have to drop items when a pet kills them.

So here is my code of an player attacking npc and pet attacking npc someone please help me

NpcAttackNpc:


Sub NpcAttackNpc(ByVal MapNum As Long, ByVal Attacker As Long, ByVal Victim As Long, ByVal Damage As Long)

Dim i As Long

Dim Buffer As clsBuffer

Dim aNpcNum As Long

Dim vNpcNum As Long

Dim n As Long

Dim PetOwner As Long

Dim NPCNum As Long

If Attacker <= 0 Or Attacker > MAX_MAP_NPCS Then Exit Sub

If Victim <= 0 Or Victim > MAX_MAP_NPCS Then Exit Sub

If Damage <= 0 Then Exit Sub

aNpcNum = MapNpc(MapNum).NPC(Attacker).Num

vNpcNum = MapNpc(MapNum).NPC(Victim).Num

If aNpcNum <= 0 Then Exit Sub

If vNpcNum <= 0 Then Exit Sub

'set the victim's target to the pet attacking it

MapNpc(MapNum).NPC(Victim).TargetType = 2 'Npc

MapNpc(MapNum).NPC(Victim).Target = Attacker

' Send this packet so they can see the person attacking

Set Buffer = New clsBuffer

Buffer.WriteLong SNpcAttack

Buffer.WriteLong Attacker

SendDataToMap MapNum, Buffer.ToArray()

Set Buffer = Nothing

If Damage >= MapNpc(MapNum).NPC(Victim).Vital(Vitals.HP) Then

	 SendActionMsg MapNum, "-" & Damage, BrightRed, 1, (MapNpc(MapNum).NPC(Victim).x * 32), (MapNpc(MapNum).NPC(Victim).y * 32)

	 SendBlood MapNum, MapNpc(MapNum).NPC(Victim).x, MapNpc(MapNum).NPC(Victim).y

	 ' npc is dead.

	 'Call GlobalMsg(CheckGrammar(Trim$(Npc(vNpcNum).Name), 1) & " has been killed by " & CheckGrammar(Trim$(Npc(aNpcNum).Name)) & "!", BrightRed)

	 ' Set NPC target to 0

	 MapNpc(MapNum).NPC(Attacker).Target = 0

	 MapNpc(MapNum).NPC(Attacker).TargetType = 0

	 'reset the targetter for the player

	 If MapNpc(MapNum).NPC(Attacker).IsPet = YES Then

		 TempPlayer(MapNpc(MapNum).NPC(Attacker).PetData.Owner).Target = 0

		 TempPlayer(MapNpc(MapNum).NPC(Attacker).PetData.Owner).TargetType = TARGET_TYPE_NONE

		 PetOwner = MapNpc(MapNum).NPC(Attacker).PetData.Owner

		 SendTarget PetOwner

		 'Give the player the pet owner some experience from the kill

		 Call SetPlayerExp(PetOwner, GetPlayerExp(PetOwner) + NPC(MapNpc(MapNum).NPC(Victim).Num).exp)

		 CheckPlayerLevelUp PetOwner

		 SendActionMsg MapNum, "+" & NPC(MapNpc(MapNum).NPC(Victim).Num).exp & "Exp", White, 1, GetPlayerX(PetOwner) * 32, GetPlayerY(PetOwner) * 32

		 SendEXP PetOwner

	 ElseIf MapNpc(MapNum).NPC(Victim).IsPet = YES Then

		 'Get the pet owners' index

		 PetOwner = MapNpc(MapNum).NPC(Victim).PetData.Owner

		 'Set the NPC's target on the owner now

		 MapNpc(MapNum).NPC(Attacker).TargetType = 1 'player

		 MapNpc(MapNum).NPC(Attacker).Target = PetOwner

		 'Disband the pet

		 PetDisband PetOwner, GetPlayerMap(PetOwner)

	 End If

	 ' Drop the goods if they get it

	 'For n = 1 To MAX_NPC_DROPS

	 If NPC(vNpcNum).DropItem <> 0 Then

		 If Rnd <= NPC(vNpcNum).DropChance Then

			 Call SpawnItem(NPC(vNpcNum).DropItem, NPC(vNpcNum).DropItemValue, MapNum, MapNpc(MapNum).NPC(Victim).x, MapNpc(MapNum).NPC(Victim).y)

		 End If

	 End If

	 'Next

	 ' Reset victim's stuff so it dies in loop

	 MapNpc(MapNum).NPC(Victim).Num = 0

	 MapNpc(MapNum).NPC(Victim).SpawnWait = GetTickCount

	 MapNpc(MapNum).NPC(Victim).Vital(Vitals.HP) = 0

	 ' send npc death packet to map

	 Set Buffer = New clsBuffer

	 Buffer.WriteLong SNpcDead

	 Buffer.WriteLong Victim

	 SendDataToMap MapNum, Buffer.ToArray()

	 Set Buffer = Nothing

	 If PetOwner > 0 Then

		 PetFollowOwner PetOwner

	 End If

Else

	 ' npc not dead, just do the damage

	 MapNpc(MapNum).NPC(Victim).Vital(Vitals.HP) = MapNpc(MapNum).NPC(Victim).Vital(Vitals.HP) - Damage

	 ' Say damage

	 SendActionMsg MapNum, "-" & Damage, BrightRed, 1, (MapNpc(MapNum).NPC(Victim).x * 32), (MapNpc(MapNum).NPC(Victim).y * 32)

	 SendBlood MapNum, MapNpc(MapNum).NPC(Victim).x, MapNpc(MapNum).NPC(Victim).y

End If

'Send both Npc's Vitals to the client

SendMapNpcVitals MapNum, Attacker

SendMapNpcVitals MapNum, Victim

End Sub

And PlayerAttackNpc (there is nothing wrong whit this sub this is just so you ppl can see how my drop looks like if players attack npcs):


Sub NpcAttackPlayer(ByVal mapNpcNum As Long, ByVal Victim As Long, ByVal Damage As Long)

Dim Name As String

Dim exp As Long

Dim MapNum As Long

Dim i As Long

Dim Buffer As clsBuffer

' Check for subscript out of range

If mapNpcNum <= 0 Or mapNpcNum > MAX_MAP_NPCS Or IsPlaying(Victim) = False Then

	 Exit Sub

End If

' Check for subscript out of range

If MapNpc(GetPlayerMap(Victim)).NPC(mapNpcNum).Num <= 0 Then

	 Exit Sub

End If

MapNum = GetPlayerMap(Victim)

Name = Trim$(NPC(MapNpc(MapNum).NPC(mapNpcNum).Num).Name)

' Send this packet so they can see the npc attacking

Set Buffer = New clsBuffer

Buffer.WriteLong SNpcAttack

Buffer.WriteLong mapNpcNum

SendDataToMap MapNum, Buffer.ToArray()

Set Buffer = Nothing

If Damage <= 0 Then

	 Exit Sub

End If

' set the regen timer

MapNpc(MapNum).NPC(mapNpcNum).stopRegen = True

MapNpc(MapNum).NPC(mapNpcNum).stopRegenTimer = GetTickCount

If Damage >= GetPlayerVital(Victim, Vitals.HP) Then

	 ' Say damage

	 SendActionMsg GetPlayerMap(Victim), "-" & GetPlayerVital(Victim, Vitals.HP), BrightRed, 1, (GetPlayerX(Victim) * 32), (GetPlayerY(Victim) * 32)

	 ' send the sound

	 SendMapSound Victim, GetPlayerX(Victim), GetPlayerY(Victim), SoundEntity.seNpc, MapNpc(MapNum).NPC(mapNpcNum).Num

	 ' kill player

	 KillPlayer Victim

	 ' Player is dead

	 Call GlobalMsg(GetPlayerName(Victim) & " has been killed by " & Name, BrightRed)

	 ' Set NPC target to 0

	 MapNpc(MapNum).NPC(mapNpcNum).Target = 0

	 MapNpc(MapNum).NPC(mapNpcNum).TargetType = 0

Else

	 ' Player not dead, just do the damage

	 Call SetPlayerVital(Victim, Vitals.HP, GetPlayerVital(Victim, Vitals.HP) - Damage)

	 Call SendVital(Victim, Vitals.HP)

	 Call SendAnimation(MapNum, NPC(MapNpc(GetPlayerMap(Victim)).NPC(mapNpcNum).Num).Animation, 0, 0, TARGET_TYPE_PLAYER, Victim)

	 ' send vitals to party if in one

	 If TempPlayer(Victim).inParty > 0 Then SendPartyVitals TempPlayer(Victim).inParty, Victim

	 ' send the sound

	 SendMapSound Victim, GetPlayerX(Victim), GetPlayerY(Victim), SoundEntity.seNpc, MapNpc(MapNum).NPC(mapNpcNum).Num

	 ' Say damage

	 SendActionMsg GetPlayerMap(Victim), "-" & Damage, BrightRed, 1, (GetPlayerX(Victim) * 32), (GetPlayerY(Victim) * 32)

	 SendBlood GetPlayerMap(Victim), GetPlayerX(Victim), GetPlayerY(Victim)

	 ' set the regen timer

	 TempPlayer(Victim).stopRegen = True

	 TempPlayer(Victim).stopRegenTimer = GetTickCount

End If

End Sub

The error is type mismatch and it marks this : <>

have you tried uncommenting the drop code?

If i leave the drop code out it works perfectly BUT I NEED A DROP

Only if my pet attacks the npc then i don’t get the drop (ofcourse)

NVM ill make my fully own custom pet system cuz lightnings system is ducked up

Log in to reply