• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How to implement RPG weapons and magic affects on various types of enemies.

I'm in the somewhat early stages of developing a game. I have a decent system for enemy AI as well as various weapons, and magic for the player.

However, I am not sure how to implement a manageable system for weapon/magic affects on different types of enemies. For example, what is the easiest way to manage the effectiveness of 10 different attacks of magic and weaponry to 10 different types of enemies?

To clarify: If an ice blast collided with an enemy, I would like to quickly determine the affect on the enemy. Obviously, I don't want to have numerous "if" statements. Is the enemy vulnerable to ice attacks? (-10 HP or so) Or immune (-0 HP)? Or is it slightly effective (-2 HP)?

I think it may be a combo of ds_maps, and switches, but I'm really lost as to how to begin coding something efficient.

(I think I butchered the usage of "affect" and "effect" Lol!!)

I would greatly appreciate some guidance/info on best practices.
 

Rob

Member
If you have an array for the weapons and the damage/type of damage they do, have a similar array for the enemies that sets how much resistance the enemies have against that particular type of weapon.

You can then just check which type of weapon is being used when an enemy is hit and work out damage based on that particular entry in its array
 

woods

Member
the more involved the system, the more hairy the code gets ;o)

example:
enemy stats:
hp = 100
armor = 50
melee resist= 10
magic resist = 10
fire resist =10
ice resist = 0

weapon attack stats:
damage = 15
type_fire = +10%
type_ice = +0%

maybe something along these lines...
psudo code
Code:
with (weapon_flame_sword)
{ 
    total dam = (weapon.damage + weapon.type_fire + weapon.type_ice) - (enemy.armor + enemy.melee.resist + enemy.fire_resist))
}
 
Thank you for the responses. Indeed "the more involved the system, the more hairy the code gets"!!!

I started implementing your suggestions. I only have 2 weapons at the moment and they are working as planned. However, moving forward, as I add more weapons and magic it will get a bit dicey! :)
 

Rob

Member
Thank you for the responses. Indeed "the more involved the system, the more hairy the code gets"!!!

I started implementing your suggestions. I only have 2 weapons at the moment and they are working as planned. However, moving forward, as I add more weapons and magic it will get a bit dicey! :)
That's why coding and planning using arrays or data structures will benefit you. If you get it right for 2 weapons, it should work for 100.
 

Paskaler

Member
Another way you could implement this is: have the enemies store all their resistance values in an array or ds map. Then make all weapons have a customized script that runs whenever they're supposed to deal damage. So, for example, a "fire sword" type weapon could check in its script resistance to fire and ice and modify how much damage it deals. Bonus, since weapons have their own scripts, you could make the fire sword inflict a "burn" effect to the enemy making it take damage for N number of seconds, or other fun stuff such as this
 

jackquake

Member
As mentioned earlier, map this out in a spreadsheet, do significant testing of the model there first. Then put it to code. If not, you will rewrite lots of code to get it right in the end.
 

JackTurbo

Member
Another approach to dealing damage with effects, elements and resistances is to decouple the attack and the resolving of damage.

That's something I do in my game. If the player attacks an enemy it passes the attack damage and any element or status effect to the enemy. In the end step event the enemy checks if it has damage waiting to be applied and resolves it checking it's own resistance/weaknesses etc.
 
Top