ID:1651225
 
(See the best response by GhostAnime.)
Code:
mob
var
adelay=55
onadelay=0

mob
verb
A()
if(src.onadelay)
return
else
flick("Attack1",src)
for(var/mob/M in get_step(src,src.dir))
var/damage=(usr.Strength*2)
view(M)<<"[M] has been hit for [damage]!"
M.TakeDamage(damage,src)
src.onadelay=1
sleep(src.adelay)
src.onadelay=0


Problem description:

Well, like I said in previous topics, my coding skill isn't the greatest. I'm trying to set a thing that monitors punching speed, but I'm not sure exactly how to do it.

Passive Name: Melee Speed
Passive Description: Melee Speed determines the delay between your punches
Passive Values: 0/10
How to Train: By punching
Stat Reqs: 5 Agi
Class: Parent
Notes: Those below 15 Agility will not be able to exceed 6/10. Melee Delay decreases by 5 per point(reducing speed from 55 to 5 at 10). At 10/10, delay is almost unnoticable

This is a description of the passive that dictates melee speed. What could I set in the melee code(more specifically, in the sleep proc I have in there) that reduces melee's delay based on the melee speed(src.MeleeSpeed) passive?

Best response
Apophis0 wrote:
Notes: Those below 15 Agility will not be able to exceed 6/10.

The format X?Y:Z can be thought as a compact-if() statement, which translates to if(X){return Y}else{return Z}
min( src.Agi, ((src.Agi < 15)?6:10),  ....

Here, if Agi is < 15, min() will return 6 at most. If Agi >= 15, up to 10 is possible.

Really, this needs to be fixed. As it is currently, only if Agi < 6 will the value be lower. Between 6-14, the agi will be 6 (as 6 will be picked via min()). >= 15 will be 10 due to min()

Melee Delay decreases by 5 per point(reducing speed from 55 to 5 at 10). At 10/10, delay is almost unnoticable
MeleeDelay - (5 * Agi_Statement_above)


This is a description of the passive that dictates melee speed. What could I set in the melee code(more specifically, in the sleep proc I have in there) that reduces melee's delay based on the melee speed(src.MeleeSpeed) passive?


An example of all of the above together:
sleep(\
max(5, \ // Lowest possible wait time = 5 ticks
MeleeDelay \
- (5 * min( src.Agi, ((src.Agi < 15)?6:10)) \
- src.MeleeSpeed \
)


Mind you, this is just an example. You just have to break everything down, translate it and piece it together (like transcription/translation of DNA)
Let me explain a bit more. You set your build between 4 stats. Strength, Agility, Endurance and Magical Power. If your base Agility is under 15, you'll never be able to raise the passive above 6, but that's not the problem. That's a simple thing to code.

The issue is, I need to know how to set the attack delay based on the MeleeSpeed passive, not agility.
It would be efficient to have a procedure calculate it then:
mob/proc/MeleeDelay(Time = 10, ReduceFactor = 1, MinTime = 1)
return max(MinTime, round(Time - src.MeleeSpeed/ReduceFactor))

...
sleep(src.MeleeDelay(50, 2, 5))
This example has the delay set to, at most, 5 seconds. Every 2 MeleeSpeed points reduces 0.1 seconds. The lowest possible sleep() time is set to 5 ticks (0.5 seconds which is attained when you have a MeleeSpeed of >= 90)

(50-5) = 45 [Level/2] * 2 [Factor] = 90 Level