ID:954470
 
(See the best response by GreatFisher.)
Code:
mob
icon = 'player.dmi'
var
level = 1
maxhp = 50
hp = 50
str = 10
def = 2
exp = 0
nexp = 10
Login()
loc = locate(/turf/start)
..()


Problem description:This is the code I have for the player.

mob
enemy
badguy
New()
..()
spawn() Wander()
icon = 'badguy.dmi'
var
maxhp = 40
hp = 40
str = 3
def = 1
..()

This is where the problem begins. I want to create a different set of stats for the enemy making them slightly weaker than the player. It won't let me name the stats the same as the player stats even though they are variables under different mobs. The error comes up saying duplicate definition

mob
verb
Attack(mob/M as mob in oview(1))
var/damage = usr.str - M.def
if(damage <= 0)
usr << "Your attack does not hurt [M] at all!"
M << "You are unhurt by [usr]'s attack."
else
M.hp -= damage
M:deathcheck()
M:levelup()


This is the attack code. Would I have to name the variables on badguy something different and make a new attack code for him? or is there an easier way to have mobs have different stats but fall under the same attack code?

I'm still learning and new to dm. I would like tips and suggestions. Please don't do it all for me :).
Best response
You don't have a problem really just remove the var line from the enemy code and move all the stats back an indentation and your done.

As for the Attack verb change the usr(You should really avoid using usr and : if you can, they can cause all sorts of bugs) in it to src and make deathcheck() and levelup() mov procs like this:
mob
proc
deathcheck()
//deathcheck stuff
levelup()
//levelup stuff

Then just after after the deduction for hp do this:
         else
M.hp -= damage
M.deathcheck()
if(!istype(M, /mob/enemy))
M.levelup()


And then you can just call the Attack() verb for the enemy npc as if it were a proc:
mob
enemy
bump(mob/M)
Attack()


Should all work, I haven't actually tested it but I hope it helps you.

In response to GreatFisher
Thanks! You saved me from so much frustration!
No problem. :D
In response to GreatFisher
Should all work, except the indentation error in the 'damage then check for death' bit.
In response to NNAAAAHH
Whoops I was using a copy and pasted indentation and wrote that in my browser. :P