ID:1600499
 
Keywords: a, implement, macros, to, trying
Code:
mob
icon = 'mob.dmi'


Login()

..()
winset(client, "q", "parent=macro;name=q;command=keydown+q")
winset(client, "q+up", "parent=macro;name=q+up;command=keyup+q")

proc/attack()//a closed range attack
for(var/mob/m in oview(1))
if(usr.Tgt==m)
(usr.health)--
FaceTowards(m)
if(usr.health > 0)
usr<<"You Attacked [m]"
else
usr<<"[m] Died"

verb/keydown(k as text)
set hidden = 1
set instant = 1
if(k == "q") q = 1

verb/keyup(k as text)
set hidden = 1
set instant = 1
if(k == "q") q = 0


Problem description:

So im working on the macros of my game and im trying to implement the macro "q" into the proc attack(), but i cannot find a way to do it, any help?, im new at this

Rigth now i just want make this work when the things get more complicated i will start using this kind of libs
that library just make it so you dont need to call each macro, i get that, but i dont need it, i just want to use the macro i code and use it into a proc

but it helped to make my code work(kinda) i just need to figure how to repeat the macro while the key is pressed down

here is the code
mob
icon = 'mob.dmi'


Login()

..()
winset(client, "q", "parent=macro;name=q;command=keydown+q")
winset(client, "q+up", "parent=macro;name=q+up;command=keyup+q")

proc/attack()//a closed range attack
for(var/mob/m in oview(1))
if(usr.Tgt==m)
(usr.health)--
FaceTowards(m)
if(usr.health > 0)
usr<<"You Attacked [m]"
else
usr<<"[m] Died"

verb/keydown(k as text)
set hidden = 1
set instant = 1
if(k == "q") q = 1
if(q == 1) attack()//this is what i change

verb/keyup(k as text)
set hidden = 1
set instant = 1
if(k == "q") q = 0
Turn:
if(q == 1) attack()
Into a loop so long as q is true, run the loop with whatever other precautions inside it.
In response to Legacy of Caine
thanks i fix it, here is the code if someone is interested

mob
icon = 'mob.dmi'


Login()

..()
winset(client, "q", "parent=macro;name=q;command=keydown+q")
winset(client, "q+up", "parent=macro;name=q+up;command=keyup+q")

proc/attack()//a closed range attack
for(var/mob/m in oview(1))
if(usr.Tgt==m)
(usr.health)--
FaceTowards(m)
if(usr.health > 0)
usr<<"You Attacked [m]"
else
usr<<"[m] Died"
if(q == 1)//so long as q is true
spawn(world.tick_lag) attack()//run the loop

verb/keydown(k as text)
set hidden = 1
set instant = 1
if(k == "q") q = 1
if(q == 1) attack()//to activate the proc pressing "q"

verb/keyup(k as text)
set hidden = 1
set instant = 1
if(k == "q") q = 0
You are making the check twice.
    if(q == 1)//so long as q is true
spawn(world.tick_lag) attack()//run the loop


This is redundant as you are already calling it here
        if(k == "q") q = 1
if(q == 1) attack()//to activate the proc pressing "q"


I suggest you revise your code
In response to FishMan123
the reason i did that is because, i wanted to stop the loop when the key "q" were not pressed down(if you remove " if (q == 1)" from the proc it just keeps looping), its cheap and redundant, but it works, but i ended up changing the code so you need to spam "q" in order to attack, using spawn(7) so it waits 7 ticks before it lets you attack again
in other words...
    proc/attack()
if(usr.Attacking == 0)//if not attacking
for(var/mob/m in oview(1))
if(usr.Tgt==m)
FaceTowards(m)
var/damage = 10
m.health -= damage
usr <<"You Attacked [m]"
usr.Attacking = 1// attacking
spawn(7)//waits 7 ticks
usr.Attacking = 0 //back to no attacking state


the reason i made this change its because of some advance combat im planing, looping while the key is pressed down just breaks some of it
Instead of
FaceTowards(m)


Why not just use
get_dir
In response to Wissam
it's because i was trying to face my target automatically, and i could not get it to work using get_dir (well i tried for days and i didnt find a way :p)but there shoul be a way.

i just use a proc for that
basically

proc/Facetherightshit(atom/A, atom/B)
var/dx = B.x - A.x
var/dy = B.y - A.y
return arctan2(dy, dx)

/*here should defined the angle gotten from
Facetherightshit proc and then use it to
turn in any of the 8 directions For example:
proc/Face_angle
if(-180 to -157.5, 157.5 to 180)
return WEST*/


atom
proc
FaceTowards(atom/A)
dir = Face_angle(Facetherightshit(src, A))

turn to be tedious but gets the job done
usr.dir=get_dir(usr,m)


If you were using more than 8 directions you'd be better off defining your own angular system, but with the 8 directions I've never had a problem with the build in procedure unless I'm missing something here?
In response to Legacy of Caine
welp, thats it, i will ask first before doing something tedious *starts crying in a corner of the room*
Don't be silly, I bet you learnt one or two things writing your own version. There's no need to reinvent the wheel, but if you don't reinvent it how can you make a better one?
xD, thanks to you all now i have the basics of my game now i can start working on the map/animations