ID:264014
 
Code:
mob
WILD_Pidgey
icon = 'Pidgey.dmi'
gold = 2
hp = 50
maxhp = 50
player = 0
strength = 5
Expg = 2
level = 2
monster = 1
Pokemon = 1
PK = 1
NPC = 0
New()
. = ..()
spawn()
Wander()
proc/Wander(var/mob/P)
while(src)
if(P in oview(5))
step_towards(src,P)
for(P in oview(1))
break
for(P in oview(2))
break
for(P in oview(3))
break
for(P in oview(4))
break
else
step_rand(src)
sleep(5)
for(P in oview(5))
break
sleep(5)
spawn(5)
Wander()
Bump(mob/M)
if(M.Pokemon == 1)
Fight(M)
else
return
proc/Fight()
for(var/mob/E in get_step(usr,usr.dir))
var/damage = src.strength
E.hp -= damage
E << "<font color = white><font face = 'Comic Sans MS'>[src] attacks you for [damage] damage!!"
src<<"<font color = white><font face = 'Comic Sans MS'>You attack [E] for [damage] damage!!"
UserDcheck(E)
if(src.hp <= 0)
del(src)
sleep(10)
New(src)
spawn()// Right here is the error.


Problem description: After hours of trying to fix my trainers freezing the game, I finally fixed it and thought that maybe npc's were having the same problem so I tried and I fixed them too, now my trainers are working and my npc's move and attack, but what I'm trying to fix now is that im trying to make it so when the npc gets killed it gets deleted from the world and after about 30 seconds it spawns again. Any tips on how to fix this, also I have 1 error that says invalid expression and it takes me to the spot showed above.

GOD

DAMNIT

WHY WON'T THIS DIE?!

WHERE DO YOU EVEN GET THIS?

This same goddamn broken piece of crap has been around for literally years, and KEEPS ON COMING BACK. Like a goddamn zombie, no matter how many times we try to kill it, somebody - somewhere - finds it and uses it. The only explanation I can think of is that it's being used in some crappy source code (redundancy all up ins) that people are ripping.

Delete that crappy Wander() proc. This is what it shoul dbe:

proc/Wander()
while(src)
var/mob/player/P = locate() in oview(src)
if(P)
step_towards(src,P)
else
step_rand(src)
sleep(5)


All that for(P in oview()) crap is pointless, broken, and error-prone. So get rid of it.

Next, you need to fix Bump(). Bump(mob/M) just says, "when we bump into something, pretend it's a mob". It does not filter out non-mobs, you need to do that yourself. So, you need to do this:

Bump(mob/M)
if(ismob(M))
//mob-related stuff
..()


Next, you need to get rid of usr in all your procs. Somehow, you manage to half get it right with Fight(). You pass an argument, like you should, but then in the proc itself you totally ignore it and use usr, which is WRONG. And it's been WRONG for the past five years and yet people STILL KEEP ON USING IT. Remove the for() loop in Fight(), give it an argument (so, Fight(var/mob/M)), and replace E with M.

Also willing to bet good money that you're using usr in UserDcheck(), where it would be - once again - wrong. usr is only valid in verbs, and procs that are only used as verbs (such as Click()).

And, because I'm really tired of people ignoring this advice, show you've made these changes and I'll solve the problem you're describing.
In response to Garthor
Garthor I don't think you will ever solve a rip.
In response to Garthor
Sorry about the usr in procs, I keep forgetting, anyways I did what you told me it's perfect! usually whenever the npc bumps into a wall it spams blank text, but now its fixed. OK and here for proof heres the fix
 mob
WILD_Pidgey
icon = 'Pidgey.dmi'
gold = 2
hp = 50
maxhp = 50
player = 0
strength = 5
Expg = 2
level = 2
monster = 1
Pokemon = 1
PK = 1
NPC = 0
New()
. = ..()
spawn()
Wander()
proc/Wander()
while(src)
var/mob/P = locate() in oview(src)
if(P)
step_towards(src,P)
else
step_rand(src)
sleep(5)

sleep(5)
spawn(5)
Wander()
Bump(mob/M)
if(ismob(M))
Fight(M)
..()
else
return
proc/Fight(var/mob/M)
var/damage = src.strength
M.hp -= damage
M << "<font color = white><font face = 'Comic Sans MS'>[src] attacks you for [damage] damage!!"
src<<"<font color = white><font face = 'Comic Sans MS'>You attack [M] for [damage] damage!!"
UserDcheck(M)
PS: This game isn't a rip, I just learned that code from an RPG demo.
Hello, Garthor, you there?
Any help?...
In response to Element Hero creator
Forums are not a real-time medium. Don't expect help right away. Also, don't reply to your own posts, as that's annoying. Don't bump your post unless the post is both off the front page and it has been at least twenty-four hours.
In response to Element Hero creator
did not you say that you got it working?
In response to Element Hero creator
Well, that RPG demo ripped it from a VERY old tutorial that has long ago been fixed.

Anyway: your problem is that nothing can happen after del(src). When an object is deleted, all of its procs stop. So, we need to tell something else to create a new mob in X seconds, THEN delete ourselves.

Also, you've got a misconception about spawn(). It's needed here, but it has nothing to do with creating things. Rather, it starts a parallel thread of processing. Everything inside a spawn() block gets executed in one thread, and everything outside it gets executed in another. This means you have two things happening at the "same" time.

So, this is what we have to do:

//create a new type at loc, in time ticks
proc/respawn(var/type, var/atom/loc, var/time=0)
//new thread of processing, and also wait for time ticks
spawn(time)
//make sure that loc still exists
if(loc)
new type(loc)


Simple. Now, we just need to call that from the death proc:

if(src.hp < 0)
//blah blah blah
//respawn in 10 seconds:
respawn(src.type, src.loc, 100)
//now, delete ourselves
del(src)


Also note that it will be creating the thing where it stands. If you want it to respawn where it used to be, then save its original location into a variable when it's created (in New()), and use that.