ID:901590
 
(See the best response by Dipstyx.)
Code:
ttack()
if(src.Fight == 1)
var/obj/O
var/obj/N
var/obj/A
var/obj/B
var/obj/C
if(src.delayattack==1)
return
if(src.WeaponType == "Club")
O = new/obj/Attacking/Club(get_step(usr,usr.dir))
if(src.WeaponType == "Battle_Axe")
O = new/obj/Attacking/Battle_Axe(get_step(usr,usr.dir))
if(src.WeaponType == "Broad_Sword")
O = new/obj/Attacking/Broad_Sword(get_step(usr,usr.dir))
if(src.WeaponType == "Chain Sickle")
O = new/obj/Attacking/Chain_Sickle(get_step(usr,usr.dir))
N = new/obj/Attacking/Chain_Sickle(get_step(O,usr.dir))
A = new/obj/Attacking/Chain_Sickle(get_step(N,usr.dir))
B = new/obj/Attacking/Chain_Sickle(get_step(A,usr.dir))
C = new/obj/Attacking/Chain_Sickle2(get_step(B,usr.dir))

if(src.WeaponType == "Pilgrim")
O = new/obj/Attacking/Pilgrim(get_step(usr,usr.dir))
if(src.WeaponType == "Wizard")
O = new/obj/Attacking/Wizard(get_step(usr,usr.dir))
if(src.WeaponType == "Soldier")
O = new/obj/Attacking/Soldier(get_step(usr,usr.dir))
if(src.WeaponType == "Nunchaku")
O = new/obj/Attacking/Nunchaku(get_step(usr,usr.dir))
if(src.WeaponType == "Dagger")
O = new/obj/Attacking/Dagger(get_step(usr,usr.dir))
if(src.WeaponType == "SledgeHammer")
O = new/obj/Attacking/SledgeHammer(get_step(usr,usr.dir))
O.dir=usr.dir
if(N!=null)
N.dir=usr.dir
if(A!=null)
A.dir=usr.dir
if(B!=null)
B.dir=usr.dir
if(C!=null)
C.dir=usr.dir
view() << 'sounds/hit.wav'

for(var/mob/M in get_step(src,src.dir))
if(M.HP>0)
var/misschance=pick(prob((src.Agility/100)+(src.Focusing),src),prob((M.Agility/100),M))
if(misschance==M)
if(M.client)
if(!src.FriendlyFire)
if(M.Guild==src.Guild)
src.delayattack=1
src.Lock=1
sleep(4)
//del(O)
src.Lock=0
src.delayattack=0
del(O)
return
s_damage(M, 0, "blue")
src.delayattack=1
src.Lock=1
sleep(40)
del(O)
del(N)
del(A)
del(B)
del(C)
src.Lock=0
src.delayattack=0
if(!M.client)
M.Aggroing=src
del(O)
del(N)
del(A)
del(B)
del(C)
return
else
if(M.client)
M.icon_state = "hit"
sleep(10)
M.icon_state = "world"
if(!src.FriendlyFire)
if(M.Guild==src.Guild)
src.delayattack=1
src.Lock=1
sleep(4)
del(O)
src.Lock=0
src.delayattack=0
del(O)
return
Damage = (usr.Strength-M.Vitality+src.Boosting)
if(Damage <= 0)
Damage = 1
if(prob(usr.Luck))
Damage=((usr.Strength*2)-M.Vitality+src.Boosting)
if(Damage <= 0)
Damage = 1
M.HP-=(Damage)
s_damage(M, -1, "blue")
else
M.HP-=(Damage)
s_damage(M, Damage, "blue")
src.delayattack=1
src.Lock=1
sleep(4)
del(O)
del(N)
del(A)
del(B)
del(C)
src.Lock=0
src.delayattack=0
if(src.Boosting)
src.Boosting=0
var/icon/I=new(src.icon)
I.SwapColor(rgb(204,0,0),rgb(240,208,176))
src.icon=I
M.deathcheck()
if(!M.client)
M.Aggroing=src
usr.Level_Up()
del(O)
del(N)
del(A)
del(B)
del(C)
return
if(N!=null)
for(var/mob/M in get_step(O,src.dir))
if(M.HP>0)
var/misschance=pick(prob((src.Agility/100)+(src.Focusing),src),prob((M.Agility/100),M))
if(misschance==M)
if(M.client)
if(!src.FriendlyFire)
if(M.Guild==src.Guild)
src.delayattack=1
src.Lock=1
sleep(4)
del(O)
del(N)
del(A)
del(B)
del(C)
src.Lock=0
src.delayattack=0
del(O)
del(N)
del(A)
del(B)
del(C)
return
s_damage(M, 0, "blue")
src.delayattack=1
src.Lock=1
sleep(4)
del(O)
del(N)
del(A)
del(B)
del(C)
src.Lock=0
src.delayattack=0
if(!M.client)
M.Aggroing=src
del(N)
del(O)
del(N)
del(A)
del(B)
del(C)
return
else
if(M.client)
M.icon_state = "hit"
sleep(10)
M.icon_state = "world"
if(!src.FriendlyFire)
if(M.Guild==src.Guild)
src.delayattack=1
src.Lock=1
sleep(40)
del(N)
src.Lock=0
src.delayattack=0
del(N)
return
Damage = (usr.Strength-M.Vitality+src.Boosting)
if(Damage <= 0)
Damage = 1
if(prob(usr.Luck))
Damage=((usr.Strength*2)-M.Vitality+src.Boosting)
if(Damage <= 0)
Damage = 1
M.HP-=(Damage)
s_damage(M, -1, "blue")
else
M.HP-=(Damage)
s_damage(M, Damage, "blue")
src.delayattack=1
src.Lock=1
sleep(4)
del(N)
src.Lock=0
src.delayattack=0
if(src.Boosting)
src.Boosting=0
var/icon/I=new(src.icon)
I.SwapColor(rgb(204,0,0),rgb(240,208,176))
src.icon=I
M.deathcheck()
if(!M.client)
M.Aggroing=src
usr.Level_Up()
del(N)
return
if(A!=null)
for(var/mob/M in get_step(N,src.dir))
if(M.HP>0)
var/misschance=pick(prob((src.Agility/100)+(src.Focusing),src),prob((M.Agility/100),M))
if(misschance==M)
if(M.client)
if(!src.FriendlyFire)
if(M.Guild==src.Guild)
src.delayattack=1
src.Lock=1
sleep(40)
del(A)
src.Lock=0
src.delayattack=0
del(A)
return
s_damage(M, 0, "blue")
src.delayattack=1
src.Lock=1
sleep(40)
del(A)
src.Lock=0
src.delayattack=0
if(!M.client)
M.Aggroing=src
del(A)
return
else
if(M.client)
M.icon_state = "hit"
sleep(10)
M.icon_state = "world"
if(!src.FriendlyFire)
if(M.Guild==src.Guild)
src.delayattack=1
src.Lock=1
sleep(4)
del(A)
src.Lock=0
src.delayattack=0
del(A)
return
Damage = (usr.Strength-M.Vitality+src.Boosting)
if(Damage <= 0)
Damage = 1
if(prob(usr.Luck))
Damage=((usr.Strength*2)-M.Vitality+src.Boosting)
if(Damage <= 0)
Damage = 1
M.HP-=(Damage)
s_damage(M, -1, "blue")
else
M.HP-=(Damage)
s_damage(M, Damage, "blue")
src.delayattack=1
src.Lock=1
sleep(4)
del(A)
src.Lock=0
src.delayattack=0
if(src.Boosting)
src.Boosting=0
var/icon/I=new(src.icon)
I.SwapColor(rgb(204,0,0),rgb(240,208,176))
src.icon=I
M.deathcheck()
if(!M.client)
M.Aggroing=src
usr.Level_Up()
del(A)
return
if(B!=null)
for(var/mob/M in get_step(A,src.dir))
if(M.HP>0)
var/misschance=pick(prob((src.Agility/100)+(src.Focusing),src),prob((M.Agility/100),M))
if(misschance==M)
if(M.client)
if(!src.FriendlyFire)
if(M.Guild==src.Guild)
src.delayattack=1
src.Lock=1
sleep(4)
del(B)
src.Lock=0
src.delayattack=0
del(B)
return
s_damage(M, 0, "blue")
src.delayattack=1
src.Lock=1
sleep(4)
del(B)
src.Lock=0
src.delayattack=0
if(!M.client)
M.Aggroing=src
del(B)
return
else
if(M.client)
M.icon_state = "hit"
sleep(10)
M.icon_state = "world"
if(!src.FriendlyFire)
if(M.Guild==src.Guild)
src.delayattack=1
src.Lock=1
sleep(4)
del(B)
src.Lock=0
src.delayattack=0
del(B)
return
Damage = (usr.Strength-M.Vitality+src.Boosting)
if(Damage <= 0)
Damage = 1
if(prob(usr.Luck))
Damage=((usr.Strength*2)-M.Vitality+src.Boosting)
if(Damage <= 0)
Damage = 1
M.HP-=(Damage)
s_damage(M, -1, "blue")
else
M.HP-=(Damage)
s_damage(M, Damage, "blue")
src.delayattack=1
src.Lock=1
sleep(4)
del(B)
src.Lock=0
src.delayattack=0
if(src.Boosting)
src.Boosting=0
var/icon/I=new(src.icon)
I.SwapColor(rgb(204,0,0),rgb(240,208,176))
src.icon=I
M.deathcheck()
if(!M.client)
M.Aggroing=src
usr.Level_Up()
del(B)
return
if(C!=null)
for(var/mob/M in get_step(B,src.dir))
if(M.HP>0)
var/misschance=pick(prob((src.Agility/100)+(src.Focusing),src),prob((M.Agility/100),M))
if(misschance==M)
if(M.client)
if(!src.FriendlyFire)
if(M.Guild==src.Guild)
src.delayattack=1
src.Lock=1
sleep(4)
del(C)
src.Lock=0
src.delayattack=0
del(C)
return
s_damage(M, 0, "blue")
src.delayattack=1
src.Lock=1
sleep(4)
del(C)
src.Lock=0
src.delayattack=0
if(!M.client)
M.Aggroing=src
del(C)
return
else
if(M.client)
M.icon_state = "hit"
sleep(10)
M.icon_state = "world"
if(!src.FriendlyFire)
if(M.Guild==src.Guild)
src.delayattack=1
src.Lock=1
sleep(4)
del(C)
src.Lock=0
src.delayattack=0
del(C)
return
Damage = (usr.Strength-M.Vitality+src.Boosting)
if(Damage <= 0)
Damage = 1
if(prob(usr.Luck))
Damage=((usr.Strength*2)-M.Vitality+src.Boosting)
if(Damage <= 0)
Damage = 1
M.HP-=(Damage)
s_damage(M, -1, "blue")
else
M.HP-=(Damage)
s_damage(M, Damage, "blue")
src.delayattack=1
src.Lock=1
sleep(4)
del(C)
src.Lock=0
src.delayattack=0
if(src.Boosting)
src.Boosting=0
var/icon/I=new(src.icon)
I.SwapColor(rgb(204,0,0),rgb(240,208,176))
src.icon=I
M.deathcheck()
if(!M.client)
M.Aggroing=src
usr.Level_Up()
del(C)
return

del(O)
del(N)
del(A)
del(B)
del(C)
return


Problem description: the weapons stays on the map and will not delete

I'm not even sure how this snippet compiles. You're repeating so many things and using bad syntax. Did you happen to make this yourself or did you find this in some terrible source code? If it's the latter I'd suggest not using it at all. If it's the former I suggest you take a step back and have a look at these.
i tryed to add the del() to find where i can Put it but it will not del the Obj that is the weapon.
is there a better way to do this code then copy paste for every obj the weapon has?

IM trying to make weapons like Dragon Warrior Mythology had. so i was trying to remake the weapons code.
Best response
Whoa whoa! Procedures are made for a reason--so you can split stuff like this up into smaller, more manageable procedures! You can start with the procedure which handles weapons on the map.

And a tip: rather than continuously creating and deleting objects for every attack, you may consider having the player store the objects in memory and mess around with the location of the object, i.e. setting the location to get_step() whatever for attacking and to null for making the weapon disappear.
ok im am going to wipe the code and redo it. i will look in to storing the objects in memory.

Would you have a example for how to do that?