For this example, we're only going to need a few variables, so lets enter them in and give them some values.
mob/var
Hp = 10 //Health
MaxHp = 20//Max Health
Mp = 5 //Mana
MaxMp = 10//Max Mana
Atk = 30 //Attack
Def = 34 //Defense
Great, now that we have those, we can move on to our Attack proc. I'll break this down into sections. First, we will define out proc and give it some input variables.
proc/Attack(mob/User, mob/Target, Type="Normal", Value, Stat="HP", Extra, Cure, Chance=100, Chain)
I know it looks like a lot, but these variables will determine how much damage you do. Let me explain what the purpose of each one is.
- User
Person Causing Damage - Target
Person Taking Damage - Type
Type of Attack (Default: Normal) - Value
Used for Specific Values of Damage - Stat
Target Stat to damage (Default: HP) - Extra
Percentage of Damage to use - Cure
Turns damage into a negative for healing effects - Chance
Percentage Chance of Attack being successful (Default: 100) - Chain
Percentage Chance of repeating the Attack
The next thing we want to do is define our damage variable. We will alter this within the attack proc and ultimately determine the damage caused to the Target.
var/damage //The Damage User will cause Target
Before we go setting the damage, we will want to check if Chance has been set. If it has, then the attack has a chance of failing, so we want to do that first.
//If Chance of succeeding fails, stop the proc
if(!prob(Chance)) return
Now we know that if the proc gets to this point, either Chance was not set, or it has succeeded. The next thing we want to do is determine the Type of attack. This is where you can make up your own formulae to determine the damage.
switch(Type)
if("Normal")
//100% of User Attack - 50% of Target Defense
damage = User.Atk - 0.5*(Target.Def)
if("Blunt")
//80% User Attack - 10% of Target Defense
damage = 0.8*(User.Atk) - 0.1*(Target.Def)
if("Sharp")
//130% User Attack - 100% of Target Defense
damage = 1.3*(User.Atk) - Target.Def
if("Pure")
//100% of User Attack
damage = User.Atk
if("Specific")
//Equal to Value
damage = Value
if("HP")
//Current User HP
damage = User.Hp
if("HP~")
//Amount of User HP lost
damage = User.MaxHp - User.Hp
if("MP")
//Current User MP
damage = User.Mp
if("MP~")
//Amount of User MP lost
damage = User.MaxMp - User.Mp
There we have 9 basic attacks, each one having a different effect on the damage. Once we have our damage set, we have to check to see if we need to alter it in any way. Extra and Cure will alter damage, so we need to check those. We will also need to make sure that mobs can never unintentionally cause negative values of damage that will increase a Stat.
//If Extra has been set
if(Extra)
//Set Damage to [Extra]%
damage = (damage/100)*Extra
//If damage is lower than 0, set it to 0
damage = max(0,damage)
//If Cure has been set
if(Cure)
//Change damage to a negative value
damage *= -1
Now it's time to actually cause the damage to the Target. We will check the Stat, and decrease it by damage. If the proc was used to Heal the Target, then damage will be a negative value, thus the following will increase the stat by damage.
//Check which Target Stat to Damage
switch(Stat)
if("HP")
Target.Hp -= damage
if("MP")
Target.Mp -= damage
At this point, we will output the results of the attack to both the User and Target.
//If the Attack is to cure Target, output the following
if(Cure)
//If the User is the Target, and is also a Player
if(User == Target && User.client)
User << "You restore your [Stat] by [-damage] points!"
//Otherwise
else
//If User is a Player
if(User.client)
User << "You restore [Target]'s [Stat] by [-damage] points!"
//If Target is a Player
if(Target.client)
Target << "[User] restored your [Stat] by [-damage] points!"
//If the Attck is to damage the Target, output this instead
else
if(User == Target && User.client)
User << "You attack your [Stat] for [damage] Damage using a [Type] attack!"
else
if(User.client)
User << "You attack [Target]'s [Stat] for [damage] Damage using a [Type] attack!"
if(Target.client)
Target << "[User] attacked your [Stat] for [damage] Damage using a [Type] attack!"
Like all attacks, we need to check and see if we have killed our Target. So we need to add in our DeathCheck() proc. I'll add an example DeathCheck() into this post.
//If Target is Dead, end the proc
if(DeathCheck(User,Target)) return
The very last thing we will want to check is if Chain was defined. If so, then the User has a chance to repeat the attack all over again. We add this in after the DeathCheck() as there is no point in hitting a corpse.
//If the Attack can Chain Hit and succeeds
if(Chain && prob(Chain))
//Repeat the attack
Attack(User,Target,Type,Value,Stat,Extra,Cure,Chance)
And there we have our little Attack() proc. So now we'll look at how to call it, but first, we will add in that DeathCheck() proc.
//Simple DeathCheck: Reset HP, announce death.
//Returns 1 if Attackee dies.
//Returns 0 if Attackee lives.
proc/DeathCheck(mob/Attacker, mob/Attackee)
if(Attackee.Hp < 1)
Attackee.Hp = Attackee.MaxHp
Attackee << "<b>You Died!</b>"
Attacker << "<b>You killed [Attackee]!<b>"
return 1
return 0
As hitting yourself is no fun, we're going to create a victim that we can attack, let's call him Billy.
//Set the mobs name when created
mob/New(n)
..()
if(n) name = n
//Billy will be our victim
var/mob/Billy = new("Billy")
Finally, let's see how to call some of these attacks and beat up poor Billy.
mob/verb/Attack_Billy()
//A basic Normal Attack
Attack(src,Billy,"Normal")
//A Normal Attack with a 50% Chance of Success
Attack(src,Billy,"Normal",Chance=50)
//A Blunt Attack with 75% Chance to Chain Hit
Attack(src,Billy,"Blunt",Chain=75)
//A Sharp Attack with 15% Chance to Chain Hit
Attack(src,Billy,"Sharp",Chain=15)
//A Pure Attack to Targets MP
Attack(src,Billy,"Pure",Stat="MP")
//Attack for 110% of Users Current HP
Attack(src,Billy,"HP",Extra=110)
//Attack for 80% of Users HP Lost
Attack(src,Billy,"HP~",Extra=80)
//Attack for 30% of Users Current MP
Attack(src,Billy,"MP",Extra=30)
//Attack for 50% of Users MP Lost
Attack(src,Billy,"MP~",Extra=50)
//Cure Target for 50
Attack(src,Billy,"Specific",50,Cure=1)
//Cure Targets MP for 20
Attack(src,Billy,"Specific",20,Stat="MP",Cure=1)
//Cure Your Own MP by the amount of HP Lost
Attack(src,src,"HP~",Stat="MP",Cure=1) //Cure Your MP by amount of HP Lost
src << "\n" //Output a blank line
Saves a little space.