Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Needed - NPC Battle System
#1
I've converted Mirage Source into an online text-based game (See my Virellia MUD thread). I've rewritten most of the core features to work with the style of game, but I've come across a small road block which I need some guidance on.

When a player enters the room, I want a hostile NPC to automatically attack the player, I know this can be done with a loop to check if a player is in the same room as the NPC, if so, initiate attack procedure. However, if there are more players in the same room, I want the NPC to switch between each player every time it attacks.

Most of the code is pretty much the same, so feel free to refer to parts of the code.

I'm using Mirage Source 1.
Reply
#2
What if you just kept track of the amount of players in the room, and had the npc randomly choose which one to attack?
Reply
#3
Yep, that's what I'm trying to do. I'm unsure how to get the NPC to randomly choose a target. The attack code is all already there, it's just figuring out how to add that random selection which I'm having trouble with at the moment.
Reply
#4
GameBoy Wrote:Yep, that's what I'm trying to do. I'm unsure how to get the NPC to randomly choose a target. The attack code is all already there, it's just figuring out how to add that random selection which I'm having trouble with at the moment.

Just need to change the target code. Store all the indexes in an array and then randomly choose one. And select it as the target. Wink

If you want, later tonight I'll take a look at the code and see if I can do it for you.
Reply
#5
Yeah a random would work fine there. Depends how you want it really. Do you want it to just attack randomly or do you want it to attack randomly then move on to another target cycling through.
Reply
#6
It would work ok if it just chose a random target out of the players in the room. Once I've got that basic system down I can expand on it later.
Reply
#7
All you have to do is scan the map and store all the player's indexes in an array. Say you had player 1, 5 and 15 in the same room. Just store 1,5,15 in an array. You could look at the code Jacob posted on arrays, it would help big time.

Then you would have 3 players in an array, so you would need a random number between 1 and 3. If you get 3, it goes after index 15, if you get 1, it goes after index 1.

That help anymore?
Reply
#8
Random number, inbetween 0 to playersonmap
Sort indexes from low to high
Attack the result
Reply
#9
Simple enough I guess.

I'm having trouble with the current system at the moment. I may be required to rewrite the whole attack system. The current system goes off distance, map co-ordinates etc. I simply want a hostile monster to just attack the player every X seconds if they are on the same grid.

It may take me a while to work my way around this, having never played with the battle system much before.
Reply
#10
If you need any help let me know.
Reply
#11
Thanks, I'll have a play around with a new system.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)