This is for my game Dynasty Warriors Online
- 3 teams (Wu, Shu, Wei)
- NPC's should Attack, and Chase After/follow after NPC's and People not on there team.
Problem In my Code right now:
NPC's Will not fight eachother
Code:
mob/Enemies/proc/Attack(mob/M)
flick("Attack",src)
if(M.Dynasty == src.Dynasty)
return
src.Preattacking(M)
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()
mob/Enemies/proc/Wander(walking_delay
if(walking_delay == null) 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))
if(M.Dynasty == src.Dynasty)
step_rand(src)
break
found = 1
step_towards(src,M)
for(var/mob/PC/Mo in oview(1))
if(M.Dynasty <> src.Dynasty)
src.Attack(M)
break
if(found == 0) //If found is still 0, or "else".
step_rand(src)
sleep(walking_delay)