ID:602299
 
Keywords: ai, npc
(See the best response by Lugia319.)
ok i have a lil problem. let me explain what im trying to do.

a NPC, thats a mob....mob/Basic_Troop/B

the thing im trying to attack....mob/Tree/T

i want B to attack T...then bring the loot back
to a house like area..that stores all loot.
i just dont know if i should be using get_step or oview. ive tried looking into the enemy AI stuff. but i cant seem to get it to work. any help?

Use step_to proc to move the object towards the tree. You should also use get_step to find out if the tree is in the view and point the tree as an objective for the mob.
also you can use get_dist to find the distance between the mobs and objects. I would aslo use dir to point the character into the trees direction. I would place all of this in a while loop.

while(src)


meaning while the src exists the loop runs.

for(var/mob/Tree/T in oview(6))


this could be used to check if there is a mob in the view of 6 tiles .

then you could use get_step or get_dist to check if there is an obj or mob 1 tile or less away

and use

get_step(usr,T)


I am not sure if this helps there could be errors in my examples and advice since I havent done any byond coding in like 3-4 months
well this is what i have so far...

mob/proc
Attack(mob/Basic/T)
for(var/mob/Tree/M in get_step(T,T.dir))
var/damage=rand(1,3)
view(6)<<"[T] attacks [M] for [damage] damage!"



verb stuff
Collect_Wood()
for(var/mob/Basic/T in oview(8))
Attack()

now, it complies right but when i test it i get

runtime error: Cannot read null.dir
proc name: Attack (/mob/proc/Attack)
source file: procs.dm,21
usr: Cassidyx15 (/mob)
src: Cassidyx15 (/mob)
call stack:
Cassidyx15 (/mob): Attack(null)
Cassidyx15 (/mob): Collect Wood()
Place it in a while loop and do it when the mob is created via

mob
New()
idk maybe i gotta explain it to you better so you understand the full concept.....people will be able to put npcs onto the map (farmers), those npcs move around freely whenever their not doing something. right now, i want them to attack a tree and bring the wood back to a store house/warehouse.
Code:
        Collect()
for(var/mob/Farmer/F as mob)
if(istype(F,/mob/Tree/Tree))
Attack()</b>

is the current verb, to make my "farmers" attack the tree. but their not attacking it. they keep moving around freely. the code for the attack verb (new) is
Code:
mob
proc
Attack(mob/Tree/M as mob in get_step(src,src.dir)) // the mob has to be facing you to attack
set category="Fighting"/// you all know wut this is.
if(istype(M,/mob/)) // if it a Mob they we're attacking continue.
var/damage=round(usr.Strength-M.Defense/2) /// define a damage var. user's str vs. M's defence divided by two. you can edit this to your liking.
if(damage <= 0)// if the damage is less or equal to 0 make it 1 damage.
damage = 1//change it :P
M.Health-=damage//remove the damage from M's HP.
range()<<"[usr] slashed [M] with his sword inflicting <font color=red>[damage]</font> damage!"/// tell the people in ranged M's being attacked.
else
return</b>
You're not passing the argument to your Attack code.
what do you mean, "passing the argument"
Oh wait, didn't read it properly. Sorry! You don't have arguments in Attack() that actually need to be passed. Make sure that the NPC is facing the tree when you call Attack(). If you've got some kind of automove going on, make sure it pauses when you attack the tree.

Also, try
Attack(mob/Tree/M in get_step(src,src.dir))


as mob is redundant because the tree is a mob.

(Personally I would've passed the tree as an argument so I could use walk_to() or something to get to the tree, hack it, and walk back but whatever floats your boat)
the only thing im really having a problem with, is actually GETTING my people over to the tree. i can get on team viewer, and show you what im talking about. if thats easier?
Best response
Not in the slightest, on a school computer. And that's kind of what I meant in my previous post.

mob
verb
Walking(mob/M in world)
walk_to(src,M,1)


This should have you walk to another mob in world. Place a mob on the map and have a go at it. Expanding on this code, you can get the farmer to the tree.
ok well, i got to the tree, but how do i make it to where it only effects the units i made, instead of me?
I think you should be able to figure out how to make it affect only created units.
well i changed mob/M to mob/Farmer/M. but yea, still nothing. im stupid when it comes to making stuff. im used to doing small stuff, not that complicated..:\
Just takes some thinking, don't worry too much about it.