ID:264888
 
I was following this ZBT tutorial, and what im trying to do is make "gold" appear in place of a mob that gets deleted and then I also want to Respawn that mob within 30 seconds, the way he described doesn't work, I keep getting the error cannot have a proc Def. inside another proc, am I doing something wrong?




mob
proc
DeathCheck(mob/M)
if (HP <= 0)
world << "[usr] killed [src]!"
del(src) //delete w.e just died
Del()
var/obj/gold/G = new(loc)
G.amount = rand(1,10)
..()


The first problem I notice was that your using usr inside a proc, which is a no no. Here is a pretty simple Death system with a gold dropping system implemented. Not all the code is within to make it function, but you should be capable of doing the rest. You can also just use it to reference also, that way you learn more from it. Whichever you prefer I guess.


Your Code:
mob
proc
DeathCheck(mob/M)
if(HP <= 0) ///Whose HP was it checking?
world << "[usr] killed [src]!" ///You shouldn't use usr inside a proc!
del(src) //You never had a src to delete
Del() ///What is this one deleting?
var/obj/gold/G = new(loc)
G.amount = rand(1,10)
..()



My Code:
mob
proc
DeathCheck(mob/M)
if(src.HP <= 0) ///Checks to see if the mob has ran out of life
if(src.race == "Monster") ////The race of whatever you killed
if(src.gold >= 1) ////Checks to see if the Mob has money to drop
var/dropgold = src.gold ///The gold that is drop is however much the mob has
var/O = new /obj/goldbag(src.loc) ///Creates the gold where the mob was
O:gold = dropgold
del(src) ////Deletes the mob
spawn(50) ////This is the time setting until the mob respawns
src.New()
var/Random = rand(1,2) ////Changes the spawn point up, so the mob doesn't spawn in the same spot
if(Random == 1)
var/meep = /mob/Monster ////Creates the new mob
new meep(locate(X,Y,Z)) ///Location of the new mob
if(Random == 2)
var/meep = /mob/Monster
new meep(locate(X,Y,Z))
In response to Shadow813
Ok so I tried to impliment your code and also edited some stuff in it and my own code to try to Narrow down the 13 errors it gave me but now im stumped. I Narrowed this down to 6 errors which is mainly I'm entirely having trouble with the whole "race" issue, I havent read a tutorial that teaches anything regarding races such as



if(src.race == "Monster") ////The race of whatever you killed


I was thinking I have to do this with a variable? could you nudge me in the right direction? ^^ thank you in advance oh another issue im having which would probably be solved if u can nudge me with the first one is regarding src.gold, I've made an obj of gold, got the icon's made, all that good stuff. but I realize it says it is an undefined Var, that much I do understand, and also before I forget Mob/Monster, Undefined path, which as I Said I can probably fix if I just get a tiny point in the right direction ^^
In response to Silver_Gohan
Okay, the first problem your having is something most people add in to have multiple enemies. The way I used to show you isn't the only way, but it's a very common method.

Basically you need to add it in your varible list. You'll also have to add gold into your variable list. If a error says something is an undefined var, it's because it is not defined within the code itself, meaning it has no purpose.

You should have variables listed in your code like this. Something similar at least.
atom/movable
var
race
gold = 0


Now as for the Mob/Monster error, that is because your mob or whatever it is your killing might not be labeled as such in your code. Here is an example you can learn from, this is not a fully coded snippet (Not all code included to make it function)!

mob ///This is what IT is, instead of obj or turf
Monsters ///This is the list I put it under
Bandit ///This is the name of the mob which will appear in the list
density = 1
race = "Bandit" ///The race of the mob to track what happens to it on death
icon = 'Mob_Bandit.dmi'
icon_state = ""
Npc = 1
gold = 10 ///How much gold they have


This like I said is not all the code needed to make this work properly. That is up to you, this is basic stuff...I hope it helps.
In response to Shadow813
thank you so much for your Guidance, I messed around with what you gave me and got it to work, now im left with another dilima, the mob does drop gold this problem isnt from the code you gave me to work with however from the tutorial coding I picked it up from, this is the code, The gold the mob drops is always 0, never adds to it. which I assumed it would seeing as usr.gold += amount, May I have your opinion on this? Also for some odd reason, the respawn isn't working correctly..

obj
gold
icon = 'gold.dmi'
var
amount
verb
get()
set src in view(1)
usr << "You pickup [amount] gold."
usr.Gold += amount
del(src)

You're trying to override the built-in Del() procedure inside another proc. The way Dream Maker knows what's inside of what is by your indentations.
monkey
proc
poop() // proc inside of /monkey(accessible by children paths, too)

poop_thrower
proc
throw_poop() // proc inside of /monkey/hand
// normal monkeys won't have the throw_poop() proc because it isn't defined for them


In your case:
mob
// definitions for mob go on this line
// including /mob/var/X, /mob/proc/X, /mob/[sub-type], and /mob/X(override)
proc
// /mob/proc declarations go on this line
// including DeathCheck, or whatever new procs that don't exist yet
DeathCheck(mob/M)
// code indented this far and under DeathCheck will only do things for DeathCheck
if (HP <= 0)
// code indented within this if() block will only occur if the conditions are met
world << "[usr] killed [src]!"
del(src) //delete w.e just died

// here, you're trying to override a proc. This can't be done inside another proc, which is what the error said.
Del()
var/obj/gold/G = new(loc)
G.amount = rand(1,10)
..()

// This is the line where you can put Del(). Since it's built-in and has already been declared(equivalent of having /mob/proc/Del() somewhere in your code), you must override it here.
Del()
new/obj/gold(loc, rand(10)) // notice I put the rand() inside the parentheses for new()?
..()

// Now, using what you've learned, you can even override the New() proc for objects, so you can put initial gold amounts in one line, seen above.
obj
gold
New(Loc, _amount=1) // Loc is a built-in argument for New() that shouldn't be changed
// I gave the built-in proc New() another argument: _amount, which defaults to 1
amount = _amount // now gold can be created and have a set amount with only one line!
..()


Also, use <dm> tags on this website to show syntax-highlight your code. It looks better.