Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Target
#1
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.

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
Reply
#2
[Image: 1247682417052.jpg]
Reply
#3
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
                                                Insert Array here that holds the results
                                            End If
                                        End If
                                    End If
                                End If
                            Next i
                                   Using the array you inserted above, randomize for 0 to the Ubound of the array, select a target, and attack it
                        End If
                    End If
Reply
#4
I think we're all waiting for him to bump the topic a bit more.
Reply
#5
Hmm, can't seem to understand arrays. I've read up but still unsure how I'd add each player id into the array....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)