ID:152985
 

I made this Battle System for my game it's not done I still have to had alot of elements, but I'd just like to see what you guys think, or if you have any suggestions for it.



Also, I'm new to BYOND, and I havn't tested this out yet so I'm not quite sure if it works....



mob/verb/Attack(mob/M in oview(1))
if(src.weapon == "Fire")
if(prob(20))
if(M.head == "Water")
var/totalstr = (src.strength + src.attack + 3)
var/totaldef = (M.defense + M.protection + 3)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(M.head == "Fire")
var/totalstr = (src.strength + src.attack + 3)
var/totaldef = (M.defense + M.protection + 0)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(M.head == null)
var/totalstr = (src.strength + src.attack + 3)
var/totaldef = (M.defense + M.protection + 2)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(prob(15))
if(M.body == "Water")
var/totalstr = (src.strength + src.attack + 4)
var/totaldef = (M.defense + M.protection + 3)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(M.body == "Fire")
var/totalstr = (src.strength + src.attack + 4)
var/totaldef = (M.defense + M.protection + 0)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(M.body == null)
var/totalstr = (src.strength + src.attack + 4)
var/totaldef = (M.defense + M.protection + 2)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(prob(30))
if(M.arm == "Water")
var/totalstr = (src.strength + src.attack + 1)
var/totaldef = (M.defense + M.protection + 3)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(M.arm == "Fire")
var/totalstr = (src.strength + src.attack + 1)
var/totaldef = (M.defense + M.protection + 0)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(M.arm == null)
var/totalstr = (src.strength + src.attack + 1)
var/totaldef = (M.defense + M.protection + 2)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(prob(25))
if(M.leg == "Water")
var/totalstr = (src.strength + src.attack + 2)
var/totaldef = (M.defense + M.protection + 3)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(M.leg == "Fire")
var/totalstr = (src.strength + src.attack + 2)
var/totaldef = (M.defense + M.protection + 0)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
if(M.leg == null)
var/totalstr = (src.strength + src.attack + 2)
var/totaldef = (M.defense + M.protection + 2)
var/dmg = (totalstr - totaldef)
M.hp -= dmg


-Mike
If you don't know BYOND code very well, I think you ought to post pseudocode rather than actual BYOND code. That way, can can see your intentions rather than your coding skill.

Do you want players to be able to take damage multiple times for a single attack? If not, you need to use the else if command.

Only fire weapons work.

You have an awful lot of if() statements. You might want to look at the switch() statement. I think it probably saves some overhand, and it definitely makes code look a little neater.
In response to PirateHead (#1)
I'm trying to make it so theres a random chance where you hit then it checks to see what element you have equipped, and does a certain amount of damage based on weaknesses, and strengths.

Also, I know only fire works I wanted to see what people thought of the system.

Oh, and is this what you went to change it to?

    if(src.weapon == "Fire")
if(prob(20))
if(M.head == "Water")
var/totalstr = (src.strength + src.attack + 3)
var/totaldef = (M.defense + M.protection + 3)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(M.head == "Fire")
var/totalstr = (src.strength + src.attack + 3)
var/totaldef = (M.defense + M.protection + 0)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(M.head == null)
var/totalstr = (src.strength + src.attack + 3)
var/totaldef = (M.defense + M.protection + 2)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(prob(15))
if(M.body == "Water")
var/totalstr = (src.strength + src.attack + 4)
var/totaldef = (M.defense + M.protection + 3)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(M.body == "Fire")
var/totalstr = (src.strength + src.attack + 4)
var/totaldef = (M.defense + M.protection + 0)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(M.body == null)
var/totalstr = (src.strength + src.attack + 4)
var/totaldef = (M.defense + M.protection + 2)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(prob(30))
if(M.arm == "Water")
var/totalstr = (src.strength + src.attack + 1)
var/totaldef = (M.defense + M.protection + 3)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(M.arm == "Fire")
var/totalstr = (src.strength + src.attack + 1)
var/totaldef = (M.defense + M.protection + 0)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(M.arm == null)
var/totalstr = (src.strength + src.attack + 1)
var/totaldef = (M.defense + M.protection + 2)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(prob(25))
if(M.leg == "Water")
var/totalstr = (src.strength + src.attack + 2)
var/totaldef = (M.defense + M.protection + 3)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(M.leg == "Fire")
var/totalstr = (src.strength + src.attack + 2)
var/totaldef = (M.defense + M.protection + 0)
var/dmg = (totalstr - totaldef)
M.hp -= dmg
else if(M.leg == null)
var/totalstr = (src.strength + src.attack + 2)
var/totaldef = (M.defense + M.protection + 2)
var/dmg = (totalstr - totaldef)
M.hp -= dmg


-Mike
In response to Almasy (#2)
That's more efficient than what you had, and denies the chance to hit multiple times. Your code is awful long, but anything I suggest would mostly be breaking up that code into more modular form (which would probably make it longer overall). If anyone else can think of a better way to make this more concise, please post it.
In response to PirateHead (#3)
PirateHead wrote:
That's more efficient than what you had, and denies the chance to hit multiple times. Your code is awful long, but anything I suggest would mostly be breaking up that code into more modular form (which would probably make it longer overall). If anyone else can think of a better way to make this more concise, please post it.

Yeah, it is long , and thats only one weapon, and three armor types.

Theres gonna be like 30, or 40 different weapons elements, and armor elements.
In response to Almasy (#4)
Almasy wrote:
Theres gonna be like 30, or 40 different weapons elements, and armor elements.

You could create datums and make an efficient element system.

I may release a demo on this later. :O
In response to Almasy (#4)
You mean it's going to get longer? Ick. Your approach is already very unwieldly. =)

You really need to rethink how it all works, and reduce it down to a single "general case". This is like using a formula in mathematics - would you prefer to remember the roots for every possible quadratic equation (there's an infinite number!) or just memorise a single formula?

To put it another way, when you create a new kind of weapon, would you prefer to change a handful of variables, or write another 200 lines of code?

Damage/protection statistics should be represented as variables on the weapon/armour. (Including vulnerability; if fire-element weapons get a bonus against water-element armour, you shouldn't need to code this in as a different case from, say, earth-element weapons getting a bonus against fire-element armour.

Different types of weapon and armour should be implemented by changing the variables. Then you can have a single handler for all combinations of weapon and armour.

I strongly recommend you read up on subtypes... Scoobert's (misnamed but still useful) article Predefs is a good starting point.