ID:173887
 
How do I make npc's fight each other and pc's, but not fight npc's and pc's on there side?

Because i just relized that when i started making Dynasty Warriors Online. Could someone please help me out?
I have no clue about how about going to doing this.
In response to Nave
Well, stop bumping......
In response to Airjoe
I am not bumping, you just annoyed me, everyone has a bad comment, i just wanted soem help not someone telling me stuff like that.

Thanks,
Nave
How about making a team variable for each mob, and in the npc's attack, check the variable for what team the mob, who the npc is attacking, is on, and if the mob is on the same team as the npc, then just finish the proc, and if not, then attack.
In response to Lazyboy
Okay! Thanks, I didn't think of it that way! If I get errors I'll come back. Okay?

Thanks,
Nave
In response to Nave
Ok now I have most of it done, but I am confused, I don't know where to put the if blah blah do not attack


heres the code:

mob/Enemies/proc/Attack(mob/M)  //We need to set this as the default for Attack.

flick("Attack",src) //Flick the attack animation like this.
src.Preattacking(M) //This will do anything defined in the proc to M before everything else. This is most useful when lots of mobs are defined.
var/mindamage1 = src.Min_Attack
var/resist = M.Defense
var/resist2 = round(resist / 2)
var/mindamage2 = mindamage1 - resist2
var/maxdamage1 = src.Max_Attack
var/maxdamage2 = maxdamage1 - resist2
var/chance = src.DEX + M.AGI
var/chance2 = rand(1,chance)
var/damage = rand(mindamage2,maxdamage2)
if(get_dir(src,M) == SOUTHEAST) //And now, for a visual effect, the mob will actually jkump into the tile that his opponent is in and hit them.
pixel_y -= 14 //We do this by making the object LOOK as if it is in the other tile. But really, it is just the icon file's coordinates being modified. Here we make the icon go down 14 pixels.
pixel_x += 14 //Ditto for the x.
else //We will now check to see which direction the player is from the enemy again and again and set the icon to the right place.
if(get_dir(src,M) == SOUTHWEST)
pixel_y -= 14
pixel_x -= 14
else
if(get_dir(src,M) == NORTHEAST)
pixel_y += 14
pixel_x += 14
else
if(get_dir(src,M) == NORTHWEST)
pixel_y += 14
pixel_x -= 14
else
if(get_dir(src,M) == SOUTH)
pixel_y -= 14
else
if(get_dir(src,M) == NORTH)
pixel_y += 14
else
if(get_dir(src,M) == WEST)
pixel_x -= 14
else
pixel_x += 14
sleep(2) //This is set jsut right so it looks as if he also jumps back.
if(chance2 <= src.DEX)
if(damage <= 0)
damage = 1
view(usr) << "[src] hit [M] for \red[damage]\black points of damage."
M.HP -= damage
src.Postattacking(M)
else
view() << "[src] attacked [M], but missed."
src.Postattacking(M)
pixel_x = 0
pixel_y = 0 //Now, this is the same concept as above, but this time, we are reseting him back to his original position.

M.DeathCheck()
In response to Nave
They keep following me and it look like they are attacking still, here is my code:

mob/Enemies/proc/Attack(mob/M)  //We need to set this as the default for Attack.

flick("Attack",src) //Flick the attack animation like this.
if(Dynasty == src.Dynasty)
return
src.Preattacking(M) //This will do anything defined in the proc to M before everything else. This is most useful when lots of mobs are defined.
var/mindamage1 = src.Min_Attack
var/resist = M.Defense
var/resist2 = round(resist / 2)
var/mindamage2 = mindamage1 - resist2
var/maxdamage1 = src.Max_Attack
var/maxdamage2 = maxdamage1 - resist2
var/chance = src.DEX + M.AGI
var/chance2 = rand(1,chance)
var/damage = rand(mindamage2,maxdamage2)
if(get_dir(src,M) == SOUTHEAST) //And now, for a visual effect, the mob will actually jkump into the tile that his opponent is in and hit them.
pixel_y -= 14 //We do this by making the object LOOK as if it is in the other tile. But really, it is just the icon file's coordinates being modified. Here we make the icon go down 14 pixels.
pixel_x += 14 //Ditto for the x.
else //We will now check to see which direction the player is from the enemy again and again and set the icon to the right place.
if(get_dir(src,M) == SOUTHWEST)
pixel_y -= 14
pixel_x -= 14
else
if(get_dir(src,M) == NORTHEAST)
pixel_y += 14
pixel_x += 14
else
if(get_dir(src,M) == NORTHWEST)
pixel_y += 14
pixel_x -= 14
else
if(get_dir(src,M) == SOUTH)
pixel_y -= 14
else
if(get_dir(src,M) == NORTH)
pixel_y += 14
else
if(get_dir(src,M) == WEST)
pixel_x -= 14
else
pixel_x += 14
sleep(2) //This is set jsut right so it looks as if he also jumps back.
if(chance2 <= src.DEX)
if(damage <= 0)
damage = 1
view(usr) << "[src] hit [M] for \red[damage]\black points of damage."
M.HP -= damage
src.Postattacking(M)
else
view() << "[src] attacked [M], but missed."
src.Postattacking(M)
pixel_x = 0
pixel_y = 0 //Now, this is the same concept as above, but this time, we are reseting him back to his original position.

M.DeathCheck()
In response to Nave
I think maybe the problam lies in this peice of code?

mob/Enemies/proc/Wander(walking_delay)  //We need to define this before hand as a default for Wander.  In this, we made our own argument again.
if(walking_delay == null) //If you don't put anything in there when you call it, it will automaticly go to 5. This makes it so you don't need to type 5 every single time you define it again.
walking_delay = 5
if(walking_delay == 0)
walking_delay = 1 //0 walking delay is far too laggy, lets make it 1 if you accidently put 0.
while(src) //This means "While I am still in the world."
var/found = 0 //This we will use as sort of an "else" statement for the for proc.
for(var/mob/PC/M in oview(5))
found = 1
step_towards(src,M)
for(var/mob/PC/Mo in oview(1))
src.Attack(Mo)
break
break
if(found == 0) //If found is still 0, or "else".
step_rand(src)
sleep(walking_delay)
In response to Nave
Nave wrote:
mob/Enemies/proc/Attack(mob/M)
flick("Attack",src) //Flick the attack animation like this.
if(Dynasty == src.Dynasty)
return
With this, im assuming that M is the person that the mob is attacking, so shouldnt it be M.Dynasty == src.Dynasty. Also, the if statement should be the first thing that is checked, instead of flicking an attack icon.
mob/Enemies/proc/Attack(mob/M)
if(M.Dynasty == src.Dynasty)
return
else
//attack here
In response to Nave
Nave wrote:
I think maybe the problam lies in this peice of code?
> mob/Enemies/proc/Wander(walking_delay)  //We need to define this before hand as a default for Wander.  In this, we made our own argument again.
> if(walking_delay == null) //If you don't put anything in there when you call it, it will automaticly go to 5. This makes it so you don't need to type 5 every single time you define it again.
> walking_delay = 5
> if(walking_delay == 0)
> walking_delay = 1 //0 walking delay is far too laggy, lets make it 1 if you accidently put 0.
> while(src) //This means "While I am still in the world."
> var/found = 0 //This we will use as sort of an "else" statement for the for proc.
> for(var/mob/PC/M in oview(5))

Right here is when you want to do a dynasty check, so if M is on its team, then return, else, continue with the rest of the walking proc.

> found = 1
> step_towards(src,M)
> for(var/mob/PC/Mo in oview(1))
> src.Attack(Mo)
> break
> break
> if(found == 0) //If found is still 0, or "else".
> step_rand(src)
> sleep(walking_delay)
>
>
>


<edit>

My mistake. What needs to be done i think is to incorporate whats below if(found == 0) into what i wrote above. Hence
        for(var/mob/PC/M in oview(5))
if(M.Dynasty == src.Dynasty)
step_rand(src)
break
else
//other found = 1 stuff here

Hopefully this helps you more. If anyone else can elaborate on this, feel free to do so. Im sorry if this dont work, as i havent had a chance to try it.
In response to Lazyboy
Thanks alot.....im working on the rest if i run into trouble ill post
In response to Nave
I dont know how to make the npc's fight each other and the humans from different dynasty's now.
In response to Nave
I dont know what the problem is but its probably simple?



Is M = Mob by default?
In response to Nave
Ive been looking around and i cant seem to find what M means.........i just used it, seeing it from other peoples code
In response to Nave
hey yo, im an iconer guy, pretty good, liek my art or not, we still need help, BUMB
In response to Nave
Ive been looking around and i cant seem to find what M means.........i just used it, seeing it from other peoples code

That sums up your whole problem right there... you're copying things without knowing what they are. Let me tell you what M means. Pay attention because this is actually a good lesson in programming. :P

M means nothing. M means everything. M means whatever you tell the computer it means.

M is, in short, a variable. What does variable mean? It means something "varies", which means, "It can mean anything."

You ever take an algebra class? They want you to figure out what X means, but as soon as you figure out that X = 7, they give you a different problem and it turns out that X = pi squared times the cosine of eleventeen! What gives?

What gives is that variables like X and M don't actually mean anything. There is no M until you put something in your code saying that there is an M, and even then, that M doesn't mean anything until you tell the computer what it does mean. It doesn't even have to be M. It could be X. It could be Yellow. It could be Steve. The computer doesn't know the difference. The label (M, X, Steve, whatever) is purely for human eyes, so we can tell the difference between two variables.

Why is this important? The computer's not a mind reader. You want to make a proc that has someone attack someone or get something, you need to tell it, in no uncertain terms, exactly what is being attacked or gotten, and we won't understand the terms the computer uses to track these things and it sure as hell doesn't understand us. So you make a label, M. You tell the computer that M is a mob, by actually calling it (the first time you mention M in a bit of code) mob/M, so when you refer to M.HP, it doesn't go "Wait a minute! objs don't have HP! How do I know this isn't an obj!"

Then you do something to point the computer to exactly what mob this label you call "M" refers to. For instance,

for (var/mob/M in oview(src))
M.hp += green

This tells the computer, "First, find me all the mobs that src can see, one at a time. We'll call them M for convenience. Add green to their hp."

The key to all this is that the computer doesn't know what M is, it doesn't know what hp is, it doesn't know what green is, and it barely has a clue what mob is to begin with... in the whole equation, only you know what any of those things mean and the computer takes your word for it.

If you're just kinda bluffing (M? I know M! M's a good friend of mine!), then the computer, the poor trusting fool that it is, will take your word at face value and blithely generate all kinds of errors.
In response to Nave
Nave wrote:
Ive been looking around and i cant seem to find what M means.........i just used it, seeing it from other peoples code

M doesnt mean any thing, the people you have seen defigned M

Example

mob/proc/Somthing(mob/M)
In response to Wanabe
OOOOOOH I GET IT.....thanks alot, i thought M was like src, or usr. Well anyways can anyone help me out? The npc's wont attack each other.
In response to Nave
should i keep it as M?
Page: 1 2