11-09-2009, 12:36 AM
Ok. Currently, the monster attacks the first person that enters the room, and only choose one target per hit. I want the monster to randomly pick a target out of all the players in the room.
This is the part of the code in the GameAI sub that gives the NPC a target. If anybody could add the bit of code needed to randomly select the target that would be great.
This is the part of the code in the GameAI sub that gives the NPC a target. If anybody could add the bit of code needed to randomly select the target that would be great.
Code:
If NpcNum > 0 Then
' If the npc is a attack on sight, search for a player on the Room
If Npc(NpcNum).Behavior = NPC_BEHAVIOR_ATTACKONSIGHT Or Npc(NpcNum).Behavior = NPC_BEHAVIOR_GUARD Then
For i = 1 To MAX_PLAYERS
If IsPlaying(i) Then
If GetPlayerRoom(i) = y Then
If RoomNpc(y, x).Target = 0 Then
If Npc(NpcNum).Behavior = NPC_BEHAVIOR_ATTACKONSIGHT Or GetPlayerPK(i) = YES Then
If LenB(Trim$(Npc(NpcNum).AttackSay)) Then
PlayerMsg i, "A " & Trim$(Npc(NpcNum).Name) & " says, '" & Trim$(Npc(NpcNum).AttackSay) & "' to you."
End If
RoomNpc(y, x).Target = i
End If
End If
End If
End If
Next i
End If
End If