ID:270768
 
ive made a damage and health sytem.
i need help making a thing that when someones health gets down to 0 they will go to location (1,1,1).
any help?
and i need when they die a src that says "[usr] has been killed by [M]".
i dont expect code , maybe suggestions,demos,etc.
also does anyone know how to make a zone were you can't attack anyone?
urs.location=(1,1,1)

I think thats the right code :P

and for the cant attack anyone, you'd make a varable cannotattack, and when the person entered the area cannotattack=1. Then in the attack code you'd have it check to see if cannotattack=1.
Attack(mob/M in oview(1))
if(cannotattack=1)
usr<<"You cannot attack here!"
else
blah blah blah
blah blah blah
usr.deathcheck

proc/deathcheck)
if(usr.hp <= 0)
world<<"[usr] has been killed by [M]"
usr.hp=usr.maxhp
usr.location=(1,1,1)

some thing like the above, but you'd need to define M in the death check proc
In response to FriesOfDoom
thank you
In response to FriesOfDoom
FriesOfDoom wrote:
> urs.location=(1,1,1)
>

I think thats the right code :P

Wrong. First, location is not a variable to determine where a player is; loc is. You also can't just set something to a bunch of numbers; it's invalid syntax. You can use locate(), however, to get the turf in a coordinate.

usr.loc = locate(1,1,1)


and for the cant attack anyone, you'd make a varable cannotattack, and when the person entered the area cannotattack=1. Then in the attack code you'd have it check to see if cannotattack=1.

Or, you could check the /area object the player is standing on (which can be found by looking at the turf's loc, which is usually "player.loc.loc") However, if you don't only want to allow the player to attack if they're on the area, using a variable to check whether or not the player can attack would be the ideal choice.

> Attack(mob/M in oview(1))
> if(cannotattack=1)
> usr<<"You cannot attack here!"
> else
> blah blah blah
> blah blah blah
> usr.deathcheck
>
> proc/deathcheck)
> if(usr.hp <= 0)
> world<<"[usr] has been killed by [M]"
> usr.hp=usr.maxhp
> usr.location=(1,1,1)
>


Wrong again. First, you need to use the == operator to compare a variable to a value. It is also much better to just do a if(src.cannotattack) check instead since the value would only be 0 or 1 (a boolean variable).

You are also using usr in a proc, which is very wrong. usr is not "the user". src would be the player that is dying.

Other than your obvious syntax errors, you should not be helping people on the forum if you don't understand the subject completly yourself. There's nothing wrong with wanting to help someone, but it doesn't help when you're spreading bad or incorrect programming habits.

~~> Unknown Person
In response to Unknown Person
i said i though it was the right code part >_> i had a feeling it wasn't.
Besides he said he just wanted an example, so I gave him one, and one that couldn't be copied and pasted.
While i'm not a coding guru i did understand what he was asking.
I hope this is what your looking for, if not respond with more details.
mob/var/Health
mob/var/Safe

mob/verb/Attack(mob/M in get_step(usr,usr.dir))
if(M.Safe){usr<<"[M.name] can not be attacked!";return}
var/dmg=2*2//Put your damage stuff here
M.Health-=dmg
usr.deathcheck(M)
mob/proc/deathcheck(mob/M)
if(M.Health<=0)
if(M.client)
M.loc=locate(1,1,1)
world<<"[M.name] has been killed by [src.name]!"
else
del(M)

turf
Safezone
Enter(mob/M)
if(M.client)
M.Safe=1
Exit(mob/M)
if(M.client)
M.Safe=0
In response to Dalkon_101
Guys/girls who gave me code i said i don't wan't code.
i want suggestions,etc.
but thanks anyways.
In response to Kore2
Two problems I can see:

1. Your deathcheck proc is backwards. src should be the player who's dying, while the argument, M, should be the killer. It makes more sense to program it that way.

mob/proc/deathcheck(mob/M)
if(src.Health <= 0)
if(src.client)
src.loc = locate(1,1,1)
world << "[src.name] has been killed by [M.name]"
else
del(src)

mob/verb/Attack(mob/M in get_step(src, src.dir))
...
M.deathcheck(src)


2.) You should be using Entered() and Exited() instead of Enter() and Exit() because the former procs get called when something successfully entered or exited the area. You also are assuming that the enterer of the turf is a mob, which isn't always true. If a free-flying projectile were to enter the turf, it would produce a runtime error because objs don't have a "client" variable. You need to check if the enterer is a mob, and type cast accordingly.

I also suggest you to use areas instead of turfs to determine safe zones. If you are using turfs, Entered() and Exited() would be called every time you would move. Using areas would be more flexible because you would have to program the safe area code for every single turf you want to be safe. It would also only call the movement procs whenever you move into another area, since there is only one instance of an area in the whole game.

Using areas would also be an easier way to determine a safe zone because, in most cases, you can look at "src.loc.loc" to find an area a player is on. (This is only true when the player is on the actual map, and is not in anything else's contents) This could also help to stop relying on a variable to determine whether one is safe or not.

Here is an example of using a variable.
area/safezone
Entered(mob/M)
if(ismob(M) && M.client) // check if it is a mob, and if the mob has a player
M.Safe = 1
return ..() // do the default Entered() functions, and return it
Exited(mob/M)
if(ismob(M) && M.client)
M.Safe = 0
return ..()


If you don't want to rely on a safe variable, you can replace the if(M.Safe) check.

mob/verb/Attack(mob/M in get_step(src, src.dir))
if(istype(src.loc.loc, /area/safezone)) // if the player's area is a safe area
src << "[M.name] cannot be attacked!"
return
// ...

area/safezone


~~> Unknown Person
In response to Unknown Person
Unknown Person wrote:
Two problems I can see:

1. Your deathcheck proc is backwards. src should be the player who's dying, while the argument, M, should be the killer. It makes more sense to program it that way.

> mob/proc/deathcheck(mob/M)
> if(src.Health <= 0)
> if(src.client)
> src.loc = locate(1,1,1)
> world << "[src.name] has been killed by [M.name]"
> else
> del(src)
>
> mob/verb/Attack(mob/M in get_step(src, src.dir))
> ...
> M.deathcheck(src)
>
>


When calling
M.deathcheck(src)

wouldnt it check to see if the player using the verb health is <=0 instead of the mob?
In response to Kore2
Kore2 wrote:
When calling
M.deathcheck(src)

wouldnt it check to see if the player using the verb health is <=0 instead of the mob?

Think about it. In your attack verb, "M" is the player who is getting attacked. M, in the deathcheck proc, is the player who tried to or has killed src, which would be M in the Attack proc.

~~> Unknown Person