ID:141380
 
Code:
mob/npc
Rogue
name = "name"
icon = 'icon.dmi'
icon_state = "iconstate"
Health = 25
team = "team"
New()
..()
spawn(5)
src.Live()
proc/Live()
while(src)
var/mob/e
if(usr.team == "Alliance" in oview(5,src)).
step_towards(src,e)
else
sleep(10)
sleep(5)
Bump(mob/M)
if(istype(M,/mob/))
src.Eattack(M)

proc/Eattack(mob/A)
if(!canAttack) return
canAttack = FALSE
var/damage = rand(1,5)
view() << "[name] Attacked [A]"
A.Health -= damage
A.death(src)
spawn(20) canAttack = TRUE



this npc is soppost to step_towards any mobs that have team = alliance. but it doesn't step_towards any mobs.


XskyflakeX wrote:
Code:
> mob/npc
> Rogue
> name = "name"
> icon = 'icon.dmi'
> icon_state = "iconstate"
> Health = 25
> team = "team"
> New()
> ..()
> spawn(5)
> src.Live()
> proc/Live()
> while(src)
> var/mob/e
> if(usr.team == "Alliance" in oview(5,src)).
> step_towards(src,e)
> else
> sleep(10)
> sleep(5)
> Bump(mob/M)
> if(istype(M,/mob/))
> src.Eattack(M)
>
> proc/Eattack(mob/A)
> if(!canAttack) return
> canAttack = FALSE
> var/damage = rand(1,5)
> view() << "[name] Attacked [A]"
> A.Health -= damage
> A.death(src)
> spawn(20) canAttack = TRUE
>


this npc is soppost to step_towards any mobs that have team = alliance. but it doesn't step_towards any mobs.


> mob/npc
> Rogue
> name = "name"
> icon = 'icon.dmi'
> icon_state = "iconstate"
> Health = 25
> team = "team"
> New()
> ..()
> spawn(5)
> src.Live()
> proc/Live()
> while(src)
> var/mob/e
> if(e.team == "Alliance" in oview(5,src)). // try this
> step_towards(src,e)
> else
> sleep(10)
> sleep(5)
> Bump(mob/M)
> if(istype(M,/mob/))
> src.Eattack(M)
>
> proc/Eattack(mob/A)
> if(!canAttack) return
> canAttack = FALSE
> var/damage = rand(1,5)
> view() << "[name] Attacked [A]"
> A.Health -= damage
> A.death(src)
> spawn(20) canAttack = TRUE
>
mob/npc
Rogue
name = "name"
icon = 'icon.dmi'
icon_state = "iconstate"
Health = 25
team = "team"
New()
..()
spawn(5)
src.Live()
proc/Live()
while(src)
for( var/mob/e in oview(5,src) )
if(e.team=="Alliance")
step_towards(src,e)
break
sleep(10)
Bump(mob/M)
if(istype(M,/mob/))
src.Eattack(M)

proc/Eattack(mob/A)
if(!canAttack) return
canAttack = FALSE
var/damage = rand(1,5)
view() << "[name] Attacked [A]"
A.Health -= damage
A.death(src)
spawn(20) canAttack = TRUE
In response to Agrey123
proc/Live()
while(src)
var/mob/e
if(e.team == "Alliance" in oview(5,src)). // try this
step_towards(src,e)
else
sleep(10)
sleep(5)


That's not going to work, but it's on the right track.
XskyflakeX, your issue is with the mob e there.

You haven't actually assigned anything to that variable. This means that there's no actual mob for your NPC to step towards. To fix this, you need a for loop that locates all other mobs in view and picks one to step towards. Something like this:

proc/Live()
while(src)
var/mob/victim // Naming your variables properly helps a lot

for(var/mob/visiblemob in oview(5,src))
if(visiblemob.team == "Alliance")

// This part of the code picks the closest "enemy" mob
if(!victim)
victim = visiblemob
else
if(get_dist(src,visiblemob) < get_dist(src,victim))
victim = visiblemob

// If we have someone to step towards AND we aren't already touching them
if(victim && get_dist(src,victim) > 1)
step_towards(src,victim)
else
sleep(10)
sleep(5)


That should work more the way you're wanting.
Perpetr8r the Perpetu8r wrote:
> proc/Live()
> while(src)
> var/mob/e
> if(e.team == "Alliance" in oview(5,src)). // try this
> step_towards(src,e)
> else
> sleep(10)
> sleep(5)
>

That's not going to work, but it's on the right track.
XskyflakeX, your issue is with the mob e there.

You haven't actually assigned anything to that variable. This means that there's no actual mob for your NPC to step towards. To fix this, you need a for loop that locates all other mobs in view and picks one to step towards. Something like this:

> proc/Live()
> while(src)
> var/mob/victim // Naming your variables properly helps a lot
>
> for(var/mob/visiblemob in oview(5,src))
> if(visiblemob.team == "Alliance")
>
> // This part of the code picks the closest "enemy" mob
> if(!victim)
> victim = visiblemob
> else
> if(get_dist(src,visiblemob) < get_dist(src,victim))
> victim = visiblemob
>
> // If we have someone to step towards AND we aren't already touching them
> if(victim && get_dist(src,victim) > 1)
> step_towards(src,victim)
> else
> sleep(10)
> sleep(5)
>

That should work more the way you're wanting.



As far as I have ever seen, view already orders them by distance, so choosing the first one would already be the closet. Also he wants to keep smashing into it because he's using Bump() to perform the attack, so he wants to keep moving while touching them.
In response to T3h P3ngu1n
Well if that's true, then a break statement needs to be added instead of the distance checking code, else it'll bump into/run towards everything in sight.