ID:139712
 
Code:
//This was created by Randall Lee Overbey II On 9/17/2010

mob
var
HP = 10
GP = 0
Loot = 0 // Does the mob have anything ?
AT = 0 // Mob's attitude not used currently

icon = 'Person.dmi'

bug
icon = 'Bug.dmi'
HP = 6
AT = 1
proc
brain()
for()
if(AT == 0)
if(HP >= 0 )
var
YOR = rand(0,1)// does it move this time ?
if(YOR == 1)
var/SEP = rand(70,110)
Move()
.=..()
step_rand(src)
sleep(SEP)
else return 0
if(AT == 1)
for()
if(HP >= 0)
if(src in oview(1))
var/DMG = rand(0,2)
usr.HP -= DMG
world << "[src] did [DMG] to you!"
sleep(20)
else
var/SEP = rand(30,60)
Move()
.=..()
step_towards(src,usr)
sleep(SEP)
else return 0

New()
brain()
..()

Login()
world << "[usr] : Loged in"
icon_state = gender
..()
proc
DeathCheck()
if(HP <= 0)
oview() << "[src] falls in combat..."
usr << "[src] dies!"
src.Loot = rand(0,1)

verb
attack(mob/M as mob in oview(1))
if(M.HP <= 0)
usr << "[M] is dead, so you can't do that."
else
if(M.AT == 0)
M.AT = 1
usr << "You attack [M]!"
oview() << "[usr] attacks [M]!"
var/Damage = rand(2,8)
oview() << "[usr] did [Damage] damage to [M]!"
usr << "You did [Damage] damage!"
M.HP -= Damage
M.DeathCheck()
bury(mob/M as mob in oview(1))
if(M.HP <= 0)
del(M)
else
usr << "You can't do that"
loot(mob/M as mob in oview(1))
if(M.HP <= 0)
if(M.Loot == 0)
var/RM = rand(1,5)
usr.GP += RM
usr << "You recived [RM] gold!"
oview() << "[usr] took [RM] gold!"
M.Loot = 1
else
usr << "[M] has nothing"
else
usr << "Try killing [M] first"
Checkfunds()
usr << " You have [GP] GP!"
say(msg as text)
world << "[usr] : [msg]"
turf
Grass
icon = 'Grass.dmi'

world
turf = /turf/Grass


Problem description:

Okay I have a couple of bugs on the map they move. I kill them they stop moving. Everything is fine. But if I attack them and don't kill them they stop moving. When I attack with my character it should change the AT to 1 Which should make my bugs run after my character and attack him. This doesn't happen. I'm at a loss here.
As LummoxJR pointed out in your older topic; use if(var) instead of if(var == 1) and if(!var) instead of if(var == 0).
In response to Darker Legends
Darker Legends wrote:
As LummoxJR pointed out in your older topic; use if(var) instead of if(var == 1) and if(!var) instead of if(var == 0).
Also; your for() is empty I suggest you take some time to read the guide.

I have looked over the guide and I'm not a novice programmer. I understand that the for loop doesn't need a statement(right ?) but I changed it to a while loop and still doesn't work. As for LummoxJR I just now saw his post and I have fixed what I saw I needed to fix from your suggestions here is a couple changes that I have made mabey you could tell me where I'm going wrong now ?

//This was created by Randall Lee Overbey II On 9/17/2010

mob
var
HP = 10
GP = 0
Loot = 0 // Does the mob have anything ?
AT = 0 // Mob's attitude not used currently

icon = 'Person.dmi'

bug
icon = 'Bug.dmi'
HP = 6
AT = 0
proc
brain(mob/U)
while(src.HP >= 0 && !AT)
var
YOR = rand(0,1)// does it move this time ?
if(YOR)
var/SEP = rand(70,110)
Move()
.=..()
step_rand(src)
sleep(SEP)
else return 0
while(src.HP >= 0 && AT)
if(U in oview(1))
var/DMG = rand(0,2)
U.HP -= DMG
world << "[src] did [DMG] to you!"
sleep(20)
else
var/SEP = rand(30,60)
Move()
.=..()
step_towards(src,usr)
sleep(SEP)


New()
brain(usr)
..()

Login()
world << "[usr] : Loged in"
icon_state = gender
..()
proc
DeathCheck(mob/m)
if(HP <= 0)
oview() << "[src] falls in combat..."
m << "[src] dies!"
src.Loot = rand(0,1)

verb
attack(mob/M as mob in oview(1))
if(M.HP <= 0)
usr << "[M] is dead, so you can't do that."
else
if(M.AT == 0)
M.AT = 1
usr << "You attack [M]!"
oview() << "[usr] attacks [M]!"
var/Damage = rand(2,8)
oview() << "[usr] did [Damage] damage to [M]!"
usr << "You did [Damage] damage!"
M.HP -= Damage
M.DeathCheck(usr)
bury(mob/M as mob in oview(1))
if(M.HP <= 0)
del(M)
else
usr << "You can't do that"
loot(mob/M as mob in oview(1))
if(M.HP <= 0)
if(!M.Loot)
var/RM = rand(1,5)
usr.GP += RM
usr << "You recived [RM] gold!"
oview() << "[usr] took [RM] gold!"
M.Loot = 1
else
usr << "[M] has nothing"
else
usr << "Try killing [M] first"
Checkfunds()
usr << " You have [GP] GP!"
say(msg as text)
world << "[usr] : [msg]"
turf
Grass
icon = 'Grass.dmi'

world
turf = /turf/Grass
In your New() proc the brain() statement comes before ..(). Try setting it the other way around and also adding a spawn.

Ex:
New()
..()
spawn(0) brain()


If anything it'll be less likely to bug up on you in the first place.
In response to Drox
Drox wrote:
>           brain(mob/U)
> while(src.HP >= 0 && !AT)
> var
> YOR = rand(0,1)// does it move this time ?
> if(YOR)
> var/SEP = rand(70,110)
> Move()
> .=..()
> step_rand(src)
> sleep(SEP)
> else return 0
> while(src.HP >= 0 && AT)
> if(U in oview(1))
> var/DMG = rand(0,2)
> U.HP -= DMG
> world << "[src] did [DMG] to you!"
> sleep(20)
> else
> var/SEP = rand(30,60)
> Move()
> .=..()
> step_towards(src,usr)
> sleep(SEP)
>
>
>


First off, lets start by saying, why are there 2 whiles? You can easily put if's in them. Secondly, returns in the whiles? One you use a return on the brain() the process is canceled. This means it will never loop again unless called. (Which in your case it isn't... ever... called again, so returning, not the best idea)

Also, you'll notice, when brain(usr) is called, usr happens to be the bug. Cool, yet when you go into the actual brain() you're using U as the target. If your targetting had been in view(1) the bug would literally attack itself. So here's what we'll do. Take out the useless mob/U as there's probably no mob when this is actually called.
        target = null //Mob's target

icon = 'Person.dmi'

bug
icon = 'Bug.dmi'
HP = 6
AT = 0
proc

brain()
while(src && src.HP >= 0)
var/mob/U = null
if(src.target && !(src.target in oview(6))) //If target is not in range then it stops chasing
src.target = null
else if(src.target) U = src.target //Sets U to the target
if(U.HP <= 0) //If U happens to be dead, stops chasing
src.target = null
U = null
if(!U) //If there is no target
if(prob(50)) // rand(0,1) is 50% chance of moving, this is the same thing
step_rand(src)
sleep(rand(70,110)) //No need to define a variable, just put the equation directly in
else if(U) //If there is a target
if(U in oview(1))
var/DMG = rand(0,2)
U.HP -= DMG
U << "[src] did [DMG] to you!" //You had world <<, since the bug is attacking a player I don't think its correct to have it's attacking YOU. So I made the message just for the person getting hit
sleep(20)
else
step_towards(src,U)
sleep(rand(30,60))


Now don't copy and paste this in and expect it to work. First thing you'll have to do is go into your deathcheck proc, and have something like
if(!PERSONGETTINGHIT.client&&!PERSONGETTINGHIT.target) PERSONGETTINGHIT.target = PERSONATTACKING
//Where persongettinghit should be src and personattacking M or some other defined mob, but since that's not in the code I don't know what you used.

Secondly, don't forget to add the target variable I thew up top, no need for your AT variable, as its pretty much just for determining if there's a target to attack, in which case a target variable is needed anyway, so why have 2?

Other things you may want to note, there is no deathcheck for when the bug is attacking someone, this means that they won't die unless you check some other way (Which I'm sure you don't) so may want to toss the check into there. Anyway, I've tossed in some other helpful hints into the code that you should see, try it out and see how it works.