ID:142167
 
Code:
mob/proc
Death(mob/M)
if(src.type == /mob/player)// If a player dies
PlayerDie()
if(src.type == /mob/monster)// If a monster dies
Monsterdie()
// if(src.HP <=0)

PlayerDie(mob/M)//If the player dies.
if(src.HP <= 0)// if hp is smaller than 0
view() << "[src] died!"// In the view tells who died.
src.loc = locate(1,1,100)// Sends player to death screen.
sleep(30)
src.loc = locate(10,10,1)// Sends player to spawn point.
src.HP = MaxHP
src.Energy = MaxEnergy
src.locked=0
src.firing=0

Monsterdie(mob/M)
if(M.HP <= 0)
view() << "[src] was killed!"// In the view tells who died.


src.loc = locate(1,1,99)// sends NPC to NPC death screen.
src.locked=1
src.firing=1
sleep(1000)
src.loc = locate(50,50,1)// sends the NPC to its respawn point.
src.HP = src.MaxHP
src.Energy = src.MaxEnergy
src.locked=0
src.firing=0

mob/monster/Student
icon = 'Student.dmi'
icon_state = "NPC"
name = "Student"
monster=1
HP = 100
MaxHP = 100
Power = 10




Problem description: When a player attacks an NPC there HP does down but the Monsterdie() proc doesn't work. If anyone can help modify this code or just point me in the right direction i'd be grateful.

Look up the istype proc. == /mob/monster etc. isn't very robust. Also, why are you passing an arg for M? You're calling the proc for the src, yet you check M's health. Because M is null, you get runtime errors.
In response to Jeff8500
Jeff8500 wrote:
Look up the istype proc. == /mob/monster etc. isn't very robust. Also, why are you passing an arg for M? You're calling the proc for the src, yet you check M's health. Because M is null, you get runtime errors.

Im sorry but im having this same problem, but i dont understand what you mean. Could you simplify it. My coding is almost exactly like his.
In response to Kevin Mask
Did you guys even read the ZBT's? An arguement is like a variable in a way. When you call a proc, you put the value of the arguements in the parenthises.

For example:

mob/proc/Pie(t) //this creates an arguement called t. Just because you define it
//doesn't give it a value!
world << t //this outputs the value of t to the world

mob/verb/Call_Pie()
usr.Pie() //this calls the Pie proc without an arg for t. Thus, t is equal to its default, null.
usr.Pie("This is an arg!") //this calls the Pie proc with an arg. Therefore it will say t = "this is"...

mob/proc/Pie2(t="Wewt") //for the Pie2() proc, the default for t is "Wewt"
world << t //outputs the value of t to the world

mob/verb/Call_Pie2()
usr.Pie2() //this would output "Wewt" to the world, because that is the default


You also don't want to use usr in procs (just a fair warning). The problem is, M defaults to null (nothing), and you never pass a value for it. Therefore, M stays nothing. Because of this, M doesn't have an HP var.


You don't need to pass arguements in a proc like that. src would suffice as long as the proc is defined under something. For example:

mob/proc/Thing()
world << src //output the name of the src to the world

mob/verb/SRC_CHECK()
usr.Thing() //have the usr call the Thing() proc. Whatever calls the proc is the src.
//therefore, it would output the usr to the world!
You need to look up then use the istype() proc (this means read about it in the DM Reference, which is also available by pressing F1 in Dream Maker). Comparing the types is fine and dandy, but most often it is unsuitable. As you should know, an object's type var contains the actual type path of that object, and the == operator compares 2 values to check if they're equal. However, istype() is a proc for checking types, that checks if an object is derived (is of type, or a child of) of the type used. Consider your monster object: /mob/monster/Student. In your Death() proc, you are checking if the monster's type equals /mob/monster, but it will return false for your Student because his type is /mob/monster/Student, which is a different type (not equal) than /mob/monster, so it doesn't execute the if():
if(/mob/monster/Student == /mob/monster)
//will never run, of course


Also, when checking the same value (or similar) for multiple conditions, instead of using a chain of if()s use else-if()s afterwards, so it doesn't keep checking the value if an if() already passed. And on the last condition, you can most often simply put an 'else' statement, as you should know. So in this case you could have only 1 if() and 1 else.

Also, it looks like you're aware that the 'usr' variable shouldn't be used inside most procs, but here:
Triomax202 programmed:
>   Monsterdie(mob/M)
> if(M.HP <= 0)
> view() << "[src] was killed!"// In the view tells who died.


The 'usr' variable is used in the view() call. Why? You have supplied no arguments (the parentheses are empty), and if you look view() up in the DM Reference, you'll see that the default Center argument is usr. This is good for verbs, but for procs you must remember to always specify a proper Center argument.
Additionally - this is a common mistake - you actually shouldn't be using the view() proc for this. The view() proc returns the atoms in the view/sight of the Center, so (after you fix the Center) the message will be output to people that the monster can see, instead of all the people that can see the monster. It is easy to see that this will sometimes not work well, since if a player can see the monster for whatever reason while the monster can't see him, he won't be notified. This is the same principle as for things like Say() verbs. Anyway, you need to use a different proc for this - viewers(). It returns the people that can see the Center object. =) You should look it up; it has the same default Center argument as view(), so remember to specify it correctly.
In response to Jeff8500
M is not a null var.

    Monsterdie(mob/M)//see M is not a null var, he just got to delete mob/M it should be Monsterdie()
if(M.HP <= 0)//all he got to do is remplace M for src
view() << "[src] was killed!"// In the view tells who died.


src.loc = locate(1,1,99)// sends NPC to NPC death screen.
src.locked=1
src.firing=1
sleep(1000)
src.loc = locate(50,50,1)// sends the NPC to its respawn point.
src.HP = src.MaxHP
src.Energy = src.MaxEnergy
src.locked=0
src.firing=0

In response to Bleach Studio
Bleach Studio wrote:
M is not a null var.

Not true. In context, when he calls that proc here:

mob/proc
Death(mob/M)
if(src.type == /mob/player)
PlayerDie()
if(src.type == /mob/monster)
Monsterdie() //<-------


He does not define M, thus it is null.
In response to K'ros Trikare
my bad, my bad, anyways, i did read the post too fast.