ID:139471
 
Code:
The deathcheck:
mob/Pokemon/deathcheck(mob/M)
if(src.hp<=0)
src.wandering=0
src.following=0
src.happiness-=5
src.fainted=1
src.contd2=1
client.cont=null
client.eye=usr
if(src.owned)
src.loc=locate(src.owner)
oview(12) << "[src] fainted!"
else
del(src)

The proc:
mob/proc/deathcheck()
if(src.hp<=0)
..()

A return verb.
    Return()
set category = "PokeCommands"
for(var/mob/Pokemon/P in oview(12)&usr.pokemonlist)
if(P.owner==usr&&P.returned==1)
usr<<"They are already in your bag!"
return
if(usr.PkmInInven==6)
usr << "You cant hold anymore pokemon in your pockets!"
return
else
walk(P,0)
P.loc=usr
P.returned=1
P.following=0
P.wandering=0
P.Training=0
P.contd2=1
client.cont=null
client.eye=usr
// Pmove=0
view(12) << "[usr]: [P] return!"
usr.PkmInInven+=1
return


Problem description:
Well, what I basicly want to do is when the pokemon faints, it goes back to his owner's backpack and put the fainted var on 1, and do the things that the return verb does like P.contd2=1
client.cont=null
client.eye=usr

But the pokemon doesn't seem to faint anymore after I changed the deathcheck like I thought it would work out.. Also I got a blackscreen before when the code was still working but I didn't add
P.contd2=1
client.cont=null
client.eye=usr

to it yet.
I can't seem to work this out by myself so any help would be greatly appreciated.
locate(src.owner) is not going to give you the owner. In that form, src.owner would have to be a text string, and it would locate an object with its tag set to be equal to that string. What you probably want is just src.owner alone.

Additionally, you are using usr in procs, which you should not be. Namely, the line client.eye = usr is using usr, and oview(12) is implicitly using usr as it defaults to oview(12,usr). You should replace the first one with whatever it is you actually want to set the client's eye to (presumably, their actual mob, so that would be client.mob) and the second with oview(12,src).
In response to Garthor
Well, I changed everything you said. But the pokemon doesn't get in his owner's contents. This doesn't work either:
        client.cont=null
client.eye=client.mob
if(src.owned)
src.loc=src.owner
oview(12,src) << "[src] fainted!"

The message doesn't pop up. The client eye doesn't go back to his trainer, etc. And I don't know what's wrong.. Everything at the Return verb works fine.
In response to Raimo
Note that oview() at that point is going to solely be the player and his contents, as you've already moved src.

As for what's wrong... that's something YOU need to figure out. Narrow down exactly where it's failing by printing messages every step of the way.
In response to Garthor
Well Garthor, I've been trying to make it work for the last few hours, but I can't seem to succeed. The fainted var is being set to 1. But the pokemon doesn't 'teleports' to the his owner's contents..
In response to Raimo
Did you test src.owned to make sure it was true?
In response to Pirion
No, that's something I didn't test yet. I did test src.owner though by
world<<"[src.owner]"

And that worked perfectly like I thought. I will test src.owned right now.

Edit: I tested src.owned like the same way I did with src.owner, and the variable is true because '1' is being outputted to the world.
In response to Raimo

I noticed you use usr, not src.owner in your return.
What about checking the type of src.owner?

It has to be an instance not a text string, how do you assign it ?
In response to Nerion
src.owner is the usr who catched the pokemon.
In response to Raimo
Out of pure curiousity, why have both "owned" and "owner" as a variable? "owner" can pretty much act as both

// Catch something
owner = src

// Release something

owner = null

// Check owner

if(owner) world<<owner
In response to Emasym
Hmm, I use owned to check if the pokemon is catched, if it's '1' then you can't catch it, if it's '0', then you can catch it.
In response to Raimo
Checking if "owner" exists would do exactly the same, which would be my point.
In response to Emasym
True, but I don't want to go trough whole my codes again to see where I checked for owned and change it to owner =o.
In response to Raimo
mob/Pokemon/deathcheck(mob/M)
if(src.hp<=0)
src.wandering=0
src.following=0
src.happiness-=5
src.fainted=1
src.contd2=1
if(src.owned)
src.Return()
oview(12) << "[src] fainted!"
else
del(src)
In response to Xerif
I get this error:
pokemon tab.dm:219:error: src.Return: undefined proc
Do you suggest me making a proc like the Return verb?
In response to Raimo
Please re-read, requires some thought and maybe some testing.

This is your code so we need you to test the suggestions and provide something informative to be able to help you.
In response to Nerion
Well, I've tried to use the call() proc now, but it still doesn't work:
mob/Pokemon/deathcheck(mob/M)
if(src.hp<=0)
src.happiness-=5
src.fainted=1
if(src.owned)
oview(12) << "[src] fainted!"
call(src,/mob/Trainer/verb/Return)()
else
del(src)
In response to Raimo
Well, I always get this runtime error: runtime error: Cannot modify null.cont.
At this piece of code:
mob/proc/returno()
client.cont=null
client.eye=usr
usr.PkmInInven+=1


Deathcheck I use the proc in:
mob/Pokemon/deathcheck(mob/M)
if(src.hp<=0)
src.happiness-=5
src.fainted=1
if(src.owned)
oview(12) << "[src] fainted!"
returning()
call(src.owner,returno())()
else
del(src)

But at the Return verb, it works fine:
    Return()
set category = "PokeCommands"
for(var/mob/Pokemon/P in oview(12)&usr.pokemonlist)
if(P.owner==usr&&P.returned==1)
usr<<"They are already in your bag!"
return
if(usr.PkmInInven==6)
usr << "You cant hold anymore pokemon in your pockets!"
return
else
walk(P,0)
P.loc=usr
P.returned=1
P.following=0
P.wandering=0
P.Training=0
P.contd2=1
client.cont=null
client.eye=usr
// Pmove=0
view(12) << "[usr]: [P] return!"
usr.PkmInInven+=1
return


I've been trying to do a few things, but it doesn't work =O.
In response to Raimo
Guys, I'm really desperate at the moment, so I'm bumping this. Although I don't know if this is a legit bump.