//Attack Code
Attack(mob/player/P,mob/monsters/M,list/monstergroup)
var/mob/monsters/enemy = Targetting(P,M,monstergroup)
var/damage = (P.tempstr * P.tempdex + rand(-10,10)) - (enemy.tempstr * enemy.tempdex + rand(-10,10))
var/chancehit = (P.tempagl * (rand(7,14)/10) + rand(-100,100)) - (enemy.tempagl * (rand(7,14)/10) + rand(-100,100))
var/chancehit2 = rand(0,2)
var/critical = (P.tempstr * P.tempagl * P.tempdex + rand(0,50)) - (enemy.tempstr * enemy.tempagl * enemy.tempdex + rand(0,50))
var/realchance = rand(1,20)
if(M.defending)
damage /= 2
critical /= 2
damage = round(damage)
critical = round(critical)
if(realchance == 5 || realchance == 15)
if(critical >= 1)
var/criticalchance = (P.tempagl * (rand(10,20)/10) + rand(-50,50)) - (enemy.tempagl * (rand(10,20)/10) + rand(-50,50))
if(criticalchance >= 1)
DamageAddInfo(P,"You attack [enemy]!","Critical! ","[critical] damage!",'attack.wav','hit.wav',"Critical!")
enemy.hp -= critical
sleep(12)
if(enemy.hp <= 0)
P.Deathcheck(P,M,monstergroup)
else
DamageAddInfo(P,"You attack [enemy]!","Critical! ","Miss!",'attack.wav','dodge.wav',"Critical!")
sleep(12)
else
DamageAddInfo(P,"You attack [enemy]!","Critical! ","Miss!",'attack.wav','dodge.wav',"Critical!")
sleep(12)
else if(chancehit <= 0)
if(chancehit2 == 1)
DamageAddInfo(P,"You attack [enemy]!","1 damage!",'attack.wav','hit.wav')
enemy.hp --
sleep(12)
if(enemy.hp <= 0)
P.Deathcheck(P,M,monstergroup)
else
DamageAddInfo(P,"You attack [enemy]!","Miss!",'attack.wav','dodge.wav')
sleep(12)
else
if(damage >= 1)
DamageAddInfo(P,"You attack [enemy]!","[damage] damage!",'attack.wav','hit.wav')
enemy.hp -= damage
sleep(12)
if(enemy.hp <= 0)
P.Deathcheck(P,M,monstergroup)
else
if(chancehit2 == 1)
DamageAddInfo(P,"You attack [enemy]!","1 damage!",'attack.wav','hit.wav')
enemy.hp --
sleep(12)
if(enemy.hp <= 0)
P.Deathcheck(P,M,monstergroup)
else
DamageAddInfo(P,"You attack [enemy]!","No effect!",'attack.wav','dodge.wav')
sleep(12)
//DamageAddInfo Stuff
DamageAddInfo(mob/player/P,string1,string2,wav1,wav2,critstring)
for(var/obj/O in P.battlelist)
del(O)
var/color
if(round(P.hp/P.mhp*100) < 16)
color = "red"
else if(round(P.hp/P.mhp*100) < 36)
color = "green"
else
color = "white"
var/client/C = P.client
var/x = 1; var/px = 17; var/y = 15
for(var/leng = 1; leng <= length(string1); leng++)
var/obj/letter/let = new /obj/letter
let.icon = 'font.dmi'
let.icon_state = "[color][copytext(string1,leng,leng+1)]"
let.layer = MOB_LAYER + 2
let.screen_loc = "[x]:[px],[y]"
px += 17
P.battlelist += let
if(px > 32)
x++
px -= 32
C.screen += let
if(wav1)P << wav1
sleep(10)
var/reset = 0
if(critstring)
x = 1; px = 17; y = 14
for(var/leng = 1; leng <= length(critstring); leng++)
var/obj/letter/let = new /obj/letter
let.icon = 'font.dmi'
let.icon_state = "[color][copytext(critstring,leng,leng+1)]"
let.layer = MOB_LAYER + 2
let.screen_loc = "[x]:[px],[y]:9"
px += 17
P.battlelist += let
if(px > 32)
x++
px -= 32
C.screen += let
P << 'criticalhit.wav'
sleep(5)
reset = 1
if(reset == 0)
x = 1; px = 17; y = 14
for(var/leng = 1; leng <= length(string2); leng++)
var/obj/letter/let = new /obj/letter
let.icon = 'font.dmi'
let.icon_state = "[color][copytext(string2,leng,leng+1)]"
let.layer = MOB_LAYER + 2
let.screen_loc = "[x]:[px],[y]:9"
px += 17
P.battlelist += let
if(px > 32)
x++
px -= 32
C.screen += let
if(wav2)P << wav2
Problem description:
When in the Battle System that I have created, when I attack, once in a while, and completely randomly as far as I can tell, the game will temporarly freeze, extend the screen size horozontally, and post the 2nd line of text in the text panel.
Example:
Screen Text:
Line 1: "You attack the Weak Slime-A!"
Line 2: "" *FREEZE HERE, TEXT NEVER APPEARS!*
Text Panel on Right of DS:
"Miss!" *Appears AFTER freeze*
I don't understand what possibly could be wrong. I've gone over the code numerous times. It also happens when I actually do damage as well, so it isnt at the Miss only parts, so I cannot understand the problem. I know that when you add more stuff to the client.size than it can normally hold, it increases the screen size, so I understand why that happens, but theres no actual text appearing...
Sequence:
Line 1 Appears
Small Freeze
Screen Size Increases
Large Freeze
Text Appears in Text Panel
Small Freeze again
Continuation of Battle Sequence.
Thanks to anyone that can help with this problem.
Ploaris, I suggest you replace [enemy] with [enemy.name] if you want 'the' to be gone >_>
If you want a % chance of happening, rather than doing rand() to pick certain values, you can use prob().. eg: rand(1,10); if that == 1 or 3 can be written as prob(20), which means 20% chance of happening..
You should really make a generalized procedure which takes away health, that way you don't need to keep checking if health < 0 [or program it in the deathcheck to make sure nothing happens if health<0], just a lil' advice.
And try .OGG rather than .WAV, it'll help reduce the resource size A LOT... and condensing the system with little tricks such as the compact if [eg:
if(apple)
"pie"
else
"NOO"
Can be written as
apple?"pie" : "NOO"]
Anyways:
From what I can gather, it COULD be caused from the creation of the object (such as there's too much info going on at first to go through thus it freezes) or from the sleep() statements but I'd go with the former unless someone proves me wrong (which should be easy).
- GhostAnime