santa-clause Posted April 12, 2013 Author Share Posted April 12, 2013 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 meNpcAttackNpc:```Sub NpcAttackNpc(ByVal MapNum As Long, ByVal Attacker As Long, ByVal Victim As Long, ByVal Damage As Long)Dim i As LongDim Buffer As clsBufferDim aNpcNum As LongDim vNpcNum As LongDim n As LongDim PetOwner As LongDim NPCNum As LongIf Attacker <= 0 Or Attacker > MAX_MAP_NPCS Then Exit SubIf Victim <= 0 Or Victim > MAX_MAP_NPCS Then Exit SubIf Damage <= 0 Then Exit SubaNpcNum = MapNpc(MapNum).NPC(Attacker).NumvNpcNum = MapNpc(MapNum).NPC(Victim).NumIf aNpcNum <= 0 Then Exit SubIf vNpcNum <= 0 Then Exit Sub'set the victim's target to the pet attacking itMapNpc(MapNum).NPC(Victim).TargetType = 2 'NpcMapNpc(MapNum).NPC(Victim).Target = Attacker' Send this packet so they can see the person attackingSet Buffer = New clsBufferBuffer.WriteLong SNpcAttackBuffer.WriteLong AttackerSendDataToMap MapNum, Buffer.ToArray()Set Buffer = NothingIf 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 IfElse ' 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).yEnd If'Send both Npc's Vitals to the clientSendMapNpcVitals MapNum, AttackerSendMapNpcVitals MapNum, VictimEnd 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 StringDim exp As LongDim MapNum As LongDim i As LongDim Buffer As clsBuffer' Check for subscript out of rangeIf mapNpcNum <= 0 Or mapNpcNum > MAX_MAP_NPCS Or IsPlaying(Victim) = False Then Exit SubEnd If' Check for subscript out of rangeIf MapNpc(GetPlayerMap(Victim)).NPC(mapNpcNum).Num <= 0 Then Exit SubEnd IfMapNum = GetPlayerMap(Victim)Name = Trim$(NPC(MapNpc(MapNum).NPC(mapNpcNum).Num).Name)' Send this packet so they can see the npc attackingSet Buffer = New clsBufferBuffer.WriteLong SNpcAttackBuffer.WriteLong mapNpcNumSendDataToMap MapNum, Buffer.ToArray()Set Buffer = NothingIf Damage <= 0 Then Exit SubEnd If' set the regen timerMapNpc(MapNum).NPC(mapNpcNum).stopRegen = TrueMapNpc(MapNum).NPC(mapNpcNum).stopRegenTimer = GetTickCountIf 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 = 0Else ' 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 = GetTickCountEnd IfEnd Sub```The error is type mismatch and it marks this : <> Link to comment Share on other sites More sharing options...
kris_hole Posted April 12, 2013 Share Posted April 12, 2013 have you tried uncommenting the drop code? Link to comment Share on other sites More sharing options...
santa-clause Posted April 12, 2013 Author Share Posted April 12, 2013 If i leave the drop code out it works perfectly BUT I NEED A DROPOnly if my pet attacks the npc then i don't get the drop (ofcourse) Link to comment Share on other sites More sharing options...
santa-clause Posted April 12, 2013 Author Share Posted April 12, 2013 NVM ill make my fully own custom pet system cuz lightnings system is ducked up Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now