ID:140848
 
Code:
        govern
density=1
Click()
if(usr.attacka!=1)
usr<<"You are not in war mode to attack this unit"
return
usr<<"You target this units with your selected units"
for(var/mob/unit/B as mob in world)
if(B in usr.selected)
B.target=src
B.target()
verb
Train()
set src in view()
if(src.onwer!=usr)
usr<<"This is city is not yours!"
return
var/a=input("Train what?")in src.cantrain
if(a=="Worker")
usr<<"Building worker, it will take 10 seconds"
sleep(100)
var/mob/unit/Worker/S = new(src.loc)
S.onwer=usr
S.overlays+='aaa.dmi'+"[usr.red]"
else
return
mob/verb
War_Mode()
switch(alert("Do you want to change into war mode?",,"Activate","Desactivate"))
if("Activate")
usr.attacka=1
if("Desactivate")
usr.attacka=0
Auto_Counter()
switch(alert("Do you want to turn auto counter on?",,"Activate","Desactivate"))
if("Activate")
usr.aatk=1
if("Desactivate")
usr.aatk=0
turf
Click()
for(var/mob/unit/B as mob in world)
if(B in usr.selected)
walk_to(B,src)
B.untarget()
mob/unit/
Click()
if(src.s==1)
if(src.onwer!=usr)
if(usr.attacka==0)
usr<<"You are not in war mode to attack this unit"
return
usr<<"You target this units with your selected units"
for(var/mob/unit/B as mob in world)
if(B in usr.selected)
B.target=src
B.target()
return
usr<<"You unselected [src]"
usr.selected-=src
var/icon/I=new(icon='aaa.dmi'+"[usr.red]",icon_state="1")
src.overlays-=I
src.s=0
else
if(src.onwer!=usr)
if(usr.attacka==0)
usr<<"You are not in war mode to attack this unit"
return
usr<<"You target this units with your selected units"
for(var/mob/unit/B as mob in world)
if(B in usr.selected)
B.target=src
B.target()
return
usr<<"You selected [src]"
usr.selected+=src
var/icon/I=new(icon='aaa.dmi'+"[usr.red]",icon_state="1")
src.overlays+=I
src.s=1
proc
Attack()
sleep(src.atkspd)
if(src.atking==1)
return
src.atking=1
for(var/mob/M as mob in world)
if(M==src.onwer)
if(M.attacka==1)
if(src.ranged==0)
for(var/mob/unit/X as mob in get_step(src,src.dir))
if(X.onwer==M)
M<<"Cant attack own units!"
return
var/dmg=src.attack*M.atkm+M.atkb
for(var/mob/K as mob in world)
if(X.onwer==K)
if(K.inalliance==1)
if(K.alliance==M.alliance)
M<<"can't attack people from the same alliance as you!"
src.untarget()
return
if(X.ona==1)
if(X.onaa==M.alliance)
M<<"can't attack people from the same alliance as you!"
src.untarget()
return
var/defe=X.defence*K.defm+K.defb
var/result=dmg-defe
src.atking=0
src.target()
if(X.aatk==1||K.aatk==1)
X.target=src
X.target()
if(result<=1)
result=1
X.hp-=result
src.xp+=0.5
src.target()
if(X.hp<=0)
del(X)
src.xp+=10
src.untarget()
K<<"Unit lost!"
return
for(var/obj/center/govern/H as obj in get_step(src,src.dir))
if(H.onwer==M)
M<<"Cant attack own units!"
return
for(var/mob/D as mob in world)
if(H.onwer==D)
if(D.inalliance==1)
if(D.alliance==M.alliance)
M<<"Cant attack cities from your alliance"
src.untarget()
var/dmg=src.attack*M.atkm+M.atkb
var/defe=10
for(var/mob/unit/C as mob in H.contents)
defe += C.defence*0.5
var/l=dmg-defe
if(l<=0)
l=1
H.health-=l
src.atking=0
src.target()
if(H.health<=0)
H.health=H.mhealth
for(var/mob/unit/A in H.contents)
del(A)
H.overlays=null
src.xp+=70
world<<"[M.country] rised their flag in the city of [H] that belonged to [H.onwer]!"
H.onwer=M
H.icon='buildings.dmi'
H.icon_state="govern"
H.overlays+=M.flag2
M.dominated++
src.untarget()
M.cities++
for(var/mob/D as mob in world)
if(H.onwer==D)
D.cities--
D<<"You lost a city"
return


target()
for(var/mob/unit/B as mob in world)
for(var/atom/C in world)
if(C==B.target)
if(B in usr.selected)
walk_to(B,C)
var/icon/I=new(icon='aaa.dmi',icon_state="a")
B.overlays+=I
Attack()
untarget()
var/icon/I=new(icon='aaa.dmi',icon_state="a")
src.overlays-=I
src.target=null
src.atking=0


Problem description:
it says when i try to attack other units
Infinite loop suspected--switching proc to background.
If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0.
proc name: target (/mob/unit/proc/target)
usr: Karffebon (/mob)
src: Worker (/mob/unit/Worker)
call stack:
Worker (/mob/unit/Worker): target()
Worker (/mob/unit/Worker): Click(the grass (14,19,2) (/turf/grass), "default.map1", "icon-x=17;icon-y=20;left=1;scr...")

and the game gets pretty slow


when i try to attack cities

Infinite loop suspected--switching proc to background.
If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0.
proc name: target (/mob/unit/proc/target)
usr: Karffebon (/mob)
src: Worker (/mob/unit/Worker)
call stack:
Worker (/mob/unit/Worker): target()
Boltavia (/obj/center/govern): Click(the grass (12,15,2) (/turf/grass), "default.map1", "icon-x=14;icon-y=23;left=1;scr...")

Plz help me i really dont know what to do, i'm lost now i really dont know any other way to code this attack proc and it's still imcomplete cause i need to make a better alliance check because when people are logged out you'll be able to attack them even if they are in your alliance and i still need to code ranged attack. PLZ help me
This is because you are nesting loops you should not be nesting. Nowhere should you need a single for(blah blah blah in world) loop, anywhere in your code there. I can't even tell what half of them are meant to do.

If you have a variable, and you are looping through EVERY SINGLE OBJECT IN EXISTENCE to find the one that is equal to that variable... YOU SHOULD JUST BE USING THAT VARIABLE IN THE FIRST PLACE.