ID:141993
 
Code:
mob
var/HP = 9999

proc
Deathcheck()
if (HP <= 0)
world << "[usr] has died."
del (src)

verb
Attack(mob/Victim in oview(1))
var/damage
if (src.icon == "Mog.dmi") damage = 204
if (src.icon == "Shadow.dmi") damage = 220
oview() << "[usr] attacks [Victim] for [damage]"
HP -= damage


Problem description:
I'm trying to make damage causes by the attack verb different depending on the icon used. Yet it isn't working and i've tried several outcomes and they all choose the attack as 0.

Icons = single quotes, not double quotes. That's not a very good way of doing damage, though; why not create a strength variable?
In response to Jeff8500 (#1)
Oh they were single quotes, I changed my icons to icon states to see if that worked, I didn't want to make a str verb as I wanted certain icons to have certain attack strengths then with their own unique attacks with different strengths and weakness'
In response to Gyroz (#2)
Still, there are better ways to do it. I understand that you're learning still, however, and I know this would help you a lot.
Yes, icons are not the way to go at all; checking by those, or similar things like the name, is very bad and not robust. It's simply a bad solution. Indeed the best course of action would be to add a variable to the mobs that can engage in combat that determines their varying attack strength.
mob/character
var/strength = 1
Mog
strength = 25
Shadow
strength = 35
verb/Attack(mob/M in get_step(src,src.dir))
var/dmg = rand(strength/2,strength) //quick formula (the result should be rounded already because rand() with arguments returns integers)
viewers(src) << "[src] attacks [M] for [dmg] damage!"

Usually a 'defense' var is also implemented and used in the damage formula, though it often requires some balancing and thinking of the right formula.
Also, take care when using the 'usr' var. In this case you're using it in a verb which is okay, though, you're also using src, for the same object. usr and src refer to the same object in mob verbs in most cases (provided you don't override the default src setting for them), but you should stick to using one (preferably 'src', mind you) and not use both to refer to the same object, because that is not robust as they are situations when they're not the same, and it's also not uniform. Additionally note that 'usr' is also used in your oview() call, because as you've supplied no arguments (parameters), it assumes you want to use the default value, which is usr.
Other than the double-quote/single-quote problem, your Deathcheck() is going to tell the world that the attacker died, because you're using usr. I suggest switching usr into src.

Although now that I look at your attack verb, you don't even call Deathcheck().
In response to Kaiochao (#5)
Kaiochao wrote:
Other than the double-quote/single-quote problem, your Deathcheck() is going to tell the world that the attacker died, because you're using usr. I suggest switching usr into src.

The point is .. ?

usr would be the same person as src in that proc. Just that src is more correct, so if he changed, he'd still have that problem, depending on how he called the proc. <_<
mob/character
var
HP = 9999
str = 1
tmp
attacking = 0
Mog
str = 204
Shadow
str = 220

proc
Deathcheck(mob/killer)
if (HP <= 0)
world << "[src] has been killed by [killer]."
del (src)

verb
Attack(mob/character/Victim in get_step(src,src.dir))
if(attacking)
return
var/damage = src.str
view()<<"[Victim] has been attacked by [src] for [damage] damage"
Victim.HP -= damage
Victim.Deathcheck(src)
/* If you want some delay for attacking once delete /*
attacking = 1

sleep(3)
attacking = 0
*/



I hope i helped you =)
In response to Andre-g1 (#6)
If Deathcheck() was called in Attack(), usr is the person who called Attack(). usr is the attacker.

Either way, it's usr abuse :\
In response to Kaiochao (#8)
Not if he does Victim.DeathCheck()
In response to Andre-g1 (#9)
usr is determined by the caller of the proc that called it.

You click Attack(). All procs within Attack() initially has usr=You unless changed within the proc.

In Victim.Deathcheck(), Victim is the src.
In response to Kaiochao (#10)
All procs within Attack() initially has usr=You

That's err, incorrect ..

If you do it like this for example;

mob/var
HP=50
mob/verb/Attack()
var/mob/M = locate() in get_step(usr,usr.dir)
flick("attack",usr)
if(M)
M.HP -= rand(1,20)
if(M.HP <= 0)
M.DeathCheck(usr)
mob/proc/DeathCheck(mob/Killer)
src << "You have been killed by [Killer]"
del src


The src in the DeathCheck() is NOT the same as usr in Attack().
In response to Andre-g1 (#11)
But you guys were talking about usr, not src...

In both Attack() and DeathCheck(), the usr is the same. Attack()'s current usr is automatically passed to DeathCheck() when it is called.
In response to Kaioken (#12)
Exactly what I said.