ID:140086
 
Code:
mob
cpu
slime
name = "Slime"
icon = 'slime.dmi'
hp=5
str=1
move=1
maxmove=1
atk=1
maxatk=1
ingame=0
New()
..()
Battlecheck()
proc
Battlecheck()
while(1)
sleep(10)
if(src.ingame == 1)
Fightingmode()

Fightingmode()
for(var/mob/M in view())
while(1)
sleep(10)
if(src.atk >= 0)
Cpumovement(M)
if(src.move >=0)
Cpuattack(M)

Cpumovement(mob/T)
sleep(10)
if(src.move >=0)
src.move -= 1
walk_to(src,T)

Cpuattack(mob/T)
sleep(10)
if(src.atk >=0)
src.atk -= 1
T.hp -= src.atk
view() << "[src] damaged [T] by [src.atk] points."


Problem description:
Let me show you what this is meant to do. this is my battle system for my game.its meant to be for testing purposes for now.In this the Slime should fight/check as soon as one is made, but when i added this coding to my game nothing happens and my player doesnt teleport [look down for more coding. This only happens if the coding above is added or if i leave everything except when is under New().

What i wish to happen is for the player, when he enters a certain area, he will tele and battle a slime wish will auto attack him. Dont worry about death, ill do that later


area
one
Entered(mob/b)
b.cpufight(1,b)

mob
proc
cpufight(cpu,mob/p1)
if(cpu == 1)
var/mob/cpu/slime/S = new
battle(p1,S)
mob/proc/battle(mob/p1,mob/p2,mob/p3,mob/p4)
var/turnHandler/game = new
if(p1) //player add//
p1.ingame = 1 //make sure ur ingame//
game.addPlayer(p1)
p1.loc = locate(12,20,1)
if(p2)
p2.ingame = 1
game.addPlayer(p2)
p2.loc = locate(19,20,1)
if(p3)
p3.ingame = 1
game.addPlayer(p3)
p3.loc = locate(19,27,1)
if(p4)
p4.ingame = 1
game.addPlayer(p4)
p4.loc = locate(12,27,1)
//Rest will not be shown due to the reason that i dont want anyone copying//
                var/mob/cpu/slime/S = new


This creates a new mob/cpu/slime, which calls its New() proc, which is inherited from mob/cpu. mob/cpu/New() calls Battlecheck(). Battlecheck() never, ever returns. Therefore, the line above never finishes, and it never reaches the next line, which actually starts the battle.

You should not have anything in the mob/cpu/New(). Instead of having it search for a battle it's in, first create the battle, and THEN tell the mob that it's in the battle and to do its thing.

Also, you are using view() in Fightingmode() and Cpuattack(), which defaults to view(usr), and you should not be using usr in procs. Use view(src) instead.
In response to Garthor (#1)
Sorry for the long reply i been of comp for a week or longer. Thanks for the help.