ID:156807   Jul 22 2010, 7:30 pm Heya all, (not sure if this belongs in philosophy but it is more of a how to though) so anyway this topic is more of a how would i go about doing something then how would i actually do it. So i decided i wanted my system to be based on stats and naturally require a weapon at all times (havnt really decided on that fully yet.) So how would i go about making weapons all run different kinds of checks for weapons. exampling is: wep quality will give a pre defined boost in damage and then be factored in with the rest of the damage. Gloves = (quality = 100 + str) etc short sword = (quality = 20)+(str+agi/2) etc etc for a number of weps (upwards of 15) each with its own damage calculation. So any ideas on how i would go about this, Demos, Libraries and dream maker threads welcome. ~Midget
 Jul 22 2010, 9:34 pm Define a procedure to get the amount of damage. For example, lets say that the base damage is 10: ```mob var/weapon_path/weapon = null // Default = no weapon = fist proc/recalculate_damage(original_damage, /weapon_path/weapon_reference) // Of course, I would pick shorter names switch(weapon_reference.name) if("Gun") . = src.accuracy/100 * original_damage if("Sword") . = (src.strength * weapon_reference.quality/100)/100 * original_damage else // None of the above = treated like a fist . = damage_reference/(100-src.strength) . = max(0, round(.))/*What is .? It is the default return value. When you have "return" anywhere and/or no return at the end of the procedure, it/there actually is an invisible "return .".max(0, X) picks the largest number, assuring that the lowest possible value is 0. ex: max(0, 10) = 10, max(0, -10) = 0.*/ ```
 Jul 22 2010, 9:41 pm In response to GhostAnime That switch() statement is very, very bad. Instead, just make a call to some proc for the weapon (call it calc_damage()), and override it for the different types to use different formulas.
 Jul 22 2010, 9:49 pm (Edited on Jul 22 2010, 10:45 pm) In response to Garthor A, true, true; I totally forgot about over-writing previously defined procedures... you know you haven't been programming in BYOND for a while when this type of thing slips your mind (or it could be due to a lack of sleep at 4:45 AM in the morning... though I think it's really a combination of the two). In fact, I don't even know why I had the weapon_reference argument, could have used the weapon variable instead >_>' ```mob var/weapon_path/weapon_var = null // Default = no weapon = fist proc/recalculate_damage(original_damage) // Of course, I would pick shorter names var/new_damage = 0 if(!src.weapon_var) // If there's no weapons attached, meaning all you have is just your fist new_damage = damage_reference/(100-src.strength) else new_damage = round(weapon_var.calculate_damage(original_damage)) return max(0, new_damage)Weapon proc/calculate_damage(original_damage) CRASH("h oh, looks like someone forgot to redefine the calculate_damage on [src.type]" Gun calculate_damage(original_damage) return (src.accuracy/100 * original_damage) Sword Default calculate_damage(original_damage) . = (src.strength * weapon_reference.quality/100)/100 * original_damage TEH_ULTIMATE_SWORD calculate_damage(original_damage) return (9000 + original_damage) // It's over 9,000! ``` ^_^ Edit: Thanks for the reminder Garthor and you're welcome Midgetbuster
 Jul 22 2010, 10:42 pm In response to GhostAnime Arr. i thought it was something along those lines but i was WAY off. Thanks garthor and ghost.