ID:262143
 
Sigh new problem

        Attack()
var/mob/M = locate() in get_step(src,src.dir)
if (!M)
return
if(src.NPC == 1)
usr<< "<font size = 1>You cant attack that"
if(usr.hitting == 0)
if(usr.Strength - M.Defence > 0)
usr.hitting = 1
flick("punch",usr)
var/dmg = usr.Strength - M.Defence
if(M.HitPoints- dmg <= 0)
if(alert(usr,"Spare [M]?","Spare","Yes","No")=="No")
M.HitPoints -= dmg
src.Update(src)
M.PowerlevelCheck()
sleep(1)
usr.hitting = 0
else
src.Update(src)
usr.hitting = 1
M.HitPoints -= 1
M.PowerlevelCheck()
usr.hitting = 0


ok when i attack my friend it says do you wish to spare but when he attacks me it dosent ?!?!?
Is this a proc? If it is...why didn't you listen to Lummox Jr...No usr in proc. Ungh.

Even it is a verb, you should try to avoid usr. Replace it with src or somekind of arguement.

Also I think that you should do
M.hitpoints - dmg = somerandomvar
if(somerandomvar <=0)
//Blah blah blah
In response to N1ghtW1ng
ok its still doing it
In response to Dranzer_Solo
Are you using usr?
In response to N1ghtW1ng
ok i wasnt sure but do i change M to src also or just usr?

mob
proc
Attack()
var/mob/M = locate() in get_step(src,src.dir)
if (!M)
return
if(src.NPC == 1)
usr<< "<font size = 1>You cant attack that"
return
if(usr.hitting == 0)
if(src.Strength - M.Defence > 0)
usr.hitting = 1
flick("punch",usr)
var/dmg = src.Strength - M.Defence
if(M.HitPoints- dmg <= 0)
if(alert(usr,"Do You Wish To Spare [M] Life?","Spare?","Yes","No")=="No")
M.HitPoints -= dmg
src.Update(src)
M.PowerlevelCheck()
sleep(1)
src.hitting = 0
else
src.Update(src)
src.hitting = 1
M.HitPoints -= 1
M.PowerlevelCheck()
src.hitting = 0
In response to Dranzer_Solo
Dranzer_Solo wrote:
ok i wasnt sure but do i change M to src also or just usr?

No, don't do that. "usr", to put it simply, is the last player to do something. Therefore, when using procs, one could end up with "usr" being equal to something totally different then they wanted.

The fix:
mob
proc
Attack(mob/M as mob in oview(1))//oview(1) means that the player may choose from a list of every mob within 1 tile of him, exculding the tile in which he occupies.
if(src.NPC)
usr<< "<font size = 1>You cant attack that"
return
if(!src.hitting)//Notice how I used the ! operator. This protects aginst hitting being equal to null or "" or any other 0-like values, in addition to of course, 0.
if(src.Strength - M.Defence > 0)
usr.hitting = 1
flick("punch",usr)
var/dmg = src.Strength - M.Defence
if(M.HitPoints- dmg <= 0)
if(alert(src,"Do You Wish To Spare [M] Life?","Spare?","Yes","No")=="No")
M.HitPoints -= dmg
src.Update(src)
M.PowerlevelCheck()
sleep(1)
src.hitting = 0
else
src.Update(src)
src.hitting = 1
M.HitPoints -= 1
M.PowerlevelCheck()
src.hitting = 0

In response to Wizkidd0123
Now i get a runtime error

runtime error: Cannot read null.Defence
proc name: Attack (/mob/proc/Attack)
source file: Attack_System.dm,8
usr: Dave (/mob/Player/Saiyan)
src: Dave (/mob/Player/Saiyan)
call stack:
Dave (/mob/Player/Saiyan): Attack(null)
Hit (/obj/Hud/Hit): Click(the grass2 (55,111,1) (/turf/earth/grass2))