ID:645881
 
(See the best response by NNAAAAHH.)



mob
var
attack
maxhp
hp
damage

mob
verb
Attack(mob/trg in oview(1))
set category = "Attack"
var/damage = rand(usr.attack,usr.attack+rand(1,10))
hp = trg.maxhp - usr.damage
usr << "[usr] hits [trg] with [damage] points"


Problem description: It just seems to be correct and all it works, but whenever I try to add some death proc... it never works... can someone tell me what to add on and what to modify if it is needed? and then some explanations.

The issue is you're setting the hp variable instead of subtracting hp. Which means the only way you'll do enough damage to kill is if you can take all of their hp at once.
To clarify what Lugia said, you're using trg.maxhp to determine their remaining health after taking a hit. You should be using trg.hp.
Best response
mob
var
attack
maxhp
hp
damage
mob
proc
Damage(var/damage,mob/M)
if(!damage||!isnum(damage)) return
if(!M||!ismob(M)) return
if(damage>src.hp) damage=src.hp
src.hp -= damage
oview() << "[M] hits [src] for [damage] points."
src.Death(M)
Death(mob/M)
if(src.hp>0) return
//if(!src.client) del(src) // --optional - will delete any non-player mob uppon death
world<<"[src] was killed by [M]"
src.loc=locate(1,1,1)//alter to prefrence
src.hp=src.hpmax
verb
Attack(mob/trg in oview(1))
set category = "Attack"
var/damage = rand(usr.attack,usr.attack+rand(1,10))
trg.Damage(damage,usr)
What is the M for? What is this M? Do I need to know any other programming languages to learn DM?
mob/M is the person attacking in both the Damage() and Death() procs
Hmmmm. So trg is the targeted mob/npc? (Brand new to programming. haha, this is my first language)
No, you don't. He passed M as an argument so he could access the attacker in the damage proc.

trg.Damage(damage,usr)
//Here he passed damage and usr as the first and
//second arguments, respectively.

proc/Damage(var/damage,mob/M)
//Here he defines which arguments can be taken and
//in what order, as well as typecasting M as a mob.
Well, I've been alerted to NOT post any code you could just copy into your source, though my intentions were to just show you the proper form of doing what you intended.

I apologize if I've somehow hendered your learning process.

trg is the mob being attacked, usr in the Attack() verb is the one attacking trg.

In both the Death() and Damage() procs, M is the usr from the Attack() verb and src is the trg from the Attack() verb.
DM is an easy language to pick up because a lot of the bigger work is done for you. You'll be fine.
Haha thanks guys, and @NNAAAHH, you did not hinder the learning process for me, you actually gave me some insight. Can I communicate any of you on MSN, or anything else in order to have some guidance, or is DM more of a solitary learning?
I would suggest doing some tutorials if you're having trouble, there are plenty around that cover the basics. ZBT, Forum_Account's tutorials, and Falacy's tutorial series are all decent options.

There's also the Dream Tutor series that LummoxJr did some time ago when you're ready for some more advanced topics.
Hmmmm alright, ill give them a shot ^_^ Thanks for the welcoming guys and help.
Also, if you're actually interested in learning, my MSN is on my profile. I don't mind helping people on a more personal level, but don't expect a 24/7 help line.
Thats understandable haha ^_^
OK, I'm gonna try to explain the code I posted in full.

mob/proc/Damage(var/damage,mob/M) and mob/proc/Death(mob/M) are both universal procs, available to be called with all mobs. The damage proc is called like so: mob.Damage(damage,attacker) in which the damage proc checks the damage number to ensure the mob's hp does not fall under 0. Then calls the death proc as so: mob.Death(attacker), in this proc it ensures that the mob dosn't have any more hp before killing it, reseting it's hp to the max amount allowed. Then this proc sends the mob to a spawning point, I have it set to 1,1,1 (x,y,z), this is a specific location on the map.

in-short: call Damage(damage,attacker) whenever a mob is injured.

mob/verb/Attack(mob/trg in oview(1)) will form a list of mobs within one tile of the usr, then prompt the usr to select a mob to attack, if only one mob is present it will choose that mob by default. In this verb, you want to calculate how much damage will be delivered to the trg, then call trg.Damage(damage,usr).
In response to NNAAAAHH
However, in a realtime fight, having to stop and select a mob to do damage to in a prompt is highly undesirable. The pop-up effect alone is very annoying, let alone having to decide AFTER executing the attack. This is why most developers use some kind of "target based" system, where the player will establish a "target" that all of their "skills" and whatnot will attack by default.
In response to Spunky_Girl
Alot of the games I look at select the target from the usr's dir using get_step().

I didn't say that the way used is the best way, just the way it was set up in the code.
And should there be multiple possible targets in front of the player, then that annoying pop-up will appear. Bad design is still bad design.
In response to Spunky_Girl
How would I do that then?
Page: 1 2