ID:148384
 
Ok in the prevous topic i said about building, ok now you can build troops but, the troops dont actully move..

mob/allies
var/owner=""
var/mob/allies/M
New()
.=..()
spawn(1)
Wander()
proc/Wander()
while(src)
if (M in oview(5))
if(M.owner == src.owner)
..()
else
step_towards(src,M)
else
for(M in view(src))
break
sleep(10)
spawn(30)
Wander()
Bump(mob/M)
if (istype(M,/mob/allies))
attack(M)
proc/attack(mob/M)
var/damage = rand(1,str)
if(usr.str - M.defense > 0)
M.hp -= usr.str - M.defense
view(4) << "[src] attacks [M] for <font color = red><b>[damage]</b><font color = black> !!"
M.DeathCheck
else
return
infantry_b
icon='Player.dmi'
icon_state="infantryb"
str=5
defense=3
hp=20


Im going to bed, i'll check this tomorow.
Maybe indent the Wander() proc by one.
In response to Unknown Person (#1)
Unknown Person wrote:
Maybe indent the Wander() proc by one.

The indention is fine, i think it is calling the Wander proc, but its trying to walk into it self...There for no walking around, :-|
Wanabe wrote:
Ok in the prevous topic i said about building, ok now you can build troops but, the troops dont actully move..

There are a few problems. The first was pointed out by Unknown Person: You have an indentation error.
    New()
.=..()
spawn(1)
Wander()

That's where he meant you need to indent by one. spawn() should be followed by an indented line if you're gonna do anything with it, or else you could just put it all on one line as spawn(1) Wander().

Second, the Wander() proc is massively screwed up:
    proc/Wander()
while(src)
if (M in oview(5))
if(M.owner == src.owner)
..()
else
step_towards(src,M)
else
for(M in view(src))
break
sleep(10)
spawn(30)
Wander()

Here are the problems with it:

  • Since you're looping while(src), what's the need for the spawn(30) Wander() at the end? That does nothing; get rid of it.

  • Why are you calling ..()? This is a brand new proc; it has no older version of Wander() to fall back on. ..() will do nothing here. In fact it'd be nice if DM threw a warning for when people misuse it.

  • oview(5)? Tsk tsk tsk. That should be oview(5,src).

  • The way you're choosing M is friggin' screwy. I mean just drop dead awful. The loop through view(src) is non-selective, so it doesn't just choose mobs with a different owner, and so it's not going to find anything useful: The first mob it finds should always be itself, I think, and so it's what's causing your problem. And while I'm on the subject, why is the search for a new M put after the step_towards() call instead of before it?

    So here's how your proc should look:
proc/Wander()
var/mob/M
while(src)
// pick a new M if there isn't one
if(!M || !(M in oview(5,src)))
for(M in oview(5,src))
if(M.owner != owner) break
// follow the target, if there is one
if(M)
step_towards(src,M)
sleep(4) // movement delay
else
step_rand(src)
sleep(10) // sleep while waiting for a new target
If you want to make the monster even more tenacious, increase the first oview() from 5 to something larger like 7 or 8. Then it'll follow you even if you get a little way out of sight, and only give up if you get farther away. Better still, you could also change the first oview() to orange() so hiding behind something won't fool the monster, and change step_towards() to step_to() to use built-in pathfinding. The second call to oview(), however, should remain as it is because that's for picking a target, not following a known target.
    proc/attack(mob/M)
var/damage = rand(1,str)
if(usr.str - M.defense > 0)
M.hp -= usr.str - M.defense
view(4) << "[src] attacks [M] for <font color = red><b>[damage]</b><font color = black> !!"
M.DeathCheck
else
return

Everywhere you put usr in this proc, it should be src, so change it. M.DeathCheck should be M.DeathCheck(src), and the "else return" you can just plain delete.</dm>
Lummox JR
In response to Lummox JR (#3)
ok thanks lummox, but, i seem to be getting a loop error, (keeps on looping a LOT and slows down game play) its in the wander proc, but i cant see whats making it loop over and over... :-|..so um yeah mind helping?.....

[edit] the error is on this line: while(src) , im geussing its because that loops it, but umm how do i get it to stop looping so much?, should i just put a sleep or somthing before or after it? [/edit]
In response to Wanabe (#4)
Wanabe wrote:
ok thanks lummox, but, i seem to be getting a loop error, (keeps on looping a LOT and slows down game play) its in the wander proc, but i cant see whats making it loop over and over... :-|..so um yeah mind helping?.....

[edit] the error is on this line: while(src) , im geussing its because that loops it, but umm how do i get it to stop looping so much?, should i just put a sleep or somthing before or after it? [/edit]

The revised proc I showed you will sleep one way or the other, so it shouldn't have that kind of problem.

Lummox JR
In response to Lummox JR (#5)
Well, heres what i have;

mob/allies
New()
.=..()
spawn(1) Wander(src)
proc/Wander()
var/mob/M
while(src)
if(!M || !(M in oview(5,src)))
for(M in oview(5,src))
if(M.owner != owner) break
// follow the target, if there is one
if(M)
step_towards(src,M)
sleep(4) // movement delay
else
step_rand(src)
sleep(10) // sleep while waiting for a new target

Bump(mob/M)
if (istype(M,/mob/allies))
attack(M)
proc/attack(mob/M)
var/damage = rand(1,src.str)
if(src.str - M.defense > 0)
M.hp -= src.str - M.defense
view(4) << "[src] attacks [M] for <font color = red><b>[damage]</b><font color = black> !!"
M.DeathCheck(src)


the reason why i removed 'var/owner' since you thought it would be a good idea to check for all mobs, instead, i had to put var/owner in a var for all mobs, not just certain ones.
In response to Wanabe (#6)
You've managed to indent that last if/else pair two tabs too far, putting them not just inside the loop, but inside the if() before it. How you did that I don't know, since my code has them indented correctly.

Lummox JR
In response to Lummox JR (#7)
its the forum, in DM its all indented fine, ill send you the files to prove that...or are you meaning somthing else? that i havnt clicked on to.
In response to Wanabe (#8)
Wanabe wrote:
its the forum, in DM its all indented fine, ill send you the files to prove that...or are you meaning somthing else? that i havnt clicked on to.

It's not the forum; your code is definitely indented too far in that section, by two tabs. And if it was the forum, then it would mean you were mixing spaces and tabs, which is an indent problem in itself.

Lummox JR
In response to Lummox JR (#9)
Lummox JR wrote:
Wanabe wrote:
its the forum, in DM its all indented fine, ill send you the files to prove that...or are you meaning somthing else? that i havnt clicked on to.

It's not the forum; your code is definitely indented too far in that section, by two tabs. And if it was the forum, then it would mean you were mixing spaces and tabs, which is an indent problem in itself.

Lummox JR

I noticed, that in the forums it looks like it is out by two tabs, but in the thing its only out by one, whitch is indented. And there is no Spaces, i made sure of that :-)[edit] ok i just deleted a tab, ill see if it works now [/edit] [edit2]ok tried that, no good. [/edit2]
In response to Wanabe (#10)
Wanabe wrote:
I noticed, that in the forums it looks like it is out by two tabs, but in the thing its only out by one, whitch is indented. And there is no Spaces, i made sure of that :-)[edit] ok i just deleted a tab, ill see if it works now [/edit] [edit2]ok tried that, no good. [/edit2]

If you hit the "reply with quote" button you'll see the tabs as they are, and the section was definitely in by two, not one. So you've just made a random edit, which didn't help you. If you'd actually change the code to fit what I showed you in the first place, it would work.

Lummox JR
In response to Lummox JR (#11)
Lummox JR wrote:
Wanabe wrote:
I noticed, that in the forums it looks like it is out by two tabs, but in the thing its only out by one, whitch is indented. And there is no Spaces, i made sure of that :-)[edit] ok i just deleted a tab, ill see if it works now [/edit] [edit2]ok tried that, no good. [/edit2]

If you hit the "reply with quote" button you'll see the tabs as they are, and the section was definitely in by two, not one. So you've just made a random edit, which didn't help you. If you'd actually change the code to fit what I showed you in the first place, it would work.

Lummox JR

hehe, as soon as you said that i thought 'oh just a dumb mistake' then i do it, and theyre only tabbed..by one...