Mirage Source http://www.miragesource.net/forums/ |
|
Help Needed - NPC Battle System http://www.miragesource.net/forums/viewtopic.php?f=207&t=6079 |
Page 1 of 1 |
Author: | Xlithan [ Fri Jul 31, 2009 10:20 pm ] |
Post subject: | Help Needed - NPC Battle System |
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. |
Author: | Matt [ Fri Jul 31, 2009 10:27 pm ] |
Post subject: | Re: Help Needed - NPC Battle System |
What if you just kept track of the amount of players in the room, and had the npc randomly choose which one to attack? |
Author: | Xlithan [ Sat Aug 01, 2009 12:46 am ] |
Post subject: | Re: Help Needed - NPC Battle System |
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. |
Author: | Matt [ Sat Aug 01, 2009 12:52 am ] |
Post subject: | Re: Help Needed - NPC Battle System |
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. If you want, later tonight I'll take a look at the code and see if I can do it for you. |
Author: | halla [ Sun Aug 02, 2009 8:54 pm ] |
Post subject: | Re: Help Needed - NPC Battle System |
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. |
Author: | Xlithan [ Sun Aug 02, 2009 10:14 pm ] |
Post subject: | Re: Help Needed - NPC Battle System |
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. |
Author: | Matt [ Mon Aug 03, 2009 12:59 pm ] |
Post subject: | Re: Help Needed - NPC Battle System |
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? |
Author: | Joost [ Mon Aug 03, 2009 10:09 pm ] |
Post subject: | Re: Help Needed - NPC Battle System |
Random number, inbetween 0 to playersonmap Sort indexes from low to high Attack the result |
Author: | Xlithan [ Wed Aug 05, 2009 10:18 am ] |
Post subject: | Re: Help Needed - NPC Battle System |
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. |
Author: | Matt [ Wed Aug 05, 2009 1:04 pm ] |
Post subject: | Re: Help Needed - NPC Battle System |
If you need any help let me know. |
Author: | Xlithan [ Thu Aug 06, 2009 2:48 pm ] |
Post subject: | Re: Help Needed - NPC Battle System |
Thanks, I'll have a play around with a new system. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |