ID:142747
 
Code:
mob
proc
Deathcheck()
if(src.Hp <= 0)
if(istype(src.client))
src << "You have died, [usr] killed you!"
usr << "You killed [src]"
src.loc = locate(1,1,2)






mob
verb/Attack(mob/M in oview(1))
set category = "Battle"
var/damage = src.Str - M.Rfx
if(M.client)
M.Hp -= damage
src <<"You attack [M] for [damage]!"
M <<"You are being attacked by [src]!"
src.Levelup()
M.Deathcheck(src)
else
M.Hp -= damage
src <<"You attack [M] for [damage]!"
M <<"You are being attacked by [src]!"
var/random = rand(1,3)
if(random == 1)
src.Exp += 4
if(random == 2)
src.Exp += 3
if(random == 3)
src.Exp ++
src.Levelup()
M.Deathcheck()





obj
Fireball
icon='fireball.dmi'


mob/verb
StraightAttack()
var/obj/Fireball/A=new(src.loc)
A.dir=src.dir
var/dmg=usr.Str-src.Rfx//Set damage equations here
var/mob/M=Projectile(src,A,5,dmg,2,0,0,0,0,0)
if(M==1)
//You could show stop animation here, this means that it ran out of distance.
del(A)
else if(M)//If hit
world<<"[src.name] hit [M.name] for [dmg]!"//Set damage procs here.
del(A)
M.Deathcheck()


HomingAttack()
var/list/L=list()
for(var/mob/M in oview(6,src))
L+=M
var/mob/H=input(src,"Who?") in L//If homing, who to hit? XD
var/obj/Fireball/A=new(src.loc)
A.dir=src.dir
var/dmg=usr.Str-src.Rfx
var/mob/M=Projectile(src,A,5,dmg,2,1,0,H,0,0)
if(M==1)
del(A)
else if(M)
world<<"[src.name] hit [M.name] for [dmg]!"
del(A)
M.Deathcheck()

//I'll explain the first one, the rest should be self explanitory.
proc/Projectile(mob/M,obj/O,distance,dmg,delay,Homing,Area,mob/H,duration,radious)//Set all your values here, M=usr, O=obj called upon, distance=distance in tiles, delay=delay between movements, homing/area=if homing/area 1 on true 0 on false, H = hommed upon, duration if area in seconds, radious in tiles if area.
if(Homing&&H)//If its homing, and someone to home apon
while(distance>0&&O&&M&&H)//whiole there is someone to home, its not travled distance, obj still here, and usr is.
var/mob/target//Set a target if hit
O.dir=get_dir(O,H)//sets the obj dir to face H
for(var/mob/A in get_step(O,O.dir)) //for every mob in 1 step in front of you
if(A&&A!=M&&ismob(A))//if there is one, and if its not you and its a mob
target=A//target it for attacking
step_towards(O,H)//step towards the H(Being homed)
sleep(delay)//wait the delay
distance--//take away a distance in tiles travled
if(target) return target//If a target was hit, return and set the target attack to him
if(M&&O&&H)//If everything here
return 1//return 1, which means stopped.
else if(!H&&M&&O)//If everyone but H is here
Homing=0//Attack isnt homing
Projectile(M,O,distance,dmg,delay,0,0,0,0,0)//and continues to move forward
else if(Area)//If an area attack
while(duration>0&&O&&M)
duration-=1
var/list/mob/targets=list()
for(var/mob/S in oview(radious,O))
if(S!=M)
targets+=S//sets mobs in the target list to attack
sleep(10)
if(targets) return targets
else
while(distance>0&&O&&M)
var/mob/target
for(var/mob/A in get_step(O,O.dir))
if(A&&A!=M&&ismob(A))
target=A
step(O,O.dir)
sleep(delay)
distance--
if(target) return target
if(M&&O)
return 1



mob
human
icon='human.dmi'
src.Deathcheck()


Problem description:

ok well im trying to make a guy in my game die when his hp hits 0. ok i got death check so when he hits 0 he dies. so i made a mob just to try it out. now whenever i hit him withmore then 100 damage he still doesnt die..even tho his mob/var/Hp=100 .. heres a code
That's because you've restricted the death proc to only clients with the following:

if(istype(src.client))


Which should be:

if(src.client)


With the ultimate code being:

mob/proc/Deathcheck(var/mob/killer, var/mob/dying)
if(dying.Hp <= 0 && dying.client)
dying << "You have died, [killer] killed you!"
killer << "You killed [dying]"
dying.loc = locate(1,1,2)


Ugh thanks to DoS for pointing out an embarrassing mistake. ;P
In response to Siientxx
With the killer/victim arguements, you could further simplify that by making it a generic proc instead of a mob proc.

Well... if you didn't mess up the arguements, anyway. var/mob/killer, not mob/var/killer.
In response to Devourer Of Souls
sorry but none of these worked :'(
In response to Agrey123
Because the human mob isn't a client. Clients are real players that login. Just use: if(ismob(M)).
In response to Takoma
Takoma wrote:
Because the human mob isn't a client. Clients are real players that login. Just use: if(ismob(M)).

what?? where do i put that if(ismob(M))??? im so confused. my death check wont kill the mob i made not a real player what do i have to do to make it so i can attack it witha real player and it dies if ITS hp goes to 0 a mob char not a real char
In response to Agrey123
Post your new code.
In response to Agrey123
mob
proc
Deathcheck(mob/M) //mob/M in the one that got killed
if(M.Hp <= 0)
M << "You have died, [src] killed you!"
src << "You killed [M]"
M.loc = locate(1,1,2)

mob
verb/Attack(mob/M in oview(1))
set category = "Battle"
var/damage = src.Str - M.Rfx
if(M.client)
M.Hp -= damage
src <<"You attack [M] for [damage]!"
M <<"You are being attacked by [src]!"
src.Levelup()
src.Deathcheck(M)
else
M.Hp -= damage
src <<"You attack [M] for [damage]!"
M <<"You are being attacked by [src]!"
var/random = rand(1,3)
if(random == 1)
src.Exp += 4
if(random == 2)
src.Exp += 3
if(random == 3)
src.Exp ++
src.Levelup()
src.Deathcheck(M) // also changed this so M in included in the Death proc
In response to Takoma
Takoma wrote:
> mob
> proc
> Deathcheck(mob/M) //mob/M in the one that got killed
> if(M.Hp <= 0)
> M << "You have died, [src] killed you!"
> src << "You killed [M]"
> M.loc = locate(1,1,2)
>
> mob
> verb/Attack(mob/M in oview(1))
> set category = "Battle"
> var/damage = src.Str - M.Rfx
> if(M.client)
> M.Hp -= damage
> src <<"You attack [M] for [damage]!"
> M <<"You are being attacked by [src]!"
> src.Levelup()
> src.Deathcheck(M)
> else
> M.Hp -= damage
> src <<"You attack [M] for [damage]!"
> M <<"You are being attacked by [src]!"
> var/random = rand(1,3)
> if(random == 1)
> src.Exp += 4
> if(random == 2)
> src.Exp += 3
> if(random == 3)
> src.Exp ++
> src.Levelup()
> src.Deathcheck(M) // also changed this so M in included in the Death proc
>
>


ty that worked with my attack verb but what about my techs how do i make them work so that they also can kill mobs and normal ppl :S


mob/verb
StraightAttack()
var/obj/Fireball/A=new(src.loc)
A.dir=src.dir
var/dmg=usr.Str-src.Rfx//Set damage equations here
var/mob/M=Projectile(src,A,5,dmg,2,0,0,0,0,0)
if(M==1)
//You could show stop animation here, this means that it ran out of distance.
del(A)
else if(M)//If hit
world<<"[src.name] hit [M.name] for [dmg]!"//Set damage procs here.
del(A)



HomingAttack()
var/list/L=list()
for(var/mob/M in oview(6,src))
L+=M
var/mob/H=input(src,"Who?") in L//If homing, who to hit? XD
var/obj/Fireball/A=new(src.loc)
A.dir=src.dir
var/dmg=usr.Str-src.Rfx
var/mob/M=Projectile(src,A,5,dmg,2,1,0,H,0,0)
if(M==1)
del(A)
else if(M)
world<<"[src.name] hit [M.name] for [dmg]!"
del(A)
In response to Siientxx
how do i make my techs hit and kill mobs and humans now :S

mob/verb
StraightAttack()
var/obj/Fireball/A=new(src.loc)
A.dir=src.dir
var/dmg=usr.Str-src.Rfx//Set damage equations here
var/mob/M=Projectile(src,A,5,dmg,2,0,0,0,0,0)
if(M==1)
//You could show stop animation here, this means that it ran out of distance.
del(A)
else if(M)//If hit
world<<"[src.name] hit [M.name] for [dmg]!"//Set damage procs here.
del(A)



HomingAttack()
var/list/L=list()
for(var/mob/M in oview(6,src))
L+=M
var/mob/H=input(src,"Who?") in L//If homing, who to hit? XD
var/obj/Fireball/A=new(src.loc)
A.dir=src.dir
var/dmg=usr.Str-src.Rfx
var/mob/M=Projectile(src,A,5,dmg,2,1,0,H,0,0)
if(M==1)
del(A)
else if(M)
world<<"[src.name] hit [M.name] for [dmg]!"
del(A)
In response to Agrey123
This should work. I rushed it, so tell me if anything fails.

proc
deathcheck(var/mob/ref, var/mob/target)
if(target.health <= 0)
target <<"<b>Oh no!</b> You've died."
ref <<"You've killed [target]!"
// Do whatever here to revive the dead target.

obj
proc
Travel()
var/turf/T = get_step(src,src.dir)
if(!T)
del src
step(src,src.dir)
spawn(5) Travel()

Fireball
var/mob/owner
density = 1
Bump(atom/A)
if(ismob(A))
var/mob/M = A
if(M.client)
var/damage = rand(1,10)
M <<"You were hit by a fireball. You take [damage] damage."
owner <<"Your fireball hit [M] for [damage] damage."
M.health -= damage
deathcheck(owner, M)

..(); del src

mob
verb
Fireball()
var/obj/Fireball/F = new(get_step(src,src.dir))
F.dir = src.dir
F.owner = src
F.Travel()
src <<"You summon a blistering fireball!"
In response to Siientxx
err the only thing this does is summon a fire ball in front of u, all i want to do is use my code that ihave for my fire homing and fire straight attacks to actually kill the other person..
In response to Agrey123
Check the code again. I edited it.
In response to Siientxx
now when i do it , it summons a fire ball... but when it hits the mob.. it doesnt hurt them.. they dont die... thats what i wanted the hole time.. i jsut want when the fireball hits the mob they actually take the damage to there hp and die when ther 0 hp
In response to Agrey123
if(M.client) // The program will only execute the code below this if the variable (M) is a client, in laymen terms, a human being; a player.


if(!M.client) // The program will only execute the code below this if the variable (M) is not a real human being, and is a client-less atom.


Want the fireball to work on both humans and AI characters? Take out the if(M.client) or if(!M.client) check.
In response to Siientxx
so if u were to give me the code for all of this so i can attack with my hominh and straight fireball attack and actually HURT the person not using the code u made the one i posted how would i look?
In response to Agrey123
Sorry, I don't feel like sorting through all of that.
In response to Siientxx
dang i i wish i knew how to do it tho..
I'm getting tired of all this bad advice. Here's how you write deathcheck():

mob/proc/deathcheck(var/mob/killer)
if(hp <= 0)
src.death(killer)

mob/proc/death(var/mob/killer)
//if we were killed by somebody
if(killer)
view(src) << "[src] has been killed by [killer]!"
//if we were killed by nothing
else
view(src) << "[src] has spontaneously combusted!"
del(src)

//players die in a different manner
mob/player/death(var/mob/killer)
if(killer)
view(src) << "[src] has been killed by [killer]!"
else
view(src) << "[src] has spontaneously combusted!"
loc = locate(1,1,2)
hp = maxhp


All players must be of type mob/player or one of its subtypes. For mobs that you want to do something different on death, just override the death() proc like I've done for mob/player. For example, that's where you'd put a mob dropping loot, or creating a corpse, or giving exp to the killer.

For making a working projectile:

obj/projectile
density = 1
var/damage = 10
var/mob/owner
//used to create a projectile
New(var/mob/owner)
src.owner = owner
loc = owner.loc
dir = owner.dir
spawn() projectileloop()
proc
projectileloop()
//step forward until the step fails
while(step(src,dir))
continue
//we've failed a movement, so look for a mob to hurt
var/mob/M = locate() in get_step(src,dir)
//if we found one, hurt them
if(M)
M.hp -= damage
//give the credit for damage to our owner
M.deathcheck(owner)
//delete the projectile because it's run into something
del(src)