Problem description: I was wondering if anyone could give me hints on making a system to check if the player is in Combat or not. The way I see the idea in my head is, you won't get in combat until someone hits you, and the effect lasts for about 3-4 seconds before the system indicates that the player isn't in combat.
|
Dec 8 2012, 5:57 am
|
|
I supposed the easiest solution is if you get hit, change a variable InCombat to 1 and call a function the sets it to zero after a while.
|
Yea, you can do that. It pretty much depends on your game and what this "in combat" indicator is for.
|
Lugia319 wrote:
I supposed the easiest solution is if you get hit, change a variable InCombat to 1 and call a function the sets it to zero after a while. - I thought about that also, but I remember whenever I tried doing that in the past, the var always reset while in the fight because I gave it a 4 second delay. I want this system to be able to check if I'm still fighting or not for it won't reset the var until 4 seconds after the fight. Jemai1 wrote: Yea, you can do that. It pretty much depends on your game and what this "in combat" indicator is for. - It's a health regeneration proc. |
I don't fully know the mechanics of how you want InCombat to work so I made two solutions
/* Solution 1 - Absolute Solution. If you are attacked, In the first solution, upon each attack, 4 seconds of InCombat are added. The combat timer will keep getting ticks if you keep getting attacked. In the second solution, there's a secondary CombatDelay variable which keeps track of the time you're in battle (in seconds). Since you're setting the CombatDelay upon each attack, it'll keep doing the while loop if you get attacked at say, CombatDelay = 2. EDIT: Forgot my if() The if will prevent you from calling CombatTimer() more than once per CombatDelay = 1 |
The second solution looks pretty much what I was thinking, the first solution could be bad. Just imagine getting ganged up on by 5 people, that's a 20 second cool-down. Thanks Lugia. :D
|
The easiest way is to have a counter that increments and decrements naturally.
mob Whenever you attack / take damage, call the Combat proc. The Combat proc will increment incombat and will negate that increment after the specified delay which is 4 secs by default. The value of incombat does not really matter. You just have to determine if it is 0 or not. It will reset to 0 on time. Checking if your mob is in combat is as easy as if(mob.incombat) // where mob is your mob |
Why not just have an incombat variable that get flipped to 1 when you attack, get attacked, or what have you, then calls a looping function or a function after each combat action that checks for any enemies within your "combat range". If it finds none, flip the variable back off.
I do something similar where the player accumulates threat during combat and a function checks after every action. If no enemies are found, your threat is cleared. |
In response to Pyro_dragons
|
|
Pyro_dragons wrote:
Why not just have an incombat variable that get flipped to 1 when you attack, get attacked, or what have you, then calls a looping function or a function after each combat action that checks for any enemies within your "combat range". If it finds none, flip the variable back off. You could do that, but it take a bit more processing. It's better to use a more fundamental variable, and take advantage of the way if(a) works...which is, true when a is any number other than zero. |
The difference in processing is negligible. It doesn't take much to do a for(enemy in view(5)) or whatever the range is. Especially since you would just stop the for() loop after finding the first one. It's easier to just do a quick check for enemies and flip the flag based on what it finds, in my opinion.
You could do something like this every time something dies: mob/proc |
Well..
mob Lugia does a pretty good job on a in-combat timer, my setup is more open-ended, to which it falls under my own project's set up, which I use the container for 'shared exp' on kills, based on attackers. Lugia's will work better than mine if you only intend to use it for that purpose, no reason not to have both other than the whole clutter issue. However, let me just point some things out for Lugia: mob/proc/CombatTimer()//Same proc as displayed in their post |
If you don't like my first suggestion which keeps the number of combat interactions for the past 4 secs, here is another approach
mob No sleep/spawn. No loops. Good thing about it is that you can check if the mob is in combat for, say, 6 secs by calling mob.InCombat(60) which would return TRUE or FALSE. |
In response to Pyro_dragons
|
|
Pyro_dragons wrote:
The difference in processing is negligible. It doesn't take much to do a for(enemy in view(5)) or whatever the range is. Well in that case, it "doesn't take much" to scale an icon to 2x size, and change a range of rgb values to a different range of rgb values. But try doing it 4,000 times and you may have a different experience |