In response to Blanke
Well, no. Not really. You could theoretically do that, but it's bad practice.

Here, I'll give you an easy way to fix the problem.

mob
proc
attack(var/mob/target,var/damage)
if(target)
target << "[src] attacks you for [damage] damage!"
src << "You attack [target] for [damage] damage!"
target.HP -= damage
if(target.HP<=0)
target.death_check()
verb
make_attack()
set name = "attack"
set src in oview(1)
usr.attack(src,X) //replace X with the damage the user does


This way, you can actually just change the pursue function's attack line to:

This way's kind of backwards, and I don't usually do it this way, but it's the quickest approach, and I don't want to stay awake much longer.

src.attack(src.target,src.damage)


And still keep your attack verbs relatively the same.

Let me know if I lost you.
In response to Ter13
Yeah I get that pretty well I think. Like you said, I am tired so I can't think if i would just pop it under the other code or in somewhere else but I get what all of that coding does. that bottom set of code lost me though :p
In response to Blanke
Swap the last line I listed in that post with the line in mob/NPC/monster/proc/pursue() with the line that just says: "src.attack()". Just replace that line, and now it ought to work-ish.
In response to Ter13
gah, more issues.

Attacking.dm:36:error:src.damage:undefined var

And that is when I replaced the thing. to mae it src.attack(src.target,src.damage)
In response to Blanke
You have to define a variable called damage under the mob/NPC/Monster.

Then, you have to set it to an arbitrary value. Or perhaps a not-so arbitrary value.
In response to Ter13
there isn't any errors. But there isn't any monster activity still X_D Well, I am tired now and dont want to code until i get the monsters attackin... So if you could maybe contemplate and think of something to make the mosnters attack Ter13? I will look over the code myself, I doubt I will find anything though. I am not too good of a coder :p Well, night everyone. Thanks for the help guys and thanks in advance Ter13 uf ya get the rest of the code for me =D
In response to Blanke
Works fine on my end.

Everything I gave you works great for me.

I just slapped up a project with unmodified code, and it worked great.

Must be something on your end interfering with my snippet...

I had to make a slight change to the code though, monsters could be pinged if they already had a target, just forgot to add the line, but I edited it back in in my prior posts.
In response to Ter13
Well, I'm still up :p I will just post all of my coding thus far. it isn't much. and I will shorten what I can.

mob
bug
icon = 'bug.dmi'
HP = 30
var
HP
MP
Str
Int
Agi
End
Luk
Exp
Exp_Needed
Palladium
Knight
Sage //White mage
Tempest //Black mage
Cronos //time mage
Ninja
Berserker
Caller
Class
mob
icon = 'players.dmi'
Login()
src.Class=input("What class are you?","Class") in list("Knight","Sage","Tempest","Cronos","Ninja","Berserker","Caller")
if(src.Class=="Knight")
//stats
icon_state = "Warrior"
//other classes
..()

proc
DeathCheck()
if (HP <= 0)
world << "[src] dies!"
del(src) //delete whatever just died
Del()
var/obj/gold/G = new(loc) //create a new obj from the gold blueprint
G.amount = rand(1,100) //set its amount variable randomly
..() //call the parent
mob
proc
attack(var/mob/target,var/damage)
if(target)
target << "[src] attacks you for [damage] damage!"
src << "You attack [target] for [damage] damage!"
target.HP -= damage
if(target.HP<=0)
target.DeathCheck()
verb
make_attack()
set name = "attack"
set src in oview(1)
usr.attack(src,rand(1,10)) //replace X with the damage the user does


say(msg as text) //what the usr says is passed into "msg" as text
world << "[usr]: [msg]" //the world sees chatroom-like output

obj
gold //define a "gold" prototype, which is a kind of obj
icon = 'gold.dmi' //set the default icon
var
amount //declare a new variable called "amount"
verb
get() //obj/gold/verb/get()
set src in view(1) //src must be close
usr << "You pick up [amount] Palladium pieces."
usr.Palladium += amount //add to usr.wealth
del(src) //delete the gold

turf
Grasses //define a "grass" prototype, which is a kind of turf...
icon = 'Grasses.dmi' //that has an icon named 'grass.dmi'. In single quotes!
world //set one of our world's characteristics:
turf = /turf/Grasses //its default turf is the grass turf.

----------------------//and your code---------------------------------------
mob
being
player //this typepath can be changed, but I always use this one.
Move()
. = ..() //call the parent proc
if(.) //if parent proc is true (move succeeds)
if(src.client) //is actually a player.
for(var/mob/NPC/monster/M in range(12,src))
M.pinged(src) //pings every monster in a range of 12 of the player's new location.
return . //returns the parent proc's return value.
mob
NPC
monster
var
mob/being/player/target //holds the current target, or null if turned off.
chase_range = 6 //set at what range the monster begins pursuit.
move_delay = 10 //moves once per second
attack_delay = 7 //attacks every 0.7 seconds
damage
proc
pinged(var/mob/being/pinger)
if(get_dist(src,pinger)<=src.chase_range) //if the target is close enough to the monster.
if(pinger.client) //if the pinger is a player.
if(pinger in view(src,src.chase_range)) //if the monster can 'see' the player.
src.target = pinger //set the target, so that the monster doesn't chase anybody else.
src.pursue() //commence chase!
return 1
return 0
pursue()
var/rng = get_dist(src,src.target) //store the distance in a local variable.
if(rng<=src.chase_range&&src.target in view(src,src.chase_range)) //stop chasing if the player is hiding, or has gotten out of range.
if(rng>1)
step_towards(src,src.target) //take one step to the target.
spawn(src.move_delay)
src.pursue() //after X milliseconds, keep chasing.
else
src.attack(src.target,src.damage) //call the attack function. You are going to have to define this.
spawn(src.attack_delay)
src.pursue() //after X milliseconds, keep chasing or attacking.
else //if out of range, or out of view.
src.target = null //give up on target
src.find_target() //try looking for another target.
find_target()
var/mob/being/player/found //store the next target locally.
var/fdst = src.chase_range+1 //next target's distance (starts higher than potential range for ease of use)
for(var/mob/being/player/tgt in view(src,src.chase_range))
if(tgt.client) //if is a player.
if(get_dist(src,tgt)<fdst) //compare distances to find the closest potential target.
found = tgt
fdst = get_dist(src,tgt)
if(found) //if there is another target.
src.target = found //set next target
src.pursue() //being pursuit!
return 1
return 0 //switch off


I know, your code is like 65% of it XD
In response to Blanke
Wow you provided way too much info here man, but I took a stab at what looked like the problem. I tried to rewrite it for you to be a little more efficient and working, so let me know how it turns out.

mob
being
player
Move()
for(var/mob/NPC/monster/M in range(6,src)) M.pinged(src)
// This could get really laggy you loop each time a player moves.
return 1

NPC
monster
var
mob/being/player/target //holds the current target, or null if turned off.
move_delay = 10 //moves once per second
attack_delay = 7 //attacks every 0.7 seconds
damage
proc
pinged()
var/mob/being/pinger
if(pinger in range(6,src) && !src.target)
src.target=pinger
src.pursue() //commence chase!
return 1
else return 0

pursue()
var/rng=get_dist(src,src.target)
while(src && src.target in view())
// Use this kind of loop instead of calling the proc over and over
if(rng>1)
sleep(move_delay)
step_towards(src,src.target) //take one step to the target.
else
sleep(attack_delay)
src.attack(src.target,src.damage) //call the attack function. You are going to have to define this.
//If the player steps out of range or the monster dies the proc ends.
src.target=null
src.find_target() //To me this seems redundant, seeing how they are attracted by steps.
return

find_target()
var/mob/being/player/tgt
for(tgt in range(6,src)) break
if(tgt) //if is a player.
src.target = found //set next target
src.pursue() //being pursuit!
return


EDIT: I messed up your timing a little, so I fixed it.
In response to The Naked Ninja
TNN, I really don't want to be rude, but you took a stab, and somehow managed to decapitate yourself.

You completely screwed the pooch when trying to fix this snippet, and didn't read half the posts in the thread.

Don't mislead him, having a loop in every successful move, in this case, is actually much more efficient than the alternative.

Second, you made the Move function LESS efficient in most cases, you completely misunderstand the use of find_target after losing the first target, and you just generally completely ruined the entire system.

Well done. Couldn't have thrown the wrench at a better cog myself.
In response to Ter13
He linked me to this post, I looked at what I saw wrong and I made it work better IMO. I didn't have time to read every post in this topic and I feel my method was alot better than what was given to him in the first place.

Recalling a procedure is redundant, and I explained the loop to him. I also didn't remove the find_target procedure, I simply said that it's meaningless with every player's step calling the focus of surrounding mobs.

Whoever gave him this code is a horrible programmer, I figured it was his and I tried to make sense of it in the time allotted, I apologize if you fail to understand.

-Ken

P.S: The loop is much more efficient than the prior method, I'd like to know where you get your information. This whole snippet itself is terrible though, like I said I tried to make it a little better. I also directed him to a few useful libraries that would better aid him in learning to program, including Dantom's "Your First World".
In response to The Naked Ninja
Speaking of efficiency, I think working with <code>area.Entered()</code> and <code>area.Exited()</code> to activate AI, while more complicated to implant, would be more efficient cpu-wise. I dislike checking nearest 12 squares every movement a player makes (which is probably over 20 times a second when 20 players are logged in).
In response to The Naked Ninja
Thanks a lot for that NN, I was wondering though. Cold I get those links again? Or the link to the topic you posted them in? I exited out of byond before I got to look at anything besides the first world thing.
In response to Blanke
Most of the good links can be found on The Start Page or Newbie Questions. Both of which I feel should be heavily publicized.
In response to The Naked Ninja
Okay. I remember most of the names of the libraries you mentioned. I will definetely look into them. Thanks again The Naked Ninja. :)
In response to The Naked Ninja
I'm sorry, TNN, the find_target function is NOT unnecessary. If one player moves out of the monster's range, it will search for other players already in the range. If it loses the target, and another player is standing right next to it, the monster will not chase the player until the other player moves.

Second, for the entire function being terrible, I'd like to know what you are talking about.

The fact of the matter is, TNN, your method of doing this is more laggy than mine is. Second, your "fixed" version leaves a lot of functional bugs in the code.

Third, you didn't even read half the posts in this thread. You can't just waltz in here, and start changing code you don't understand.

If you didn't fully understand the snippet, you can't possibly be helping.
In response to DivineO'peanut
What about area edges? You could literally walk up to a monster, and attack it, if you were on the edge of one area, and it was on the edge of another.

My method really doesn't cause a lot of lag, it seems like it would, but when you look at how little that loop is doing, and consider the alternatives, it's not at all that bad.
In response to Ter13
You are nitpicking where it is not necessary. Obviously steps would be taken to avoid these sort of situations. For example: each area will have a "nearby" list which lists areas nearby that area, and when a client enters an area, every monster in that area and its nearby areas ping()s. Opposite when a client exits that area.

The concept is what's important here, not potent problems within the programming design of the concept.

My method really doesn't cause a lot of lag, it seems like it would, but when you look at how little that loop is doing, and consider the alternatives, it's not at all that bad.

That is true. Your method could probably handle 50 players at a time on a good server, but your method should also take a 100, or 200 players into consideration. When designing a system, you don't think about the average situation, but rather the high-end exceptional.
In response to DivineO'peanut
Well then, I guess what I will do now then is look at the libraries I was given, and see what I can engender from those sources. Then I will paste Ter13's code by itself into an environment (You said it worked by itself) and then search for a good way to get things started.
Page: 1 2