ID:261716
 
When i use this code...

DeathCheck(mob/M)
if(!src)
oview() << "DFJSD"
return

if(istype(src,/mob/Monster))
NPCDeathCheck(src)
goto END
if(M.HP <= 0)
if(M.Dead)
world << "
[src] has killed [M] in battle!"
M << "You have died! You lost half of your gold."
M.icon_state = "Dead"
M.Locked = 1
M.Dead = 1
M.density = 0
sleep(50)
M.loc = locate("[M.LastCity]respawn")
M.Locked = 0
M.density = 1
else
..()
END

It works for the NPC. But when i attack a client it doesn't work, but when i attack an NPC, it works. Any problem with this?
Unknown Person wrote:
It works for the NPC. But when i attack a client it doesn't work, but when i attack an NPC, it works. Any problem with this?

Yes, lots.

  • You're using oview() instead of oview(src) in a proc.
  • You didn't close all of your HTML tags or put your code in <DM> tags for the forum.
  • You're using goto where it shouldn't be used at all; a simple "else" before the next if() will suffice.

    Lummox JR
    DeathCheck()
if(!src)
oview(src) << "DFJSD"
return
if(istype(src,/mob/Monster))
NPCDeathCheck(src)
if(src.HP <= 0)
if(src.Dead)
world << "[src] has killed [M] in battle!"
src << "You have died! You lost half of your gold."
src.icon_state = "Dead"
src.Locked = 1
src.Dead = 1
src.density = 0
sleep(50)
src.loc = locate("[src.LastCity]respawn")
src.Locked = 0
src.density = 1


RaeKwon
In response to RaeKwon
RaeKwon wrote:
    DeathCheck()
if(!src)
oview(src) << "DFJSD"
return
if(istype(src,/mob/Monster))
NPCDeathCheck(src)
if(src.HP <= 0)
if(src.Dead)
world << "[src] has killed [M] in battle!"

Actually that'd be "[M] has killed [src]", except you never specified M:
DeathCheck(mob/M)   // M is the killer, src the victim

Lummox JR
In response to Lummox JR
Lummox JR wrote:
RaeKwon wrote:
    DeathCheck()
> if(!src)
> oview(src) << "DFJSD"
> return
> if(istype(src,/mob/Monster))
> NPCDeathCheck(src)
> if(src.HP <= 0)
> if(src.Dead)
> world << "[src] has killed [M] in battle!"

Actually that'd be "[M] has killed [src]", except you never specified M:
DeathCheck(mob/M)   // M is the killer, src the victim

Lummox JR

Oops, or
world<<"[usr] has killed [src] in battle!"


usr is the killer, src is the victim. Works great =)

RaeKwon
In response to RaeKwon
RaeKwon wrote:
Oops, or
world<<"[usr] has killed [src] in battle!"

usr is the killer, src is the victim. Works great =)

Except for the fact that it doesn't, since this is in a proc and usr has no place there.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Except for the fact that it doesn't, since this is in a proc and usr has no place there.

Lummox JR

Yeah, it works, i've used this in Zeta from Day 1.

    DeathCheck()
if(istype(src,/mob/training_units/pbag))if(src.powerlevel<=0){src.powerlevel=1;usr.exp+=1;usr.Skills();..()}
if(istype(src,/mob/player))
if(src.powerlevel <= 0)
if(src.arena==1&&usr.arena==1)
world << "<b>Arena:</b>[src] was demolished by [usr]."
src.dead=1
src.arena=0
usr.arena=0
usr.challenge=0
src.challenge=0
usr.powerlevel=usr.maxpowerlevel
src.powerlevel=src.maxpowerlevel
if(src.ibh==1)src.ibh=0
usr.challenged=0
src.challenged=0
src.loc=locate(138,4,2)
usr.loc=locate(129,14,1)
src.pk=0
usr.pk=0
playerslain++
return
else
src.powerlevel = 5
new/obj/RIP(src.loc)
src.loc=locate(138,4,2)
src.deaths+=1
src.overlays+='halo.dmi'
src.dead=1
src.inbar=0
src.ingmr=0
if(usr.grav>0)world<<"<font color=red><B>Info: [src] Died while training under gravity."
else if(src==usr)world<<"<font color=red><B>Info: [usr] Has Killed Himself."
else world<<"<font color=red><B>Info: [src] Was Killed By [usr]."
usr.zenni += src.zenni
src.zenni = 0
usr.grav = 0
usr.kills+=1
usr.Skills()
playerslain++
if(src.ibh==1)src.ibh=0
if(src.inbuildingland==1)
src.inbuildingland=0
src.verbs-=/mob/build/verb/BUILD
src.verbs-=/mob/build/verb/BUILD
switch(rand(1,2)){if(1){usr.maxpowerlevel+=1;usr.powerlevel+=1}if(2){usr.maxpowerlevel+=0;usr.powerlevel+=0}}
usr.staminaCheck()
if(istype(usr,/mob/player))usr.icon_state = ""
usr.attacking=0
usr.DeathCheck()
return


// There is more but I cut it off.

RaeKwon
In response to RaeKwon
usr doesn't belong in procs.
In response to RaeKwon
RaeKwon wrote:
Yeah, it works, i've used this in Zeta from Day 1.

Who gives a crap if it's worked in the past? Point is, usr is unsafe in procs unless the proc is only ever called by a verb where usr is a known value.

For safety's sake, it's better never to put usr in a proc at all. It's safest to restrict usr only to verbs, and have them call procs with additional vars if necessary.

It may "work" for you in your particular program, but export that DeathCheck() to any other program and it could introduce a host of difficult-to-trace errors. And the practice of putting usr in procs in general is just boneheaded, and shouldn't be encouraged.

In essence right now we're partly paying for your bad programming practices because these idiots asking for help on ripped Zeta code keep re-introducing errors into the community. Granted you never meant that code to get out, but I use this just to illustrate how one mistake can beget hundreds. It's bad enough to program in bad code in the first place, but to tell others to use it when you know better is asinine.

To put it bluntly: Don't go telling people to replace a var that should be in their proc with usr, which pretty much shouldn't be in any proc. DUH!

Lummox JR